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/betwixt/src/test/org/apache/commons/betwixt/io/read TestMappingActions.java
Date Sat, 21 Feb 2004 13:39:06 GMT
rdonkin     2004/02/21 05:39:06

  Modified:    betwixt  Tag: REFACTORING-BRANCH_2004-01-13 project.xml
               betwixt/src/java/org/apache/commons/betwixt Tag:
                        REFACTORING-BRANCH_2004-01-13 XMLIntrospector.java
               betwixt/src/java/org/apache/commons/betwixt/io Tag:
                        REFACTORING-BRANCH_2004-01-13 BeanRuleSet.java
               betwixt/src/test/org/apache/commons/betwixt/introspection
                        Tag: REFACTORING-BRANCH_2004-01-13
                        TestDeclarativeIntrospection.java
               betwixt/src/test/org/apache/commons/betwixt/io/read Tag:
                        REFACTORING-BRANCH_2004-01-13
                        TestMappingActions.java
  Removed:     betwixt/src/java/org/apache/commons/betwixt/io/read Tag:
                        REFACTORING-BRANCH_2004-01-13 BodyUpdateAction.java
  Log:
  Renamed BodyUpdateAction and simplified action mapping.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.32.2.2  +8 -0      jakarta-commons/betwixt/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/project.xml,v
  retrieving revision 1.32.2.1
  retrieving revision 1.32.2.2
  diff -u -r1.32.2.1 -r1.32.2.2
  --- project.xml	1 Feb 2004 13:48:27 -0000	1.32.2.1
  +++ project.xml	21 Feb 2004 13:39:06 -0000	1.32.2.2
  @@ -166,6 +166,14 @@
                   </resource>
               </resources>
           </unitTest>
  +        <resources>
  +            <resource>
  +                <directory>${pom.build.unitTestSourceDirectory}</directory>
  +                <includes>
  +                    <include>**/*.betwixt</include>
  +                </includes>
  +            </resource>
  +        </resources>
     </build>
   
   </project>
  
  
  
  No                   revision
  No                   revision
  1.27.2.10 +12 -6     jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/XMLIntrospector.java
  
  Index: XMLIntrospector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/XMLIntrospector.java,v
  retrieving revision 1.27.2.9
  retrieving revision 1.27.2.10
  diff -u -r1.27.2.9 -r1.27.2.10
  --- XMLIntrospector.java	8 Feb 2004 12:11:17 -0000	1.27.2.9
  +++ XMLIntrospector.java	21 Feb 2004 13:39:06 -0000	1.27.2.10
  @@ -820,14 +820,20 @@
                                         
                           children[n].setUpdater( adder.getKeyUpdater() );
                           children[n].setSingularPropertyType(  keyType );
  +                        if ( isPrimitiveType(keyType) ) {
  +                            children[n].setHollow(false);
  +                        }
                           if ( getLog().isTraceEnabled() ) {
                               getLog().trace( "Key descriptor: " + children[n]);
                           }                                               
                                                   
                       } else if ( "value".equals( children[n].getLocalName() ) ) {
   
  -                            children[n].setUpdater( adder.getValueUpdater() );
  -                            children[n].setSingularPropertyType( valueType );
  +                        children[n].setUpdater( adder.getValueUpdater() );
  +                        children[n].setSingularPropertyType( valueType );
  +                        if ( isPrimitiveType( valueType) ) {
  +                            children[n].setHollow(false);
  +                        }
                           if ( getLog().isTraceEnabled() ) { 
                               getLog().trace( "Value descriptor: " + children[n]);
                           }
  
  
  
  No                   revision
  No                   revision
  1.16.2.5  +28 -93    jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/BeanRuleSet.java
  
  Index: BeanRuleSet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/BeanRuleSet.java,v
  retrieving revision 1.16.2.4
  retrieving revision 1.16.2.5
  diff -u -r1.16.2.4 -r1.16.2.5
  --- BeanRuleSet.java	18 Jan 2004 22:25:22 -0000	1.16.2.4
  +++ BeanRuleSet.java	21 Feb 2004 13:39:06 -0000	1.16.2.5
  @@ -60,6 +60,7 @@
    */
   package org.apache.commons.betwixt.io;
   
  +import java.beans.IntrospectionException;
   import java.util.Map;
   
   import org.apache.commons.betwixt.BindingConfiguration;
  @@ -69,7 +70,7 @@
   import org.apache.commons.betwixt.digester.XMLIntrospectorHelper;
   import org.apache.commons.betwixt.expression.Context;
   import org.apache.commons.betwixt.io.read.BeanBindAction;
  -import org.apache.commons.betwixt.io.read.BodyUpdateAction;
  +import org.apache.commons.betwixt.io.read.SimpleTypeBindAction;
   import org.apache.commons.betwixt.io.read.MappingAction;
   import org.apache.commons.betwixt.io.read.ReadConfiguration;
   import org.apache.commons.betwixt.io.read.ReadContext;
  @@ -287,100 +288,34 @@
               Attributes attributes,
               ReadContext context)
               throws Exception {
  -            MappingAction result = MappingAction.EMPTY;
  +                
  +            MappingAction result = null;
  +            if (context.currentMappingAction() == null)
  +            {
  +                result =  BeanBindAction.INSTANCE;   
  +            } else {
  +                
  +                result = createAction(name, context);
  +            }
  +            return result.begin(namespace, name, attributes, context);
  +        }
   
  -            // TODO: replace with declarative system
  -            // this is rubbish and needs to be replaced with something more declarative
  -            // may need to think about whether ElementDescritor would be the right place
for this information
  +        private MappingAction createAction(String name, ReadContext context)
  +            throws Exception, IntrospectionException {
  +            MappingAction result = MappingAction.EMPTY;
  +            
               ElementDescriptor activeDescriptor = context.getCurrentDescriptor();
               if (activeDescriptor != null) {
  -                Class lastMapped = context.getLastMappedClass();
  -                if (context.getXMLIntrospector().
  -                    isPrimitiveType(activeDescriptor.getPropertyType())) {
  -                    // primitives are mapped to body update actions
  -                    result = BodyUpdateAction.INSTANCE;
  -                } else if (lastMapped == null) {
  -                    // The basic action must be a bean bind
  -                    result = BeanBindAction.INSTANCE;
  -
  -                } else if (activeDescriptor.getUpdater() != null) {
  -                    Class singular = activeDescriptor.getPropertyType();
  -                    // TODO: this is a workaround and needs to be fixed!
  -                    // really, need a marker to indicate whether a element descriptor 
  -                    // is hollow
  -                    if (activeDescriptor.getElementDescriptors().length != 0
  -                        && context.getXMLIntrospector().isLoopType(singular)) {
  -                        result = MappingAction.EMPTY;
  -                    } else if (singular == null) {
  -                        // workaround for map support
  -                        if ("value".equals(name)) {
  -                            result = BeanBindAction.INSTANCE;
  -                        } else {
  -
  -                            result = BodyUpdateAction.INSTANCE;
  -                        }
  -                    } else {
  -                        if (XMLIntrospectorHelper
  -                            .isPrimitiveType(
  -                                activeDescriptor.getSingularPropertyType())) {
  -                            result = BodyUpdateAction.INSTANCE;
  -
  -                        } else {
  -                            result = BeanBindAction.INSTANCE;
  -                        }
  -                    }
  -
  -                } else if (context.currentMappingAction() == null) {
  -                    // the basic action is bean bind
  +                if (activeDescriptor.isHollow())
  +                {
                       result = BeanBindAction.INSTANCE;
  -
  -                } else {
  -                    boolean isElementWithinLoop = false;
  -                    Class singularType = null;
  -                    Class loopType = null;
  -                    // TODO: this seems wrong to me
  -                    // the structure of the element descriptors should reflect
  -                    // the structure of the xml
  -                    XMLBeanInfo childXMLBeanInfo =
  -                        context.getLastMappedClassXMLBeanInfo();
  -                    ElementDescriptor parentDescriptor =
  -                        childXMLBeanInfo.getElementDescriptor().findParent(
  -                            activeDescriptor);
  -                    Class parent = parentDescriptor.getPropertyType();
  -                    if (XMLIntrospectorHelper.isLoopType(parent)) {
  -                        isElementWithinLoop = true;
  -                        singularType =
  -                            parentDescriptor.getSingularPropertyType();
  -                        loopType = parent;
  -                    }
  -
  -                    //TODO: this is too much work to discover whether an element
  -                    //      is within a loop
  -                    //      should probably just mark extra elements in loops
  -                    //      as unmapped elements (to be ignored)
  -                    if (isElementWithinLoop) {
  -                    	//TODO: the ElementDescriptor.isPrimitiveType
  -                        //      does seems to work in the same way as
  -                    	//      the XMLIntrospectorHelper version
  -                    	//      Need to generalize 
  -                        if (XMLIntrospectorHelper
  -                            .isPrimitiveType(singularType)) {
  -
  -                            result = BodyUpdateAction.INSTANCE;
  -                            
  -                        } else if (Map.class.isAssignableFrom(loopType)) {
  -                            //TODO: this is needed because there's no marking
  -                            // 		for element descriptors that have no
  -                            //		mapping  
  -                            result = MappingAction.EMPTY;
  -                        } else {
  -                            result = BeanBindAction.INSTANCE;
  -                        }
  -                    }
  +                }
  +                else if (activeDescriptor.isSimple())
  +                {
  +                    result = SimpleTypeBindAction.INSTANCE;
                   }
               }
  -
  -            return result.begin(namespace, name, attributes, context);
  +            return result;
           }
   
           /**
  
  
  
  No                   revision
  No                   revision
  1.1.2.7   +66 -4     jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/introspection/Attic/TestDeclarativeIntrospection.java
  
  Index: TestDeclarativeIntrospection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/introspection/Attic/TestDeclarativeIntrospection.java,v
  retrieving revision 1.1.2.6
  retrieving revision 1.1.2.7
  diff -u -r1.1.2.6 -r1.1.2.7
  --- TestDeclarativeIntrospection.java	8 Feb 2004 12:11:17 -0000	1.1.2.6
  +++ TestDeclarativeIntrospection.java	21 Feb 2004 13:39:06 -0000	1.1.2.7
  @@ -299,4 +299,66 @@
           }
       }
       
  +    /** Tests for setting for map with a simple key */
  +    public void testMapWithSimpleKey() throws Exception {
  +        XMLIntrospector introspector = new XMLIntrospector();
  +        introspector.getConfiguration().setWrapCollectionsInElement(false);
  +        introspector.getConfiguration().setAttributesForPrimitives(true);
  +        XMLBeanInfo out = introspector.introspect(AddressBook.class);
  +        
  +        ElementDescriptor formatterDescriptor = out.getElementDescriptor();
  +        ElementDescriptor[] formatterChildDescriptors = formatterDescriptor.getElementDescriptors();
  +        
  +        assertEquals("Two top level children", 2, formatterChildDescriptors.length);
  +        
  +        ElementDescriptor entryDescriptor = formatterChildDescriptors[0];
  +        assertEquals("Must be called entry", "entry" , entryDescriptor.getLocalName());
  +        assertFalse("Is not hollow",  entryDescriptor.isHollow());
  +        assertNull("No updater for entry spacer",  entryDescriptor.getUpdater());
  +        
  +        ElementDescriptor[] entryChildDesciptors = entryDescriptor.getElementDescriptors();
  +        assertEquals("Entry has two children", 2, entryChildDesciptors.length);
  +        
  +        ElementDescriptor keyDescriptor = entryChildDesciptors[0];
  +        assertEquals("Must be called key", "key", keyDescriptor.getLocalName());
  +        assertFalse("Is simple therefore not hollow",  keyDescriptor.isHollow());
  +        assertNotNull("Key should have an updater", keyDescriptor.getUpdater());
  +        
  +        ElementDescriptor valueDescriptor = entryChildDesciptors[1];
  +        assertEquals("Must be called key", "value", valueDescriptor.getLocalName());
  +        assertTrue("Is not simple therefore hollow",  valueDescriptor.isHollow());
  +        assertNotNull("Value should have an updater", valueDescriptor.getUpdater());
  +    }
  +    
  +    /** Tests introspector of map with simple entries */
  +    public void testMapWithSimpleEntry() throws Exception {
  +        XMLIntrospector introspector = new XMLIntrospector();
  +        introspector.getConfiguration().setWrapCollectionsInElement(false);
  +        introspector.getConfiguration().setAttributesForPrimitives(true);
  +        XMLBeanInfo out = introspector.introspect(AddressBook.class);
  +        
  +        ElementDescriptor formatterDescriptor = out.getElementDescriptor();
  +        ElementDescriptor[] formatterChildDescriptors = formatterDescriptor.getElementDescriptors();
  +        
  +        assertEquals("Two top level children", 2, formatterChildDescriptors.length);
  +        
  +        ElementDescriptor entryDescriptor = formatterChildDescriptors[1];
  +        assertEquals("Must be called entry", "entry" , entryDescriptor.getLocalName());
  +        assertFalse("Is not hollow",  entryDescriptor.isHollow());
  +        assertNull("No updater for entry spacer",  entryDescriptor.getUpdater());
  +        
  +        ElementDescriptor[] entryChildDesciptors = entryDescriptor.getElementDescriptors();
  +        assertEquals("Entry has two children", 2, entryChildDesciptors.length);
  +        
  +        ElementDescriptor keyDescriptor = entryChildDesciptors[0];
  +        assertEquals("Must be called key", "key", keyDescriptor.getLocalName());
  +        assertTrue("Is not simple therefore hollow",  keyDescriptor.isHollow());
  +        assertNotNull("Key should have an updater", keyDescriptor.getUpdater());
  +        
  +        ElementDescriptor valueDescriptor = entryChildDesciptors[1];
  +        assertEquals("Must be called key", "value", valueDescriptor.getLocalName());
  +        assertFalse("Is simple therefore not hollow",  valueDescriptor.isHollow());
  +        assertNotNull("Value should have an updater", valueDescriptor.getUpdater());
  +    }
  +    
   }
  
  
  
  No                   revision
  No                   revision
  1.1.2.2   +7 -7      jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/io/read/Attic/TestMappingActions.java
  
  Index: TestMappingActions.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/io/read/Attic/TestMappingActions.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- TestMappingActions.java	13 Jan 2004 22:08:04 -0000	1.1.2.1
  +++ TestMappingActions.java	21 Feb 2004 13:39:06 -0000	1.1.2.2
  @@ -146,7 +146,7 @@
           context.markClassMap(AddressBean.class);
           context.pushElement("NoMatch");
           context.setXMLIntrospector(introspector);
  -        BodyUpdateAction action = new BodyUpdateAction();
  +        SimpleTypeBindAction action = new SimpleTypeBindAction();
           action.body("Street value", context);
           assertEquals("Street is unset", "DEFAULT", bean.getStreet());
           assertEquals("Country is unset", "DEFAULT", bean.getCountry());
  @@ -166,7 +166,7 @@
           context.markClassMap(AddressBean.class);
           context.pushElement("street");
           context.setXMLIntrospector(introspector);
  -        BodyUpdateAction action = new BodyUpdateAction();
  +        SimpleTypeBindAction action = new SimpleTypeBindAction();
           action.body("Street value", context);
           assertEquals("Street is set", "Street value", bean.getStreet());
           assertEquals("Country is unset", "DEFAULT", bean.getCountry());
  
  
  

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