rdonkin     2002/10/02 12:23:12

  Modified:    digester/src/java/org/apache/commons/digester
                        BeanPropertySetterRule.java Digester.java Rule.java
  Log:
  This is an important change but is backward compatible. This changes the basic rule 
abstract class so that name and namespace information are be supplied to the rule. 
Existing rules that do not require this functionality can continue to use the old 
(deprecated) version. Submitted by Christopher Lenz.
  
  Revision  Changes    Path
  1.9       +28 -23    
jakarta-commons/digester/src/java/org/apache/commons/digester/BeanPropertySetterRule.java
  
  Index: BeanPropertySetterRule.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/BeanPropertySetterRule.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- BeanPropertySetterRule.java       23 Mar 2002 17:45:57 -0000      1.8
  +++ BeanPropertySetterRule.java       2 Oct 2002 19:23:12 -0000       1.9
  @@ -144,6 +144,7 @@
           this((String)null);
   
       }
  +    
       // ----------------------------------------------------- Instance Variables
   
   
  @@ -165,45 +166,51 @@
       /**
        * Process the body text of this element.
        *
  -     * @param bodyText The body text of this element
  +     * @param namespace the namespace URI of the matching element, or an 
  +     *   empty string if the parser is not namespace aware or the element has
  +     *   no namespace
  +     * @param name the local name if the parser is namespace aware, or just 
  +     *   the element name otherwise
  +     * @param text The text of the body of this element
        */
  -    public void body(String bodyText) throws Exception {
  +    public void body(String namespace, String name, String text)
  +        throws Exception {
   
           // log some debugging information
           if (digester.log.isDebugEnabled()) {
               digester.log.debug("[BeanPropertySetterRule]{" +
  -                    digester.match + "} Called with text " + bodyText);
  +                    digester.match + "} Called with text '" + text + "'");
           }
   
  -        this.bodyText = bodyText.trim();
  +        bodyText = text.trim();
   
       }
   
   
       /**
        * Process the end of this element.
  +     *
  +     * @param namespace the namespace URI of the matching element, or an 
  +     *   empty string if the parser is not namespace aware or the element has
  +     *   no namespace
  +     * @param name the local name if the parser is namespace aware, or just 
  +     *   the element name otherwise
        */
  -    public void end() throws Exception {
  +    public void end(String namespace, String name) throws Exception {
   
           String property = propertyName;
   
           if (property == null) {
               // If we don't have a specific property name,
               // use the element name.
  -            String match = digester.match;
  -            int slash = match.lastIndexOf('/');
  -            if (slash >= 0) {
  -                match = match.substring(slash + 1);
  -            }
  -
  -            property = match;
  -
  +            property = name;
           }
   
           // log some debugging information
           if (digester.log.isDebugEnabled()) {
               digester.log.debug("[BeanPropertySetterRule]{" + digester.match +
  -                    "} Setting property " + property + " with text " + bodyText);
  +                    "} Setting property " + property + " with text " +
  +                    bodyText);
           }
   
           // going to use beanutils so need to specify property using map
  @@ -219,12 +226,10 @@
                   digester.log.debug("[BeanPropertySetterRule]{" +
                           digester.match + "} Top object is null.");
               }
  -            return;
  +        } else {
  +            // populate property on top object
  +            BeanUtils.populate(top, map);
           }
  -
  -        // populate property on top object
  -        BeanUtils.populate(top, map);
  -
       }
   
   
  
  
  
  1.68      +22 -12    
jakarta-commons/digester/src/java/org/apache/commons/digester/Digester.java
  
  Index: Digester.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/Digester.java,v
  retrieving revision 1.67
  retrieving revision 1.68
  diff -u -r1.67 -r1.68
  --- Digester.java     30 Sep 2002 19:48:50 -0000      1.67
  +++ Digester.java     2 Oct 2002 19:23:12 -0000       1.68
  @@ -1013,6 +1013,13 @@
               log.debug("  bodyText='" + bodyText + "'");
           }
   
  +        // the actual element name is either in localName or qName, depending 
  +        // on whether the parser is namespace aware
  +        String name = localName;
  +        if ((name == null) || (name.length() < 1)) {
  +            name = qName;
  +        }
  +
           // Fire "body" events for all relevant rules
           List rules = getRules().match(namespaceURI, match);
           if ((rules != null) && (rules.size() > 0)) {
  @@ -1023,7 +1030,7 @@
                       if (debug) {
                           log.debug("  Fire body() for " + rule);
                       }
  -                    rule.body(bodyText);
  +                    rule.body(namespaceURI, name, bodyText);
                   } catch (Exception e) {
                       log.error("Body event threw exception", e);
                       throw createSAXException(e);
  @@ -1053,7 +1060,7 @@
                       if (debug) {
                           log.debug("  Fire end() for " + rule);
                       }
  -                    rule.end();
  +                    rule.end(namespaceURI, name);
                   } catch (Exception e) {
                       log.error("End event threw exception", e);
                       throw createSAXException(e);
  @@ -1229,16 +1236,19 @@
           }
           bodyText = new StringBuffer();
   
  +        // the actual element name is either in localName or qName, depending 
  +        // on whether the parser is namespace aware
  +        String name = localName;
  +        if ((name == null) || (name.length() < 1)) {
  +            name = qName;
  +        }
  +
           // Compute the current matching rule
           StringBuffer sb = new StringBuffer(match);
           if (match.length() > 0) {
               sb.append('/');
           }
  -        if ((localName == null) || (localName.length() < 1)) {
  -            sb.append(qName);
  -        } else {
  -            sb.append(localName);
  -        }
  +        sb.append(name);
           match = sb.toString();
           if (debug) {
               log.debug("  New match='" + match + "'");
  @@ -1254,7 +1264,7 @@
                       if (debug) {
                           log.debug("  Fire begin() for " + rule);
                       }
  -                    rule.begin(list);
  +                    rule.begin(namespaceURI, name, list);
                   } catch (Exception e) {
                       log.error("Begin event threw exception", e);
                       throw createSAXException(e);
  
  
  
  1.8       +82 -4     
jakarta-commons/digester/src/java/org/apache/commons/digester/Rule.java
  
  Index: Rule.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/Rule.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Rule.java 23 Mar 2002 17:45:58 -0000      1.7
  +++ Rule.java 2 Oct 2002 19:23:12 -0000       1.8
  @@ -71,6 +71,7 @@
    * a corresponding nested pattern of XML elements has been matched.
    *
    * @author Craig McClanahan
  + * @author Christopher Lenz
    * @version $Revision$ $Date$
    */
   
  @@ -167,6 +168,9 @@
        * is encountered.
        *
        * @param attributes The attribute list of this element
  +     * @deprecated Use the {@link #begin(String,String,Attributes) begin}
  +     *   method with <code>namespace</code> and <code>name</code>
  +     *   parameters instead.
        */
       public void begin(Attributes attributes) throws Exception {
   
  @@ -176,11 +180,37 @@
   
   
       /**
  +     * This method is called when the beginning of a matching XML element
  +     * is encountered. The default implementation delegates to the deprecated
  +     * method {@link #begin(Attributes) begin} without the 
  +     * <code>namespace</code> and <code>name</code> parameters, to retain 
  +     * backwards compatibility.
  +     *
  +     * @param namespace the namespace URI of the matching element, or an 
  +     *   empty string if the parser is not namespace aware or the element has
  +     *   no namespace
  +     * @param name the local name if the parser is namespace aware, or just 
  +     *   the element name otherwise
  +     * @param attributes The attribute list of this element
  +     * @since Digester 1.4
  +     */
  +    public void begin(String namespace, String name, Attributes attributes)
  +        throws Exception {
  +
  +        begin(attributes);
  +
  +    }
  +
  +
  +    /**
        * This method is called when the body of a matching XML element
        * is encountered.  If the element has no body, this method is
        * not called at all.
        *
        * @param text The text of the body of this element
  +     * @deprecated Use the {@link #body(String,String,String) body} method
  +     *   with <code>namespace</code> and <code>name</code> parameters
  +     *   instead.
        */
       public void body(String text) throws Exception {
   
  @@ -190,12 +220,60 @@
   
   
       /**
  +     * This method is called when the body of a matching XML element is 
  +     * encountered.  If the element has no body, this method is not called at 
  +     * all. The default implementation delegates to the deprecated method 
  +     * {@link #body(String) body} without the <code>namespace</code> and
  +     * <code>name</code> parameters, to retain backwards compatibility.
  +     *
  +     * @param namespace the namespace URI of the matching element, or an 
  +     *   empty string if the parser is not namespace aware or the element has
  +     *   no namespace
  +     * @param name the local name if the parser is namespace aware, or just 
  +     *   the element name otherwise
  +     * @param text The text of the body of this element
  +     * @since Digester 1.4
  +     */
  +    public void body(String namespace, String name, String text)
  +        throws Exception {
  +
  +        body(text);
  +
  +    }
  +
  +
  +    /**
        * This method is called when the end of a matching XML element
        * is encountered.
  +     * 
  +     * @deprecated Use the {@link #end(String,String) end} method with 
  +     *   <code>namespace</code> and <code>name</code> parameters instead.
        */
       public void end() throws Exception {
   
           ;    // The default implementation does nothing
  +
  +    }
  +
  +
  +    /**
  +     * This method is called when the end of a matching XML element
  +     * is encountered. The default implementation delegates to the deprecated
  +     * method {@link #end end} without the 
  +     * <code>namespace</code> and <code>name</code> parameters, to retain 
  +     * backwards compatibility.
  +     *
  +     * @param namespace the namespace URI of the matching element, or an 
  +     *   empty string if the parser is not namespace aware or the element has
  +     *   no namespace
  +     * @param name the local name if the parser is namespace aware, or just 
  +     *   the element name otherwise
  +     * @since Digester 1.4
  +     */
  +    public void end(String namespace, String name)
  +        throws Exception {
  +
  +        end();
   
       }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to