commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject cvs commit: jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/io BeanCreateRule.java BeanReader.java
Date Tue, 28 May 2002 23:01:08 GMT
jstrachan    02/05/28 16:01:08

  Modified:    betwixt/src/java/org/apache/commons/betwixt/digester
                        XMLBeanInfoDigester.java ElementRule.java
                        AttributeRule.java InfoRule.java HideRule.java
                        XMLIntrospectorHelper.java RuleSupport.java
                        AddDefaultsRule.java
               betwixt  project.properties build.xml
               betwixt/src/java/org/apache/commons/betwixt/strategy
                        DefaultPluralStemmer.java PluralStemmer.java
               betwixt/src/test/org/apache/commons/betwixt
                        TestBeanReader.java TestMavenProject.java
               betwixt/src/java/org/apache/commons/betwixt/expression
                        MethodUpdater.java
               betwixt/src/test/org/apache/commons/digester/rss
                        Channel.betwixt Image.betwixt
               betwixt/src/java/org/apache/commons/betwixt
                        XMLIntrospector.java
               betwixt/src/java/org/apache/commons/betwixt/io
                        BeanCreateRule.java BeanReader.java
  Added:       betwixt/src/java/org/apache/commons/betwixt/strategy
                        DecapitalizeNameMapper.java NameMapper.java
                        DefaultNameMapper.java
  Log:
  Got all the unit test cases working at last. The betwixt build is now fully Maven-ized!
  
  The Maven test case now works, we can round trip Maven project beans properly now. We have 2 plugin strategies
  
  * PluralStemmer (for detecting plural property descriptors from a singular property from the adder method)
  * NameMapper (for turning bean type names into XML elements)
  
  along with default implementations that match Maven / Turbine results.
  
  We still need to test the round tripping more with all fields of the Maven / Turbine XML schemas to check there are no bugs left, but its certainly looking pretty close.
  
  Revision  Changes    Path
  1.5       +10 -10    jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/XMLBeanInfoDigester.java
  
  Index: XMLBeanInfoDigester.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/XMLBeanInfoDigester.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- XMLBeanInfoDigester.java	17 May 2002 15:24:12 -0000	1.4
  +++ XMLBeanInfoDigester.java	28 May 2002 23:01:07 -0000	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/XMLBeanInfoDigester.java,v 1.4 2002/05/17 15:24:12 jstrachan Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/05/17 15:24:12 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/XMLBeanInfoDigester.java,v 1.5 2002/05/28 23:01:07 jstrachan Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/05/28 23:01:07 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: XMLBeanInfoDigester.java,v 1.4 2002/05/17 15:24:12 jstrachan Exp $
  + * $Id: XMLBeanInfoDigester.java,v 1.5 2002/05/28 23:01:07 jstrachan Exp $
    */
   package org.apache.commons.betwixt.digester;
   
  @@ -80,7 +80,7 @@
     * containing XMLBeanInfo definitions for a JavaBean.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.4 $
  +  * @version $Revision: 1.5 $
     */
   public class XMLBeanInfoDigester extends Digester {
   
  @@ -175,11 +175,11 @@
            
               // add the various rules
               
  -            addRule( "info", new InfoRule( this ) );
  -            addRule( "*/element", new ElementRule( this ) );
  -            addRule( "*/attribute", new AttributeRule( this ) );
  -            addRule( "*/hide", new HideRule( this ) );
  -            addRule( "*/addDefaults", new AddDefaultsRule( this ) );
  +            addRule( "info", new InfoRule() );
  +            addRule( "*/element", new ElementRule() );
  +            addRule( "*/attribute", new AttributeRule() );
  +            addRule( "*/hide", new HideRule() );
  +            addRule( "*/addDefaults", new AddDefaultsRule() );
           }
           
           // now initialize
  
  
  
  1.5       +6 -7      jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/ElementRule.java
  
  Index: ElementRule.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/ElementRule.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ElementRule.java	17 May 2002 15:24:12 -0000	1.4
  +++ ElementRule.java	28 May 2002 23:01:07 -0000	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/ElementRule.java,v 1.4 2002/05/17 15:24:12 jstrachan Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/05/17 15:24:12 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/ElementRule.java,v 1.5 2002/05/28 23:01:07 jstrachan Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/05/28 23:01:07 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: ElementRule.java,v 1.4 2002/05/17 15:24:12 jstrachan Exp $
  + * $Id: ElementRule.java,v 1.5 2002/05/28 23:01:07 jstrachan Exp $
    */
   package org.apache.commons.betwixt.digester;
   
  @@ -89,7 +89,7 @@
   /** <p><code>ElementRule</code> the digester Rule for parsing the &lt;element&gt; elements.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.4 $
  +  * @version $Revision: 1.5 $
     */
   public class ElementRule extends RuleSupport {
   
  @@ -100,8 +100,7 @@
       
       private Class beanClass;
       
  -    public ElementRule(Digester digester) {
  -        super(digester);
  +    public ElementRule() {
           this.classLoader = getClass().getClassLoader();
       }
       
  
  
  
  1.4       +6 -7      jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/AttributeRule.java
  
  Index: AttributeRule.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/AttributeRule.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AttributeRule.java	17 May 2002 15:24:12 -0000	1.3
  +++ AttributeRule.java	28 May 2002 23:01:07 -0000	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/AttributeRule.java,v 1.3 2002/05/17 15:24:12 jstrachan Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/05/17 15:24:12 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/AttributeRule.java,v 1.4 2002/05/28 23:01:07 jstrachan Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/05/28 23:01:07 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: AttributeRule.java,v 1.3 2002/05/17 15:24:12 jstrachan Exp $
  + * $Id: AttributeRule.java,v 1.4 2002/05/28 23:01:07 jstrachan Exp $
    */
   package org.apache.commons.betwixt.digester;
   
  @@ -88,7 +88,7 @@
   /** <p><code>AttributeRule</code> the digester Rule for parsing the &lt;attribute&gt; elements.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.3 $
  +  * @version $Revision: 1.4 $
     */
   public class AttributeRule extends RuleSupport {
   
  @@ -99,8 +99,7 @@
       
       private Class beanClass;
       
  -    public AttributeRule(Digester digester) {
  -        super(digester);
  +    public AttributeRule() {
           this.classLoader = getClass().getClassLoader();
       }
       
  
  
  
  1.4       +6 -7      jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/InfoRule.java
  
  Index: InfoRule.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/InfoRule.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- InfoRule.java	17 May 2002 15:24:12 -0000	1.3
  +++ InfoRule.java	28 May 2002 23:01:07 -0000	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/InfoRule.java,v 1.3 2002/05/17 15:24:12 jstrachan Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/05/17 15:24:12 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/InfoRule.java,v 1.4 2002/05/28 23:01:07 jstrachan Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/05/28 23:01:07 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: InfoRule.java,v 1.3 2002/05/17 15:24:12 jstrachan Exp $
  + * $Id: InfoRule.java,v 1.4 2002/05/28 23:01:07 jstrachan Exp $
    */
   package org.apache.commons.betwixt.digester;
   
  @@ -79,7 +79,7 @@
   /** <p><code>InfoRule</code> the digester Rule for parsing the info element.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.3 $
  +  * @version $Revision: 1.4 $
     */
   public class InfoRule extends RuleSupport {
   
  @@ -89,8 +89,7 @@
       private XMLBeanInfo xmlBeanInfo;
       
       
  -    public InfoRule(Digester digester) {
  -        super(digester);
  +    public InfoRule() {
       }
       
       // Rule interface
  
  
  
  1.3       +6 -7      jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/HideRule.java
  
  Index: HideRule.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/HideRule.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- HideRule.java	17 May 2002 15:24:12 -0000	1.2
  +++ HideRule.java	28 May 2002 23:01:07 -0000	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/HideRule.java,v 1.2 2002/05/17 15:24:12 jstrachan Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/05/17 15:24:12 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/HideRule.java,v 1.3 2002/05/28 23:01:07 jstrachan Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/05/28 23:01:07 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: HideRule.java,v 1.2 2002/05/17 15:24:12 jstrachan Exp $
  + * $Id: HideRule.java,v 1.3 2002/05/28 23:01:07 jstrachan Exp $
    */
   package org.apache.commons.betwixt.digester;
   
  @@ -74,7 +74,7 @@
   /** <p><code>HideRule</code> hides the property of the given name.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.2 $
  +  * @version $Revision: 1.3 $
     */
   public class HideRule extends RuleSupport {
   
  @@ -82,8 +82,7 @@
       private static final Log log = LogFactory.getLog( HideRule.class );
       
       
  -    public HideRule(Digester digester) {
  -        super(digester);
  +    public HideRule() {
       }
       
       // Rule interface
  
  
  
  1.7       +39 -38    jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/XMLIntrospectorHelper.java
  
  Index: XMLIntrospectorHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/XMLIntrospectorHelper.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XMLIntrospectorHelper.java	28 May 2002 14:17:22 -0000	1.6
  +++ XMLIntrospectorHelper.java	28 May 2002 23:01:07 -0000	1.7
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/XMLIntrospectorHelper.java,v 1.6 2002/05/28 14:17:22 jstrachan Exp $
  - * $Revision: 1.6 $
  - * $Date: 2002/05/28 14:17:22 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/XMLIntrospectorHelper.java,v 1.7 2002/05/28 23:01:07 jstrachan Exp $
  + * $Revision: 1.7 $
  + * $Date: 2002/05/28 23:01:07 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: XMLIntrospectorHelper.java,v 1.6 2002/05/28 14:17:22 jstrachan Exp $
  + * $Id: XMLIntrospectorHelper.java,v 1.7 2002/05/28 23:01:07 jstrachan Exp $
    */
   package org.apache.commons.betwixt.digester;
   
  @@ -99,7 +99,7 @@
     * common code shared between the digestor and introspector.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.6 $
  +  * @version $Revision: 1.7 $
     */
   public class XMLIntrospectorHelper {
   
  @@ -334,28 +334,17 @@
                           // is not one already
                           ElementDescriptor descriptor = findGetCollectionDescriptor( introspector, rootDescriptor, propertyName );
                           if ( descriptor != null ) {
  -                            if ( descriptor.getUpdater() == null ) {
  -                                if ( log.isDebugEnabled() ) {
  -                                    log.debug( 
  -                                        "Adding the updater for the method: " + method 
  -                                        + " on type: " + beanClass.getName() 
  -                                    );
  -                                }
  -                                descriptor.setUpdater( new MethodUpdater( method ) );
  -                                descriptor.setSingularPropertyType( types[0] );
  -                            }
  +                            descriptor.setUpdater( new MethodUpdater( method ) );
  +                            descriptor.setSingularPropertyType( types[0] );
                               
  -                            if ( introspector.isWrapCollectionsInElement() ) {
  -                                // lets wrap the descriptor in a dummy element
  -                                ElementDescriptor parent = new ElementDescriptor();
  -                                parent.setQualifiedName( descriptor.getPropertyName() );
  -                                ElementDescriptor[] children = new ElementDescriptor[] {
  -                                    descriptor
  -                                };
  -                                parent.setElementDescriptors( children );
  -                                descriptor.setQualifiedName( propertyName );
  -                                // now lets try swap in the new element descriptor above the current one
  -                                swapDescriptor( rootDescriptor, descriptor, parent );
  +                            // is there a child element with no localName
  +                            ElementDescriptor[] children = descriptor.getElementDescriptors();
  +                            if ( children != null && children.length > 0 ) {
  +                                ElementDescriptor child = children[0];
  +                                String localName = child.getLocalName();
  +                                if ( localName == null || localName.length() == 0 ) {
  +                                    child.setLocalName( propertyName );
  +                                }
                               }
                           }
                           else {
  @@ -384,7 +373,10 @@
       
       /** Returns true for primitive types */
       public static boolean isPrimitiveType(Class type) {
  -        if ( type.isPrimitive() ) {
  +        if ( type == null ) {
  +            return false;
  +        }
  +        else if ( type.isPrimitive() ) {
               return true;
           }
           else if ( type.equals( Object.class ) ) {
  @@ -406,24 +398,33 @@
        * descriptor for the 'children' getter property should be returned.
        */
       protected static ElementDescriptor findGetCollectionDescriptor( XMLIntrospector introspector, ElementDescriptor rootDescriptor, String propertyName ) {
  +        // create the Map of propertyName -> descriptor that the PluralStemmer will choose
  +        Map map = new HashMap();
  +        //String propertyName = rootDescriptor.getPropertyName();
  +        if (propertyName != null) {
  +            map.put(propertyName, rootDescriptor);
  +        }
  +        makeElementDescriptorMap( rootDescriptor, map );
  +        
           PluralStemmer stemmer = introspector.getPluralStemmer();
  +        return stemmer.findPluralDescriptor( propertyName, map );
  +    }
  +
  +    /**
  +     * Creates a map where the keys are the property names and the values are the ElementDescriptors
  +     */
  +    protected static void makeElementDescriptorMap( ElementDescriptor rootDescriptor, Map map ) {
           ElementDescriptor[] children = rootDescriptor.getElementDescriptors();
           if ( children != null ) {
               for ( int i = 0, size = children.length; i < size; i++ ) {
  -                ElementDescriptor child = children[i];
  -                String childPropertyName = child.getPropertyName();                
  -                if ( childPropertyName != null ) {
  -                    if ( stemmer.isPluralNameFor(childPropertyName, propertyName) ) {
  -                        return child;
  -                    }
  -                }
  -                ElementDescriptor answer = findGetCollectionDescriptor( introspector, child, propertyName );
  -                if ( answer != null ) {
  -                    return answer;
  +                ElementDescriptor child = children[i];                
  +                String propertyName = child.getPropertyName();                
  +                if ( propertyName != null ) {
  +                    map.put( propertyName, child );
                   }
  +                makeElementDescriptorMap( child, map );
               }
           }
  -        return null;
       }
   
       /**
  
  
  
  1.4       +6 -7      jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/RuleSupport.java
  
  Index: RuleSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/RuleSupport.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RuleSupport.java	28 May 2002 13:38:26 -0000	1.3
  +++ RuleSupport.java	28 May 2002 23:01:07 -0000	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/RuleSupport.java,v 1.3 2002/05/28 13:38:26 jstrachan Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/05/28 13:38:26 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/RuleSupport.java,v 1.4 2002/05/28 23:01:07 jstrachan Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/05/28 23:01:07 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: RuleSupport.java,v 1.3 2002/05/28 13:38:26 jstrachan Exp $
  + * $Id: RuleSupport.java,v 1.4 2002/05/28 23:01:07 jstrachan Exp $
    */
   package org.apache.commons.betwixt.digester;
   
  @@ -89,15 +89,14 @@
     * helper methods.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.3 $
  +  * @version $Revision: 1.4 $
     */
   public class RuleSupport extends Rule {
   
       /** Logger */
       private static final Log log = LogFactory.getLog( RuleSupport.class );
       
  -    public RuleSupport(Digester digester) {
  -        super(digester);
  +    public RuleSupport() {
       }
       
       
  
  
  
  1.6       +6 -7      jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/AddDefaultsRule.java
  
  Index: AddDefaultsRule.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/AddDefaultsRule.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AddDefaultsRule.java	28 May 2002 13:38:26 -0000	1.5
  +++ AddDefaultsRule.java	28 May 2002 23:01:07 -0000	1.6
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/AddDefaultsRule.java,v 1.5 2002/05/28 13:38:26 jstrachan Exp $
  - * $Revision: 1.5 $
  - * $Date: 2002/05/28 13:38:26 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/digester/AddDefaultsRule.java,v 1.6 2002/05/28 23:01:07 jstrachan Exp $
  + * $Revision: 1.6 $
  + * $Date: 2002/05/28 23:01:07 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: AddDefaultsRule.java,v 1.5 2002/05/28 13:38:26 jstrachan Exp $
  + * $Id: AddDefaultsRule.java,v 1.6 2002/05/28 23:01:07 jstrachan Exp $
    */
   package org.apache.commons.betwixt.digester;
   
  @@ -87,7 +87,7 @@
     * to the current element.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.5 $
  +  * @version $Revision: 1.6 $
     */
   public class AddDefaultsRule extends RuleSupport {
   
  @@ -95,8 +95,7 @@
       private static final Log log = LogFactory.getLog( AddDefaultsRule.class );
       
       
  -    public AddDefaultsRule(Digester digester) {
  -        super(digester);
  +    public AddDefaultsRule() {
       }
       
       // Rule interface
  
  
  
  1.3       +9 -3      jakarta-commons-sandbox/betwixt/project.properties
  
  Index: project.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/project.properties,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- project.properties	28 May 2002 11:49:29 -0000	1.2
  +++ project.properties	28 May 2002 23:01:07 -0000	1.3
  @@ -2,12 +2,18 @@
   # P R O J E C T  P R O P E R T I E S
   # -------------------------------------------------------------------
   
  -compile.debug = on
  -compile.optimize = off
  -compile.deprecation = off
  +maven.compile.debug = on
  +maven.compile.optimize = off
  +maven.compile.deprecation = on
   
   maven.jarResources.basedir=${basedir}/src/java
   maven.junit.usefile = false  
  +
  +#
  +# Maven callback for unit test stuff to copy .betwixt files 
  +#
  +maven.test.callback.pre-test.buildFile = build.xml
  +maven.test.callback.pre-test.buildTarget = test-resources
   
   # use Sun coding standards
   
  
  
  
  1.19      +27 -2     jakarta-commons-sandbox/betwixt/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/build.xml,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- build.xml	28 May 2002 13:38:26 -0000	1.18
  +++ build.xml	28 May 2002 23:01:07 -0000	1.19
  @@ -1,6 +1,6 @@
   <?xml version="1.0"?>
   
  -<!-- $Id: build.xml,v 1.18 2002/05/28 13:38:26 jstrachan Exp $ -->
  +<!-- $Id: build.xml,v 1.19 2002/05/28 23:01:07 jstrachan Exp $ -->
   <project name="betwixt" default="maven:jar" basedir=".">
   
   
  @@ -190,6 +190,9 @@
   	  <path id="test.classpath">
   	    <pathelement path="${maven.build.dest}"/>
   	    <pathelement path="${maven.test.dest}"/>
  +	    
  +	    <!-- pick up the test .betwixt files -->
  +	    <pathelement path="src/test"/>
           <path refid="maven.dependency.classpath"/>
       	<pathelement location="${lib.repo}/junit-3.7.jar"/>
       	<pathelement location="${lib.repo}/xmlParserAPIs-2.0.0.jar"/>
  @@ -197,6 +200,9 @@
           <path path="${classpath}"/>
           <path path="${java.classpath}"/>
   	  </path>
  +	  
  +	  <echo message="test callback file: ${maven.test.callback.pre-test.buildFile} and target: ${maven.test.callback.pre-test.buildTarget}"/>
  +
       </target>	
   
   	<target name="compile.tests" depends="compile, maven:compile-test"/>
  @@ -204,6 +210,15 @@
   	<target name="dist" depends="maven:dist"/>
   	<target name="site" depends="maven:site"/>
   	
  +	<target name="test-resources" 
  +	  description="Copies all resources required by the test cases into the build area">
  +	  <echo message="Runing the test-resources target!!!"/>
  +	  
  +	  <copy todir="${maven.test.dest}">
  +        <fileset dir="${maven.unitTestSourceDirectory}" includes="**/*.betwixt"/>
  +      </copy>
  +    </target>	
  +
   
   <!-- ========== Unit Test Targets ========================================= -->
   
  @@ -246,6 +261,16 @@
       </java>
      </target>
   
  +   <target name="test.rss.debug" depends="compile.tests" 
  +      description="Runs the RSS round trip unit tests with debugging on">
  +    <java classname="org.apache.commons.betwixt.TestRSSRoundTrip" 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>
  +
      <target name="test.maven"
         description="Runs the Maven unit test">
   	<property name="maven.testcase" value="org.apache.commons.betwixt.TestMavenProject"/>	
  @@ -254,7 +279,7 @@
   
   
      <target name="test.maven.debug" depends="compile.tests" 
  -      description="Runs the Maven unit test, with debugging on">
  +      description="Runs the Maven unit test with debugging on">
       <java classname="org.apache.commons.betwixt.TestMavenProject" fork="yes">
         <classpath refid="test.classpath"/>
         <sysproperty key="org.apache.commons.logging.simplelog.defaultlog" value="debug"/>
  
  
  
  1.2       +29 -18    jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/strategy/DefaultPluralStemmer.java
  
  Index: DefaultPluralStemmer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/strategy/DefaultPluralStemmer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultPluralStemmer.java	28 May 2002 13:38:26 -0000	1.1
  +++ DefaultPluralStemmer.java	28 May 2002 23:01:07 -0000	1.2
  @@ -61,10 +61,15 @@
    */
   package org.apache.commons.betwixt.strategy;
   
  +import org.apache.commons.betwixt.ElementDescriptor;
  +
  +import java.util.Iterator;
  +import java.util.Map;
  +
   /** 
    * A default implementation of the plural name stemmer which
  - * uses a simple starts-with algorithm and then tests for some common
  - * english plural/singular patterns.
  + * tests for some common english plural/singular patterns and
  + * then uses a simple starts-with algorithm 
    * 
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.8 $
  @@ -72,24 +77,30 @@
   public class DefaultPluralStemmer implements PluralStemmer {
   
       /**
  -     * @return true if the given plural name matches the singular name
  +     * @return the plural descriptor for the given singular property name
        */
  -    public boolean isPluralNameFor(String pluralName, String singularName) {
  -        if ( pluralName.startsWith( singularName ) ) {
  -            return true;
  -        }
  -        
  -        // test for common english singlular/plural endings
  -        if ( pluralName.endsWith( "ies" ) && singularName.endsWith( "y" ) ) {
  -            String pluralStart = pluralName.substring(0, pluralName.length() - 3 ); 
  -            String singularStart = singularName.substring(0, singularName.length() - 1 ); 
  -            if ( pluralStart.equals( singularStart ) ) {
  -                return true;
  +    public ElementDescriptor findPluralDescriptor( String propertyName, Map map) {
  +        ElementDescriptor answer = (ElementDescriptor) map.get( propertyName + "s" );
  +        if ( answer == null ) {
  +            int length = propertyName.length();
  +            if ( propertyName.endsWith( "y" ) && length > 1 ) {
  +                String key = propertyName.substring(0, length - 1) + "ies";                
  +                answer = (ElementDescriptor) map.get( key );             
  +            }
  +            
  +            if ( answer == null ) {
  +                // lets find the first one that starts with the propertyName
  +                for ( Iterator iter = map.keySet().iterator(); iter.hasNext(); ) {
  +                    String key = (String) iter.next();
  +                    if ( key.startsWith( propertyName ) ) {
  +                        answer = (ElementDescriptor) map.get(key);
  +                        break;
  +                    }
  +                    // ### could maybe warn if duplicate properties match
  +                }
               }
           }
  -
  -        // None of the tests detected a plural
  -        return false;
  +        return answer;
  +        
       }
  -
   }
  
  
  
  1.2       +13 -5     jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/strategy/PluralStemmer.java
  
  Index: PluralStemmer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/strategy/PluralStemmer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PluralStemmer.java	28 May 2002 13:38:26 -0000	1.1
  +++ PluralStemmer.java	28 May 2002 23:01:07 -0000	1.2
  @@ -61,10 +61,15 @@
    */
   package org.apache.commons.betwixt.strategy;
   
  +import org.apache.commons.betwixt.ElementDescriptor;
  +
  +import java.util.Map;
  +
   /** 
  - * A plugin Strategy pattern for detecting matching singular and plural
  - * names on bean properties. When composite properties (such as properties
  - * of type Collection, List, Iterator, Enumeration) are used we need to
  + * A plugin Strategy pattern which will detect the plural property which
  + * maps to a singular property name.
  + * This Strategy is used when composite properties (such as properties
  + * of type Collection, List, Iterator, Enumeration) are used as we need to
    * match the adder-method, which typically uses a singular name.
    * This interface allows a variety of different implementations to be used.
    * 
  @@ -74,8 +79,11 @@
   public interface PluralStemmer {
   
       /**
  -     * @return true if the given plural name matches the singular name
  +     * @return the plural descriptor for the given singular property name
  +     * @param propertyName is the singular property name, from the adder method
  +     * @param map is a map with the keys are the property names of the available
  +     *  descriptors and the values are the descriptors.
        */
  -    boolean isPluralNameFor(String pluralName, String singularName);
  +    ElementDescriptor findPluralDescriptor( String propertyName, Map map );
   
   }
  
  
  
  1.1                  jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/strategy/DecapitalizeNameMapper.java
  
  Index: DecapitalizeNameMapper.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/NodeDescriptor.java,v 1.8 2002/05/17 15:24:09 jstrachan Exp $
   * $Revision: 1.8 $
   * $Date: 2002/05/17 15:24:09 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: NodeDescriptor.java,v 1.8 2002/05/17 15:24:09 jstrachan Exp $
   */
  package org.apache.commons.betwixt.strategy;
  
  import java.beans.Introspector;
  
  /** 
   * A name mapper which converts types to a decapitalized String. So
   * a bean type of Foo will be converted to the element name "foo"
   * 
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.8 $
   */
  public class DecapitalizeNameMapper implements NameMapper {
  
      /**
       * @return the element name for the given bean type name
       */
      public String mapTypeToElementName(String typeName) {
          return Introspector.decapitalize( typeName );
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/strategy/NameMapper.java
  
  Index: NameMapper.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/NodeDescriptor.java,v 1.8 2002/05/17 15:24:09 jstrachan Exp $
   * $Revision: 1.8 $
   * $Date: 2002/05/17 15:24:09 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: NodeDescriptor.java,v 1.8 2002/05/17 15:24:09 jstrachan Exp $
   */
  package org.apache.commons.betwixt.strategy;
  
  /** 
   * A plugin Strategy pattern for converting java type names into element names.
   * 
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.8 $
   */
  public interface NameMapper {
  
      /**
       * @return the element name for the given bean type name
       */
      String mapTypeToElementName(String typeName);
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/strategy/DefaultNameMapper.java
  
  Index: DefaultNameMapper.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/NodeDescriptor.java,v 1.8 2002/05/17 15:24:09 jstrachan Exp $
   * $Revision: 1.8 $
   * $Date: 2002/05/17 15:24:09 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: NodeDescriptor.java,v 1.8 2002/05/17 15:24:09 jstrachan Exp $
   */
  package org.apache.commons.betwixt.strategy;
  
  /** 
   * A default implementation of the name mapper.
   * 
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.8 $
   */
  public class DefaultNameMapper implements NameMapper {
  
      /**
       * @return the element name for the given bean type name
       */
      public String mapTypeToElementName(String typeName) {
          return typeName;
      }
  }
  
  
  
  1.7       +6 -6      jakarta-commons-sandbox/betwixt/src/test/org/apache/commons/betwixt/TestBeanReader.java
  
  Index: TestBeanReader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/src/test/org/apache/commons/betwixt/TestBeanReader.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestBeanReader.java	28 May 2002 11:49:29 -0000	1.6
  +++ TestBeanReader.java	28 May 2002 23:01:08 -0000	1.7
  @@ -5,15 +5,15 @@
    * version 1.1, a copy of which has been included with this distribution in
    * the LICENSE file.
    * 
  - * $Id: TestBeanReader.java,v 1.6 2002/05/28 11:49:29 jstrachan Exp $
  + * $Id: TestBeanReader.java,v 1.7 2002/05/28 23:01:08 jstrachan Exp $
    */
   package org.apache.commons.betwixt;
   
   import java.io.FileInputStream;
  -import java.io.StringWriter;
  -import java.io.StringBufferInputStream;
   import java.io.InputStream;
   import java.io.IOException;
  +import java.io.StringReader;
  +import java.io.StringWriter;
   
   import junit.framework.Test;
   import junit.framework.TestCase;
  @@ -31,7 +31,7 @@
   /** Test harness for the BeanReader
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.6 $
  +  * @version $Revision: 1.7 $
     */
   public class TestBeanReader extends TestCase {
       
  @@ -93,7 +93,7 @@
           
           BeanReader reader = new BeanReader();
           reader.registerBeanClass( PersonBean.class );
  -        bean = (PersonBean) reader.parse(new StringBufferInputStream(xml));
  +        bean = (PersonBean) reader.parse(new StringReader(xml));
           
           assertEquals("Person age wrong", 21 , bean.getAge());
           assertEquals("Person name wrong", "Samual Smith" , bean.getName());
  @@ -110,7 +110,7 @@
           reader = new BeanReader();
           reader.getXMLIntrospector().setAttributesForPrimitives(true);
           reader.registerBeanClass( PersonBean.class );
  -        bean = (PersonBean) reader.parse(new StringBufferInputStream(xml));
  +        bean = (PersonBean) reader.parse(new StringReader(xml));
           
           assertEquals("[Attribute] Person age wrong", 19 , bean.getAge());
           assertEquals("[Attribute] Person name wrong", "John Smith" , bean.getName());
  
  
  
  1.4       +72 -9     jakarta-commons-sandbox/betwixt/src/test/org/apache/commons/betwixt/TestMavenProject.java
  
  Index: TestMavenProject.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/src/test/org/apache/commons/betwixt/TestMavenProject.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestMavenProject.java	28 May 2002 14:17:23 -0000	1.3
  +++ TestMavenProject.java	28 May 2002 23:01:08 -0000	1.4
  @@ -77,6 +77,7 @@
   
   import org.apache.commons.betwixt.io.BeanReader;
   import org.apache.commons.betwixt.io.BeanWriter;
  +import org.apache.commons.betwixt.strategy.DecapitalizeNameMapper;
   
   import org.apache.maven.project.Dependency;
   import org.apache.maven.project.Developer;
  @@ -105,9 +106,42 @@
       public TestMavenProject(String testName) {
           super(testName);
       }
  -    
  -    
   
  +    /**
  +     * Tests the introspector
  +     */
  +    public void testIntrospector() throws Exception {
  +        XMLIntrospector introspector = createXMLIntrospector();
  +        XMLBeanInfo info = introspector.introspect( Project.class );
  +        ElementDescriptor root = info.getElementDescriptor();
  +        
  +        assertEquals( "project", root.getLocalName() );
  +        
  +        ElementDescriptor descriptor = findDescriptorsForLocalName( 
  +            root.getElementDescriptors(), "dependencies" 
  +        );
  +        assertTrue( "Could not find a descriptor for 'dependencies'", descriptor != null );
  +        assertTrue( "Should have an updater on the dependencies descriptor", descriptor.getUpdater() != null );
  +        assertEquals( "dependencies", descriptor.getPropertyName() );
  +        
  +        ElementDescriptor[] dependencies = descriptor.getElementDescriptors();
  +        assertTrue( "Should only find one child descriptor of dependencies", dependencies.length == 1 );
  +        
  +        
  +        ElementDescriptor dependency = dependencies[0];
  +
  +/*        
  +        System.out.println( "Found: " + dependency );
  +        ElementDescriptor[] children = dependency .getElementDescriptors();
  +        for ( int i = 0, size = children.length; i < size; i++ ) {
  +            System.out.println( "Child: " + children[i] );
  +        }
  +*/        
  +        
  +        assertEquals( "dependency", dependency.getLocalName() );
  +        assertTrue( "Should not have an updater on the dependency descriptor", dependency.getUpdater() == null );
  +    }    
  +    
       /** 
        * Tests we can parse a project.xml
        */
  @@ -118,7 +152,6 @@
   
           testProject( project );
       }
  -    
   
       /**
        * Tests we can round trip from the XML -> bean -> XML -> bean.
  @@ -156,17 +189,34 @@
       
       protected BeanReader createBeanReader() throws Exception {
           BeanReader reader = new BeanReader();
  +        reader.setXMLIntrospector( createXMLIntrospector() );
  +        reader.registerBeanClass( Project.class );
  +        return reader;
  +    }
  +
  +    /** 
  +     * ### it would be really nice to move this somewhere shareable across
  +     * Maven / Turbine projects. Maybe a static helper method - question is
  +     * what to call it???
  +     */
  +    protected XMLIntrospector createXMLIntrospector() {    
  +        XMLIntrospector introspector = new XMLIntrospector();
           
           // set elements for attributes to true
  -        reader.getXMLIntrospector().setAttributesForPrimitives(false);
  +        introspector.setAttributesForPrimitives(false);
  +        
           // wrap collections in an XML element
  -        reader.getXMLIntrospector().setWrapCollectionsInElement(true);
  +        //introspector.setWrapCollectionsInElement(true);
           
  -        // #### remove the need to name the element, via a lower-case-naming strategy
  -        reader.registerBeanClass( "project", Project.class );
  -        return reader;
  +        // turn bean elements into lower case
  +        introspector.setNameMapper( new DecapitalizeNameMapper() );
  +        
  +        return introspector;
       }
           
  +    /** 
  +     * Tests the value of the Project object that has just been parsed
  +     */        
       protected void testProject(Project project) throws Exception {    
           assertTrue( "Returned null project instance", project != null );        
           assertEquals( "commons-betwixt", project.getName() );
  @@ -192,9 +242,22 @@
           
       protected void write(Object bean, Writer out) throws Exception {
           BeanWriter writer = new BeanWriter(out);
  -        writer.getXMLIntrospector().setAttributesForPrimitives(false);
  +        writer.setXMLIntrospector( createXMLIntrospector() );
           writer.enablePrettyPrint();
           writer.write( bean );
  +    }
  +    
  +    /** 
  +     * Finds a descriptor in the given array which matches the given local name.
  +     */
  +    protected ElementDescriptor findDescriptorsForLocalName( ElementDescriptor[] descriptors, String localName ) {
  +        for ( int i = 0, size = descriptors.length; i < size; i++ ) {
  +            ElementDescriptor descriptor = descriptors[i];
  +            if ( localName.equals( descriptor.getLocalName() ) ) {
  +                return descriptor;
  +            }
  +        }
  +        return null;
       }
   }
   
  
  
  
  1.6       +28 -13    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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MethodUpdater.java	17 May 2002 15:24:11 -0000	1.5
  +++ MethodUpdater.java	28 May 2002 23:01:08 -0000	1.6
  @@ -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.5 2002/05/17 15:24:11 jstrachan Exp $
  + * $Id: MethodUpdater.java,v 1.6 2002/05/28 23:01:08 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.5 $
  +  * @version $Revision: 1.6 $
     */
   public class MethodUpdater implements Updater {
   
  @@ -50,14 +50,37 @@
                   // try to convert into primitive types
                   newValue = ConvertUtils.convert( (String) newValue, valueType );
               }
  +            if ( newValue != null ) {
  +                // check that it is of the correct type
  +/*                
  +                if ( ! valueType.isAssignableFrom( newValue.getClass() ) ) {
  +                    log.warn( 
  +                        "Cannot call setter method: " + method.getName() + " on bean: " + bean
  +                        + " with type: " + bean.getClass().getName() 
  +                        + " as parameter should be of type: " + valueType.getName() 
  +                        + " but is: " + newValue.getClass().getName() 
  +                    );
  +                    return;
  +                }
  +*/                
  +            }                    
               Object[] arguments = { newValue };
               try {
                   if ( log.isDebugEnabled() ) {
  -                    log.debug( "Calling setter method: " + method.getName() + " on bean: " + bean + " with new value: " + newValue );
  +                    log.debug( 
  +                        "Calling setter method: " + method.getName() + " on bean: " + bean 
  +                        + " with new value: " + newValue 
  +                    );
                   }
                   method.invoke( bean, arguments );
               }
               catch (Exception e) {
  +                String valueTypeName = (newValue != null) ? newValue.getClass().getName() : "null";
  +                log.warn( 
  +                    "Cannot evaluate method: " + method.getName() + " on bean: " + bean 
  +                    + " of type: " + bean.getClass().getName() + " with value: " + newValue 
  +                    + " of type: " + valueTypeName 
  +                );
                   handleException(context, e);
               }
           }
  @@ -82,16 +105,8 @@
       //-------------------------------------------------------------------------    
       
       /** 
  -      * <p> Log error to context's logger. </p> 
  -      *
  -      * <p> Allows derived objects to handle exceptions differently. </p>
  -      */
  +     * Strategy method to allow derivations to handle exceptions differently.
  +     */
       protected void handleException(Context context, Exception e) {
  -        // use the context's logger to log the problem
  -        context.getLog().error(
  -            "[MethodUpdater] Cannot evaluate method: " + method 
  -            + " on bean: " + context.getBean() 
  -            + ". Exception: " + e, e 
  -        );
       }
   }
  
  
  
  1.4       +17 -17    jakarta-commons-sandbox/betwixt/src/test/org/apache/commons/digester/rss/Channel.betwixt
  
  Index: Channel.betwixt
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/src/test/org/apache/commons/digester/rss/Channel.betwixt,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Channel.betwixt	4 Mar 2002 03:15:54 -0000	1.3
  +++ Channel.betwixt	28 May 2002 23:01:08 -0000	1.4
  @@ -1,18 +1,18 @@
  -<?xml version="1.0" encoding="UTF-8" ?>
  -<info primitiveTypes="element">
  -  <element name="rss">
  -    <attribute name="version" property="version"/>
  -    <element name="channel">
  -      <element name="title"  property="title"/>
  -      <element name="item"  property="items"/>
  -      <element name="textinput"  property="textInput"/>
  -      <element name="skipDays">
  -        <element name="day" property="skipDays"/>
  -      </element>
  -      <element name="skipHours">
  -        <element name="hour" property="skipHours"/>
  -      </element>
  -      <addDefaults/>
  -    </element>
  -  </element>
  +<?xml version="1.0" encoding="UTF-8" ?>
  +<info primitiveTypes="element">
  +  <element name="rss">
  +    <attribute name="version" property="version"/>
  +    <element name="channel">
  +      <element name="title"  property="title"/>
  +      <element name="item"  property="items"/>
  +      <element name="textinput"  property="textInput"/>
  +      <element name="skipDays">
  +        <element name="day" property="skipDays"/>
  +      </element>
  +      <element name="skipHours">
  +        <element name="hour" property="skipHours"/>
  +      </element>
  +      <addDefaults/>
  +    </element>
  +  </element>
   </info>
  
  
  
  1.2       +5 -6      jakarta-commons-sandbox/betwixt/src/test/org/apache/commons/digester/rss/Image.betwixt
  
  Index: Image.betwixt
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/src/test/org/apache/commons/digester/rss/Image.betwixt,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Image.betwixt	19 Feb 2002 15:31:30 -0000	1.1
  +++ Image.betwixt	28 May 2002 23:01:08 -0000	1.2
  @@ -1,7 +1,6 @@
  -<?xml version="1.0" encoding="UTF-8" ?>
  -<info primitiveTypes="element">
  -  <element name="image">
  -    <element name="url" property="URL"/>
  -    <addDefaults/>
  -  </element>
  +<?xml version="1.0" encoding="UTF-8" ?>
<info primitiveTypes="element">
  +  <element name="image">
  +    <element name="url" property="URL"/>
  +    <addDefaults/>
  +  </element>
   </info>
  
  
  
  1.25      +36 -6     jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/XMLIntrospector.java
  
  Index: XMLIntrospector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/XMLIntrospector.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- XMLIntrospector.java	28 May 2002 14:17:22 -0000	1.24
  +++ XMLIntrospector.java	28 May 2002 23:01:08 -0000	1.25
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/XMLIntrospector.java,v 1.24 2002/05/28 14:17:22 jstrachan Exp $
  - * $Revision: 1.24 $
  - * $Date: 2002/05/28 14:17:22 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/XMLIntrospector.java,v 1.25 2002/05/28 23:01:08 jstrachan Exp $
  + * $Revision: 1.25 $
  + * $Date: 2002/05/28 23:01:08 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: XMLIntrospector.java,v 1.24 2002/05/28 14:17:22 jstrachan Exp $
  + * $Id: XMLIntrospector.java,v 1.25 2002/05/28 23:01:08 jstrachan Exp $
    */
   package org.apache.commons.betwixt;
   
  @@ -91,7 +91,9 @@
   import org.apache.commons.betwixt.expression.StringExpression;
   import org.apache.commons.betwixt.digester.XMLBeanInfoDigester;
   import org.apache.commons.betwixt.digester.XMLIntrospectorHelper;
  +import org.apache.commons.betwixt.strategy.DefaultNameMapper;
   import org.apache.commons.betwixt.strategy.DefaultPluralStemmer;
  +import org.apache.commons.betwixt.strategy.NameMapper;
   import org.apache.commons.betwixt.strategy.PluralStemmer;
   
   /** <p><code>XMLIntrospector</code> an introspector of beans to create a XMLBeanInfo instance.</p>
  @@ -102,7 +104,7 @@
     * Later requests for the same class will return the cached value.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.24 $
  +  * @version $Revision: 1.25 $
     */
   public class XMLIntrospector {
   
  @@ -129,6 +131,9 @@
       /** The strategy used to detect matching singular and plural properties */
       private PluralStemmer pluralStemmer;
       
  +    /** The strategy used to convert bean type names into element names */
  +    private NameMapper nameMapper;
  +    
       /** Base constructor */
       public XMLIntrospector() {
       }
  @@ -219,7 +224,7 @@
           Class beanClass = beanDescriptor.getBeanClass();
           
           ElementDescriptor elementDescriptor = new ElementDescriptor();
  -        elementDescriptor.setLocalName( beanDescriptor.getName() );
  +        elementDescriptor.setLocalName( getNameMapper().mapTypeToElementName( beanDescriptor.getName() ) );
           elementDescriptor.setPropertyType( beanInfo.getBeanDescriptor().getBeanClass() );
           
           log.trace(elementDescriptor);
  @@ -323,6 +328,24 @@
           this.pluralStemmer = pluralStemmer;
       }
   
  +    /** 
  +     * @return the strategy used to convert bean type names into element names
  +     */
  +    public NameMapper getNameMapper() {
  +        if ( nameMapper == null ) {
  +            nameMapper = createNameMapper();
  +        }
  +        return nameMapper;
  +    }
  +    
  +    /** 
  +     * Sets the strategy used to convert bean type names into element names
  +     */
  +    public void setNameMapper(NameMapper nameMapper) {
  +        this.nameMapper = nameMapper;
  +    }
  +
  +
       
       // Implementation methods
       //-------------------------------------------------------------------------        
  @@ -332,6 +355,13 @@
        */
       protected PluralStemmer createPluralStemmer() {
           return new DefaultPluralStemmer();
  +    }
  +    
  +    /** 
  +     * A Factory method to lazily create a strategy used to convert bean type names into element names
  +     */
  +    protected NameMapper createNameMapper() {
  +        return new DefaultNameMapper();
       }
       
       /** 
  
  
  
  1.9       +31 -25    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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- BeanCreateRule.java	28 May 2002 11:49:30 -0000	1.8
  +++ BeanCreateRule.java	28 May 2002 23:01:08 -0000	1.9
  @@ -5,7 +5,7 @@
    * version 1.1, a copy of which has been included with this distribution in
    * the LICENSE file.
    * 
  - * $Id: BeanCreateRule.java,v 1.8 2002/05/28 11:49:30 jstrachan Exp $
  + * $Id: BeanCreateRule.java,v 1.9 2002/05/28 23:01:08 jstrachan Exp $
    */
   package org.apache.commons.betwixt.io;
   
  @@ -33,7 +33,7 @@
     * from the betwixt XML metadata.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.8 $
  +  * @version $Revision: 1.9 $
     */
   public class BeanCreateRule extends Rule {
   
  @@ -53,20 +53,18 @@
       /** The prefix added to digester rules */
       private String pathPrefix;
       
  -    public BeanCreateRule(BeanReader digester, ElementDescriptor descriptor, Class beanClass, String pathPrefix) {
  -        super( digester );
  +    public BeanCreateRule(ElementDescriptor descriptor, Class beanClass, String pathPrefix) {
           this.descriptor = descriptor;
           this.context = new Context();
           this.beanClass = beanClass;
           this.pathPrefix = pathPrefix;
       }
       
  -    public BeanCreateRule(BeanReader digester, ElementDescriptor descriptor, Class beanClass) {
  -        this( digester, descriptor, beanClass, descriptor.getQualifiedName() + "/" );
  +    public BeanCreateRule(ElementDescriptor descriptor, Class beanClass) {
  +        this( descriptor, beanClass, descriptor.getQualifiedName() + "/" );
       }
       
  -    public BeanCreateRule(BeanReader digester, ElementDescriptor descriptor, Context context, String pathPrefix) {
  -        super( digester );
  +    public BeanCreateRule(ElementDescriptor descriptor, Context context, String pathPrefix) {
           this.descriptor = descriptor;        
           this.context = context;
           this.beanClass = descriptor.getSingularPropertyType();
  @@ -187,7 +185,7 @@
               log.debug( "Could not create instance of type: " + beanClass.getName() );
               return null;
           }
  -    }
  +    }    
           
       /** Adds the rules to the digester for all child elements */
       protected void addChildRules() {
  @@ -198,7 +196,7 @@
           }
       }
                           
  -    protected void addChildRules(String prefix, ElementDescriptor currentDescriptor) {
  +    protected void addChildRules(String prefix, ElementDescriptor currentDescriptor ) {
           BeanReader digester = getBeanReader();            
   
           // if we are a reference to a type we should lookup the original
  @@ -209,7 +207,6 @@
   
           ElementDescriptor[] childDescriptors = typeDescriptor.getElementDescriptors();
           if ( childDescriptors != null ) {
  -
               for ( int i = 0, size = childDescriptors.length; i < size; i++ ) {
                   final ElementDescriptor childDescriptor = childDescriptors[i];
   
  @@ -220,28 +217,37 @@
                   }
                   String path = prefix + qualifiedName;
                   
  -                if ( propertyName != null ) {
  -                    Rule rule = null;
  +                if ( childDescriptor.getUpdater() != null ) {
                       if ( isPrimitiveType( childDescriptor ) ) {
  -                        rule = new Rule( digester ) {
  +                        Rule rule = new Rule() {
                               public void body(String text) throws Exception {
  -                                if ( log.isDebugEnabled() ) {
  -                                    log.debug( "Calling updater on bean: " + context.getBean() + " with text: " + text );
  -                                }
                                   childDescriptor.getUpdater().update( context, text );
                               }        
                           };
  -
  +                        digester.addRule( path, rule );
  +                        if ( log.isDebugEnabled() ) {
  +                            log.debug( "Added rule to path: "+ path + " rule: " + rule );
  +                        }
                       }
                       else {
  -                        rule = new BeanCreateRule( digester, childDescriptor, context, path + "/" );
  -                    }                    
  -                    digester.addRule( path, rule );
  -                    
  -                    if ( log.isDebugEnabled() ) {
  -                        log.debug( "Added rule: " + rule + " to path: " + path );
  +                        // add the first child to the path
  +                        ElementDescriptor[] grandChildren = childDescriptor.getElementDescriptors();
  +                        if ( grandChildren != null && grandChildren.length > 0 ) {
  +                            ElementDescriptor grandChild = grandChildren[0];
  +                            String grandChildQName = grandChild.getQualifiedName();
  +                            if ( grandChildQName != null && grandChildQName.length() > 0 ) {
  +                                path += "/" + grandChildQName;
  +                            }
  +                        }
  +                        
  +                        Rule rule = new BeanCreateRule( childDescriptor, context, path + "/" );
  +                        digester.addRule( path, rule );
  +                        if ( log.isDebugEnabled() ) {
  +                            log.debug( "Added rule to path: "+ path + " rule: " + rule );
  +                        }
                       }
  -                }
  +                }                    
  +                
   
                   ElementDescriptor[] grandChildren = childDescriptor.getElementDescriptors();
                   if ( grandChildren != null && grandChildren.length > 0 ) {
  
  
  
  1.7       +5 -5      jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/io/BeanReader.java
  
  Index: BeanReader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/io/BeanReader.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- BeanReader.java	28 May 2002 11:49:29 -0000	1.6
  +++ BeanReader.java	28 May 2002 23:01:08 -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: BeanReader.java,v 1.6 2002/05/28 11:49:29 jstrachan Exp $
  + * $Id: BeanReader.java,v 1.7 2002/05/28 23:01:08 jstrachan Exp $
    */
   package org.apache.commons.betwixt.io;
   
  @@ -34,14 +34,14 @@
   /** <p><code>BeanReader</code> reads a tree of beans from an XML document.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.6 $
  +  * @version $Revision: 1.7 $
     */
   public class BeanReader extends Digester {
   
       /** Introspector used */
       private XMLIntrospector introspector = new XMLIntrospector();    
       /** Log used for logging (Doh!) */
  -    private Log log = LogFactory.getLog( BeanReader.class.getName() );
  +    private Log log = LogFactory.getLog( BeanReader.class );
       /** The registered classes */
       private Set registeredClasses = new HashSet();
       
  @@ -153,11 +153,11 @@
        * Adds a new bean create rule for the specified path
        */
       protected void addBeanCreateRule( String path, ElementDescriptor elementDescriptor, Class beanClass ) {
  -        Rule rule = new BeanCreateRule( this, elementDescriptor, beanClass, path + "/" );
  +        Rule rule = new BeanCreateRule( elementDescriptor, beanClass, path + "/" );
           addRule( path, rule );
   
           if ( log.isDebugEnabled() ) {
  -            log.debug( "Added rule: " + rule + " to path: " + path );
  +            log.debug( "Added root rule to path: " + path + " rule: " + rule );
           }
       }
           
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message