commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1130654 - in /commons/sandbox/digester3/trunk/src/examples/api/addressbook/src/main/java/org/apache/commons/digester3/examples/api/addressbook: Address.java AddressBook.java Main.java Person.java
Date Thu, 02 Jun 2011 17:05:59 GMT
Author: simonetripodi
Date: Thu Jun  2 17:05:58 2011
New Revision: 1130654

URL: http://svn.apache.org/viewvc?rev=1130654&view=rev
Log:
code reformatted

Modified:
    commons/sandbox/digester3/trunk/src/examples/api/addressbook/src/main/java/org/apache/commons/digester3/examples/api/addressbook/Address.java
    commons/sandbox/digester3/trunk/src/examples/api/addressbook/src/main/java/org/apache/commons/digester3/examples/api/addressbook/AddressBook.java
    commons/sandbox/digester3/trunk/src/examples/api/addressbook/src/main/java/org/apache/commons/digester3/examples/api/addressbook/Main.java
    commons/sandbox/digester3/trunk/src/examples/api/addressbook/src/main/java/org/apache/commons/digester3/examples/api/addressbook/Person.java

Modified: commons/sandbox/digester3/trunk/src/examples/api/addressbook/src/main/java/org/apache/commons/digester3/examples/api/addressbook/Address.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/api/addressbook/src/main/java/org/apache/commons/digester3/examples/api/addressbook/Address.java?rev=1130654&r1=1130653&r2=1130654&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/examples/api/addressbook/src/main/java/org/apache/commons/digester3/examples/api/addressbook/Address.java
(original)
+++ commons/sandbox/digester3/trunk/src/examples/api/addressbook/src/main/java/org/apache/commons/digester3/examples/api/addressbook/Address.java
Thu Jun  2 17:05:58 2011
@@ -20,58 +20,69 @@ package org.apache.commons.digester3.exa
 /**
  * See Main.java.
  */
-public class Address {
+public class Address
+{
+
     private String type;
+
     private String street;
+
     private String city;
+
     private String state;
+
     private String zip;
+
     private String country;
 
-    public String toString() {
+    public String toString()
+    {
         StringBuilder sb = new StringBuilder();
-        sb.append( " address (type "+ type + ")\n");
-        sb.append( "       " + street + "\n");
-        sb.append( "       " + city + " " + state + " " + zip + "\n");
-        sb.append( "       " + country + "\n");
+        sb.append( " address (type " + type + ")\n" );
+        sb.append( "       " + street + "\n" );
+        sb.append( "       " + city + " " + state + " " + zip + "\n" );
+        sb.append( "       " + country + "\n" );
         return sb.toString();
     }
 
-    public void print(java.io.PrintStream out, int indentAmount) {
-        StringBuilder indentStr = new StringBuilder(indentAmount);
-        for(; indentAmount > 0; --indentAmount) {
-            indentStr.append(' ');
+    public void print( java.io.PrintStream out, int indentAmount )
+    {
+        StringBuilder indentStr = new StringBuilder( indentAmount );
+        for ( ; indentAmount > 0; --indentAmount )
+        {
+            indentStr.append( ' ' );
         }
-        
-        out.print(indentStr);
-        out.print("address type: ");
-        out.println(type);
-        
-        out.print(indentStr);
-        out.println("  " + street);
-        
-        out.print(indentStr);
-        out.println("  " + city + " " + state + " " + zip);
-        
-        out.print(indentStr);
-        out.println("  " + country);
+
+        out.print( indentStr );
+        out.print( "address type: " );
+        out.println( type );
+
+        out.print( indentStr );
+        out.println( "  " + street );
+
+        out.print( indentStr );
+        out.println( "  " + city + " " + state + " " + zip );
+
+        out.print( indentStr );
+        out.println( "  " + country );
     }
-    
+
     /**
      * Returns the value of street.
      */
     public String getStreet()
     {
-         return street; 
+        return street;
     }
 
     /**
      * Sets the value of street.
+     * 
      * @param street The value to assign to street.
      */
-    public void setStreet(String street)
+    public void setStreet( String street )
     {
-        this.street = street; 
+        this.street = street;
     }
 
     /**
@@ -79,16 +90,17 @@ public class Address {
      */
     public String getCity()
     {
-        return city; 
+        return city;
     }
 
     /**
      * Sets the value of city.
+     * 
      * @param city The value to assign to city.
      */
-    public void setCity(String city)
+    public void setCity( String city )
     {
-        this.city = city; 
+        this.city = city;
     }
 
     /**
@@ -96,16 +108,17 @@ public class Address {
      */
     public String getState()
     {
-        return state; 
+        return state;
     }
 
     /**
      * Sets the value of state.
+     * 
      * @param state The value to assign to state.
      */
-    public void setState(String state)
+    public void setState( String state )
     {
-        this.state = state; 
+        this.state = state;
     }
 
     /**
@@ -113,16 +126,17 @@ public class Address {
      */
     public String getZip()
     {
-        return zip; 
+        return zip;
     }
 
     /**
      * Sets the value of zip.
+     * 
      * @param zip The value to assign to zip.
      */
-    public void setZip(String zip)
+    public void setZip( String zip )
     {
-        this.zip = zip; 
+        this.zip = zip;
     }
 
     /**
@@ -130,16 +144,17 @@ public class Address {
      */
     public String getCountry()
     {
-        return country; 
+        return country;
     }
 
     /**
      * Sets the value of country.
+     * 
      * @param country The value to assign to country.
      */
-    public void setCountry(String country)
+    public void setCountry( String country )
     {
-        this.country = country; 
+        this.country = country;
     }
 
     /**
@@ -147,17 +162,17 @@ public class Address {
      */
     public String getType()
     {
-        return type; 
+        return type;
     }
 
     /**
      * Sets the value of type.
+     * 
      * @param type The value to assign to type.
      */
-    public void setType(String type)
+    public void setType( String type )
     {
-        this.type = type; 
+        this.type = type;
     }
-}
-
 
+}

Modified: commons/sandbox/digester3/trunk/src/examples/api/addressbook/src/main/java/org/apache/commons/digester3/examples/api/addressbook/AddressBook.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/api/addressbook/src/main/java/org/apache/commons/digester3/examples/api/addressbook/AddressBook.java?rev=1130654&r1=1130653&r2=1130654&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/examples/api/addressbook/src/main/java/org/apache/commons/digester3/examples/api/addressbook/AddressBook.java
(original)
+++ commons/sandbox/digester3/trunk/src/examples/api/addressbook/src/main/java/org/apache/commons/digester3/examples/api/addressbook/AddressBook.java
Thu Jun  2 17:05:58 2011
@@ -23,19 +23,25 @@ import java.util.Iterator;
 /**
  * See Main.java.
  */
-public class AddressBook {
+public class AddressBook
+{
+
     LinkedList people = new LinkedList();
-    
-    public void addPerson(Person p) {
-        people.addLast(p);
+
+    public void addPerson( Person p )
+    {
+        people.addLast( p );
     }
-    
-    public void print() {
-        System.out.println("Address book has " + people.size() + " entries");
 
-        for(Iterator i = people.iterator(); i.hasNext(); ) {
+    public void print()
+    {
+        System.out.println( "Address book has " + people.size() + " entries" );
+
+        for ( Iterator i = people.iterator(); i.hasNext(); )
+        {
             Person p = (Person) i.next();
             p.print();
         }
     }
+
 }

Modified: commons/sandbox/digester3/trunk/src/examples/api/addressbook/src/main/java/org/apache/commons/digester3/examples/api/addressbook/Main.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/api/addressbook/src/main/java/org/apache/commons/digester3/examples/api/addressbook/Main.java?rev=1130654&r1=1130653&r2=1130654&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/examples/api/addressbook/src/main/java/org/apache/commons/digester3/examples/api/addressbook/Main.java
(original)
+++ commons/sandbox/digester3/trunk/src/examples/api/addressbook/src/main/java/org/apache/commons/digester3/examples/api/addressbook/Main.java
Thu Jun  2 17:05:58 2011
@@ -37,118 +37,126 @@ import org.apache.commons.digester3.Dige
  * <p>
  * Usage: java Main example.xml
  */
-public class Main {
-    
+public class Main
+{
+
     /**
      * Main method : entry point for running this example program.
      * <p>
      * Usage: java Example example.xml
      */
-    public static void main(String[] args) {
-        if (args.length != 1) {
+    public static void main( String[] args )
+    {
+        if ( args.length != 1 )
+        {
             usage();
-            System.exit(-1);
+            System.exit( -1 );
         }
-        
+
         String filename = args[0];
-        
+
         // Create a Digester instance
         Digester d = new Digester();
-        
+
         // Prime the digester stack with an object for rules to
         // operate on. Note that it is quite common for "this"
         // to be the object pushed.
         AddressBook book = new AddressBook();
-        d.push(book);
-        
+        d.push( book );
+
         // Add rules to the digester that will be triggered while
         // parsing occurs.
-        addRules(d);
-        
+        addRules( d );
+
         // Process the input file.
-        try {
-            java.io.File srcfile = new java.io.File(filename);
-            d.parse(srcfile);
+        try
+        {
+            java.io.File srcfile = new java.io.File( filename );
+            d.parse( srcfile );
         }
-        catch(java.io.IOException ioe) {
-            System.out.println("Error reading input file:" + ioe.getMessage());
-            System.exit(-1);
+        catch ( java.io.IOException ioe )
+        {
+            System.out.println( "Error reading input file:" + ioe.getMessage() );
+            System.exit( -1 );
         }
-        catch(org.xml.sax.SAXException se) {
-            System.out.println("Error parsing input file:" + se.getMessage());
-            System.exit(-1);
+        catch ( org.xml.sax.SAXException se )
+        {
+            System.out.println( "Error parsing input file:" + se.getMessage() );
+            System.exit( -1 );
         }
-        
-        
+
         // Print out all the contents of the address book, as loaded from
         // the input file.
         book.print();
     }
-    
-    private static void addRules(Digester d) {
 
-        //--------------------------------------------------        
+    private static void addRules( Digester d )
+    {
+
+        // --------------------------------------------------
         // when we encounter a "person" tag, do the following:
 
         // create a new instance of class Person, and push that
         // object onto the digester stack of objects
-        d.addObjectCreate("address-book/person", Person.class);
-        
+        d.addObjectCreate( "address-book/person", Person.class );
+
         // map *any* attributes on the tag to appropriate
         // setter-methods on the top object on the stack (the Person
-        // instance created by the preceeding rule). 
+        // instance created by the preceeding rule).
         //
         // For example:
-        // if attribute "id" exists on the xml tag, and method setId 
+        // if attribute "id" exists on the xml tag, and method setId
         // with one parameter exists on the object that is on top of
         // the digester object stack, then a call will be made to that
         // method. The value will be type-converted from string to
-        // whatever type the target method declares (where possible), 
+        // whatever type the target method declares (where possible),
         // using the commons ConvertUtils functionality.
         //
         // Attributes on the xml tag for which no setter methods exist
         // on the top object on the stack are just ignored.
-        d.addSetProperties("address-book/person");
+        d.addSetProperties( "address-book/person" );
 
         // call the addPerson method on the second-to-top object on
         // the stack (the AddressBook object), passing the top object
         // on the stack (the recently created Person object).
-        d.addSetNext("address-book/person", "addPerson");        
-        
-        //--------------------------------------------------        
+        d.addSetNext( "address-book/person", "addPerson" );
+
+        // --------------------------------------------------
         // when we encounter a "name" tag, call setName on the top
         // object on the stack, passing the text contained within the
         // body of that name element [specifying a zero parameter count
-        // implies one actual parameter, being the body text]. 
-        // The top object on the stack will be a person object, because 
-        // the pattern address-book/person always triggers the 
+        // implies one actual parameter, being the body text].
+        // The top object on the stack will be a person object, because
+        // the pattern address-book/person always triggers the
         // ObjectCreateRule we added previously.
-        d.addCallMethod("address-book/person/name", "setName", 0);
-        
-        //--------------------------------------------------        
+        d.addCallMethod( "address-book/person/name", "setName", 0 );
+
+        // --------------------------------------------------
         // when we encounter an "email" tag, call addEmail on the top
         // object on the stack, passing two parameters: the "type"
         // attribute, and the text within the tag body.
-        d.addCallMethod("address-book/person/email", "addEmail", 2);
-        d.addCallParam("address-book/person/email", 0, "type");
-        d.addCallParam("address-book/person/email", 1);
-        
-        //--------------------------------------------------        
+        d.addCallMethod( "address-book/person/email", "addEmail", 2 );
+        d.addCallParam( "address-book/person/email", 0, "type" );
+        d.addCallParam( "address-book/person/email", 1 );
+
+        // --------------------------------------------------
         // When we encounter an "address" tag, create an instance of class
         // Address and push it on the digester stack of objects. After
         // doing that, call addAddress on the second-to-top object on the
         // digester stack (a "Person" object), passing the top object on
         // the digester stack (the "Address" object). And also set things
         // up so that for each child xml element encountered between the start
-        // of the address tag and the end of the address tag, the text 
-        // contained in that element is passed to a setXXX method on the 
+        // of the address tag and the end of the address tag, the text
+        // contained in that element is passed to a setXXX method on the
         // Address object where XXX is the name of the xml element found.
-        d.addObjectCreate("address-book/person/address", Address.class);
-        d.addSetNext("address-book/person/address", "addAddress");
-        d.addSetNestedProperties("address-book/person/address");
+        d.addObjectCreate( "address-book/person/address", Address.class );
+        d.addSetNext( "address-book/person/address", "addAddress" );
+        d.addSetNestedProperties( "address-book/person/address" );
     }
 
-    private static void usage() {
-        System.out.println("Usage: java Main example.xml");
+    private static void usage()
+    {
+        System.out.println( "Usage: java Main example.xml" );
     }
-}
\ No newline at end of file
+
+}

Modified: commons/sandbox/digester3/trunk/src/examples/api/addressbook/src/main/java/org/apache/commons/digester3/examples/api/addressbook/Person.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/api/addressbook/src/main/java/org/apache/commons/digester3/examples/api/addressbook/Person.java?rev=1130654&r1=1130653&r2=1130654&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/examples/api/addressbook/src/main/java/org/apache/commons/digester3/examples/api/addressbook/Person.java
(original)
+++ commons/sandbox/digester3/trunk/src/examples/api/addressbook/src/main/java/org/apache/commons/digester3/examples/api/addressbook/Person.java
Thu Jun  2 17:05:58 2011
@@ -25,53 +25,67 @@ import java.util.List;
 /**
  * See Main.java.
  */
-public class Person {
-  private int id;
-  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
-   * converts the id to an integer.
-   */
-  public void setId(int id) {
-      this.id = id;
-  }
-  
-  public void setCategory(String category) {
-      this.category = category;
-  }
-  
-  public void setName(String name) {
-      this.name = name;
-  }
-  
-  /** we assume only one email of each type... */
-  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);
-      System.out.println("  category=" + category);
-      System.out.println("  name=" + name);
-      
-      for(Iterator i = emails.keySet().iterator(); i.hasNext(); ) {
-          String type = (String) i.next();
-          String address = (String) emails.get(type);
-          
-          System.out.println("  email (type " + type + ") : " + address);
-      }
-      
-      for(Iterator i = addresses.iterator(); i.hasNext(); ) {
-          Address addr = (Address) i.next();
-          addr.print(System.out, 2);
-      }
-  }
+public class Person
+{
+
+    private int id;
+
+    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 converts the id
to an integer.
+     */
+    public void setId( int id )
+    {
+        this.id = id;
+    }
+
+    public void setCategory( String category )
+    {
+        this.category = category;
+    }
+
+    public void setName( String name )
+    {
+        this.name = name;
+    }
+
+    /** we assume only one email of each type... */
+    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 );
+        System.out.println( "  category=" + category );
+        System.out.println( "  name=" + name );
+
+        for ( Iterator i = emails.keySet().iterator(); i.hasNext(); )
+        {
+            String type = (String) i.next();
+            String address = (String) emails.get( type );
+
+            System.out.println( "  email (type " + type + ") : " + address );
+        }
+
+        for ( Iterator i = addresses.iterator(); i.hasNext(); )
+        {
+            Address addr = (Address) i.next();
+            addr.print( System.out, 2 );
+        }
+    }
+
 }



Mime
View raw message