You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sk...@apache.org on 2005/05/16 12:41:47 UTC
svn commit: r170355 -
/jakarta/commons/proper/logging/trunk/src/java/org/apache/commons/logging/LogFactory.java
Author: skitching
Date: Mon May 16 03:41:44 2005
New Revision: 170355
URL: http://svn.apache.org/viewcvs?rev=170355&view=rev
Log:
Simple rearrangement of code only; no functionality change (though the diffs don't show that clearly).
Turned a complicated anonymous class declaration into a simple anonymous class that calls a method
on LogFactory containing all the code previously within the anonymous class declaration.
Modified:
jakarta/commons/proper/logging/trunk/src/java/org/apache/commons/logging/LogFactory.java
Modified: jakarta/commons/proper/logging/trunk/src/java/org/apache/commons/logging/LogFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/trunk/src/java/org/apache/commons/logging/LogFactory.java?rev=170355&r1=170354&r2=170355&view=diff
==============================================================================
--- jakarta/commons/proper/logging/trunk/src/java/org/apache/commons/logging/LogFactory.java (original)
+++ jakarta/commons/proper/logging/trunk/src/java/org/apache/commons/logging/LogFactory.java Mon May 16 03:41:44 2005
@@ -632,67 +632,7 @@
Object result = AccessController.doPrivileged(
new PrivilegedAction() {
public Object run() {
- // This will be used to diagnose bad configurations
- // and allow a useful message to be sent to the user
- Class logFactoryClass = null;
- try {
- if (classLoader != null) {
- try {
- // First the given class loader param (thread class loader)
-
- // Warning: must typecast here & allow exception
- // to be generated/caught & recast properly.
- logFactoryClass = classLoader.loadClass(factoryClass);
- return (LogFactory) logFactoryClass.newInstance();
-
- } catch (ClassNotFoundException ex) {
- if (classLoader == LogFactory.class.getClassLoader()) {
- // Nothing more to try, onwards.
- throw ex;
- }
- // ignore exception, continue
- } catch (NoClassDefFoundError e) {
- if (classLoader == LogFactory.class.getClassLoader()) {
- // Nothing more to try, onwards.
- throw e;
- }
-
- } catch(ClassCastException e){
-
- if (classLoader == LogFactory.class.getClassLoader()) {
- // Nothing more to try, onwards (bug in loader implementation).
- throw e;
- }
- }
- // Ignore exception, continue
- }
-
- /* At this point, either classLoader == null, OR
- * classLoader was unable to load factoryClass.
- * Try the class loader that loaded this class:
- * LogFactory.getClassLoader().
- *
- * Notes:
- * a) LogFactory.class.getClassLoader() may return 'null'
- * if LogFactory is loaded by the bootstrap classloader.
- * b) The Java endorsed library mechanism is instead
- * Class.forName(factoryClass);
- */
- // Warning: must typecast here & allow exception
- // to be generated/caught & recast properly.
- logFactoryClass = Class.forName(factoryClass);
- return (LogFactory) logFactoryClass.newInstance();
- } catch (Exception e) {
- // Check to see if we've got a bad configuration
- if (logFactoryClass != null
- && !LogFactory.class.isAssignableFrom(logFactoryClass)) {
- return new LogConfigurationException(
- "The chosen LogFactory implementation does not extend LogFactory."
- + " Please check your configuration.",
- e);
- }
- return new LogConfigurationException(e);
- }
+ return createFactory(factoryClass, classLoader);
}
});
@@ -700,6 +640,79 @@
throw (LogConfigurationException)result;
return (LogFactory)result;
+ }
+
+ /**
+ * Implements the operations described in the javadoc for newFactory.
+ *
+ * @param factoryClass
+ * @param classLoader
+ *
+ * @returns either a LogFactory object or a LogConfigurationException object.
+ */
+ protected static Object createFactory(String factoryClass, ClassLoader classLoader) {
+
+ // This will be used to diagnose bad configurations
+ // and allow a useful message to be sent to the user
+ Class logFactoryClass = null;
+ try {
+ if (classLoader != null) {
+ try {
+ // First the given class loader param (thread class loader)
+
+ // Warning: must typecast here & allow exception
+ // to be generated/caught & recast properly.
+ logFactoryClass = classLoader.loadClass(factoryClass);
+ return (LogFactory) logFactoryClass.newInstance();
+
+ } catch (ClassNotFoundException ex) {
+ if (classLoader == LogFactory.class.getClassLoader()) {
+ // Nothing more to try, onwards.
+ throw ex;
+ }
+ // ignore exception, continue
+ } catch (NoClassDefFoundError e) {
+ if (classLoader == LogFactory.class.getClassLoader()) {
+ // Nothing more to try, onwards.
+ throw e;
+ }
+
+ } catch(ClassCastException e){
+
+ if (classLoader == LogFactory.class.getClassLoader()) {
+ // Nothing more to try, onwards (bug in loader implementation).
+ throw e;
+ }
+ }
+ // Ignore exception, continue
+ }
+
+ /* At this point, either classLoader == null, OR
+ * classLoader was unable to load factoryClass.
+ * Try the class loader that loaded this class:
+ * LogFactory.getClassLoader().
+ *
+ * Notes:
+ * a) LogFactory.class.getClassLoader() may return 'null'
+ * if LogFactory is loaded by the bootstrap classloader.
+ * b) The Java endorsed library mechanism is instead
+ * Class.forName(factoryClass);
+ */
+ // Warning: must typecast here & allow exception
+ // to be generated/caught & recast properly.
+ logFactoryClass = Class.forName(factoryClass);
+ return (LogFactory) logFactoryClass.newInstance();
+ } catch (Exception e) {
+ // Check to see if we've got a bad configuration
+ if (logFactoryClass != null
+ && !LogFactory.class.isAssignableFrom(logFactoryClass)) {
+ return new LogConfigurationException(
+ "The chosen LogFactory implementation does not extend LogFactory."
+ + " Please check your configuration.",
+ e);
+ }
+ return new LogConfigurationException(e);
+ }
}
private static InputStream getResourceAsStream(final ClassLoader loader,
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org