jstrachan    02/05/30 00:48:38

  Modified:    betwixt/src/java/org/apache/commons/betwixt/io
                        BeanCreateRule.java
  Log:
  Patched the code to fix all the unit test cases. The handling of collections of 
primitive types are now handled correctly.
  
  I think Betwixt now works for all Maven test cases
  
  Revision  Changes    Path
  1.11      +26 -28    
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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- BeanCreateRule.java       29 May 2002 12:26:51 -0000      1.10
  +++ BeanCreateRule.java       30 May 2002 07:48:38 -0000      1.11
  @@ -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.10 2002/05/29 12:26:51 jvanzyl Exp $
  + * $Id: BeanCreateRule.java,v 1.11 2002/05/30 07:48:38 jstrachan Exp $
    */
   package org.apache.commons.betwixt.io;
   
  @@ -33,7 +33,7 @@
     * from the betwixt XML metadata.</p>
     *
     * @author <a href="mailto:[EMAIL PROTECTED]";>James Strachan</a>
  -  * @version $Revision: 1.10 $
  +  * @version $Revision: 1.11 $
     */
   public class BeanCreateRule extends Rule {
   
  @@ -218,16 +218,8 @@
                   String path = prefix + qualifiedName;
                   
                   if ( childDescriptor.getUpdater() != null ) {
  -                    if ( isPrimitiveType( childDescriptor ) ) {
  -                        Rule rule = new Rule() {
  -                            public void body(String text) throws Exception {
  -                                childDescriptor.getUpdater().update( context, text 
);
  -                            }        
  -                        };
  -                        digester.addRule( path, rule );
  -                        if ( log.isDebugEnabled() ) {
  -                            log.debug( "Added rule to path: "+ path + " rule: " + 
rule );
  -                        }
  +                    if ( childDescriptor.isPrimitiveType() ) {
  +                        addPrimitiveTypeRule(path, childDescriptor);
                       }
                       else {
                           // add the first child to the path
  @@ -240,14 +232,20 @@
                               }
                           }
                           
  -                        Rule rule = new BeanCreateRule( childDescriptor, context, 
path + "/" );
  -                        digester.addRule( path, rule );
  -                        if ( log.isDebugEnabled() ) {
  -                            log.debug( "Added rule to path: "+ path + " rule: " + 
rule );
  +                        // maybe we are adding a primitve type to a collection/array
  +                        Class beanClass = childDescriptor.getSingularPropertyType();
  +                        if ( XMLIntrospectorHelper.isPrimitiveType( beanClass ) ) {
  +                            addPrimitiveTypeRule(path, childDescriptor);
  +                        }
  +                        else {
  +                            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 ) {
  @@ -282,17 +280,17 @@
       }
       
       /** 
  -     * @return true if this descriptor is a primitive type or
  -     * the property descriptor is a collection of primitive types
  +     * Adds a new Digester rule to process the text as a primitive type
        */
  -    protected boolean isPrimitiveType( ElementDescriptor descriptor ) {
  -        if ( descriptor.isPrimitiveType() ) {
  -            return true;
  -        }
  -        else {
  -            // maybe we are adding a primitve type to a collection/array
  -            Class beanClass = descriptor.getSingularPropertyType();
  -            return XMLIntrospectorHelper.isPrimitiveType( beanClass );
  +    protected void addPrimitiveTypeRule(String path, final ElementDescriptor 
childDescriptor) {
  +        Rule rule = new Rule() {
  +            public void body(String text) throws Exception {
  +                childDescriptor.getUpdater().update( context, text );
  +            }        
  +        };
  +        digester.addRule( path, rule );
  +        if ( log.isDebugEnabled() ) {
  +            log.debug( "Added rule to path: "+ path + " rule: " + rule );
           }
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to