sanders     01/07/19 13:55:52

  Modified:    digester/src/java/org/apache/commons/digester
                        CallMethodRule.java Digester.java
                        ObjectCreateRule.java SetNextRule.java
                        SetTopRule.java
  Log:
  Update to be able to enable/disable use of the context classloader.
  Partial patch contributed by Immanuel, Gidado-Yisa <[EMAIL PROTECTED]>
  
  Should we be setting the default to true(use) or false(do not use)?
  
  Revision  Changes    Path
  1.3       +14 -11    
jakarta-commons/digester/src/java/org/apache/commons/digester/CallMethodRule.java
  
  Index: CallMethodRule.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/CallMethodRule.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CallMethodRule.java       2001/05/12 17:25:52     1.2
  +++ CallMethodRule.java       2001/07/19 20:55:52     1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/CallMethodRule.java,v
 1.2 2001/05/12 17:25:52 sanders Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/05/12 17:25:52 $
  + * $Header: 
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/CallMethodRule.java,v
 1.3 2001/07/19 20:55:52 sanders Exp $
  + * $Revision: 1.3 $
  + * $Date: 2001/07/19 20:55:52 $
    *
    * ====================================================================
    *
  @@ -77,7 +77,7 @@
    *
    * @author Craig McClanahan
    * @author Scott Sanders
  - * @version $Revision: 1.2 $ $Date: 2001/05/12 17:25:52 $
  + * @version $Revision: 1.3 $ $Date: 2001/07/19 20:55:52 $
    */
   
   public class CallMethodRule extends Rule {
  @@ -129,16 +129,19 @@
               this.paramTypes = new Class[paramTypes.length];
               for (int i = 0; i < this.paramTypes.length; i++) {
                   try {
  -                    // Check to see if the context class loader is set,
  -                    // and if so, use it, as it may be set in server-side
  -                    // environments and Class.forName() may cause issues
  -                    ClassLoader ctxLoader = 
  +
  +                    // Check to see if the context class loader is set, and if so, 
use
  +                    // it (only if allowed to by the associated digester), as it may
  +                    // be set in server-side environments and Class.forName() may
  +                    // cause issues
  +                    ClassLoader ctxLoader =
                           Thread.currentThread().getContextClassLoader();
  -                    if (ctxLoader == null) {
  -                        this.paramTypes[i] = Class.forName(paramTypes[i]);
  -                    } else {
  +                    if (ctxLoader!=null && digester.getUseContextClassLoader()) {
                           this.paramTypes[i] = ctxLoader.loadClass(paramTypes[i]);
  +                    } else {
  +                        this.paramTypes[i] = Class.forName(paramTypes[i]);
                       }
  +
                   } catch (ClassNotFoundException e) {
                       this.paramTypes[i] = null; // Will cause NPE later
                   }
  
  
  
  1.7       +38 -4     
jakarta-commons/digester/src/java/org/apache/commons/digester/Digester.java
  
  Index: Digester.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/Digester.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Digester.java     2001/06/24 17:02:21     1.6
  +++ Digester.java     2001/07/19 20:55:52     1.7
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/Digester.java,v
 1.6 2001/06/24 17:02:21 sanders Exp $
  - * $Revision: 1.6 $
  - * $Date: 2001/06/24 17:02:21 $
  + * $Header: 
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/Digester.java,v
 1.7 2001/07/19 20:55:52 sanders Exp $
  + * $Revision: 1.7 $
  + * $Date: 2001/07/19 20:55:52 $
    *
    * ====================================================================
    *
  @@ -105,7 +105,8 @@
    * even from the same thread.</p>
    *
    * @author Craig McClanahan
  - * @version $Revision: 1.6 $ $Date: 2001/06/24 17:02:21 $
  + * @author Scott Sanders
  + * @version $Revision: 1.7 $ $Date: 2001/07/19 20:55:52 $
    */
   
   public class Digester extends DefaultHandler {
  @@ -143,6 +144,13 @@
   
   
       /**
  +     * Do we want to use the Context ClassLoader when loading classes
  +     * for instantiating new objects?  Default is <code>false</code>.
  +     */
  +    protected boolean useContextClassLoader = false;
  +
  +
  +    /**
        * The body text of the current element.
        */
       protected StringBuffer bodyText = new StringBuffer();
  @@ -390,6 +398,32 @@
           this.writer = writer;
   
       }
  +
  +
  +    /**
  +     * Return the boolean as to whether the context classloader should be used.
  +     */
  +    public boolean getUseContextClassLoader() {
  +
  +        return useContextClassLoader;
  +
  +    }
  +
  +
  +    /**
  +     * Determine whether to use the Context ClassLoader (the one found by
  +     * calling <code>Thread.currentThread().getContextClassLoader()</code>)
  +     * to resolve/load classes that are defined in various rules.  If not
  +     * using Context ClassLoader, then the class-loading defaults to
  +     * using the calling-class' ClassLoader.
  +     *
  +     * @param boolean determines whether to use Context ClassLoader.
  +     */
  +    public void setUseContextClassLoader(boolean use) {
  +
  +        useContextClassLoader = use;
  +
  +     }
   
   
       // ---------------------------------------------- DocumentHandler Methods
  
  
  
  1.3       +12 -12    
jakarta-commons/digester/src/java/org/apache/commons/digester/ObjectCreateRule.java
  
  Index: ObjectCreateRule.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/ObjectCreateRule.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ObjectCreateRule.java     2001/05/12 17:25:54     1.2
  +++ ObjectCreateRule.java     2001/07/19 20:55:52     1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/ObjectCreateRule.java,v
 1.2 2001/05/12 17:25:54 sanders Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/05/12 17:25:54 $
  + * $Header: 
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/ObjectCreateRule.java,v
 1.3 2001/07/19 20:55:52 sanders Exp $
  + * $Revision: 1.3 $
  + * $Date: 2001/07/19 20:55:52 $
    *
    * ====================================================================
    *
  @@ -74,7 +74,7 @@
    *
    * @author Craig McClanahan
    * @author Scott Sanders
  - * @version $Revision: 1.2 $ $Date: 2001/05/12 17:25:54 $
  + * @version $Revision: 1.3 $ $Date: 2001/07/19 20:55:52 $
    */
   
   public class ObjectCreateRule extends Rule {
  @@ -153,15 +153,15 @@
        // Instantiate the new object and push it on the context stack
       Class clazz = null;
   
  -    // Check to see if the context class loader is set,
  -    // and if so, use it, as it may be set in server-side
  -    // environments and Class.forName() may cause issues
  -    ClassLoader ctxLoader = 
  -        Thread.currentThread().getContextClassLoader();
  -    if (ctxLoader == null) {
  -        clazz = Class.forName(realClassName);
  -    } else {
  +    // Check to see if the context class loader is set, and if so, use
  +    // it (only if allowed to by the associated digester), as it may
  +    // be set in server-side environments and Class.forName() may
  +    // cause issues
  +    ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
  +    if (ctxLoader!=null && digester.getUseContextClassLoader()) {
           clazz = ctxLoader.loadClass(realClassName);
  +    } else {
  +        clazz = Class.forName(realClassName);
       }
        
       Object instance = clazz.newInstance();
  
  
  
  1.3       +12 -11    
jakarta-commons/digester/src/java/org/apache/commons/digester/SetNextRule.java
  
  Index: SetNextRule.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/SetNextRule.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SetNextRule.java  2001/05/12 17:25:54     1.2
  +++ SetNextRule.java  2001/07/19 20:55:52     1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/SetNextRule.java,v
 1.2 2001/05/12 17:25:54 sanders Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/05/12 17:25:54 $
  + * $Header: 
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/SetNextRule.java,v
 1.3 2001/07/19 20:55:52 sanders Exp $
  + * $Revision: 1.3 $
  + * $Date: 2001/07/19 20:55:52 $
    *
    * ====================================================================
    *
  @@ -75,7 +75,7 @@
    *
    * @author Craig McClanahan
    * @author Scott Sanders
  - * @version $Revision: 1.2 $ $Date: 2001/05/12 17:25:54 $
  + * @version $Revision: 1.3 $ $Date: 2001/07/19 20:55:52 $
    */
   
   public class SetNextRule extends Rule {
  @@ -153,15 +153,16 @@
        Class paramTypes[] = new Class[1];
        if (paramType != null) {
   
  -        // Check to see if the context class loader is set,
  -        // and if so, use it, as it may be set in server-side
  -        // environments and Class.forName() may cause issues
  -        ClassLoader ctxLoader = 
  +        // Check to see if the context class loader is set, and if so, use
  +        // it (only if allowed to by the associated digester), as it may
  +        // be set in server-side environments and Class.forName() may
  +        // cause issues
  +        ClassLoader ctxLoader =
               Thread.currentThread().getContextClassLoader();
  -        if (ctxLoader == null) {
  -            paramTypes[0] = Class.forName(paramType);
  -        } else {
  +        if (ctxLoader!=null && digester.getUseContextClassLoader()) {
               paramTypes[0] = ctxLoader.loadClass(paramType);
  +        } else {
  +            paramTypes[0] = Class.forName(paramType);
           }
   
        } else {
  
  
  
  1.3       +12 -11    
jakarta-commons/digester/src/java/org/apache/commons/digester/SetTopRule.java
  
  Index: SetTopRule.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/SetTopRule.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SetTopRule.java   2001/05/12 17:25:55     1.2
  +++ SetTopRule.java   2001/07/19 20:55:52     1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/SetTopRule.java,v
 1.2 2001/05/12 17:25:55 sanders Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/05/12 17:25:55 $
  + * $Header: 
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/SetTopRule.java,v
 1.3 2001/07/19 20:55:52 sanders Exp $
  + * $Revision: 1.3 $
  + * $Date: 2001/07/19 20:55:52 $
    *
    * ====================================================================
    *
  @@ -74,7 +74,7 @@
    *
    * @author Craig McClanahan
    * @author Scott Sanders
  - * @version $Revision: 1.2 $ $Date: 2001/05/12 17:25:55 $
  + * @version $Revision: 1.3 $ $Date: 2001/07/19 20:55:52 $
    */
   
   public class SetTopRule extends Rule {
  @@ -152,15 +152,16 @@
        Class paramTypes[] = new Class[1];
        if (paramType != null) {
   
  -        // Check to see if the context class loader is set,
  -        // and if so, use it, as it may be set in server-side
  -        // environments and Class.forName() may cause issues
  -        ClassLoader ctxLoader = 
  +        // Check to see if the context class loader is set, and if so, use
  +        // it (only if allowed to by the associated digester), as it may
  +        // be set in server-side environments and Class.forName() may
  +        // cause issues
  +        ClassLoader ctxLoader =
               Thread.currentThread().getContextClassLoader();
  -        if (ctxLoader == null) {
  -            paramTypes[0] = Class.forName(paramType);
  -        } else {
  +        if (ctxLoader!=null && digester.getUseContextClassLoader()) {
               paramTypes[0] = ctxLoader.loadClass(paramType);
  +        } else {
  +            paramTypes[0] = Class.forName(paramType);
           }
   
       } else {
  
  
  

Reply via email to