You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-dev@jakarta.apache.org by vm...@apache.org on 2002/05/12 21:41:15 UTC

cvs commit: jakarta-cactus/framework/src/java/share/org/apache/cactus/util/log LogAspect.java

vmassol     02/05/12 12:41:14

  Modified:    framework/src/java/share/org/apache/cactus/util
                        ClassLoaderUtils.java Configuration.java
               framework/src/java/share/org/apache/cactus/util/log
                        LogAspect.java
  Log:
  * when loading classes , try first with webapp classloader and then only with context classloader and not the other way round !
  * try to load property resource from context class loader too
  
  Revision  Changes    Path
  1.2       +41 -6     jakarta-cactus/framework/src/java/share/org/apache/cactus/util/ClassLoaderUtils.java
  
  Index: ClassLoaderUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/util/ClassLoaderUtils.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ClassLoaderUtils.java	12 May 2002 12:44:00 -0000	1.1
  +++ ClassLoaderUtils.java	12 May 2002 19:41:14 -0000	1.2
  @@ -56,12 +56,17 @@
    */
   package org.apache.cactus.util;
   
  +import java.util.ResourceBundle;
  +import java.util.PropertyResourceBundle;
  +import java.util.MissingResourceException;
  +import java.util.Locale;
  +
   /**
    * Utiliy methods related to class loading in a webapp environment.
    *
    * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
    *
  - * @version $Id: ClassLoaderUtils.java,v 1.1 2002/05/12 12:44:00 vmassol Exp $
  + * @version $Id: ClassLoaderUtils.java,v 1.2 2002/05/12 19:41:14 vmassol Exp $
    */
   public class ClassLoaderUtils
   {
  @@ -84,13 +89,13 @@
           Class clazz = null;
   
           try {
  -            // Try first from Context class loader so that we can put the
  -            // Cactus jar as an external library.
  -            clazz = loadClassFromContextClassLoader(theClassName);
  -        } catch (Exception internalException) {
  -            // It failed... Try from the webapp classloader.
  +            // try loading from webapp classloader first
               clazz = loadClassFromWebappClassLoader(theClassName,
                   theReferrer);
  +        } catch (Exception internalException) {
  +            // Then try first from Context class loader so that we can put the
  +            // Cactus jar as an external library.
  +            clazz = loadClassFromContextClassLoader(theClassName);
           }
   
           return clazz;
  @@ -126,4 +131,34 @@
       {
           return Class.forName(theClassName, true, theReferrer.getClassLoader());
       }
  +
  +
  +    /**
  +     * Try loading a resource bundle from either the context class loader or
  +     * the
  +     *
  +     * @param theName the resource bundle name
  +     * @param theReferrer the resource bundle will be loaded using the
  +     *        classloader which has loaded this referrer class
  +     * @return the loaded resource bundle
  +     */
  +    public static ResourceBundle loadPropertyResourceBundle(
  +        String theName, Class theReferrer)
  +    {
  +        ResourceBundle bundle;
  +
  +        try {
  +            // Then, try to load from the referrer class loader first
  +            bundle = PropertyResourceBundle.getBundle(theName,
  +                Locale.getDefault(), theReferrer.getClassLoader());
  +        } catch (MissingResourceException e) {
  +            // Then, try to load from context classloader
  +            bundle = PropertyResourceBundle.getBundle(theName,
  +                Locale.getDefault(),
  +                Thread.currentThread().getContextClassLoader());
  +        }
  +
  +        return bundle;
  +    }
  +
   }
  
  
  
  1.3       +3 -2      jakarta-cactus/framework/src/java/share/org/apache/cactus/util/Configuration.java
  
  Index: Configuration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/util/Configuration.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Configuration.java	5 May 2002 14:28:50 -0000	1.2
  +++ Configuration.java	12 May 2002 19:41:14 -0000	1.3
  @@ -66,7 +66,7 @@
    *
    * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
    *
  - * @version $Id: Configuration.java,v 1.2 2002/05/05 14:28:50 vmassol Exp $
  + * @version $Id: Configuration.java,v 1.3 2002/05/12 19:41:14 vmassol Exp $
    */
   public class Configuration
   {
  @@ -111,7 +111,8 @@
               if (configOverride == null) {
                   // Try to read the default cactus configuration file from the
                   // classpath
  -                config = PropertyResourceBundle.getBundle(CONFIG_DEFAULT_NAME);
  +                config = ClassLoaderUtils.loadPropertyResourceBundle(
  +                    CONFIG_DEFAULT_NAME, Configuration.class);
               } else {
                   try {
                       config = new PropertyResourceBundle(
  
  
  
  1.2       +3 -2      jakarta-cactus/framework/src/java/share/org/apache/cactus/util/log/LogAspect.java
  
  Index: LogAspect.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/util/log/LogAspect.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LogAspect.java	1 Mar 2002 00:43:47 -0000	1.1
  +++ LogAspect.java	12 May 2002 19:41:14 -0000	1.2
  @@ -61,7 +61,7 @@
    *
    * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
    *
  - * @version $Id: LogAspect.java,v 1.1 2002/03/01 00:43:47 vmassol Exp $
  + * @version $Id: LogAspect.java,v 1.2 2002/05/12 19:41:14 vmassol Exp $
    */
   public aspect LogAspect
   {
  @@ -70,7 +70,8 @@
        * perform the logging and thus at execution time we would enter an infinite recursive loop.
        */
       pointcut logObjectCalls() :
  -        execution(public * org.apache.cactus.util.log..*(..));
  +        execution(public * org.apache.cactus.util.log..*(..)) ||
  +        execution(public * org.apache.cactus.util.ClassLoaderUtils.loadPropertyResourceBundle(..));
   
       /**
        * All public static methods that have parameters.
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>