costin      02/02/26 11:00:27

  Modified:    logging/src/java/org/apache/commons/logging LogFactory.java
               logging/src/java/org/apache/commons/logging/impl
                        LogFactoryImpl.java
  Log:
  Deal with the posiblity that a commons-logging is loaded in
  a loader, and the thread loader is set to point to a different
  loader that doesn't include logging ( or to a wrong value ).
  
  This happens when logging is used in certain container components,
  where the thread loader will point to an app that may not
  have/use logging.
  
  XXX What's the right order ? From a 'feature' point of view,
  it's better to try the thread loader first, so apps can
  override the default. From a security point of view,
  we should try the Class.forName() first, i.e. whatever
  is loaded in the parent loader.
  
  The current fix leaves the original order ( with thread loader
  used if available ).
  
  Revision  Changes    Path
  1.5       +17 -9     
jakarta-commons/logging/src/java/org/apache/commons/logging/LogFactory.java
  
  Index: LogFactory.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/logging/src/java/org/apache/commons/logging/LogFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- LogFactory.java   14 Feb 2002 21:09:19 -0000      1.4
  +++ LogFactory.java   26 Feb 2002 19:00:27 -0000      1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons/logging/src/java/org/apache/commons/logging/LogFactory.java,v
 1.4 2002/02/14 21:09:19 costin Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/02/14 21:09:19 $
  + * $Header: 
/home/cvs/jakarta-commons/logging/src/java/org/apache/commons/logging/LogFactory.java,v
 1.5 2002/02/26 19:00:27 costin Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/02/26 19:00:27 $
    *
    * ====================================================================
    *
  @@ -84,7 +84,7 @@
    *
    * @author Craig R. McClanahan
    * @author Costin Manolache
  - * @version $Revision: 1.4 $ $Date: 2002/02/14 21:09:19 $
  + * @version $Revision: 1.5 $ $Date: 2002/02/26 19:00:27 $
    */
   
   public abstract class LogFactory {
  @@ -483,21 +483,29 @@
        */
       protected static LogFactory newFactory(String factoryClass,
                                              ClassLoader classLoader)
  -        throws LogConfigurationException {
  -
  +        throws LogConfigurationException
  +    {
  +        
           try {
               Class clazz = null;
               if (classLoader == null) {
                   clazz = Class.forName(factoryClass);
               } else {
  -                clazz = classLoader.loadClass(factoryClass);
  +                try {
  +                    // first the thread class loader
  +                    clazz = classLoader.loadClass(factoryClass);
  +                } catch( ClassNotFoundException ex ) {
  +                    // if this failed ( i.e. no implementation is
  +                    // found in the webapp itself ) try the
  +                    // caller's loader 
  +                    clazz = Class.forName( factoryClass );
  +                }
               }
               return ((LogFactory) clazz.newInstance());
           } catch (Exception e) {
  +            e.printStackTrace();
               throw new LogConfigurationException(e);
           }
   
       }
  -
  -
   }
  
  
  
  1.5       +22 -8     
jakarta-commons/logging/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java
  
  Index: LogFactoryImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/logging/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- LogFactoryImpl.java       15 Feb 2002 05:42:35 -0000      1.4
  +++ LogFactoryImpl.java       26 Feb 2002 19:00:27 -0000      1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons/logging/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java,v
 1.4 2002/02/15 05:42:35 costin Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/02/15 05:42:35 $
  + * $Header: 
/home/cvs/jakarta-commons/logging/src/java/org/apache/commons/logging/impl/LogFactoryImpl.java,v
 1.5 2002/02/26 19:00:27 costin Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/02/26 19:00:27 $
    *
    * ====================================================================
    *
  @@ -104,7 +104,7 @@
    *
    * @author Rod Waldhoff
    * @author Craig R. McClanahan
  - * @version $Revision: 1.4 $ $Date: 2002/02/15 05:42:35 $
  + * @version $Revision: 1.5 $ $Date: 2002/02/26 19:00:27 $
    */
   
   public class LogFactoryImpl extends LogFactory {
  @@ -395,7 +395,7 @@
           // Attempt to load the Log implementation class
           Class logClass = null;
           try {
  -            logClass = findClassLoader().loadClass(logClassName);
  +            logClass = loadClass(logClassName);
               if (!Log.class.isAssignableFrom(logClass)) {
                   throw new LogConfigurationException
                       ("Class " + logClassName + " does not implement Log");
  @@ -423,10 +423,24 @@
   
       }
   
  +    /** Load a class, try first the thread class loader, and
  +        if it fails use the loader that loaded this class
  +    */
  +    static Class loadClass( String name )
  +        throws ClassNotFoundException
  +    {
  +        ClassLoader threadCL=findClassLoader();
  +        try {
  +            return threadCL.loadClass(name);
  +        } catch( ClassNotFoundException ex ) {
  +            return Class.forName( name );
  +        }
  +    }
  +
       protected void guessConfig() {
           if( isLog4JAvailable() ) {
               try {
  -                Class proxyClass=findClassLoader().
  +                Class proxyClass=
                       loadClass( "org.apache.commons.logging.Log4jFactory" );
                   proxyFactory=(LogFactory)proxyClass.newInstance();
               } catch( Throwable t ) {
  @@ -444,7 +458,7 @@
       protected boolean isJdk14Available() {
   
           try {
  -            findClassLoader().loadClass("java.util.logging.Logger");
  +            loadClass("java.util.logging.Logger");
               return (true);
           } catch (Throwable t) {
               return (false);
  @@ -459,7 +473,7 @@
       protected boolean isLog4JAvailable() {
   
           try {
  -            findClassLoader().loadClass("org.apache.log4j.Category");
  +            loadClass("org.apache.log4j.Category");
               return (true);
           } catch (Throwable t) {
               return (false);
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to