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/examples/xmlrules/addressbook Address.java Person.java example.xml readme.txt xmlrules.xml
Date Mon, 17 Jan 2005 09:45:24 GMT
skitching    2005/01/17 01:45:24

  Modified:    digester/src/examples/xmlrules/addressbook Person.java
                        example.xml readme.txt xmlrules.xml
  Added:       digester/src/examples/xmlrules/addressbook Address.java
  Log:
  Add example of SetNestedPropertiesRule usage. Patch provided by
  Wendy Smoak.
  
  Revision  Changes    Path
  1.2       +10 -0     jakarta-commons/digester/src/examples/xmlrules/addressbook/Person.java
  
  Index: Person.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/examples/xmlrules/addressbook/Person.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Person.java	17 Apr 2004 10:54:06 -0000	1.1
  +++ Person.java	17 Jan 2005 09:45:23 -0000	1.2
  @@ -14,8 +14,10 @@
    * limitations under the License.
    */ 
   
  +import java.util.ArrayList;
   import java.util.HashMap;
   import java.util.Iterator;
  +import java.util.List;
   
   /**
    * See Main.java.
  @@ -25,6 +27,7 @@
     private String category;
     private String name;
     private HashMap emails = new HashMap();
  +  private List addresses = new ArrayList();
     
     /** 
      * A unique id for this person. Note that the Digester automatically
  @@ -46,6 +49,10 @@
     public void addEmail(String type, String address) {
         emails.put(type, address);
     }
  +  
  +  public void addAddress( Address addr ) {
  +     addresses.add( addr );
  +  }
   
     public void print() {
         System.out.println("Person #" + id);
  @@ -58,5 +65,8 @@
             
             System.out.println("  email (type " + type + ") : " + address);
         }
  +      
  +      System.out.println( addresses );
  +      
     }
   }
  
  
  
  1.3       +24 -0     jakarta-commons/digester/src/examples/xmlrules/addressbook/example.xml
  
  Index: example.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/examples/xmlrules/addressbook/example.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- example.xml	9 Sep 2004 20:38:21 -0000	1.2
  +++ example.xml	17 Jan 2005 09:45:23 -0000	1.3
  @@ -18,12 +18,36 @@
     <person id="1" category="acquaintance">
       <name>Gonzo</name>
       <email type="business">gonzo@muppets.com</email>
  +    <address>
  +      <type>home</type>
  +      <street>123 Maine Ave.</street>
  +      <city>Las Vegas</city>
  +      <state>NV</state>
  +      <zip>01234</zip>
  +      <country>USA</country>
  +    </address>
  +    <address>
  +      <type>business</type>
  +      <street>234 Maple Dr.</street>
  +      <city>Los Angeles</city>
  +      <state>CA</state>
  +      <zip>98765</zip>
  +      <country>USA</country>
  +    </address>
     </person>
   
     <person id="2" category="rolemodel">
       <name>Kermit</name>
       <email type="business">kermit@muppets.com</email>
       <email type="home">kermie@acme.com</email>
  +    <address>
  +      <type>business</type>
  +      <street>987 Brown Rd</street>
  +      <city>Las Cruces</city>
  +      <state>NM</state>
  +      <zip>75321</zip>
  +      <country>USA</country>
  +    </address>
     </person>
   
   </address-book>
  
  
  
  1.3       +2 -0      jakarta-commons/digester/src/examples/xmlrules/addressbook/readme.txt
  
  Index: readme.txt
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/examples/xmlrules/addressbook/readme.txt,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- readme.txt	9 Sep 2004 20:38:21 -0000	1.2
  +++ readme.txt	17 Jan 2005 09:45:23 -0000	1.3
  @@ -26,6 +26,8 @@
   * how to use the "object create" rule to create java objects
   * how to use the "set properties" rule (basic usage) to map xml attributes
     to java bean properties.
  +* how to use the "set nested properties" rule (basic usage) to map nested
  +  elements to java bean properties.
   * how to use the "set next" rule to build trees of java objects.
   * how to use the "call method rule" (basic usage)
   * how to use the "call parameter rule" to process the text contained
  
  
  
  1.2       +7 -0      jakarta-commons/digester/src/examples/xmlrules/addressbook/xmlrules.xml
  
  Index: xmlrules.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/examples/xmlrules/addressbook/xmlrules.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- xmlrules.xml	17 Apr 2004 10:54:06 -0000	1.1
  +++ xmlrules.xml	17 Jan 2005 09:45:23 -0000	1.2
  @@ -36,6 +36,13 @@
           <call-param-rule paramnumber='0' attrname='type'/>
           <call-param-rule paramnumber='1'/>
         </pattern>
  +      
  +      <pattern value="address">
  +        <object-create-rule classname="Address"/>
  +        <set-nested-properties-rule/>
  +        <set-next-rule methodname="addAddress"/>
  +      </pattern>
  +      
       </pattern>
     </pattern>
   </digester-rules>
  
  
  
  1.1                  jakarta-commons/digester/src/examples/xmlrules/addressbook/Address.java
  
  Index: Address.java
  ===================================================================
  /*
   * Copyright 2001-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */ 
  
  import java.util.HashMap;
  import java.util.Iterator;
  
  /**
   * See Main.java.
   */
  public class Address {
    private String type;
    private String street;
    private String city;
    private String state;
    private String zip;
    private String country;
    
  
    public String toString() {
        StringBuffer sb = new StringBuffer();
        sb.append( " address (type "+ type + ")\n");
        sb.append( "       " + street + "\n");
        sb.append( "       " + city + " " + state + " " + zip + "\n");
        sb.append( "       " + country + "\n");
        return sb.toString();
    }
  
  	/**
  	 * Returns the value of street.
  	 */
  	public String getStreet()
  	{
  		 return street; 
  	}
  
  	/**
  	 * Sets the value of street.
  	 * @param street The value to assign to street.
  	 */
  	public void setStreet(String street)
  	{
  		 this.street = street; 
  	}
  
  	/**
  	 * Returns the value of city.
  	 */
  	public String getCity()
  	{
  		 return city; 
  	}
  
  	/**
  	 * Sets the value of city.
  	 * @param city The value to assign to city.
  	 */
  	public void setCity(String city)
  	{
  		 this.city = city; 
  	}
  
  	/**
  	 * Returns the value of state.
  	 */
  	public String getState()
  	{
  		 return state; 
  	}
  
  	/**
  	 * Sets the value of state.
  	 * @param state The value to assign to state.
  	 */
  	public void setState(String state)
  	{
  		 this.state = state; 
  	}
  
  	/**
  	 * Returns the value of zip.
  	 */
  	public String getZip()
  	{
  		 return zip; 
  	}
  
  	/**
  	 * Sets the value of zip.
  	 * @param zip The value to assign to zip.
  	 */
  	public void setZip(String zip)
  	{
  		 this.zip = zip; 
  	}
  
  	/**
  	 * Returns the value of country.
  	 */
  	public String getCountry()
  	{
  		 return country; 
  	}
  
  	/**
  	 * Sets the value of country.
  	 * @param country The value to assign to country.
  	 */
  	public void setCountry(String country)
  	{
  		 this.country = country; 
  	}
  
  	/**
  	 * Returns the value of type.
  	 */
  	public String getType()
  	{
  		 return type; 
  	}
  
  	/**
  	 * Sets the value of type.
  	 * @param type The value to assign to type.
  	 */
  	public void setType(String type)
  	{
  		 this.type = type; 
  	}
  }
  
  
  
  
  

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