Author: rdonkin Date: Mon Oct 3 15:24:54 2005 New Revision: 293460 URL: http://svn.apache.org/viewcvs?rev=293460&view=rev Log: Factored out collective types into separate strategy. This allows subclasses of standard java types to be (optionally) regarded as plain POJOs.
Added: jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/strategy/CollectiveTypeStrategy.java jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/strategy/impl/OverrideCollectiveTypeStategy.java Modified: jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/IntrospectionConfiguration.java jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml Modified: jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/IntrospectionConfiguration.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/IntrospectionConfiguration.java?rev=293460&r1=293459&r2=293460&view=diff ============================================================================== --- jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/IntrospectionConfiguration.java (original) +++ jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/IntrospectionConfiguration.java Mon Oct 3 15:24:54 2005 @@ -22,6 +22,7 @@ import java.util.Map; import org.apache.commons.betwixt.strategy.ClassNormalizer; +import org.apache.commons.betwixt.strategy.CollectiveTypeStrategy; import org.apache.commons.betwixt.strategy.DefaultNameMapper; import org.apache.commons.betwixt.strategy.DefaultPluralStemmer; import org.apache.commons.betwixt.strategy.MappingDerivationStrategy; @@ -89,7 +90,8 @@ private SimpleTypeMapper simpleTypeMapper = new StandardSimpleTypeMapper(); /** Binding strategy for Java type */ private TypeBindingStrategy typeBindingStrategy = TypeBindingStrategy.DEFAULT; - + /** Strategy used for determining which types are collective */ + private CollectiveTypeStrategy collectiveTypeStrategy = CollectiveTypeStrategy.DEFAULT; /** * Strategy used to determine whether the bind or introspection time type is to be used to @@ -385,6 +387,23 @@ this.propertySuppressionStrategy = propertySuppressionStrategy; } + /** + * Gets the strategy used to determine which types are collective. + * @return <code>CollectiveTypeStrategy</code>, not null + */ + public CollectiveTypeStrategy getCollectiveTypeStrategy() { + return collectiveTypeStrategy; + } + + /** + * Sets the strategy used to determine which types are collective. + * @param collectiveTypeStrategy <code>CollectiveTypeStrategy</code>, not null + */ + public void setCollectiveTypeStrategy( + CollectiveTypeStrategy collectiveTypeStrategy) { + this.collectiveTypeStrategy = collectiveTypeStrategy; + } + /** * Is this a loop type class? * @since 0.7 @@ -392,16 +411,6 @@ * @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 ) - || Map.Entry.class.isAssignableFrom( type ) ; + return getCollectiveTypeStrategy().isCollective(type); } } Added: jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/strategy/CollectiveTypeStrategy.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/strategy/CollectiveTypeStrategy.java?rev=293460&view=auto ============================================================================== --- jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/strategy/CollectiveTypeStrategy.java (added) +++ jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/strategy/CollectiveTypeStrategy.java Mon Oct 3 15:24:54 2005 @@ -0,0 +1,66 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.betwixt.strategy; + +import java.util.Collection; +import java.util.Enumeration; +import java.util.Iterator; +import java.util.Map; + +/** + * Specifies which types should be regarded as collective + */ +public abstract class CollectiveTypeStrategy { + + /** + * Default collective type strategy + */ + public static final CollectiveTypeStrategy DEFAULT = new Default(); + + /** + * Is this a loop type class? + * @since 0.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 + */ + public abstract boolean isCollective(Class type); + + /** + * Default collective type strategy + */ + public static class Default extends CollectiveTypeStrategy { + + /** + * Basic implementation returns true for all the standard java + * collective types and their subclasses. + */ + public boolean isCollective(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 ) + || Map.Entry.class.isAssignableFrom( type ) ; + + } + + } +} Added: jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/strategy/impl/OverrideCollectiveTypeStategy.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/strategy/impl/OverrideCollectiveTypeStategy.java?rev=293460&view=auto ============================================================================== --- jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/strategy/impl/OverrideCollectiveTypeStategy.java (added) +++ jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/strategy/impl/OverrideCollectiveTypeStategy.java Mon Oct 3 15:24:54 2005 @@ -0,0 +1,83 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.betwixt.strategy.impl; + +import java.util.ArrayList; +import java.util.Collection; + +import org.apache.commons.betwixt.strategy.CollectiveTypeStrategy; + +/** + * Strategy that allows specific classes to be marked as + * collective ([EMAIL PROTECTED] #overrideCollective(Class)}) + * or not collective ([EMAIL PROTECTED] #overrideNotCollective(Class)}) + */ +public class OverrideCollectiveTypeStategy extends CollectiveTypeStrategy { + + private final CollectiveTypeStrategy delegate; + + private final Collection collectiveClasses; + private final Collection notCollectiveClasses; + + /** + * Constructs a strategy which delegates to CollectiveTypeStrategy#DEFAULT + * + */ + public OverrideCollectiveTypeStategy() { + this(CollectiveTypeStrategy.DEFAULT); + } + + /** + * Constructs a strategy which delegates all those that it does not override. + * @param delegate + */ + public OverrideCollectiveTypeStategy(CollectiveTypeStrategy delegate) { + super(); + this.delegate = delegate; + collectiveClasses = new ArrayList(); + notCollectiveClasses = new ArrayList(); + } + + /** + * Marks the given type to be treated as collective. + * @param type <code>Class</code>, not null + */ + public void overrideCollective(Class type) { + collectiveClasses.add(type); + } + + /** + * Marks the given type to be treated as not collective + * @param type + */ + public void overrideNotCollective(Class type) { + notCollectiveClasses.add(type); + } + + /** + * @see CollectiveTypeStrategy#isCollective(Class) + */ + public boolean isCollective(Class type) { + boolean result = delegate.isCollective(type); + if (collectiveClasses.contains(type)) { + result = true; + } else if (notCollectiveClasses.contains(type)) { + result = false; + } + return result; + } + +} Modified: jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml?rev=293460&r1=293459&r2=293460&view=diff ============================================================================== --- jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml (original) +++ jakarta/commons/proper/betwixt/trunk/xdocs/tasks.xml Mon Oct 3 15:24:54 2005 @@ -200,6 +200,10 @@ <subsection name='Since 0.7'> <ul> <li> +Improved support for subclasses of Java collective types +by factoring collective type recognition into strategy. + </li> + <li> Added support for multiple contained polymorphic mappings. </li> <li> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]