- API change for the constructor of Loader: if not specified, the loader will get...
authorremm <remm@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 1 Sep 2006 23:06:02 +0000 (23:06 +0000)
committerremm <remm@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 1 Sep 2006 23:06:02 +0000 (23:06 +0000)
  avoiding the problems of ignoring the privileged flag in some cases as seen in bug 39704.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@439501 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/loader/WebappLoader.java
java/org/apache/catalina/startup/ContextRuleSet.java

index 10f4f69..b7db51f 100644 (file)
@@ -770,7 +770,7 @@ public class WebappLoader
         WebappClassLoader classLoader = null;
 
         if (parentClassLoader == null) {
-            parentClassLoader = Thread.currentThread().getContextClassLoader();
+            parentClassLoader = container.getParentClassLoader();
         }
         Class[] argTypes = { ClassLoader.class };
         Object[] args = { parentClassLoader };
index 252b311..e52faba 100644 (file)
@@ -144,10 +144,9 @@ public class ContextRuleSet extends RuleSetBase {
                             "addLifecycleListener",
                             "org.apache.catalina.LifecycleListener");
 
-        digester.addRule(prefix + "Context/Loader",
-                         new CreateLoaderRule
-                             ("org.apache.catalina.loader.WebappLoader",
-                              "className"));
+        digester.addObjectCreate(prefix + "Context/Loader",
+                            "org.apache.catalina.loader.WebappLoader",
+                            "className");
         digester.addSetProperties(prefix + "Context/Loader");
         digester.addSetNext(prefix + "Context/Loader",
                             "setLoader",
@@ -219,74 +218,3 @@ public class ContextRuleSet extends RuleSetBase {
     }
 
 }
-
-
-// ----------------------------------------------------------- Private Classes
-
-
-/**
- * Rule that creates a new <code>Loader</code> instance, with the parent
- * class loader associated with the top object on the stack (which must be
- * a <code>Container</code>), and pushes it on to the stack.
- */
-
-final class CreateLoaderRule extends Rule {
-
-    public CreateLoaderRule(String loaderClass, String attributeName) {
-
-        this.loaderClass = loaderClass;
-        this.attributeName = attributeName;
-
-    }
-
-    private String attributeName;
-
-    private String loaderClass;
-
-    public void begin(String namespace, String name, Attributes attributes)
-        throws Exception {
-
-        // Look up the required parent class loader
-        ClassLoader parentClassLoader = null;
-        Object ojb = digester.peek();
-        if (ojb instanceof Container) {
-            parentClassLoader = ((Container)ojb).getParentClassLoader();
-        }
-
-        // Bugzilla 36852: http://issues.apache.org/bugzilla/show_bug.cgi?id=36852
-        if((ojb instanceof org.apache.catalina.Context) &&
-           (((org.apache.catalina.Context) ojb).getPrivileged())) {
-            parentClassLoader = ojb.getClass().getClassLoader();
-        }
-
-        // Instantiate a new Loader implementation object
-        String className = loaderClass;
-        if (attributeName != null) {
-            String value = attributes.getValue(attributeName);
-            if (value != null)
-                className = value;
-        }
-        Class clazz = Class.forName(className);
-        Class types[] = { ClassLoader.class };
-        Object args[] = { parentClassLoader };
-        Constructor constructor = clazz.getDeclaredConstructor(types);
-        Loader loader = (Loader) constructor.newInstance(args);
-
-        // Push the new loader onto the stack
-        digester.push(loader);
-        if (digester.getLogger().isDebugEnabled())
-            digester.getLogger().debug("new " + loader.getClass().getName());
-
-    }
-
-    public void end(String namespace, String name)
-        throws Exception {
-
-        Loader loader = (Loader) digester.pop();
-        if (digester.getLogger().isDebugEnabled())
-            digester.getLogger().debug("pop " + loader.getClass().getName());
-
-    }
-
-
-}