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 digester-rules.dtd
Date Sat, 15 Mar 2003 18:38:54 GMT
rdonkin     2003/03/15 10:38:54

  Modified:    digester/src/java/org/apache/commons/digester/xmlrules
                        DigesterLoader.java DigesterRuleParser.java
                        digester-rules.dtd
  Log:
  Added support to the xml rules for non-propagation of exceptions. This will (when the correct
options are set) allow a digestion to continue when an object creation has failed.
  
  Revision  Changes    Path
  1.5       +65 -1     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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DigesterLoader.java	2 Feb 2003 15:53:56 -0000	1.4
  +++ DigesterLoader.java	15 Mar 2003 18:38:54 -0000	1.5
  @@ -61,6 +61,7 @@
   
   import java.io.IOException;
   import java.io.InputStream;
  +import java.io.Reader;
   import java.net.URL;
   
   import org.apache.commons.digester.RuleSet;
  @@ -147,6 +148,36 @@
               throw new DigesterLoadingException(ex.getMessage(), ex);
           }
       }
  +    
  +    /**
  +     * Given the digester rules XML file, a class loader, and an input stream,
  +     * this method parses the input into Java objects. The class loader
  +     * is used by the digester to create the Java objects.
  +     * @param digesterRules URL to the XML document defining the digester rules
  +     * @param classLoader the ClassLoader to register with the digester
  +     * @param reader Reader over the XML file to parse into Java objects
  +     * @return an Object which is the root of the network of Java objects
  +     * created by digesting fileURL
  +     */
  +    public static Object load(
  +                                URL digesterRules, 
  +                                ClassLoader classLoader,
  +                                Reader reader) 
  +                                    throws 
  +                                        IOException, 
  +                                        SAXException, 
  +                                        DigesterLoadingException {
  +        Digester digester = createDigester(digesterRules);
  +        digester.setClassLoader(classLoader);
  +        try {
  +            return digester.parse(reader);
  +        } catch (XmlLoadException ex) {
  +            // This is a runtime exception that can be thrown by
  +            // FromXmlRuleSet#addRuleInstances, which is called by the Digester
  +            // before it parses the file.
  +            throw new DigesterLoadingException(ex.getMessage(), ex);
  +        }
  +    }
   
   
       /**
  @@ -195,5 +226,38 @@
               throw new DigesterLoadingException(ex.getMessage(), ex);
           }
       }
  -
  +    
  +    /**
  +     * Given the digester rules XML file, a class loader, and an input stream,
  +     * this method parses the input into Java objects. The class loader
  +     * is used by the digester to create the Java objects.
  +     * @param digesterRules URL to the XML document defining the digester rules
  +     * @param classLoader the ClassLoader to register with the digester
  +     * @param input Reader over the XML file to parse into Java objects
  +     * @param rootObject an Object to push onto the digester's stack, prior
  +     * to parsing the input
  +     * @return an Object which is the root of the network of Java objects
  +     * created by digesting fileURL
  +     */
  +    public static Object load(
  +                                URL digesterRules, 
  +                                ClassLoader classLoader,
  +                                Reader input, 
  +                                Object rootObject) 
  +                                    throws 
  +                                        IOException, 
  +                                        SAXException,
  +                                        DigesterLoadingException {
  +        Digester digester = createDigester(digesterRules);
  +        digester.setClassLoader(classLoader);
  +        digester.push(rootObject);
  +        try {
  +            return digester.parse(input);
  +        } catch (XmlLoadException ex) {
  +            // This is a runtime exception that can be thrown by
  +            // FromXmlRuleSet#addRuleInstances, which is called by the Digester
  +            // before it parses the file.
  +            throw new DigesterLoadingException(ex.getMessage(), ex);
  +        }
  +    }
   }
  
  
  
  1.12      +4 -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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- DigesterRuleParser.java	10 Mar 2003 21:10:11 -0000	1.11
  +++ DigesterRuleParser.java	15 Mar 2003 18:38:54 -0000	1.12
  @@ -568,10 +568,12 @@
           public Object createObject(Attributes attributes) {
               String className = attributes.getValue("classname");
               String attrName = attributes.getValue("attrname");
  +            boolean ignoreExceptions = 
  +                "true".equalsIgnoreCase(attributes.getValue("ignore-exceptions"));
               return (attrName == null || attrName.length() == 0) ?
  -                new FactoryCreateRule( className)
  +                new FactoryCreateRule( className, ignoreExceptions)
                   :
  -                new FactoryCreateRule( className, attrName);
  +                new FactoryCreateRule( className, attrName, ignoreExceptions);
           }
       }
       
  
  
  
  1.7       +10 -3     jakarta-commons/digester/src/java/org/apache/commons/digester/xmlrules/digester-rules.dtd
  
  Index: digester-rules.dtd
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/xmlrules/digester-rules.dtd,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- digester-rules.dtd	10 Mar 2003 21:10:11 -0000	1.6
  +++ digester-rules.dtd	15 Mar 2003 18:38:54 -0000	1.7
  @@ -87,12 +87,19 @@
       paramnumber CDATA #REQUIRED
       attrname CDATA #IMPLIED>
   
  -<!-- FactoryCreateRule -->
  +<!-- 
  +    FactoryCreateRule 
  +    
  +    ignore-exceptions - if this attribute is (ignore case) 'true' then any exceptions
  +                        thrown by the object create rule will be ignore.
  +                        This will allow processing to continue.
  +    -->
   <!ELEMENT factory-create-rule EMPTY>
   <!ATTLIST factory-create-rule
       pattern   CDATA #IMPLIED
       classname CDATA #REQUIRED
  -    attrname  CDATA #IMPLIED>
  +    attrname  CDATA #IMPLIED
  +    ignore-exceptions  CDATA #IMPLIED> 
   
   <!-- ObjectCreateRule -->
   <!ELEMENT object-create-rule EMPTY>
  
  
  

---------------------------------------------------------------------
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