commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1130665 - in /commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog: AudioVisual.java Book.java BookFactory.java Catalog.java Item.java Main.java
Date Thu, 02 Jun 2011 17:24:31 GMT
Author: simonetripodi
Date: Thu Jun  2 17:24:30 2011
New Revision: 1130665

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

Modified:
    commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog/AudioVisual.java
    commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog/Book.java
    commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog/BookFactory.java
    commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog/Catalog.java
    commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog/Item.java
    commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog/Main.java

Modified: commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog/AudioVisual.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog/AudioVisual.java?rev=1130665&r1=1130664&r2=1130665&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog/AudioVisual.java
(original)
+++ commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog/AudioVisual.java
Thu Jun  2 17:24:30 2011
@@ -20,50 +20,63 @@ package org.apache.commons.digester3.exa
 /**
  *  See Main.java.
  */
- 
-public class AudioVisual implements Item {
+public class AudioVisual
+    implements Item
+{
 
     private int yearMade;
+
     private String category;
+
     private String name;
+
     private String desc;
+
     private Integer runtime;
+
     private String type;
 
     // note: digester can convert a string in the xml file to an int.
-    public void setYearMade(int yearMade) {
+    public void setYearMade( int yearMade )
+    {
         this.yearMade = yearMade;
     }
 
-    public void setCategory(String category) {
+    public void setCategory( String category )
+    {
         this.category = category;
     }
 
-    public void setName(String name) {
+    public void setName( String name )
+    {
         this.name = name;
     }
 
-    public void setDesc(String desc) {
+    public void setDesc( String desc )
+    {
         this.desc = desc;
     }
 
     // note: digester can convert a string in the xml file to an Integer
-    public void setRuntime(Integer runtime) {
+    public void setRuntime( Integer runtime )
+    {
         this.runtime = runtime;
     }
 
-    public void setType(String type) {
+    public void setType( String type )
+    {
         this.type = type;
     }
 
-    public void print() {
-        System.out.println("AudioVisual:");
-        System.out.println("  type=" + type);
-        System.out.println("  yearMade=" + yearMade);
-        System.out.println("  category=" + category);
-        System.out.println("  name=" + name);
-        System.out.println("  desc=" + desc);
-        System.out.println("  runtime=" + runtime);
+    public void print()
+    {
+        System.out.println( "AudioVisual:" );
+        System.out.println( "  type=" + type );
+        System.out.println( "  yearMade=" + yearMade );
+        System.out.println( "  category=" + category );
+        System.out.println( "  name=" + name );
+        System.out.println( "  desc=" + desc );
+        System.out.println( "  runtime=" + runtime );
     }
-}
 
+}

Modified: commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog/Book.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog/Book.java?rev=1130665&r1=1130664&r2=1130665&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog/Book.java
(original)
+++ commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog/Book.java
Thu Jun  2 17:24:30 2011
@@ -20,34 +20,45 @@ package org.apache.commons.digester3.exa
 /**
  * See Main.java.
  */
-public class Book implements Item {
+public class Book
+    implements Item
+{
+
+    private String isbn;
+
+    private String title;
+
+    private String author;
+
+    private String desc;
+
+    public Book( String isbn )
+    {
+        this.isbn = isbn;
+    }
+
+    public void setTitle( String title )
+    {
+        this.title = title;
+    }
+
+    public void setAuthor( String author )
+    {
+        this.author = author;
+    }
+
+    public void setDesc( String desc )
+    {
+        this.desc = desc;
+    }
+
+    public void print()
+    {
+        System.out.println( "Book:" );
+        System.out.println( "  isbn=" + isbn );
+        System.out.println( "  title=" + title );
+        System.out.println( "  author=" + author );
+        System.out.println( "  desc=" + desc );
+    }
 
-  private String isbn;
-  private String title;
-  private String author;
-  private String desc;
-
-  public Book(String isbn) {
-      this.isbn = isbn;
-  }
-  
-  public void setTitle(String title) {
-      this.title = title;
-  }
-  
-  public void setAuthor(String author) {
-      this.author = author;
-  }
-  
-  public void setDesc(String desc) {
-      this.desc = desc;
-  }
-  
-  public void print() {
-      System.out.println("Book:");
-      System.out.println("  isbn=" + isbn);
-      System.out.println("  title=" + title);
-      System.out.println("  author=" + author);
-      System.out.println("  desc=" + desc);
-  }
 }

Modified: commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog/BookFactory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog/BookFactory.java?rev=1130665&r1=1130664&r2=1130665&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog/BookFactory.java
(original)
+++ commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog/BookFactory.java
Thu Jun  2 17:24:30 2011
@@ -59,17 +59,21 @@ import org.apache.commons.digester3.Abst
  * inner classes or anonymous classes if appropriate, reducing the
  * overhead of using this functionality in many cases. 
  */
-public class BookFactory extends AbstractObjectCreationFactory {
+public class BookFactory
+    extends AbstractObjectCreationFactory
+{
 
-    public Object createObject(org.xml.sax.Attributes attributes) 
-    throws Exception {
-        String isbn = attributes.getValue("isbn");
-        
-        if (isbn == null) {
-            throw new Exception(
-                "Mandatory isbn attribute not present on book tag.");
+    public Object createObject( org.xml.sax.Attributes attributes )
+        throws Exception
+    {
+        String isbn = attributes.getValue( "isbn" );
+
+        if ( isbn == null )
+        {
+            throw new Exception( "Mandatory isbn attribute not present on book tag." );
         }
-        
-        return new Book(isbn);
+
+        return new Book( isbn );
     }
+
 }

Modified: commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog/Catalog.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog/Catalog.java?rev=1130665&r1=1130664&r2=1130665&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog/Catalog.java
(original)
+++ commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog/Catalog.java
Thu Jun  2 17:24:30 2011
@@ -23,19 +23,25 @@ import java.util.Iterator;
 /**
  * See Main.java.
  */
-public class Catalog {
+public class Catalog
+{
+
     LinkedList items = new LinkedList();
-    
-    public void addItem(Item item) {
-        items.addLast(item);
+
+    public void addItem( Item item )
+    {
+        items.addLast( item );
     }
-    
-    public void print() {
-        System.out.println("This catalog has " + items.size() + " items");
 
-        for(Iterator i = items.iterator(); i.hasNext(); ) {
+    public void print()
+    {
+        System.out.println( "This catalog has " + items.size() + " items" );
+
+        for ( Iterator i = items.iterator(); i.hasNext(); )
+        {
             Item item = (Item) i.next();
             item.print();
         }
     }
+
 }

Modified: commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog/Item.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog/Item.java?rev=1130665&r1=1130664&r2=1130665&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog/Item.java
(original)
+++ commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog/Item.java
Thu Jun  2 17:24:30 2011
@@ -20,6 +20,9 @@ package org.apache.commons.digester3.exa
 /**
  * See Main.java.
  */
-public interface Item {
+public interface Item
+{
+
     public void print();
+
 }

Modified: commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog/Main.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog/Main.java?rev=1130665&r1=1130664&r2=1130665&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog/Main.java
(original)
+++ commons/sandbox/digester3/trunk/src/examples/api/catalog/src/main/java/org/apache/commons/digester3/examples/api/catalog/Main.java
Thu Jun  2 17:24:30 2011
@@ -39,100 +39,106 @@ import org.apache.commons.digester3.Abst
  * <p>
  * Usage: java Main example.xml
  */
-public class Main {
-    
+public class Main
+{
+
     /**
      * Main method : entry point for running this example program.
      * <p>
      * Usage: java CatalogDigester 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();
-        
+
         // Add rules to the digester that will be triggered while
         // parsing occurs.
-        addRules(d);
-        
+        addRules( d );
+
         // Process the input file.
-        try {
-            java.io.Reader reader = getInputData(filename);
-            d.parse(reader);
+        try
+        {
+            java.io.Reader reader = getInputData( filename );
+            d.parse( reader );
         }
-        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 );
         }
 
         // Get the first object created by the digester's rules
         // (the "root" object). Note that this is exactly the same object
         // returned by the Digester.parse method; either approach works.
         Catalog catalog = (Catalog) d.getRoot();
-        
+
         // Print out all the contents of the catalog, as loaded from
         // the input file.
         catalog.print();
     }
-    
-    private static void addRules(Digester d) {
 
-        //--------------------------------------------------
+    private static void addRules( Digester d )
+    {
+
+        // --------------------------------------------------
 
         // when we encounter the root "catalog" tag, create an
-        // instance of the Catalog class. 
+        // instance of the Catalog class.
         //
-        // Note that this approach is different from the approach taken in 
-        // the AddressBook example, where an initial "root" object was 
-        // explicitly created and pushed onto the digester stack before 
+        // Note that this approach is different from the approach taken in
+        // the AddressBook example, where an initial "root" object was
+        // explicitly created and pushed onto the digester stack before
         // parsing started instead
         //
         // Either approach is fine.
-        
-        d.addObjectCreate("catalog", Catalog.class);
-        
-        //--------------------------------------------------
+
+        d.addObjectCreate( "catalog", Catalog.class );
+
+        // --------------------------------------------------
 
         // when we encounter a book tag, we want to create a Book
         // instance. However the Book class doesn't have a default
         // constructor (one with no arguments), so we can't use
         // the ObjectCreateRule. Instead, we use the FactoryCreateRule.
-        
+
         BookFactory factory = new BookFactory();
-        d.addFactoryCreate("catalog/book", factory);
-        
+        d.addFactoryCreate( "catalog/book", factory );
+
         // and add the book to the parent catalog object (which is
         // the next-to-top object on the digester object stack).
-        d.addSetNext("catalog/book", "addItem");
-        
+        d.addSetNext( "catalog/book", "addItem" );
+
         // we want each subtag of book to map the text contents of
         // the tag into a bean property with the same name as the tag.
         // eg <title>foo</title> --> setTitle("foo")
-        d.addSetNestedProperties("catalog/book");
-        
-        
-        //-----------------------------------------------
-        
+        d.addSetNestedProperties( "catalog/book" );
+
+        // -----------------------------------------------
+
         // We are using the "AudioVisual" class to represent both
         // dvds and videos, so when the "dvd" tag is encountered,
         // create an AudioVisual object.
-        
-        d.addObjectCreate("catalog/dvd", AudioVisual.class);
-        
+
+        d.addObjectCreate( "catalog/dvd", AudioVisual.class );
+
         // add this dvd to the parent catalog object
-        
-        d.addSetNext("catalog/dvd", "addItem");
-        
+
+        d.addSetNext( "catalog/dvd", "addItem" );
+
         // We want to map every xml attribute onto a corresponding
         // property-setter method on the Dvd class instance. However
         // this doesn't work with the xml attribute "year-made", because
@@ -146,9 +152,9 @@ public class Main {
         //
         // For any attributes not explicitly mapped here, the default
         // processing is applied, so xml attribute "category" --> setCategory.
-        
-        d.addSetProperties("catalog/dvd", "year-made", "yearMade");
-        
+
+        d.addSetProperties( "catalog/dvd", "year-made", "yearMade" );
+
         // We also need to tell this AudioVisual object that it is actually
         // a dvd; we can use the ObjectParamRule to pass a string to any
         // method. This usage is a little artificial - normally in this
@@ -156,73 +162,72 @@ public class Main {
         // Note also that equivalent behaviour could be implemented by
         // using factory objects to create & initialise the AudioVisual
         // objects with their type rather than using ObjectCreateRule.
-        
-        d.addCallMethod("catalog/dvd", "setType", 1);
-        d.addObjectParam("catalog/dvd", 0, "dvd"); // pass literal "dvd" string
-        
+
+        d.addCallMethod( "catalog/dvd", "setType", 1 );
+        d.addObjectParam( "catalog/dvd", 0, "dvd" ); // pass literal "dvd" string
+
         // Each tag of form "<attr id="foo" value="bar"/> needs to map
         // to a call to setFoo("bar").
         //
         // This is an alternative to the syntax used for books above (see
-        // method addSetNestedProperties), where the name of the subtag 
-        // indicated which property to set. Using this syntax in the xml has 
-        // advantages and disadvantages both for the user and the application 
-        // developer. It is commonly used with the FactoryCreateRule variant 
-        // which allows the target class to be created to be specified in an 
+        // method addSetNestedProperties), where the name of the subtag
+        // indicated which property to set. Using this syntax in the xml has
+        // advantages and disadvantages both for the user and the application
+        // developer. It is commonly used with the FactoryCreateRule variant
+        // which allows the target class to be created to be specified in an
         // xml attribute; this feature of FactoryCreateRule is not demonstrated
-        // in this example, but see the Apache Tomcat configuration files for 
+        // in this example, but see the Apache Tomcat configuration files for
         // an example of this usage.
         //
         // Note that despite the name similarity, there is no link
         // between SetPropertyRule and SetPropertiesRule.
-        
-        d.addSetProperty("catalog/dvd/attr", "id", "value");
-        
-        //-----------------------------------------------
-        
+
+        d.addSetProperty( "catalog/dvd/attr", "id", "value" );
+
+        // -----------------------------------------------
+
         // and here we repeat the dvd rules, but for the video tag.
-        d.addObjectCreate("catalog/video", AudioVisual.class);
-        d.addSetNext("catalog/video", "addItem");
-        d.addSetProperties("catalog/video", "year-made", "yearMade");
-        d.addCallMethod("catalog/video", "setType", 1);
-        d.addObjectParam("catalog/video", 0, "video");
-        d.addSetProperty("catalog/video/attr", "id", "value");
+        d.addObjectCreate( "catalog/video", AudioVisual.class );
+        d.addSetNext( "catalog/video", "addItem" );
+        d.addSetProperties( "catalog/video", "year-made", "yearMade" );
+        d.addCallMethod( "catalog/video", "setType", 1 );
+        d.addObjectParam( "catalog/video", 0, "video" );
+        d.addSetProperty( "catalog/video/attr", "id", "value" );
     }
 
     /*
-     * Reads the specified file into memory, and returns a StringReader
-     * object which reads from that in-memory buffer.
-     * <p>
-     * This method exists just to demonstrate that the input to the
-     * digester doesn't need to be from a file; for example, xml could
-     * be read from a database or generated dynamically; any old buffer
-     * in memory can be processed by the digester.
-     * <p>
-     * Clearly, if the data is always coming from a file, then calling
-     * the Digester.parse method that takes a File object would be
-     * more sensible (see AddressBook example).
+     * Reads the specified file into memory, and returns a StringReader object which reads
from that in-memory buffer.
+     * <p> This method exists just to demonstrate that the input to the digester doesn't
need to be from a file; for
+     * example, xml could be read from a database or generated dynamically; any old buffer
in memory can be processed by
+     * the digester. <p> Clearly, if the data is always coming from a file, then calling
the Digester.parse method that
+     * takes a File object would be more sensible (see AddressBook example).
      */
-    private static java.io.Reader getInputData(String filename) 
-    throws java.io.IOException {
-        java.io.File srcfile = new java.io.File(filename);
-        
-        java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(1000);
+    private static java.io.Reader getInputData( String filename )
+        throws java.io.IOException
+    {
+        java.io.File srcfile = new java.io.File( filename );
+
+        java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream( 1000 );
         byte[] buf = new byte[100];
-        java.io.FileInputStream fis = new java.io.FileInputStream(srcfile);
-        for(;;) {
-            int nread = fis.read(buf);
-            if (nread == -1) {
+        java.io.FileInputStream fis = new java.io.FileInputStream( srcfile );
+        for ( ;; )
+        {
+            int nread = fis.read( buf );
+            if ( nread == -1 )
+            {
                 break;
             }
-            baos.write(buf, 0, nread);
+            baos.write( buf, 0, nread );
         }
         fis.close();
-        
+
         return new java.io.StringReader( baos.toString() );
-        
+
     }
-    
-    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
+
+}



Mime
View raw message