rdonkin 2004/11/08 14:29:11 Modified: betwixt/src/java/org/apache/commons/betwixt BeanProperty.java ElementDescriptor.java IntrospectionConfiguration.java XMLIntrospector.java betwixt/src/java/org/apache/commons/betwixt/digester ElementRule.java XMLIntrospectorHelper.java betwixt/src/java/org/apache/commons/betwixt/io AbstractBeanWriter.java betwixt/src/test/org/apache/commons/betwixt/digester TestXMLIntrospectorHelper.java Log: Deprecated XMLIntrospectorHelper :) Revision Changes Path 1.10 +3 -3 jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/BeanProperty.java Index: BeanProperty.java =================================================================== RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/BeanProperty.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- BeanProperty.java 4 Oct 2004 21:50:35 -0000 1.9 +++ BeanProperty.java 8 Nov 2004 22:29:11 -0000 1.10 @@ -20,7 +20,6 @@ import java.util.Map; import org.apache.commons.beanutils.DynaProperty; -import org.apache.commons.betwixt.digester.XMLIntrospectorHelper; import org.apache.commons.betwixt.expression.DynaBeanExpression; import org.apache.commons.betwixt.expression.Expression; import org.apache.commons.betwixt.expression.IteratorExpression; @@ -182,7 +181,7 @@ propertyExpression, propertyUpdater); - } else if ( XMLIntrospectorHelper.isLoopType( getPropertyType() ) ) { + } else if ( configuration.isLoopType( getPropertyType() ) ) { if (log.isTraceEnabled()) { log.trace("Loop type: " + getPropertyName()); @@ -308,7 +307,7 @@ } else { result = entryDescriptor; } - + result.setCollective(true); return result; } @@ -336,6 +335,7 @@ // set the property updater (if it exists) // may be overridden later by the adder loopDescriptor.setUpdater(propertyUpdater); + loopDescriptor.setCollective(true); if ( configuration.isWrapCollectionsInElement() ) { // create wrapping desctiptor 1.20 +12 -7 jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/ElementDescriptor.java Index: ElementDescriptor.java =================================================================== RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/ElementDescriptor.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- ElementDescriptor.java 4 Oct 2004 22:27:12 -0000 1.19 +++ ElementDescriptor.java 8 Nov 2004 22:29:11 -0000 1.20 @@ -18,7 +18,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.commons.betwixt.digester.XMLIntrospectorHelper; import org.apache.commons.betwixt.expression.Expression; /** <p><code>ElementDescriptor</code> describes the XML elements @@ -79,6 +78,9 @@ /** Whether this element refers to a primitive type (or property of a parent object) */ private boolean primitiveType; + /** Is this a collective type? */ + private boolean isCollectiveType; + /** * Is this element hollow? * In other words, is this descriptor a place holder indicating the name @@ -555,12 +557,15 @@ * maybe this method is unnecessary */ public boolean isCollective() { - boolean result = false; - Class type = getPropertyType(); - if (type != null) { - result = XMLIntrospectorHelper.isLoopType(type); - } - return result; + return isCollectiveType; + } + + /** + * Sets whether the element described is a collective. + * @param isCollectiveType + */ + public void setCollective(boolean isCollectiveType) { + this.isCollectiveType = isCollectiveType; } /** 1.6 +25 -1 jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/IntrospectionConfiguration.java Index: IntrospectionConfiguration.java =================================================================== RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/IntrospectionConfiguration.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- IntrospectionConfiguration.java 4 Oct 2004 21:50:35 -0000 1.5 +++ IntrospectionConfiguration.java 8 Nov 2004 22:29:11 -0000 1.6 @@ -16,6 +16,11 @@ package org.apache.commons.betwixt; +import java.util.Collection; +import java.util.Enumeration; +import java.util.Iterator; +import java.util.Map; + import org.apache.commons.betwixt.strategy.ClassNormalizer; import org.apache.commons.betwixt.strategy.DefaultNameMapper; import org.apache.commons.betwixt.strategy.DefaultPluralStemmer; @@ -372,5 +377,24 @@ public void setPropertySuppressionStrategy( PropertySuppressionStrategy propertySuppressionStrategy) { this.propertySuppressionStrategy = propertySuppressionStrategy; + } + + /** + * Is this a loop type class? + * + * @param type is this <code>Class</code> a loop type? + * @return true if the type is a loop type, or if type is null + */ + public boolean isLoopType(Class type) { + // consider: should this be factored into a pluggable strategy? + // check for NPEs + if (type == null) { + return false; + } + return type.isArray() + || Map.class.isAssignableFrom( type ) + || Collection.class.isAssignableFrom( type ) + || Enumeration.class.isAssignableFrom( type ) + || Iterator.class.isAssignableFrom( type ); } } 1.40 +4 -3 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.39 retrieving revision 1.40 diff -u -r1.39 -r1.40 --- XMLIntrospector.java 31 Oct 2004 10:15:21 -0000 1.39 +++ XMLIntrospector.java 8 Nov 2004 22:29:11 -0000 1.40 @@ -643,6 +643,7 @@ if ( isLoopType ) { getLog().trace("Bean is loop"); ElementDescriptor loopDescriptor = new ElementDescriptor(); + loopDescriptor.setCollective(true); loopDescriptor.setContextExpression( new IteratorExpression( EmptyExpression.getInstance() ) ); @@ -956,7 +957,7 @@ loopDescriptor.setSingularPropertyType( valueType ); loopDescriptor.setPropertyType( valueType ); children[n].addElementDescriptor(loopDescriptor); - + loopDescriptor.setCollective(true); } if ( getLog().isTraceEnabled() ) { getLog().trace( "Value descriptor: " + children[n]); @@ -1326,7 +1327,7 @@ * @return true if the type is a loop type */ public boolean isLoopType(Class type) { - return XMLIntrospectorHelper.isLoopType(type); + return getConfiguration().isLoopType(type); } @@ -1437,7 +1438,7 @@ /** @see BeanType#isLoopType */ public boolean isLoopType() { - return XMLIntrospectorHelper.isLoopType( beanClass ); + return getConfiguration().isLoopType( beanClass ); } /** @see BeanType#isMapType */ 1.18 +3 -0 jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/digester/ElementRule.java Index: ElementRule.java =================================================================== RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/digester/ElementRule.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- ElementRule.java 23 Sep 2004 21:46:00 -0000 1.17 +++ ElementRule.java 8 Nov 2004 22:29:11 -0000 1.18 @@ -115,6 +115,9 @@ getPropertyType( propertyType, beanClass, propertyName ) ); + descriptor.setCollective(getXMLIntrospector().getConfiguration() + .isLoopType(descriptor.getPropertyType())); + String implementationClass = attributes.getValue( "class" ); if ( log.isTraceEnabled() ) { log.trace("'class' attribute=" + implementationClass); 1.34 +3 -0 jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/digester/XMLIntrospectorHelper.java Index: XMLIntrospectorHelper.java =================================================================== RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/digester/XMLIntrospectorHelper.java,v retrieving revision 1.33 retrieving revision 1.34 diff -u -r1.33 -r1.34 --- XMLIntrospectorHelper.java 4 Oct 2004 22:27:12 -0000 1.33 +++ XMLIntrospectorHelper.java 8 Nov 2004 22:29:11 -0000 1.34 @@ -48,6 +48,8 @@ * think about whether they need replacing with something different. * @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a> * @author <a href="mailto:[EMAIL PROTECTED]">Martin van den Bemt</a> + * + * @deprecated */ public class XMLIntrospectorHelper { @@ -549,6 +551,7 @@ * * @param type is this <code>Class</code> a loop type? * @return true if the type is a loop type, or if type is null + * @deprecated */ public static boolean isLoopType(Class type) { // check for NPEs 1.33 +2 -2 jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/AbstractBeanWriter.java Index: AbstractBeanWriter.java =================================================================== RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/AbstractBeanWriter.java,v retrieving revision 1.32 retrieving revision 1.33 diff -u -r1.32 -r1.33 --- AbstractBeanWriter.java 23 Sep 2004 21:46:00 -0000 1.32 +++ AbstractBeanWriter.java 8 Nov 2004 22:29:11 -0000 1.33 @@ -1080,7 +1080,7 @@ } // always write out loops - even when they have no elements - if ( XMLIntrospectorHelper.isLoopType( descriptor.getPropertyType() ) ) { + if ( descriptor.isCollective() ) { log.trace("Loop type so not empty."); return false; } 1.9 +2 -2 jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/digester/TestXMLIntrospectorHelper.java Index: TestXMLIntrospectorHelper.java =================================================================== RCS file: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/digester/TestXMLIntrospectorHelper.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- TestXMLIntrospectorHelper.java 13 Jun 2004 21:32:47 -0000 1.8 +++ TestXMLIntrospectorHelper.java 8 Nov 2004 22:29:11 -0000 1.9 @@ -71,7 +71,7 @@ } public void testNullParameters() throws Exception { - XMLIntrospectorHelper.isLoopType(null); + new XMLIntrospector().isLoopType(null); } /**
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]