You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2013/12/05 11:22:26 UTC
svn commit: r1548079 -
/manifoldcf/branches/CONNECTORS-781/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/ConnectorFactory.java
Author: kwright
Date: Thu Dec 5 10:22:26 2013
New Revision: 1548079
URL: http://svn.apache.org/r1548079
Log:
Clean up ConnectorFactory
Modified:
manifoldcf/branches/CONNECTORS-781/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/ConnectorFactory.java
Modified: manifoldcf/branches/CONNECTORS-781/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/ConnectorFactory.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-781/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/ConnectorFactory.java?rev=1548079&r1=1548078&r2=1548079&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-781/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/ConnectorFactory.java (original)
+++ manifoldcf/branches/CONNECTORS-781/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/ConnectorFactory.java Thu Dec 5 10:22:26 2013
@@ -34,6 +34,11 @@ public abstract class ConnectorFactory<T
{
}
+ /** Override this method to hook into a connector manager.
+ */
+ protected abstract boolean isInstalled(IThreadContext tc, String className)
+ throws ManifoldCFException;
+
/** Install connector.
*@param className is the class name.
*/
@@ -110,80 +115,12 @@ public abstract class ConnectorFactory<T
protected T getThisConnectorNoCheck(String className)
throws ManifoldCFException
{
- try
- {
- Class theClass = ManifoldCF.findClass(className);
- Class[] argumentClasses = new Class[0];
- // Look for a constructor
- Constructor c = theClass.getConstructor(argumentClasses);
- Object[] arguments = new Object[0];
- Object o = c.newInstance(arguments);
- try
- {
- return (T)o;
- }
- catch (ClassCastException e)
- {
- throw new ManifoldCFException("Class '"+className+"' does not implement IConnector.");
- }
- }
- catch (InvocationTargetException e)
- {
- Throwable z = e.getTargetException();
- if (z instanceof Error)
- throw (Error)z;
- else if (z instanceof RuntimeException)
- throw (RuntimeException)z;
- else if (z instanceof ManifoldCFException)
- throw (ManifoldCFException)z;
- else
- throw new RuntimeException("Unknown exception type: "+z.getClass().getName()+": "+z.getMessage(),z);
- }
- catch (ClassNotFoundException e)
- {
- throw new ManifoldCFException("No connector class '"+className+"' was found.",
- e);
- }
- catch (NoSuchMethodException e)
- {
- throw new ManifoldCFException("No appropriate constructor for IConnector implementation '"+
- className+"'. Need xxx().",
- e);
- }
- catch (SecurityException e)
- {
- throw new ManifoldCFException("Protected constructor for IConnector implementation '"+className+"'",
- e);
- }
- catch (IllegalAccessException e)
- {
- throw new ManifoldCFException("Unavailable constructor for IConnector implementation '"+className+"'",
- e);
- }
- catch (IllegalArgumentException e)
- {
- throw new ManifoldCFException("Shouldn't happen!!!",e);
- }
- catch (InstantiationException e)
- {
- throw new ManifoldCFException("InstantiationException for IConnector implementation '"+className+"'",
- e);
- }
- catch (ExceptionInInitializerError e)
- {
- throw new ManifoldCFException("ExceptionInInitializerError for IConnector implementation '"+className+"'",
- e);
- }
-
+ T rval = getThisConnectorRaw(className);
+ if (rval == null)
+ throw new ManifoldCFException("No connector class '"+className+"' was found.");
+ return rval;
}
- // Protected methods
-
- /** Override this method to hook into a connector manager.
- */
- protected abstract boolean isInstalled(IThreadContext tc, String className)
- throws ManifoldCFException;
-
/** Get a connector instance.
*@param className is the class name.
*@return the instance.
@@ -194,6 +131,14 @@ public abstract class ConnectorFactory<T
if (!isInstalled(threadContext,className))
return null;
+ return getThisConnectorRaw(className);
+ }
+
+ /** Instantiate a connector, but return null if the class is not found.
+ */
+ protected T getThisConnectorRaw(String className)
+ throws ManifoldCFException
+ {
try
{
Class theClass = ManifoldCF.findClass(className);
@@ -225,18 +170,12 @@ public abstract class ConnectorFactory<T
}
catch (ClassNotFoundException e)
{
- // This MAY mean that an existing connector has been uninstalled; check out this possibility!
- // We return null because that is the signal that we cannot get a connector instance for that reason.
- if (!isInstalled(threadContext,className))
- return null;
-
- throw new ManifoldCFException("No connector class '"+className+"' was found.",
- e);
+ return null;
}
catch (NoSuchMethodException e)
{
throw new ManifoldCFException("No appropriate constructor for IConnector implementation '"+
- className+"'. Need xxx(ConfigParams).",
+ className+"'. Need xxx().",
e);
}
catch (SecurityException e)