Uhhh...the previous patch had some debug code in it,
please use the one attached here.

> -----Original Message-----
> From: Immanuel, Gidado-Yisa [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, July 18, 2001 10:24 AM
> To: '[EMAIL PROTECTED]'
> Subject: [PATCH] Difficulties with Commons-Digester 1.0
> 
> 
> My patch is attatched.  I also posted bug 2669 regarding
> this issue:
>   http://nagoya.apache.org/bugzilla/show_bug.cgi?id=2669
> 
> - Gidado
> 
> 
> > I am aware of this issue, and in talking with Craig, the 
> solution is to
> add
> > a boolean useContextClassLoader to digester to turn this on 
> and off.  I
> will
> > be updating the Commons Digester to handle this hopefully 
> in the next week
> > or two.  If you want to send a patch, feel free ;-)
> >
> > Scott Sanders
> 
> 

Index: ObjectCreateRule.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-commons/digester/src/java/org/apache/commons/digester/ObjectCreateRule.java,v
retrieving revision 1.2
diff -u -r1.2 ObjectCreateRule.java
--- ObjectCreateRule.java       2001/05/12 17:25:54     1.2
+++ ObjectCreateRule.java       2001/07/18 14:54:21
@@ -153,16 +153,16 @@
        // 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 {
-        clazz = ctxLoader.loadClass(realClassName);
-    }
+    // 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();
        digester.push(instance);
Index: Digester.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-commons/digester/src/java/org/apache/commons/digester/Digester.java,v
retrieving revision 1.6
diff -u -r1.6 Digester.java
--- Digester.java       2001/06/24 17:02:21     1.6
+++ Digester.java       2001/07/18 14:55:19
@@ -239,6 +239,13 @@
     protected PrintWriter writer = null;
 
 
+    /**
+     * Do we want to use the Context ClassLoader when loading classes
+        * for instantiating new objects?  Default is <code>false</code>.
+     */
+    protected boolean useContextClassLoader = false;
+
+
     // ----------------------------------------------------------- Properties
 
 
@@ -388,6 +395,33 @@
     public void setWriter(PrintWriter writer) {
 
         this.writer = writer;
+
+    }
+
+
+
+    /**
+     * Return the logging writer for this Digester.
+     */
+    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;
 
     }

Reply via email to