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/test/org/apache/commons/digester DigesterTestCase.java
Date Thu, 22 May 2003 17:00:55 GMT
rdonkin     2003/05/22 10:00:55

  Modified:    digester/src/java/org/apache/commons/digester Digester.java
               digester/src/test/org/apache/commons/digester
                        DigesterTestCase.java
  Log:
  Added extra method that should be called once - and only once - when digester is run. This
should allow subclasses to use lazy initialization more easily. Also, changed the javadocs
to make it clear that configure may be called more than once.  Suggested by Neale Swinnerton.
  
  Revision  Changes    Path
  1.78      +37 -5     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.77
  retrieving revision 1.78
  diff -u -r1.77 -r1.78
  --- Digester.java	7 May 2003 09:28:24 -0000	1.77
  +++ Digester.java	22 May 2003 17:00:55 -0000	1.78
  @@ -2386,9 +2386,18 @@
   
   
       /**
  +     * <p>
        * Provide a hook for lazy configuration of this <code>Digester</code>
        * instance.  The default implementation does nothing, but subclasses
        * can override as needed.
  +     * </p>
  +     *
  +     * <p>
  +     * <strong>Note</strong> This method may be called more than once.
  +     * Once only initialization code should be placed in {@link #initialize}
  +     * or the code should take responsibility by checking and setting the 
  +     * {@link #configured} flag.
  +     * </p>
        */
       protected void configure() {
   
  @@ -2398,13 +2407,36 @@
           }
   
           // Perform lazy configuration as needed
  -        ; // Nothing required by default
  +        initialize(); // call hook method for subclasses that want to be initialized once
only
  +        // Nothing else required by default
   
           // Set the configuration flag to avoid repeating
           configured = true;
   
       }
  +    
  +    /**
  +     * <p>
  +     * Provides a hook for lazy initialization of this <code>Digester</code>
  +     * instance.  
  +     * The default implementation does nothing, but subclasses
  +     * can override as needed.
  +     * Digester (by default) only calls this method once.
  +     * </p>
  +     *
  +     * <p>
  +     * <strong>Note</strong> This method will be called by {@link #configure}

  +     * only when the {@link #configured} flag is false. 
  +     * Subclasses that override <code>configure</code> or who set <code>configured</code>
  +     * may find that this method may be called more than once.
  +     * </p>
  +     */
  +    protected void initialize() {
  +
  +        // Perform lazy initialization as needed
  +        ; // Nothing required by default
   
  +    }    
   
       // -------------------------------------------------------- Package Methods
   
  
  
  
  1.13      +23 -5     jakarta-commons/digester/src/test/org/apache/commons/digester/DigesterTestCase.java
  
  Index: DigesterTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/DigesterTestCase.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- DigesterTestCase.java	16 Apr 2003 11:23:49 -0000	1.12
  +++ DigesterTestCase.java	22 May 2003 17:00:55 -0000	1.13
  @@ -64,6 +64,7 @@
   
   
   import java.net.URL;
  +import java.io.StringReader;
   import java.util.Iterator;
   import java.util.List;
   import java.util.Map;
  @@ -351,5 +352,22 @@
   
       }
   
  -
  +    public void testOnceAndOnceOnly() throws Exception {
  +        
  +        class TestConfigureDigester extends Digester {
  +            public int called=0;
  +            public TestConfigureDigester() {}
  +            
  +            protected void initialize() {
  +                called++;
  +            }
  +        }
  +        
  +        TestConfigureDigester digester = new TestConfigureDigester();
  +        
  +        String xml = "<?xml version='1.0'?><document/>";
  +        digester.parse(new StringReader(xml));
  +        
  +        assertEquals("Initialize should be called once and only once", 1, digester.called);
  +    }
   }
  
  
  

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