From: markt Date: Sat, 11 Sep 2010 10:44:50 +0000 (+0000) Subject: Fix an issue where elements defined in server.xml did not use the... X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=6192a80a18205e771cbf34f2bd4639543ed2fac6;p=tomcat7.0 Fix an issue where elements defined in server.xml did not use the configClass specified by the parent element git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@996117 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/startup/LifecycleListenerRule.java b/java/org/apache/catalina/startup/LifecycleListenerRule.java index be4b1b068..2118f15a9 100644 --- a/java/org/apache/catalina/startup/LifecycleListenerRule.java +++ b/java/org/apache/catalina/startup/LifecycleListenerRule.java @@ -19,18 +19,27 @@ package org.apache.catalina.startup; -import org.apache.catalina.Lifecycle; +import org.apache.catalina.Container; import org.apache.catalina.LifecycleListener; +import org.apache.tomcat.util.IntrospectionUtils; import org.apache.tomcat.util.digester.Rule; import org.xml.sax.Attributes; /** - *

Rule that creates a new LifecycleListener instance, - * and associates it with the top object on the stack (which must - * implement LifecycleListener).

+ * Rule that creates a new {@link LifecycleListener} and associates it with the + * top object on the stack which must implement {@link Container}. The + * implementation class to be used is determined by: + *
    + *
  1. Does the top element on the stack specify an implementation class using + * the attribute specified when this rule was created?
  2. + *
  3. Does the parent {@link Container} of the {@link Container} on the top of + * the stack specify an implementation class using the attribute specified + * when this rule was created?
  4. + *
  5. Use the default implementation class specified when this rule was + * created.
  6. + *
*/ - public class LifecycleListenerRule extends Rule { @@ -83,21 +92,43 @@ public class LifecycleListenerRule extends Rule { public void begin(String namespace, String name, Attributes attributes) throws Exception { - // Instantiate a new LifecyleListener implementation object - String className = listenerClass; + Container c = (Container) digester.peek(); + Container p = null; + Object obj = digester.peek(1); + if (obj instanceof Container) { + p = (Container) obj; + } + + String className = null; + + // Check the container for the specified attribute if (attributeName != null) { String value = attributes.getValue(attributeName); if (value != null) className = value; } + + // Check the container's parent for the specified attribute + if (p != null && className == null) { + String configClass = + (String) IntrospectionUtils.getProperty(p, attributeName); + if (configClass != null && configClass.length() > 0) { + className = configClass; + } + } + + // Use the default + if (className == null) { + className = listenerClass; + } + + // Instantiate a new LifecyleListener implementation object Class clazz = Class.forName(className); LifecycleListener listener = (LifecycleListener) clazz.newInstance(); // Add this LifecycleListener to our associated component - Lifecycle lifecycle = (Lifecycle) digester.peek(); - lifecycle.addLifecycleListener(listener); - + c.addLifecycleListener(listener); }