You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by js...@apache.org on 2002/06/05 09:57:07 UTC

cvs commit: jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/expression MethodUpdater.java

jstrachan    2002/06/05 00:57:07

  Modified:    betwixt/src/test/org/apache/commons/betwixt/scarab
                        GlobalAttributeOption.java GlobalAttribute.java
                        TestScarabSettings.java
               betwixt  project.properties build.xml
               betwixt/src/java/org/apache/commons/betwixt/io
                        BeanCreateRule.java
               betwixt/src/java/org/apache/commons/betwixt/expression
                        MethodUpdater.java
  Log:
  Fixed a bug with betwixt that was causing the wrong context to be used when attempting to set properties.
  The bug was actually due to multiple similar rules being fired at the same time; the second copy of the rule would think it was nested inside the former, causing the wrong context to be used to set properties.
  
  Have we explicitly ignore multiple rules which removes this problem (as well as avoiding redundant processing).
  
  betwixt now passes all unit test cases.
  
  Revision  Changes    Path
  1.4       +5 -1      jakarta-commons-sandbox/betwixt/src/test/org/apache/commons/betwixt/scarab/GlobalAttributeOption.java
  
  Index: GlobalAttributeOption.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/src/test/org/apache/commons/betwixt/scarab/GlobalAttributeOption.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- GlobalAttributeOption.java	1 Jun 2002 18:46:59 -0000	1.3
  +++ GlobalAttributeOption.java	5 Jun 2002 07:57:07 -0000	1.4
  @@ -73,7 +73,7 @@
    * <p><code>GlobalAttributeOption</code> is a sample bean for use by the test cases.</p>
    *
    * @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
  - * @version $Id: GlobalAttributeOption.java,v 1.3 2002/06/01 18:46:59 jon Exp $
  + * @version $Id: GlobalAttributeOption.java,v 1.4 2002/06/05 07:57:07 jstrachan Exp $
    */
   public class GlobalAttributeOption implements Serializable
   {
  @@ -86,6 +86,10 @@
        */
       public GlobalAttributeOption()
       { 
  +    }
  +    
  +    public String toString() {
  +        return super.toString() + "[name=" + name + ";childOption=" + childOption + "]";
       }
   
       public void setName(String name)
  
  
  
  1.4       +5 -1      jakarta-commons-sandbox/betwixt/src/test/org/apache/commons/betwixt/scarab/GlobalAttribute.java
  
  Index: GlobalAttribute.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/src/test/org/apache/commons/betwixt/scarab/GlobalAttribute.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- GlobalAttribute.java	1 Jun 2002 18:46:59 -0000	1.3
  +++ GlobalAttribute.java	5 Jun 2002 07:57:07 -0000	1.4
  @@ -72,7 +72,7 @@
    * <p><code>GlobalAttribute</code> is a sample bean for use by the test cases.</p>
    *
    * @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
  - * @version $Id: GlobalAttribute.java,v 1.3 2002/06/01 18:46:59 jon Exp $
  + * @version $Id: GlobalAttribute.java,v 1.4 2002/06/05 07:57:07 jstrachan Exp $
    */
   public class GlobalAttribute implements Serializable
   {
  @@ -92,6 +92,10 @@
       public GlobalAttribute() 
       {
           globalAttributeOptions = new ArrayList();
  +    }
  +
  +    public String toString() {
  +        return super.toString() + "[options=" + globalAttributeOptions + "]";
       }
   
       public void addGlobalAttributeOption(GlobalAttributeOption globalAttributeOption)
  
  
  
  1.7       +6 -2      jakarta-commons-sandbox/betwixt/src/test/org/apache/commons/betwixt/scarab/TestScarabSettings.java
  
  Index: TestScarabSettings.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/src/test/org/apache/commons/betwixt/scarab/TestScarabSettings.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestScarabSettings.java	1 Jun 2002 19:08:56 -0000	1.6
  +++ TestScarabSettings.java	5 Jun 2002 07:57:07 -0000	1.7
  @@ -81,7 +81,7 @@
    * Test harness which round trips a Scarab's settings xml file
    *
    * @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
  - * @version $Id: TestScarabSettings.java,v 1.6 2002/06/01 19:08:56 jon Exp $
  + * @version $Id: TestScarabSettings.java,v 1.7 2002/06/05 07:57:07 jstrachan Exp $
    */
   public class TestScarabSettings extends AbstractTestCase
   {
  @@ -120,7 +120,6 @@
           ScarabSettings ss = (ScarabSettings) reader.parse(
               new FileInputStream("src/test/org/apache/commons/betwixt/scarab/scarab-settings.xml"));
   
  -        /*
           // now lets output it to a buffer
           StringWriter buffer = new StringWriter();
           write(ss, buffer);
  @@ -133,6 +132,7 @@
   
           System.out.println(text);
   
  +        /*
           ScarabSettings newScarabSettings = (ScarabSettings) reader.parse(new StringReader(text));
   
           // managed to parse it again!
  @@ -191,6 +191,10 @@
           assertEquals("Functional area", ga.getName());
   
           List globalAttributeOptions = ga.getGlobalAttributeOptions();
  +        
  +        System.out.println( "GlobalAttribute: " + ga);
  +        System.out.println( "globalAttributeOptions: " + globalAttributeOptions);
  +        
           assertEquals(globalAttributeOptions.size(), 2);
           GlobalAttributeOption gao = (GlobalAttributeOption) globalAttributeOptions.get(0);
           assertEquals("UI", gao.getChildOption());        
  
  
  
  1.4       +1 -1      jakarta-commons-sandbox/betwixt/project.properties
  
  Index: project.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/project.properties,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- project.properties	28 May 2002 23:01:07 -0000	1.3
  +++ project.properties	5 Jun 2002 07:57:07 -0000	1.4
  @@ -7,7 +7,7 @@
   maven.compile.deprecation = on
   
   maven.jarResources.basedir=${basedir}/src/java
  -maven.junit.usefile = false  
  +maven.junit.usefile = true  
   
   #
   # Maven callback for unit test stuff to copy .betwixt files 
  
  
  
  1.22      +18 -2     jakarta-commons-sandbox/betwixt/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/build.xml,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- build.xml	1 Jun 2002 18:17:52 -0000	1.21
  +++ build.xml	5 Jun 2002 07:57:07 -0000	1.22
  @@ -1,6 +1,6 @@
   <?xml version="1.0"?>
   
  -<!-- $Id: build.xml,v 1.21 2002/06/01 18:17:52 jon Exp $ -->
  +<!-- $Id: build.xml,v 1.22 2002/06/05 07:57:07 jstrachan Exp $ -->
   <project name="betwixt" default="maven:jar" basedir=".">
   
   
  @@ -277,7 +277,6 @@
       <maven-ant antfile="${maven.home}/plugins/test/build.xml" target="run-singletest"/>
      </target>
   
  -
      <target name="test.maven.debug" depends="compile.tests" 
         description="Runs the Maven unit test with debugging on">
       <java classname="org.apache.commons.betwixt.TestMavenProject" fork="yes">
  @@ -287,6 +286,23 @@
         <sysproperty key="org.apache.commons.logging.simplelog.log.org.apache.commons.digester.Digester.sax" value="warn"/>
       </java>
      </target>
  +
  +   <target name="test.scarab"
  +      description="Runs the Scarab unit test">
  +    <property name="maven.testcase" value="org.apache.commons.betwixt.scarab.TestScarabSettings"/>   
  +    <maven-ant antfile="${maven.home}/plugins/test/build.xml" target="run-singletest"/>
  +   </target>
  +
  +   <target name="test.scarab.debug" depends="compile.tests"
  +      description="Runs the Scarab unit test with debugging on">
  +    <java classname="org.apache.commons.betwixt.scarab.TestScarabSettings" fork="yes">
  +      <classpath refid="test.classpath"/>
  +      <sysproperty key="org.apache.commons.logging.simplelog.defaultlog" value="debug"/>
  +      <sysproperty key="org.apache.commons.logging.simplelog.log.org.apache.commons.digester.Digester" value="warn"/>
  +      <sysproperty key="org.apache.commons.logging.simplelog.log.org.apache.commons.digester.Digester.sax" value="warn"/>
  +    </java>
  +   </target>
  +
   
   <!-- ========== Sample Program Targets ==================================== -->
   
  
  
  
  1.16      +25 -13    jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/io/BeanCreateRule.java
  
  Index: BeanCreateRule.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/io/BeanCreateRule.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- BeanCreateRule.java	3 Jun 2002 20:51:08 -0000	1.15
  +++ BeanCreateRule.java	5 Jun 2002 07:57:07 -0000	1.16
  @@ -5,12 +5,13 @@
    * version 1.1, a copy of which has been included with this distribution in
    * the LICENSE file.
    * 
  - * $Id: BeanCreateRule.java,v 1.15 2002/06/03 20:51:08 jon Exp $
  + * $Id: BeanCreateRule.java,v 1.16 2002/06/05 07:57:07 jstrachan Exp $
    */
   package org.apache.commons.betwixt.io;
   
   import java.util.HashMap;
   import java.util.Iterator;
  +import java.util.List;
   import java.util.Map;
   
   import org.apache.commons.betwixt.AttributeDescriptor;
  @@ -22,6 +23,7 @@
   import org.apache.commons.betwixt.digester.XMLIntrospectorHelper;
   
   import org.apache.commons.digester.Rule;
  +import org.apache.commons.digester.Rules;
   import org.apache.commons.digester.Digester;
   
   import org.apache.commons.logging.Log;
  @@ -33,7 +35,7 @@
     * from the betwixt XML metadata.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.15 $
  +  * @version $Revision: 1.16 $
     */
   public class BeanCreateRule extends Rule {
   
  @@ -99,7 +101,7 @@
           // XXX: we should probably use a stack of booleans to test if we created a bean
           // XXX: or let digester take nulls, which would be easier for us ;-)
           createdBean = false;
  -        
  +                
           Object instance = null;
           if ( beanClass != null ) {
               instance = createBean(attributes);
  @@ -110,11 +112,12 @@
                   Updater updater = descriptor.getUpdater();
                   if ( updater != null ) {
                       if ( log.isDebugEnabled() ) {
  -                        log.debug( "Calling updater for: " + descriptor + " with: " + instance );
  +                        log.debug( "Calling updater for: " + descriptor + " with: " + instance + " on bean: " + context.getBean() );
                       }
                       updater.update( context, instance );
                   }
                   context.setBean( instance );
  +                digester.push(instance);
                   
           
                   // if we are a reference to a type we should lookup the original
  @@ -157,8 +160,6 @@
                   }
                   
                   addChildRules();
  -
  -                digester.push(instance);
               }
           }
       }
  @@ -241,10 +242,7 @@
                           }
                           else {
                               Rule rule = new BeanCreateRule( childDescriptor, context, path + '/' );
  -                            digester.addRule( path, rule );
  -                            if ( log.isDebugEnabled() ) {
  -                                log.debug( "Added rule to path1: "+ path + ", rule: " + rule + ", class: " + beanClass.getName());
  -                            }
  +                            addRule( path, rule );
                           }
                       }
                   }
  @@ -290,9 +288,23 @@
                   childDescriptor.getUpdater().update( context, text );
               }        
           };
  -        digester.addRule( path, rule );
  -        if ( log.isDebugEnabled() ) {
  -            log.debug( "Added rule to path2: "+ path + ", rule: " + rule + ", class: " + beanClass.getName());
  +        addRule( path, rule );
  +    }
  +    
  +    protected void addRule(String path, Rule rule) {
  +        Rules rules = digester.getRules();
  +        List matches = rules.match(null, path);
  +        if ( matches.isEmpty() ) {
  +            if ( log.isDebugEnabled() ) {
  +                log.debug( "Adding digester rule for path: " + path + " rule: " + rule );
  +            }
  +            digester.addRule( path, rule );
  +        }
  +        else {
  +            if ( log.isDebugEnabled() ) {
  +                log.debug( "Ignoring duplicate digester rule for path: " + path + " rule: " + rule );
  +            }
           }
       }
  +
   }
  
  
  
  1.7       +3 -2      jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/expression/MethodUpdater.java
  
  Index: MethodUpdater.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/expression/MethodUpdater.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- MethodUpdater.java	28 May 2002 23:01:08 -0000	1.6
  +++ MethodUpdater.java	5 Jun 2002 07:57:07 -0000	1.7
  @@ -5,7 +5,7 @@
    * version 1.1, a copy of which has been included with this distribution in
    * the LICENSE file.
    * 
  - * $Id: MethodUpdater.java,v 1.6 2002/05/28 23:01:08 jstrachan Exp $
  + * $Id: MethodUpdater.java,v 1.7 2002/06/05 07:57:07 jstrachan Exp $
    */
   package org.apache.commons.betwixt.expression;
   
  @@ -21,7 +21,7 @@
     * or element.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.6 $
  +  * @version $Revision: 1.7 $
     */
   public class MethodUpdater implements Updater {
   
  @@ -108,5 +108,6 @@
        * Strategy method to allow derivations to handle exceptions differently.
        */
       protected void handleException(Context context, Exception e) {
  +        log.info( "Caught exception: " + e, e );
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>