commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject cvs commit: jakarta-commons/digester/src/java/org/apache/commons/digester/xmlrules DigesterLoader.java DigesterRuleParser.java FromXmlRuleSet.java
Date Tue, 20 Aug 2002 21:15:14 GMT
rdonkin     2002/08/20 14:15:14

  Modified:    digester/src/java/org/apache/commons/digester/xmlrules
                        DigesterLoader.java DigesterRuleParser.java
                        FromXmlRuleSet.java
  Log:
  Applied patch enabling more sophisticated classloader management for xmlrules digestion.
This allows xml files packed in a ear file to be found by an xmlrules digester in j2ee server.
Submitted by Henri Chen.
  
  Revision  Changes    Path
  1.3       +19 -0     jakarta-commons/digester/src/java/org/apache/commons/digester/xmlrules/DigesterLoader.java
  
  Index: DigesterLoader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/xmlrules/DigesterLoader.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DigesterLoader.java	9 Jan 2002 20:22:50 -0000	1.2
  +++ DigesterLoader.java	20 Aug 2002 21:15:14 -0000	1.3
  @@ -74,6 +74,7 @@
    *
    * @author David H. Martin - Initial Contribution
    * @author Scott Sanders   - Added ASL, removed external dependencies
  + * @author Henri Chen - Added rulesDigester
    */
   
   public class DigesterLoader {
  @@ -85,6 +86,24 @@
        */
       public static Digester createDigester(URL rulesXml) {
           RuleSet ruleSet = new FromXmlRuleSet(rulesXml);
  +        Digester digester = new Digester();
  +        digester.addRuleSet(ruleSet);
  +        return digester;
  +    }
  +
  +    /**
  +     * Creates a new digester and initializes it from the specified XML file.
  +     * This constructor allows specifing a rulesDigester to do the XML file
  +     * loading; thus no matter the XML files is packed into a jar, a war, or a
  +     * ear, the rulesDigester can always find the XML files with properly set
  +     * ClassLoader.
  +     *
  +     * @param rulesXml URL to the XML file defining the digester rules
  +     * @param rulesDigester digester to load the specified XML file.
  +     * @return a new Digester initialized with the rules
  +     */
  +    public static Digester createDigester(URL rulesXml, Digester rulesDigester) {
  +        RuleSet ruleSet = new FromXmlRuleSet(rulesXml, rulesDigester);
           Digester digester = new Digester();
           digester.addRuleSet(ruleSet);
           return digester;
  
  
  
  1.8       +10 -6     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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DigesterRuleParser.java	8 Aug 2002 20:00:23 -0000	1.7
  +++ DigesterRuleParser.java	20 Aug 2002 21:15:14 -0000	1.8
  @@ -238,7 +238,7 @@
           digester.addFactoryCreate("*/set-properties-rule", new SetPropertiesRuleFactory());
           digester.addRule("*/set-properties-rule", new PatternRule(digester, "pattern"));
           digester.addSetNext("*/set-properties-rule", "add", ruleClassName);
  -        
  +
           digester.addRule("*/set-properties-rule/alias", new SetPropertiesAliasRule(digester));
   
           digester.addFactoryCreate("*/set-property-rule", new SetPropertyRuleFactory());
  @@ -341,7 +341,7 @@
            */
           private void includeXMLRules(String fileName)
                   throws IOException, SAXException, CircularIncludeException {
  -            URL fileURL = DigesterRuleParser.this.getClass().getClassLoader().getResource(fileName);
  +            URL fileURL = getDigester().getClassLoader().getResource(fileName);
               if (fileURL == null) {
                   throw new FileNotFoundException("File \"" + fileName + "\" not found.");
               }
  @@ -354,7 +354,11 @@
               DigesterRuleParser includedSet =
                       new DigesterRuleParser(targetDigester, patternStack, includedFiles);
               includedSet.setDigesterRulesDTD(getDigesterRulesDTD());
  +
               Digester digester = new Digester();
  +            digester.setUseContextClassLoader(getDigester().getUseContextClassLoader());
  +            digester.setClassLoader(getDigester().getClassLoader());
  +            digester.setErrorHandler(getDigester().getErrorHandler());
               digester.addRuleSet(includedSet);
               digester.push(DigesterRuleParser.this);
               digester.parse(fileName);
  @@ -373,7 +377,7 @@
                   throws ClassNotFoundException, ClassCastException,
                   InstantiationException, IllegalAccessException {
   
  -            Class cls = Class.forName(className);
  +            Class cls = Class.forName(className, true, digester.getClassLoader());
               DigesterRulesSource rulesSource = (DigesterRulesSource) cls.newInstance();
   
               // wrap the digester's Rules object, to prepend pattern
  @@ -495,10 +499,10 @@
               if (attributes.getValue("paramcount") == null) {
                   // call against empty method
                   callMethodRule = new CallMethodRule(methodName);
  -                
  +
               } else {
                   int paramCount = Integer.parseInt(attributes.getValue("paramcount"));
  -                
  +
                   String paramTypesAttr = attributes.getValue("paramtypes");
                   if (paramTypesAttr == null || paramTypesAttr.length() == 0) {
                       callMethodRule = new CallMethodRule(targetDigester, methodName,
  @@ -618,7 +622,7 @@
        * the containing SetPropertiesRule rule.
        */
       protected class SetPropertiesAliasRule extends Rule {
  -    
  +
           /**
            * <p>Base constructor.
            *
  
  
  
  1.4       +29 -3     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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FromXmlRuleSet.java	9 Jan 2002 20:22:50 -0000	1.3
  +++ FromXmlRuleSet.java	20 Aug 2002 21:15:14 -0000	1.4
  @@ -83,6 +83,7 @@
    *
    * @author David H. Martin - Initial Contribution
    * @author Scott Sanders   - Added ASL, removed external dependencies
  + * @author Henri Chen - Added rulesDigester
    */
   public class FromXmlRuleSet extends RuleSetBase {
   
  @@ -98,12 +99,28 @@
        */
       private DigesterRuleParser parser;
   
  +	/**
  +	 * The digester for loading the rules xml.
  +	 */
  +	private Digester rulesDigester;
  +
       /**
  -     * Constructs a FromXmlRuleSet using the default DigesterRuleParser
  +     * Constructs a FromXmlRuleSet using the default DigesterRuleParser and
  +     * rulesDigester.
        * @param rulesXml the path to the XML document defining the Digester rules
        */
       public FromXmlRuleSet(URL rulesXml) {
  -        this(rulesXml, new DigesterRuleParser());
  +        this(rulesXml, new DigesterRuleParser(), new Digester());
  +    }
  +
  +    /**
  +     * Constructs a FromXmlRuleSet using the default DigesterRuleParser and
  +     * a ruleDigester for loading the rules xml.
  +     * @param rulesXml the path to the XML document defining the Digester rules
  +     * @param ruleDigester the digester to read the rules xml.
  +     */
  +    public FromXmlRuleSet(URL rulesXml, Digester rulesDigester) {
  +        this(rulesXml, new DigesterRuleParser(), rulesDigester);
       }
   
       /**
  @@ -111,8 +128,18 @@
        * @param parser an instance of DigesterRuleParser, for parsing the rules from XML
        */
       public FromXmlRuleSet(URL rulesXml, DigesterRuleParser parser) {
  +		this(rulesXml, parser, new Digester());
  +	}
  +
  +    /**
  +     * @param rulesXml the path to the XML document defining the Digester rules
  +     * @param parser an instance of DigesterRuleParser, for parsing the rules from XML
  +     * @param rulesDigester the digester used to load the Xml rules.
  +     */
  +    public FromXmlRuleSet(URL rulesXml, DigesterRuleParser parser, Digester rulesDigester)
{
           xmlRules = rulesXml;
           this.parser = parser;
  +        this.rulesDigester = rulesDigester;
       }
   
       /**
  @@ -129,7 +156,6 @@
           parser.setDigesterRulesDTD(dtdURL.toString());
           parser.setTarget(digester);
   
  -        Digester rulesDigester = new Digester();
           rulesDigester.addRuleSet(parser);
           rulesDigester.push(parser);
   
  
  
  

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


Mime
View raw message