Allow pluggable property replacement object
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Sun, 19 Apr 2009 22:00:51 +0000 (22:00 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Sun, 19 Apr 2009 22:00:51 +0000 (22:00 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@766526 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/tomcat/util/digester/Digester.java
webapps/docs/config/systemprops.xml

index 735b307..5a55ff4 100644 (file)
@@ -76,10 +76,8 @@ import org.xml.sax.helpers.DefaultHandler;
 
 public class Digester extends DefaultHandler {
 
-
-    // ---------------------------------------------------------- Static Fields
-
-
+    
+    // ---------------------------------------------------------- Static Fields    
     private static class SystemPropertySource 
         implements IntrospectionUtils.PropertySource {
         public String getProperty( String key ) {
@@ -89,6 +87,28 @@ public class Digester extends DefaultHandler {
 
     protected static IntrospectionUtils.PropertySource source[] = 
         new IntrospectionUtils.PropertySource[] { new SystemPropertySource() };
+    
+    static {
+        String className = System.getProperty("org.apache.tomcat.util.digester.PROPERTY_SOURCE");
+        if (className!=null) {
+            IntrospectionUtils.PropertySource[] sources = new IntrospectionUtils.PropertySource[2];
+            sources[1] = source[0];
+            ClassLoader[] cls = new ClassLoader[] {Digester.class.getClassLoader(),Thread.currentThread().getContextClassLoader()};
+            boolean initialized = false;
+            for (int i=0; i<cls.length && (!initialized); i++) {
+                try {
+                    Class<?> clazz = Class.forName(className,true,cls[i]);
+                    IntrospectionUtils.PropertySource src = (IntrospectionUtils.PropertySource)clazz.newInstance();
+                    sources[0] = src;
+                    initialized = true;
+                } catch (Throwable t) {
+                    LogFactory.getLog("org.apache.commons.digester.Digester").
+                        error("Unable to load property source["+className+"].",t);
+                }
+            }
+            if (initialized) source = sources;
+        }
+    }
 
 
     // --------------------------------------------------------- Constructors
index dcbf89a..3a25556 100644 (file)
   the default Tomcat behaviour.</p>
 </section>
 
-
+<section name="Property replacements">
+  <properties>
+    <property name="org.apache.tomcat.util.digester. PROPERTY_SOURCE">
+      <p>Set this to a fully qualified name of a class that implements 
+         <code>org.apache.tomcat.util.IntrospectionUtils.PropertySource</code>.
+         Required to have a public constructor with no arguments.</p>
+      <p>Use this to add a property source, that will be invoked when <code>s{parameter}</code>
+         denoted parameters are found in the XML files that tomcat parses.</p>
+    </property>
+  </properties>
+  
+</section>  
 
 <section name="Clustering">
   <properties>