commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From skitch...@apache.org
Subject cvs commit: jakarta-commons/digester/src/test/org/apache/commons/digester/xmlrules FromXmlRuleSetTest.java DigesterLoaderTestSuite.java
Date Wed, 07 Apr 2004 22:17:00 GMT
skitching    2004/04/07 15:17:00

  Modified:    digester/src/java/org/apache/commons/digester/plugins
                        Declaration.java PluginConfigurationException.java
                        PluginCreateRule.java PluginDeclarationRule.java
                        PluginInvalidInputException.java PluginManager.java
                        PluginRules.java
               digester/src/java/org/apache/commons/digester/xmlrules
                        DigesterRuleParser.java FromXmlRuleSet.java
               digester/src/test/org/apache/commons/digester/plugins
                        TestAll.java TestConfigurablePluginAttributes.java
                        TestLocalRules.java
               digester/src/test/org/apache/commons/digester/xmlrules
                        DigesterLoaderTestSuite.java
  Added:       digester/src/java/org/apache/commons/digester/plugins
                        PluginContext.java PluginException.java
                        RuleFinder.java RuleLoader.java
               digester/src/java/org/apache/commons/digester/plugins/strategies
                        FinderFromClass.java FinderFromDfltClass.java
                        FinderFromDfltMethod.java
                        FinderFromDfltResource.java FinderFromFile.java
                        FinderFromMethod.java FinderFromResource.java
                        FinderSetProperties.java LoaderFromClass.java
                        LoaderFromStream.java LoaderSetProperties.java
                        package.html
               digester/src/test/org/apache/commons/digester/plugins
                        TestObject.java TestObjectRuleInfo.xml
                        TestXmlRuleInfo.java xmlrules1.xml xmlrules2.xml
               digester/src/test/org/apache/commons/digester/xmlrules
                        FromXmlRuleSetTest.java
  Log:
  Merged DIGESTER_PLUGINS_REFACTORING_BRANCH into main trunk.
  
  Revision  Changes    Path
  1.12      +87 -271   jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/Declaration.java
  
  Index: Declaration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/Declaration.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Declaration.java	29 Feb 2004 02:22:15 -0000	1.11
  +++ Declaration.java	7 Apr 2004 22:16:47 -0000	1.12
  @@ -15,27 +15,19 @@
    */ 
   package org.apache.commons.digester.plugins;
   
  -import java.io.File;
  -import java.io.FileInputStream;
  -import java.io.InputStream;
   import java.io.IOException;
  -import java.lang.reflect.Method;
  +import java.util.Properties;
  +import java.util.List;
   
  -import org.apache.commons.beanutils.MethodUtils;
  -import org.apache.commons.digester.Digester;
   import org.apache.commons.logging.Log;
  +import org.apache.commons.digester.Digester;
   
   /**
  - * Simple structure to store the set of attributes that can be present on 
  - * a plugin declaration.
  + * Represents a Class that can be instantiated by a PluginCreateRule, plus
  + * info on how to load custom digester rules for mapping xml into that
  + * plugged-in class.
    */
   public class Declaration {
  -
  -    /** 
  -     * The name of the method looked for on the plugin class and any
  -     * specific rule class.
  -     */
  -    public final static String DFLT_RULE_METHOD_NAME = "addRules";
      
       /** The class of the object to be instantiated. */
       private Class pluginClass;
  @@ -46,89 +38,66 @@
       /** See {@link #setId}. */ 
       private String id;
       
  -    /** See {@link #setRuleMethod}. */
  -    private String ruleMethodName = DFLT_RULE_METHOD_NAME;
  -    
  -    /** See {@link #setRuleClass}. */ 
  -    private Class ruleClass;
  -    
  -    /** See {@link #setRuleResource}. */
  -    private String ruleResource;
  -    
  -    /** See {@link #setRuleFile}. */
  -    private File ruleFile;
  +    /** See {@link #setProperties}. */
  +    private Properties properties = new Properties();
       
  -    /** See {@link #setAutoSetProperties}. */
  -    private boolean autoSetProperties = true;
  -
       /** See {@link #init}. */
       private boolean initialized = false;
  +
  +    /**
  +     * Class which is responsible for dynamically loading this
  +     * plugin's rules on demand.
  +     */
  +    private RuleLoader ruleLoader = null;
       
       //---------------------- constructors ----------------------------------
   
       /**
        * Constructor.
        */
  +    public Declaration(String pluginClassName) {
  +        // We can't load the pluginClass at this time, because we don't
  +        // have a digester instance yet to load it through. So just
  +        // save the name away, and we'll load the Class object in the
  +        // init method.
  +        this.pluginClassName = pluginClassName;
  +    }
  +    
  +    /**
  +     * Constructor.
  +     */
       public Declaration(Class pluginClass) {
           this.pluginClass = pluginClass;
           this.pluginClassName = pluginClass.getName();
       }
       
       /**
  -     * Constructor.
  +     * Create an instance where a fully-initialised ruleLoader instance
  +     * is provided by the caller instead of having the PluginManager
  +     * "discover" an appropriate one.
        */
  -    public Declaration(String pluginClassName) {
  -        this.pluginClassName = pluginClassName;
  +    public Declaration(Class pluginClass, RuleLoader ruleLoader) {
  +        this.pluginClass = pluginClass;
  +        this.pluginClassName = pluginClass.getName();
  +        this.ruleLoader = ruleLoader;
       }
       
       //---------------------- properties -----------------------------------
   
       /** 
  -     * The id of the object defined in a plugin declaration.
  +     * The id that the user associated with a particular plugin declaration
  +     * in the input xml. This id is later used in the input xml to refer
  +     * back to the original declaration.
  +     * <p>
        * For plugins declared "in-line", the id is null.
        */
       public void setId(String id) {
           this.id = id;
       }
       
  -    /** 
  -     * Sets the name of a method which defines custom rules. May be null. 
  -     */
  -    public void setRuleMethod(String ruleMethodName) {
  -        this.ruleMethodName = ruleMethodName;
  -    }
  -    
  -    /** 
  -     * The name of a class containing a method which defines custom rules
  -     * for the plugin class. May be null. 
  -     */
  -    public void setRuleClass(Class ruleClass) {
  -        this.ruleClass = ruleClass;
  -    }
  -    
  -    /**
  -     * The name of a resource file in the classpath containg xmlrules
  -     * specifications of custom rules for the plugin class. May be null.
  -     */
  -    public void setRuleResource(String ruleResource) {
  -        this.ruleResource = ruleResource;
  -    }
  -    
  -    /**
  -     * The name of a file containg xmlrules specifications of custom rules 
  -     * for the plugin class. May be null.
  -     */
  -    public void setRuleFile(File ruleFile) {
  -        this.ruleFile = ruleFile;
  -    }
  -    
  -    /** See {@link #autoSetProperties}. */
  -    public void setAutoSetProperties(boolean autoSetProperties) {
  -        this.autoSetProperties = autoSetProperties;
  -    }
  -    
       /**
  -     * Return the id associated with this declaration.
  +     * Return the id associated with this declaration. For plugins
  +     * declared "inline", null will be returned.
        * 
        * @return The id value. May be null.
        */
  @@ -136,6 +105,23 @@
           return id;
       }
   
  +    /** 
  +     * Copy all (key,value) pairs in the param into the properties member of
  +     * this object.
  +     * <p>
  +     * The declaration properties cannot be explicit member variables,
  +     * because the set of useful properties a user can provide on a declaration
  +     * depends on what RuleFinder classes are available - and extra RuleFinders
  +     * can be added by the user. So here we keep a map of the settings, and
  +     * let the RuleFinder objects look for whatever properties they consider
  +     * significant.
  +     * <p>
  +     * The "id" and "class" properties are treated differently.
  +     */
  +    public void setProperties(Properties p) {
  +        properties.putAll(p);
  +    }
  +    
       /**
        * Return plugin class associated with this declaration.
        * 
  @@ -145,36 +131,13 @@
           return pluginClass;
       }
   
  -    /**
  -     * return class which specifies custom rules for this plugin.
  -     * 
  -     * @return The ruleClass value. May be null.
  -     */
  -    public Class getRuleClass() {
  -        return ruleClass;
  -    }
  -
  -    /**
  -     * Indicates whether plugins which do <i>not</i> implement custom rules
  -     * should have a SetProperties rule automatically associated with the
  -     * parent tag. In almost all cases this is desirable, so autoSetProperties
  -     * defaults to true. If for some reason you are plugging in a class 
  -     * without custom rules and you do not want xml attributes to be mapped
  -     * to bean properties, you can pass <i>false</i> here to disable this.
  -     * 
  -     * @return true if SetPropertiesRule is automatically applied.
  -     */
  -    public boolean autoSetProperties() {
  -        return autoSetProperties;
  -    }
  -
       //---------------------- methods -----------------------------------
       
       /**
        * Must be called exactly once, and must be called before any call
        * to the configure method.
        */
  -    public void init(Digester digester) throws PluginWrappedException {
  +    public void init(Digester digester, PluginManager pm) throws PluginException {
           Log log = digester.getLogger();
           boolean debug = log.isDebugEnabled();
           if (debug) {
  @@ -191,10 +154,35 @@
                   pluginClass = 
                       digester.getClassLoader().loadClass(pluginClassName);
               } catch(ClassNotFoundException cnfe) {
  -                throw new PluginWrappedException(
  +                throw new PluginException(
                       "Unable to load class " + pluginClassName, cnfe);
               }
           }
  +
  +        if (ruleLoader == null) {
  +            // the caller didn't provide a ruleLoader to the constructor,
  +            // so get the plugin manager to "discover" one.
  +            log.debug("Searching for ruleloader...");
  +            ruleLoader = pm.findLoader(digester, id, pluginClass, properties);
  +        } else {
  +            log.debug("This declaration has an explicit ruleLoader.");
  +        }
  +        
  +        if (debug) {
  +            if (ruleLoader == null) {
  +                log.debug(
  +                    "No ruleLoader found for plugin declaration"
  +                    + " id [" + id + "]"
  +                    + ", class [" + pluginClass.getClass().getName() + "].");
  +            } else {
  +                log.debug(
  +                    "RuleLoader of type [" + ruleLoader.getClass().getName()
  +                    + "] associated with plugin declaration"
  +                    + " id [" + id + "]"
  +                    + ", class [" + pluginClass.getClass().getName() + "].");
  +            }
  +        }
  +        
           initialized = true;        
       }
       
  @@ -202,49 +190,13 @@
        * Attempt to load custom rules for the target class at the specified
        * pattern.
        * <p>
  -     * <ol>
  -     * <li>If there is an explicit File, load from that file.</li>
  -     * <li>If there is an explicit Resource, load from that resource.</li>
  -     * <li>If there is an explicit RuleClass, load from that class.</li>
  -     * <li>If there is an explicit RuleMethod, load from that method.</li>
  -     * <li>If there is a default method, load from that method.</li>
  -     * <li>If there is a default RuleInfo class, load from that class.</li>
  -     * <li>If there is a default resource, load from that resource.</li>
  -     * </ol>
  -     * <p>
  -     * When loading from a File or Resource (a file in the classpath), the
  -     * contents of the file are expected to be xml in xmlrules format.
  -     * <p>
  -     * When loading from a RuleClass, that class is expected to have a
  -     * method with the signature <code>public static void addRules(Digester, 
  -     * String)</code>.
  -     * <p>
  -     * When loading from a specified Method on the plugin class, that method
  -     * is expected to have signature <code> public static void xxx(Digester, 
  -     * String)</code> where xxx is the specified method name.
  -     * <p>
  -     * When loading from the default method on the plugin class, the method
  -     * is expected to have signature <code>public static void addRules(Digester,
  -     * String)</code>.
  -     * <p>
  -     * When looking for a default RuleInfo class, the plugin class name has
  -     * the suffix "RuleInfo" applied to it. If there exists a class of that
  -     * name, then that class is expected to have an addRules method on it.
  -     * <p>
  -     * When looking for a default resource file, the plugin class name has
  -     * the suffix "RuleInfo.xml" applied to it. If there exists a resource
  -     * file of that name, then that file is expected to contain xmlrules
  -     * format rules.
  -     * <p>
  -     * The first source of rules found is used, and searching stops.
  -     * <p>
        * On return, any custom rules associated with the plugin class have
        * been loaded into the Rules object currently associated with the
        * specified digester object.
        */
        
       public void configure(Digester digester, String pattern)
  -                          throws PluginWrappedException {
  +                          throws PluginException {
           Log log = digester.getLogger();
           boolean debug = log.isDebugEnabled();
           if (debug) {
  @@ -254,160 +206,24 @@
           if (!initialized) {
               throw new PluginAssertionFailure("Not initialized.");
           }
  -        
  -        // load from explicit file
  -        if (ruleFile != null) {
  -            InputStream is = null;
  -            try {
  -                is = new FileInputStream(ruleFile);
  -            } catch(IOException ioe) {
  -                throw new PluginWrappedException(
  -                    "Unable to process file [" + ruleFile + "]", ioe);
  -            }
  -            loadRulesFromStream(is, digester, pattern);
  -            return;
  -        }
  -        
  -        // load from explicit resource in classpath
  -        if (ruleResource != null) {
  -            InputStream is = 
  -                pluginClass.getClassLoader().getResourceAsStream(
  -                    ruleResource);
  -            if (is != null) {
  -                loadRulesFromStream(is, digester, pattern);
  -                return;
  -            }
  -        }
  -
  -        // load via method on explicit Rule Class        
  -        if (ruleClass != null) {
  -            loadRulesFromClass(ruleClass, digester, pattern);
  -            return;
  -        }
  -
  -        // load via method on plugin class        
  -        {
  -            Class[] paramSpec = { Digester.class, String.class };
  -            Method ruleMethod = MethodUtils.getAccessibleMethod(
  -                pluginClass, ruleMethodName, paramSpec);
  -            if (ruleMethod != null) 
  -            {
  -                try {
  -                    Object[] params = {digester, pattern};
  -                    Object none = ruleMethod.invoke(null, params);
  -                } catch (Exception e) {
  -                    throw new PluginWrappedException(
  -                        "Unable to configure class [" + pluginClass + "]" +
  -                        " using method [" + ruleMethodName + "]", e);
  -                }
  -                return;
  -            }
  -        }
  -
  -        // look for rule class
  -        {
  -            if (debug) {
  -                log.debug("plugin class type:" + pluginClass.getName());
  -            }
  -            String ruleClassName = pluginClass.getName() + "RuleInfo";
  -
  -            Class ruleClass;
  -            try {
  -                ruleClass = digester.getClassLoader().loadClass(ruleClassName);
  -            } catch(ClassNotFoundException cnfe) {
  -                ruleClass = null;
  -            }
   
  -            if (ruleClass != null) {
  -                loadRulesFromClass(ruleClass, digester, pattern);
  -                return;
  -            }
  -        }
  -        
  -        // look for  resource
  -        {
  -            String resourceName = 
  -                pluginClass.getClass().getName().replace('.', '/') +
  -                "RuleInfo.xml";
  -            InputStream is = 
  -                pluginClass.getClassLoader().getResourceAsStream(
  -                    resourceName);
  -            if (is != null) {
  -                loadRulesFromStream(is, digester, pattern);
  -                return;
  -            }
  -        }
  -        
  -        // try autoSetProperties
  -        if (autoSetProperties) {
  -            if (debug) {
  -                log.debug("adding autoset for pattern [" + pattern + "]");
  -            }
  -            digester.addSetProperties(pattern);
  +        if (ruleLoader != null) {
  +            ruleLoader.addRules(digester, pattern);
           }
       }
   
       /**
  -     * Load custom rules from a specified stream of xml data.
  -     */
  -    private void loadRulesFromStream(InputStream is, Digester digester,
  -                                     String pattern) 
  -                                     throws PluginWrappedException {
  -        try
  -        {
  -            throw new PluginAssertionFailure(
  -                "Load from stream not yet supported.");
  -        }
  -        finally {
  -            try {
  -                is.close();
  -            } catch(IOException ioe) {
  -                Log log = digester.getLogger();
  -                log.warn("Unable to close stream after reading rules", ioe);
  -            }
  -        }
  -    }
  -    
  -    /**
  -     * Load custom rules from a specified class.
  -     */
  -    private void loadRulesFromClass(Class ruleClass, Digester digester,
  -                                    String pattern)
  -                                    throws PluginWrappedException {
  -        Class[] paramSpec = { Digester.class, String.class };
  -        Method ruleMethod = MethodUtils.getAccessibleMethod(
  -            ruleClass, ruleMethodName, paramSpec);
  -        if (ruleMethod == null) {
  -            throw new PluginWrappedException(
  -                "rule class specified, but rules method not found on it.");
  -        }
  -        try {
  -            Object[] params = {digester, pattern};
  -            Object none = ruleMethod.invoke(null, params);
  -        } catch (Exception e) {
  -            throw new PluginWrappedException(
  -                "Unable to configure class [" + pluginClass + "]" +
  -                " using rule class [" + ruleClass + "]" +
  -                " method [" + ruleMethodName + "]", e);
  -        } 
  -    }
  -    
  -    /**
        * Returns true if the declarations are equivalent. Perhaps this would be
        * better as overriding equals, but then I should really override hash as
        * well and I can't be bothered.
  -     * 
  +     *
        * @param d the Declaration object to be compared to this object.
        * @return true if the specified object has the same options as this one.
        */
       public boolean isEquivalent(Declaration d) {
           if (different(id, d.id)) return false;
           if (pluginClass != d.pluginClass) return false;
  -        if (different(ruleMethodName, d.ruleMethodName)) return false;
  -        if (ruleClass != d.ruleClass) return false;
  -        if (different(ruleResource, d.ruleResource)) return false;
  -        if (different(ruleFile, d.ruleFile)) return false;
  -        if (autoSetProperties != d.autoSetProperties) return false;
  +        if (!properties.equals(d.properties)) return false;
   
           // all significant fields match; these declarations are identical.
           return true;
  
  
  
  1.7       +4 -1      jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginConfigurationException.java
  
  Index: PluginConfigurationException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginConfigurationException.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- PluginConfigurationException.java	29 Feb 2004 02:22:15 -0000	1.6
  +++ PluginConfigurationException.java	7 Apr 2004 22:16:47 -0000	1.7
  @@ -18,7 +18,10 @@
   
   /**
    * Thrown when an error occurs due to the way the calling application uses
  - * the plugins module.
  + * the plugins module. Because the pre-existing Digester API doesn't provide
  + * any option for throwing checked exceptions at some points where Plugins
  + * can potentially fail, this exception extends RuntimeException so that it
  + * can "tunnel" through these points.
    */
   
   public class PluginConfigurationException extends RuntimeException {
  
  
  
  1.15      +84 -132   jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginCreateRule.java
  
  Index: PluginCreateRule.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginCreateRule.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- PluginCreateRule.java	23 Mar 2004 07:11:00 -0000	1.14
  +++ PluginCreateRule.java	7 Apr 2004 22:16:47 -0000	1.15
  @@ -33,31 +33,13 @@
    */
   public class PluginCreateRule extends Rule implements InitializableRule {
   
  -    // the xml attribute the user uses on an xml element to specify
  -    // the plugin's class
  -    public static final String GLOBAL_PLUGIN_CLASS_ATTR_NS = null;
  -    public static final String GLOBAL_PLUGIN_CLASS_ATTR = "plugin-class";
  -
  -    // the xml attribute the user uses on an xml element to specify
  -    // the plugin's class
  -    public static final String GLOBAL_PLUGIN_ID_ATTR_NS = null;
  -    public static final String GLOBAL_PLUGIN_ID_ATTR = "plugin-id";
  -    
  -    // see setGlobalPluginClassAttribute
  -    private static String globalPluginClassAttrNs = GLOBAL_PLUGIN_CLASS_ATTR_NS;
  -    private static String globalPluginClassAttr = GLOBAL_PLUGIN_CLASS_ATTR;
  -
  -    // see setGlobalPluginIdAttribute
  -    private static String globalPluginIdAttrNs = GLOBAL_PLUGIN_ID_ATTR_NS;
  -    private static String globalPluginIdAttr = GLOBAL_PLUGIN_ID_ATTR;
  -    
       // see setPluginClassAttribute
  -    private String pluginClassAttrNs = globalPluginClassAttrNs;
  -    private String pluginClassAttr = globalPluginClassAttr;
  +    private String pluginClassAttrNs = null;
  +    private String pluginClassAttr = null;
       
       // see setPluginIdAttribute
  -    private String pluginIdAttrNs = globalPluginIdAttrNs;
  -    private String pluginIdAttr = globalPluginIdAttr;
  +    private String pluginIdAttrNs = null;
  +    private String pluginIdAttr = null;
       
       /**
        * In order to invoke the addRules method on the plugin class correctly,
  @@ -83,76 +65,6 @@
        */
       private PluginConfigurationException initException;
   
  -    //-------------------- static methods -----------------------------------
  -    
  -    /**
  -     * Sets the xml attribute which the input xml uses to indicate to a 
  -     * PluginCreateRule which class should be instantiated.
  -     * <p>
  -     * Example:
  -     * <pre>
  -     * PluginCreateRule.setGlobalPluginClassAttribute(null, "class");
  -     * </pre>
  -     * will allow this in the input xml:
  -     * <pre>
  -     *  [root]
  -     *    [some-plugin class="com.acme.widget"] ......
  -     * </pre>
  -     *
  -     * Note that this changes the default for <i>all</i> PluginCreateRule
  -     * instances. To override just specific PluginCreateRule instances (which
  -     * may be more friendly in container-based environments), see method
  -     * setPluginClassAttribute.
  -     *
  -     * @param namespaceUri is the namespace uri that the specified attribute
  -     * is in. If the attribute is in no namespace, then this should be null.
  -     * Note that if a namespace is used, the attrName value should <i>not</i>
  -     * contain any kind of namespace-prefix. Note also that if you are using
  -     * a non-namespace-aware parser, this parameter <i>must</i> be null.
  -     *
  -     * @param attrName is the attribute whose value contains the name of the
  -     * class to be instantiated.
  -     */
  -    public static void setGlobalPluginClassAttribute(String namespaceUri, 
  -                                                     String attrName) {
  -        globalPluginClassAttrNs = namespaceUri;
  -        globalPluginClassAttr = attrName;
  -    }
  -
  -    /**
  -     * Sets the xml attribute which the input xml uses to indicate to a 
  -     * PluginCreateRule which plugin declaration is being referenced.
  -     * <p>
  -     * Example:
  -     * <pre>
  -     * PluginCreateRule.setGlobalPluginIdAttribute(null, "id");
  -     * </pre>
  -     * will allow this in the input xml:
  -     * <pre>
  -     *  [root]
  -     *    [some-plugin id="widget"] ......
  -     * </pre>
  -     *
  -     * Note that this changes the default for <i>all</i> PluginCreateRule
  -     * instances. To override just specific PluginCreateRule instances (which
  -     * may be more friendly in container-based environments), see method
  -     * setPluginIdAttribute.
  -     *
  -     * @param namespaceUri is the namespace uri that the specified attribute
  -     * is in. If the attribute is in no namespace, then this should be null.
  -     * Note that if a namespace is used, the attrName value should <i>not</i>
  -     * contain any kind of namespace-prefix. Note also that if you are using
  -     * a non-namespace-aware parser, this parameter <i>must</i> be null.
  -     *
  -     * @param attrName is the attribute whose value contains the id of the
  -     * plugin declaration to be used when instantiating an object.
  -     */
  -    public static void setGlobalPluginIdAttribute(String namespaceUri, 
  -                                                  String attrName) {
  -        globalPluginIdAttrNs = namespaceUri;
  -        globalPluginIdAttr = attrName;
  -    }
  -
       //-------------------- constructors -------------------------------------
   
       /**
  @@ -163,7 +75,6 @@
        * descended from.
        */
       public PluginCreateRule(Class baseClass) {
  -        super();
           this.baseClass = baseClass;
       }
   
  @@ -179,50 +90,42 @@
        * custom rules installed for it just like a declared plugin.
        */
       public PluginCreateRule(Class baseClass, Class dfltPluginClass) {
  -        super();
           this.baseClass = baseClass;
           if (dfltPluginClass != null) {
               defaultPlugin = new Declaration(dfltPluginClass);
           }
       }
   
  -    //------------------- properties ---------------------------------------
  +    /**
  +     * Create a plugin rule where the user <i>may</i> specify a plugin.
  +     * If the user doesn't specify a plugin, then the default class specified 
  +     * in this constructor is used.
  +     * 
  +     * @param baseClass is the class which any specified plugin <i>must</i> be
  +     * descended from.
  +     * @param dfltPluginClass is the class which will be used if the user
  +     * doesn't specify any plugin-class or plugin-id. This class will have
  +     * custom rules installed for it just like a declared plugin.
  +     * @param dfltPluginRuleLoader is a RuleLoader instance which knows how
  +     * to load the custom rules associated with this default plugin.
  +     */
  +    public PluginCreateRule(Class baseClass, Class dfltPluginClass,
  +                    RuleLoader dfltPluginRuleLoader) {
   
  -    public void setDefaultRuleMethod(String dfltPluginRuleMethod) {
  -        if (defaultPlugin != null) {
  -            defaultPlugin.setRuleMethod(dfltPluginRuleMethod);
  -        }
  -    }
  -    
  -    public void setDefaultRuleClass(Class dfltPluginRuleClass) {
  -        if (defaultPlugin != null) {
  -            defaultPlugin.setRuleClass(dfltPluginRuleClass);
  -        }
  -    }
  -    
  -    public void setDefaultRuleResource(String dfltPluginRuleResource) {
  -        if (defaultPlugin != null) {
  -            defaultPlugin.setRuleResource(dfltPluginRuleResource);
  -        }
  -    }
  -    
  -    public void setDefaultRuleFile(String dfltPluginRuleFile) {
  -        if (defaultPlugin != null) {
  -            defaultPlugin.setRuleFile(new File(dfltPluginRuleFile));
  +        this.baseClass = baseClass;
  +        if (dfltPluginClass != null) {
  +            defaultPlugin = 
  +                new Declaration(dfltPluginClass, dfltPluginRuleLoader);
           }
       }
   
  -    public void setDefaultRuleAutoSetProperties(boolean enabled) {
  -        if (defaultPlugin != null) {
  -            defaultPlugin.setAutoSetProperties(enabled);
  -        }
  -    }
  +    //------------------- properties ---------------------------------------
       
       /**
        * Sets the xml attribute which the input xml uses to indicate to a 
        * PluginCreateRule which class should be instantiated.
        * <p>
  -     * See setGlobalPluginClassAttribute for more info.
  +     * See {@link PluginRules#setPluginClassAttribute} for more info.
        */
       public void setPluginClassAttribute(String namespaceUri, String attrName) {
           pluginClassAttrNs = namespaceUri;
  @@ -233,7 +136,7 @@
        * Sets the xml attribute which the input xml uses to indicate to a 
        * PluginCreateRule which plugin declaration is being referenced.
        * <p>
  -     * See setGlobalPluginIdAttribute for more info.
  +     * See {@link PluginRules#setPluginIdAttribute} for more info.
        */
       public void setPluginIdAttribute(String namespaceUri, String attrName) {
           pluginIdAttrNs = namespaceUri;
  @@ -257,7 +160,7 @@
           boolean debug = log.isDebugEnabled();
           if (debug) {
               log.debug("PluginCreateRule.postRegisterInit" + 
  -                      ": rule registered for pattern [" + pattern + "]");
  +                      ": rule registered for pattern [" + matchPattern + "]");
           }
   
           if (digester == null) {
  @@ -309,6 +212,9 @@
               baseClass = Object.class;
           }
           
  +        PluginRules rules = (PluginRules) digester.getRules();
  +        PluginManager pm = rules.getPluginManager();
  +
           // check default class is valid
           if (defaultPlugin != null) {
               if (!baseClass.isAssignableFrom(defaultPlugin.getPluginClass())) {
  @@ -321,9 +227,9 @@
               }
   
               try {
  -                defaultPlugin.init(digester);
  +                defaultPlugin.init(digester, pm);
                   
  -            } catch(PluginWrappedException pwe) {
  +            } catch(PluginException pwe) {
               
                   throw new PluginConfigurationException(
                       pwe.getMessage(), pwe.getCause());
  @@ -332,6 +238,48 @@
   
           // remember the pattern for later
           pattern = matchPattern;
  +        
  +        if (pluginClassAttr ==  null) {
  +            // the user hasn't set explicit xml attr names on this rule,
  +            // so fetch the default values
  +            pluginClassAttrNs = rules.getPluginClassAttrNs();
  +            pluginClassAttr = rules.getPluginClassAttr();
  +            
  +            if (debug) {
  +                log.debug(
  +                    "init: pluginClassAttr set to per-digester values ["
  +                    + "ns=" + pluginClassAttrNs 
  +                    + ", name=" + pluginClassAttr + "]");
  +            }
  +        } else {
  +            if (debug) {
  +                log.debug(
  +                    "init: pluginClassAttr set to rule-specific values ["
  +                    + "ns=" + pluginClassAttrNs 
  +                    + ", name=" + pluginClassAttr + "]");
  +            }
  +        }
  +        
  +        if (pluginIdAttr ==  null) {
  +            // the user hasn't set explicit xml attr names on this rule,
  +            // so fetch the default values
  +            pluginIdAttrNs = rules.getPluginIdAttrNs();
  +            pluginIdAttr = rules.getPluginIdAttr();
  +            
  +            if (debug) {
  +                log.debug(
  +                    "init: pluginIdAttr set to per-digester values ["
  +                    + "ns=" + pluginIdAttrNs 
  +                    + ", name=" + pluginIdAttr + "]");
  +            }
  +        } else {
  +            if (debug) {
  +                log.debug(
  +                    "init: pluginIdAttr set to rule-specific values ["
  +                    + "ns=" + pluginIdAttrNs 
  +                    + ", name=" + pluginIdAttr + "]");
  +            }
  +        }
       }
   
       /**
  @@ -407,21 +355,26 @@
           String pluginId; 
           if (pluginIdAttrNs == null) {
               pluginId = attributes.getValue(pluginIdAttr);
  -        }
  -        else {
  +        } else {
               pluginId = 
                   attributes.getValue(pluginIdAttrNs, pluginIdAttr);
           }
           
           if (pluginClassName != null) {
  +            // The user is using a plugin "inline", ie without a previous
  +            // explicit declaration. If they have used the same plugin class
  +            // before, we have already gone to the effort of creating a 
  +            // Declaration object, so retrieve it. If there is no existing
  +            // declaration object for this class, then create one.
  +
               currDeclaration = pluginManager.getDeclarationByClass(
                   pluginClassName);
   
               if (currDeclaration == null) {
                   currDeclaration = new Declaration(pluginClassName);
                   try {
  -                    currDeclaration.init(digester);
  -                } catch(PluginWrappedException pwe) {
  +                    currDeclaration.init(digester, pluginManager);
  +                } catch(PluginException pwe) {
                       throw new PluginInvalidInputException(
                           pwe.getMessage(), pwe.getCause());
                   }
  @@ -436,8 +389,7 @@
               }
           } else if (defaultPlugin != null) {
               currDeclaration = defaultPlugin;
  -        }
  -        else {
  +        } else {
               throw new PluginInvalidInputException(
                   "No plugin class specified for element " +
                   pattern);
  
  
  
  1.11      +14 -41    jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginDeclarationRule.java
  
  Index: PluginDeclarationRule.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginDeclarationRule.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- PluginDeclarationRule.java	29 Feb 2004 02:22:15 -0000	1.10
  +++ PluginDeclarationRule.java	7 Apr 2004 22:16:47 -0000	1.11
  @@ -16,7 +16,7 @@
   
   package org.apache.commons.digester.plugins;
   
  -import java.io.File;
  +import java.util.Properties;
   
   import org.apache.commons.digester.Rule;
   import org.apache.commons.digester.Digester;
  @@ -69,17 +69,7 @@
           
           String id = attributes.getValue("id");
           String pluginClassName = attributes.getValue("class");
  -        String ruleMethodName = attributes.getValue("method");
  -        String ruleClassName = attributes.getValue("ruleclass");
  -        String ruleResource = attributes.getValue("resource");
  -        String ruleFile = attributes.getValue("file");
  -        String autoSetPropertiesStr = attributes.getValue("setprops");
  -
  -        if (debug) {
  -            log.debug(
  -                "mapping id [" + id + "] -> [" + pluginClassName + "]");
  -        }
  -
  +        
           if (id == null) {
               throw new PluginInvalidInputException(
                       "mandatory attribute id not present on tag" +
  @@ -92,38 +82,20 @@
                          " <" + name + ">");
           }
   
  -        Declaration newDecl = new Declaration(pluginClassName);
  -        newDecl.setId(id);
  -        
  -        if (ruleMethodName != null) {
  -            newDecl.setRuleMethod(ruleMethodName);
  -        }
  -        
  -        if (ruleClassName != null) {
  -            Class ruleClass;
  -            try {
  -                ruleClass = digester.getClassLoader().loadClass(ruleClassName);
  -            } catch(ClassNotFoundException cnfe) {
  -                throw new ClassNotFoundException(
  -                    "Rule class [" + ruleClassName + "] not found.");
  +        int nAttrs = attributes.getLength();
  +        Properties props = new Properties();
  +        for(int i=0; i<nAttrs; ++i) {
  +            String key = attributes.getLocalName(i);
  +            if ((key == null) || (key.length() == 0)) {
  +                key = attributes.getQName(i);
               }
  -            newDecl.setRuleClass(ruleClass);
  +            String value = attributes.getValue(i);
  +            props.setProperty(key, value);
           }
           
  -        if (ruleResource != null) {
  -            newDecl.setRuleResource(ruleResource);
  -        }
  -        
  -        if (ruleFile != null) {
  -            newDecl.setRuleFile(new File(ruleFile));
  -        }
  -        
  -        if (autoSetPropertiesStr != null) {
  -            newDecl.setAutoSetProperties(
  -                Boolean.valueOf(autoSetPropertiesStr).booleanValue());
  -        }
  -        
  -        newDecl.init(digester);
  +        Declaration newDecl = new Declaration(pluginClassName);
  +        newDecl.setId(id);
  +        newDecl.setProperties(props);
   
           PluginRules rc = (PluginRules) digester.getRules();
           PluginManager pm = rc.getPluginManager();
  @@ -155,6 +127,7 @@
                        " which has already been mapped by some other id.");
           }
   
  +        newDecl.init(digester, pm);
           pm.addDeclaration(newDecl);
       }
   }
  
  
  
  1.7       +1 -1      jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginInvalidInputException.java
  
  Index: PluginInvalidInputException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginInvalidInputException.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- PluginInvalidInputException.java	29 Feb 2004 02:22:15 -0000	1.6
  +++ PluginInvalidInputException.java	7 Apr 2004 22:16:47 -0000	1.7
  @@ -19,7 +19,7 @@
   /**
    * Thrown when an error occurs due to bad data in the file being parsed.
    */
  -public class PluginInvalidInputException extends Exception {
  +public class PluginInvalidInputException extends PluginException {
   
       private Throwable cause = null;
   
  
  
  
  1.10      +69 -6     jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginManager.java
  
  Index: PluginManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginManager.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- PluginManager.java	29 Feb 2004 02:22:15 -0000	1.9
  +++ PluginManager.java	7 Apr 2004 22:16:47 -0000	1.10
  @@ -17,6 +17,9 @@
   package org.apache.commons.digester.plugins;
   
   import java.util.HashMap;
  +import java.util.List;
  +import java.util.Properties;
  +import java.util.Iterator;
   
   import org.apache.commons.digester.Digester;
   
  @@ -26,8 +29,7 @@
    * Coordinates between PluginDeclarationRule and PluginCreateRule objects,
    * providing a place to share data between instances of these rules.
    * <p>
  - * One instance of this class exists per PluginRules instance,
  - * ie one per Digester instance.
  + * One instance of this class exists per PluginRules instance.
    */
   
   public class PluginManager {
  @@ -40,16 +42,33 @@
   
       /** the parent manager to which this one may delegate lookups. */
       private PluginManager parent;
  -
  +    
  +    /** 
  +     * The object containing data that should only exist once for each
  +     * Digester instance.
  +     */
  +    private PluginContext pluginContext;
  +    
       //------------------- constructors ---------------------------------------
       
  -    /** Constructor. */
  -    public PluginManager() {
  +    /** Construct a "root" PluginManager, ie one with no parent. */
  +    public PluginManager(PluginContext r) {
  +        pluginContext = r;
       }
   
  -    /** Constructor. */
  +    /** 
  +     * Construct a "child" PluginManager. When declarations are added to
  +     * a "child", they are stored within the child and do not modify the
  +     * parent, so when the child goes out of scope, those declarations
  +     * disappear. When asking a "child" to retrieve a declaration, it 
  +     * delegates the search to its parent if it does not hold a matching
  +     * entry itself.
  +     * <p>
  +     * @param parent must be non-null.
  +     */
       public PluginManager(PluginManager parent) {
           this.parent = parent;
  +        this.pluginContext = parent.pluginContext;
       }
       
       //------------------- methods --------------------------------------------
  @@ -112,5 +131,49 @@
           }
   
           return decl;
  +    }
  +
  +    /**
  +     * Given a plugin class and some associated properties, scan the
  +     * list of known RuleFinder instances until one detects a source of
  +     * custom rules for this plugin (aka a RuleLoader).
  +     * <p>
  +     * If no source of custom rules can be found, null is returned.
  +     */
  +    public RuleLoader findLoader(Digester digester, String id, 
  +                        Class pluginClass, Properties props) 
  +                        throws PluginException {    
  +
  +        // iterate over the list of RuleFinders, trying each one 
  +        // until one of them locates a source of dynamic rules given
  +        // this specific plugin class and the associated declaration 
  +        // properties.
  +        Log log = LogUtils.getLogger(digester);
  +        boolean debug = log.isDebugEnabled();
  +        log.debug("scanning ruleFinders to locate loader..");
  +        
  +        List ruleFinders = pluginContext.getRuleFinders();
  +        RuleLoader ruleLoader = null;
  +        try {
  +            for(Iterator i = ruleFinders.iterator(); 
  +                i.hasNext() && ruleLoader == null; ) {
  +                    
  +                RuleFinder finder = (RuleFinder) i.next();
  +                if (debug) {
  +                    log.debug("checking finder of type " + finder.getClass().getName());
  +                }
  +                ruleLoader = finder.findLoader(digester, pluginClass, props);
  +            }
  +        }
  +        catch(PluginException e) {
  +            throw new PluginException(
  +                "Unable to locate plugin rules for plugin"
  +                + " with id [" + id + "]"
  +                + ", and class [" + pluginClass.getName() + "]"
  +                + ":" + e.getMessage(), e.getCause());
  +        }
  +        log.debug("scanned ruleFinders.");
  +        
  +        return ruleLoader;
       }
   }
  
  
  
  1.13      +64 -6     jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginRules.java
  
  Index: PluginRules.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginRules.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- PluginRules.java	23 Mar 2004 07:11:00 -0000	1.12
  +++ PluginRules.java	7 Apr 2004 22:16:47 -0000	1.13
  @@ -82,6 +82,12 @@
        */
       private PluginRules parent = null;
       
  +    /**
  +     * A reference to the object that holds all data which should only
  +     * exist once per digester instance.
  +     */
  +    private PluginContext pluginContext = null;
  +    
       // ------------------------------------------------------------- Constructor
       
       /**
  @@ -90,8 +96,7 @@
        * object before parsing starts.
        */
       public PluginRules() {
  -        decoratedRules = new RulesBase();
  -        pluginManager = new PluginManager();
  +        this(new RulesBase());
       }
   
       /**
  @@ -100,7 +105,9 @@
        */
       public PluginRules(Rules decoratedRules) {
           this.decoratedRules = decoratedRules;
  -        pluginManager = new PluginManager();
  +
  +        pluginContext = new PluginContext();
  +        pluginManager = new PluginManager(pluginContext);
       }
   
       /**
  @@ -110,6 +117,11 @@
        * One of these is created each time a PluginCreateRule's begin method 
        * fires, in order to manage the custom rules associated with whatever 
        * concrete plugin class the user has specified.
  +     *
  +     * @param mountPoint is the digester match path for the element 
  +     * matching a PluginCreateRule which caused this "nested parsing scope"
  +     * to begin.
  +     * @param parent must be non-null.
        */
        PluginRules(String mountPoint, PluginRules parent) {
           // no need to set digester or decoratedRules.digester,
  @@ -117,6 +129,7 @@
           // method on this object will be called.
           
           decoratedRules = new RulesBase();
  +        pluginContext = parent.pluginContext;
           pluginManager = new PluginManager(parent.pluginManager);
           
           this.mountPoint = mountPoint;
  @@ -177,7 +190,21 @@
       public PluginManager getPluginManager() {
           return pluginManager;
       }
  -
  +    
  +    /**
  +     * See {@link PluginContext#getRuleFinders}.
  +     */
  +    public List getRuleFinders() {
  +        return pluginContext.getRuleFinders();
  +    }
  +    
  +    /**
  +     * See {@link PluginContext#setRuleFinders}.
  +     */
  +    public void setRuleFinders(List ruleFinders) {
  +        pluginContext.setRuleFinders(ruleFinders);
  +    }
  +    
       // --------------------------------------------------------- Public Methods
   
       /**
  @@ -329,11 +356,42 @@
               // even though this object may hold some rules matching
               // this same path. See PluginCreateRule's begin, body and end
               // methods for the reason.
  -        } 
  -        else {
  +        } else {
               matches = decoratedRules.match(namespaceURI, path); 
           }
   
           return matches;
  +    }
  +
  +    /** See {@link PluginContext#setPluginClassAttribute}. */
  +    public void setPluginClassAttribute(String namespaceUri, 
  +                                        String attrName) {
  +        pluginContext.setPluginClassAttribute(namespaceUri, attrName);
  +    }
  +
  +    /** See {@link PluginContext#setPluginIdAttribute}. */
  +    public void setPluginIdAttribute(String namespaceUri, 
  +                                     String attrName) {
  +        pluginContext.setPluginIdAttribute(namespaceUri, attrName);
  +    }
  +    
  +    /** See {@link PluginContext#getPluginClassAttrNs}. */
  +    public String getPluginClassAttrNs() {
  +        return pluginContext.getPluginClassAttrNs();
  +    }
  +    
  +    /** See {@link PluginContext#getPluginClassAttr}. */
  +    public String getPluginClassAttr() {
  +        return pluginContext.getPluginClassAttr();
  +    }
  +    
  +    /** See {@link PluginContext#getPluginIdAttrNs}. */
  +    public String getPluginIdAttrNs() {
  +        return pluginContext.getPluginIdAttrNs();
  +    }
  +    
  +    /** See {@link PluginContext#getPluginIdAttr}. */
  +    public String getPluginIdAttr() {
  +        return pluginContext.getPluginIdAttr();
       }
   }
  
  
  
  1.2       +239 -0    jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginContext.java
  
  
  
  
  1.2       +58 -0     jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginException.java
  
  
  
  
  1.2       +72 -0     jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/RuleFinder.java
  
  
  
  
  1.2       +46 -0     jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/RuleLoader.java
  
  
  
  
  1.2       +124 -0    jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/strategies/FinderFromClass.java
  
  
  
  
  1.2       +92 -0     jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/strategies/FinderFromDfltClass.java
  
  
  
  
  1.2       +77 -0     jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/strategies/FinderFromDfltMethod.java
  
  
  
  
  1.2       +87 -0     jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/strategies/FinderFromDfltResource.java
  
  
  
  
  1.2       +102 -0    jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/strategies/FinderFromFile.java
  
  
  
  
  1.2       +75 -0     jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/strategies/FinderFromMethod.java
  
  
  
  
  1.2       +118 -0    jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/strategies/FinderFromResource.java
  
  
  
  
  1.2       +98 -0     jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/strategies/FinderSetProperties.java
  
  
  
  
  1.2       +99 -0     jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/strategies/LoaderFromClass.java
  
  
  
  
  1.2       +90 -0     jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/strategies/LoaderFromStream.java
  
  
  
  
  1.2       +51 -0     jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/strategies/LoaderSetProperties.java
  
  
  
  
  1.2       +62 -0     jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/strategies/package.html
  
  
  
  
  1.27      +21 -2     jakarta-commons/digester/src/java/org/apache/commons/digester/xmlrules/DigesterRuleParser.java
  
  Index: DigesterRuleParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/xmlrules/DigesterRuleParser.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- DigesterRuleParser.java	28 Feb 2004 13:32:53 -0000	1.26
  +++ DigesterRuleParser.java	7 Apr 2004 22:16:55 -0000	1.27
  @@ -76,7 +76,9 @@
        * from the Rules XML document.
        */
       protected Digester targetDigester;
  -    
  +
  +    /** See {@link #setBasePath}. */
  +    protected String basePath = "";
       
       /**
        * A stack whose toString method returns a '/'-separated concatenation
  @@ -155,6 +157,22 @@
       }
       
       /**
  +     * Set a base pattern beneath which all the rules loaded by this
  +     * object will be registered. If this string is not empty, and does
  +     * not end in a "/", then one will be added.
  +     */
  +    public void setBasePath(String path) {
  +        if (path == null) {
  +            basePath = "";
  +        }
  +        else if ((path.length() > 0) && !path.endsWith("/")) {
  +            basePath = path + "/";
  +        } else {
  +            basePath = path;
  +        }
  +    }
  +
  +    /**
        * Sets the location of the digester rules DTD. This is the DTD used
        * to validate the rules XML file.
        */
  @@ -181,7 +199,8 @@
        * @param rule a Rule to add to the target digester.
        */
       public void add(Rule rule) {
  -        targetDigester.addRule(patternStack.toString(), rule);
  +        targetDigester.addRule(
  +            basePath + patternStack.toString(), rule);
       }
       
       
  
  
  
  1.13      +23 -0     jakarta-commons/digester/src/java/org/apache/commons/digester/xmlrules/FromXmlRuleSet.java
  
  Index: FromXmlRuleSet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/xmlrules/FromXmlRuleSet.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- FromXmlRuleSet.java	28 Feb 2004 13:32:53 -0000	1.12
  +++ FromXmlRuleSet.java	7 Apr 2004 22:16:55 -0000	1.13
  @@ -138,6 +138,28 @@
        * @see org.apache.commons.digester.RuleSetBase
        */
       public void addRuleInstances(org.apache.commons.digester.Digester digester) throws XmlLoadException {
  +        addRuleInstances(digester, null);
  +    }
  +    
  +    /**
  +     * Adds to the digester the set of Rule instances defined in the
  +     * XML file for this rule set.
  +     * <p>
  +     * Note that this method doesn't have a matching one on the DigesterLoader
  +     * class, because it is not expected to be widely used, and DigesterLoader's
  +     * load method is already heavily overloaded.
  +     *
  +     * @param digester is the digester that rules will be added to.
  +     * @param basePath is a path that will be prefixed to every
  +     * pattern string defined in the xmlrules input file.
  +     *
  +     * @see org.apache.commons.digester.RuleSetBase
  +     */
  +    public void addRuleInstances(
  +    org.apache.commons.digester.Digester digester,
  +    String basePath) 
  +    throws XmlLoadException {
  +        
           URL dtdURL = getClass().getClassLoader().getResource(DIGESTER_DTD_PATH);
           if (dtdURL == null) {
               throw new XmlLoadException("Cannot find resource \"" +
  @@ -145,6 +167,7 @@
           }
           parser.setDigesterRulesDTD(dtdURL.toString());
           parser.setTarget(digester);
  +        parser.setBasePath(basePath);
   
           rulesDigester.addRuleSet(parser);
           rulesDigester.push(parser);
  
  
  
  1.6       +1 -0      jakarta-commons/digester/src/test/org/apache/commons/digester/plugins/TestAll.java
  
  Index: TestAll.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/plugins/TestAll.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TestAll.java	28 Feb 2004 13:32:54 -0000	1.5
  +++ TestAll.java	7 Apr 2004 22:16:55 -0000	1.6
  @@ -47,6 +47,7 @@
   
       public static Test suite() {
           TestSuite suite = new TestSuite();
  +        suite.addTest(TestXmlRuleInfo.suite());
           suite.addTest(TestInline.suite());
           suite.addTest(TestDelegate.suite());
           suite.addTest(TestDeclaration.suite());
  
  
  
  1.3       +45 -52    jakarta-commons/digester/src/test/org/apache/commons/digester/plugins/TestConfigurablePluginAttributes.java
  
  Index: TestConfigurablePluginAttributes.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/plugins/TestConfigurablePluginAttributes.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestConfigurablePluginAttributes.java	28 Feb 2004 13:32:54 -0000	1.2
  +++ TestConfigurablePluginAttributes.java	7 Apr 2004 22:16:56 -0000	1.3
  @@ -119,61 +119,50 @@
           PluginRules rc = new PluginRules();
           digester.setRules(rc);
   
  -        PluginCreateRule.setGlobalPluginIdAttribute(null, "id");
  -        PluginCreateRule.setGlobalPluginClassAttribute(null, "class");
  +        rc.setPluginIdAttribute(null, "id");
  +        rc.setPluginClassAttribute(null, "class");
        
  +        PluginDeclarationRule pdr = new PluginDeclarationRule();
  +        digester.addRule("root/plugin", pdr);
  +        
  +        PluginCreateRule widgetPluginRule = new PluginCreateRule(Widget.class);
  +        digester.addRule("root/widget", widgetPluginRule);
  +        digester.addSetNext("root/widget", "addWidget");
  +
  +        PluginCreateRule gadgetPluginRule = new PluginCreateRule(Widget.class);
  +        digester.addRule("root/gadget", gadgetPluginRule);
  +        digester.addSetNext("root/gadget", "addGadget");
  +
  +        MultiContainer root = new MultiContainer();
  +        digester.push(root);
  +        
           try {
  -            PluginDeclarationRule pdr = new PluginDeclarationRule();
  -            digester.addRule("root/plugin", pdr);
  -            
  -            PluginCreateRule widgetPluginRule = new PluginCreateRule(Widget.class);
  -            digester.addRule("root/widget", widgetPluginRule);
  -            digester.addSetNext("root/widget", "addWidget");
  -    
  -            PluginCreateRule gadgetPluginRule = new PluginCreateRule(Widget.class);
  -            digester.addRule("root/gadget", gadgetPluginRule);
  -            digester.addSetNext("root/gadget", "addGadget");
  -    
  -            MultiContainer root = new MultiContainer();
  -            digester.push(root);
  -            
  -            try {
  -                digester.parse(
  -                    TestAll.getInputStream(this, "test7.xml"));
  -                    
  -            } catch(Exception e) {
  -                throw e;
  -            }
  -    
  -            Object child;
  -            
  -            List widgets = root.getWidgets();
  -            assertTrue(widgets != null);
  -            assertEquals(4, widgets.size());
  -    
  -            assertEquals(Slider.class, widgets.get(0).getClass());
  -            assertEquals(Slider.class, widgets.get(1).getClass());
  -            assertEquals(Slider.class, widgets.get(2).getClass());
  -            assertEquals(Slider.class, widgets.get(3).getClass());
  -            
  -            List gadgets = root.getGadgets();
  -            assertTrue(gadgets != null);
  -            assertEquals(4, gadgets.size());
  -    
  -            assertEquals(Slider.class, gadgets.get(0).getClass());
  -            assertEquals(Slider.class, gadgets.get(1).getClass());
  -            assertEquals(Slider.class, gadgets.get(2).getClass());
  -            assertEquals(Slider.class, gadgets.get(3).getClass());
  -        } finally {
  -            // reset the global values to their defaults
  -            PluginCreateRule.setGlobalPluginIdAttribute(
  -                PluginCreateRule.GLOBAL_PLUGIN_ID_ATTR_NS,
  -                PluginCreateRule.GLOBAL_PLUGIN_ID_ATTR);
  +            digester.parse(
  +                TestAll.getInputStream(this, "test7.xml"));
                   
  -            PluginCreateRule.setGlobalPluginClassAttribute(
  -                PluginCreateRule.GLOBAL_PLUGIN_CLASS_ATTR_NS,
  -                PluginCreateRule.GLOBAL_PLUGIN_CLASS_ATTR);
  +        } catch(Exception e) {
  +            throw e;
           }
  +
  +        Object child;
  +        
  +        List widgets = root.getWidgets();
  +        assertTrue(widgets != null);
  +        assertEquals(4, widgets.size());
  +
  +        assertEquals(Slider.class, widgets.get(0).getClass());
  +        assertEquals(Slider.class, widgets.get(1).getClass());
  +        assertEquals(Slider.class, widgets.get(2).getClass());
  +        assertEquals(Slider.class, widgets.get(3).getClass());
  +        
  +        List gadgets = root.getGadgets();
  +        assertTrue(gadgets != null);
  +        assertEquals(4, gadgets.size());
  +
  +        assertEquals(Slider.class, gadgets.get(0).getClass());
  +        assertEquals(Slider.class, gadgets.get(1).getClass());
  +        assertEquals(Slider.class, gadgets.get(2).getClass());
  +        assertEquals(Slider.class, gadgets.get(3).getClass());
       }
       
       public void testInstanceOverride() throws Exception {
  @@ -188,7 +177,11 @@
   
           PluginDeclarationRule pdr = new PluginDeclarationRule();
           digester.addRule("root/plugin", pdr);
  -        
  +
  +        // for plugins at pattern "root/widget", use xml attributes "id" and
  +        // "class" in the custom namespace as the values for plugin id and
  +        // class, not the default (and non-namespaced) values of 
  +        // "plugin-id" and "plugin-class".
           PluginCreateRule widgetPluginRule = new PluginCreateRule(Widget.class);
           widgetPluginRule.setPluginIdAttribute(
               "http://jakarta.apache.org/digester/plugins", "id");
  
  
  
  1.5       +3 -1      jakarta-commons/digester/src/test/org/apache/commons/digester/plugins/TestLocalRules.java
  
  Index: TestLocalRules.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/plugins/TestLocalRules.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestLocalRules.java	28 Feb 2004 13:32:54 -0000	1.4
  +++ TestLocalRules.java	7 Apr 2004 22:16:57 -0000	1.5
  @@ -111,7 +111,9 @@
       
       public void testNonStandardLocalRules() throws Exception {
           // * tests that using PluginDeclarationRule to declare an alternate
  -        //   rule method name invokes that alternate method instead.
  +        //   rule method name invokes that alternate method instead (the
  +        //   input xml specifies that a method other than addRules is to
  +        //   be used)
           // * tests that if a rule method is defined, then a SetProperties
           //   rule is not automatically added.
           // * tests that a SetProperties rule applying to one class doesn't
  
  
  
  1.2       +37 -0     jakarta-commons/digester/src/test/org/apache/commons/digester/plugins/TestObject.java
  
  
  
  
  1.2       +9 -0      jakarta-commons/digester/src/test/org/apache/commons/digester/plugins/TestObjectRuleInfo.xml
  
  
  
  
  1.2       +171 -0    jakarta-commons/digester/src/test/org/apache/commons/digester/plugins/TestXmlRuleInfo.java
  
  
  
  
  1.2       +9 -0      jakarta-commons/digester/src/test/org/apache/commons/digester/plugins/xmlrules1.xml
  
  
  
  
  1.2       +9 -0      jakarta-commons/digester/src/test/org/apache/commons/digester/plugins/xmlrules2.xml
  
  
  
  
  1.9       +1 -0      jakarta-commons/digester/src/test/org/apache/commons/digester/xmlrules/DigesterLoaderTestSuite.java
  
  Index: DigesterLoaderTestSuite.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/xmlrules/DigesterLoaderTestSuite.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DigesterLoaderTestSuite.java	28 Feb 2004 13:32:55 -0000	1.8
  +++ DigesterLoaderTestSuite.java	7 Apr 2004 22:16:59 -0000	1.9
  @@ -40,6 +40,7 @@
   
       public static junit.framework.Test suite() {
           TestSuite suite = new TestSuite();
  +        suite.addTestSuite(FromXmlRuleSetTest.class);
           suite.addTestSuite(DigesterLoaderTest.class);
           suite.addTestSuite(DigesterPatternStackTest.class);
           suite.addTestSuite(DigesterLoaderRulesTest.class);
  
  
  
  1.2       +108 -0    jakarta-commons/digester/src/test/org/apache/commons/digester/xmlrules/FromXmlRuleSetTest.java
  
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message