git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271741 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -459,19 +459,16 @@ public class DefaultConfigurer | |||
| } | |||
| // Create an instance | |||
| Object child = childConfigurer.createValue( state ); | |||
| if( null == child ) | |||
| Object child = null; | |||
| if( childConfigurer == state.getConfigurer().getTypedProperty() ) | |||
| { | |||
| if( childConfigurer == state.getConfigurer().getTypedProperty() ) | |||
| { | |||
| // Typed property | |||
| child = createTypedObject( name, type ); | |||
| } | |||
| else | |||
| { | |||
| // Named property | |||
| child = createNamedObject( type ); | |||
| } | |||
| // Typed property | |||
| child = createTypedObject( name, type ); | |||
| } | |||
| else | |||
| { | |||
| // Named property | |||
| child = createNamedObject( type ); | |||
| } | |||
| // Configure the object | |||
| @@ -12,11 +12,9 @@ import java.lang.reflect.Modifier; | |||
| import java.util.ArrayList; | |||
| import java.util.Collection; | |||
| import java.util.HashMap; | |||
| import java.util.HashSet; | |||
| import java.util.Iterator; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| import java.util.Set; | |||
| import org.apache.avalon.excalibur.i18n.ResourceManager; | |||
| import org.apache.avalon.excalibur.i18n.Resources; | |||
| import org.apache.avalon.framework.configuration.ConfigurationException; | |||
| @@ -72,58 +70,28 @@ class DefaultObjectConfigurer | |||
| public void enableAll() | |||
| throws ConfigurationException | |||
| { | |||
| // TODO - get rid of creators | |||
| enableProperties(); | |||
| enableContent(); | |||
| } | |||
| /** | |||
| * Enables all creators + adders. | |||
| * Enables all adders. | |||
| */ | |||
| private void enableProperties() | |||
| throws ConfigurationException | |||
| { | |||
| final Map creators = findCreators(); | |||
| final Map adders = findAdders(); | |||
| // Add the elements | |||
| final Set elemNames = new HashSet(); | |||
| elemNames.addAll( creators.keySet() ); | |||
| elemNames.addAll( adders.keySet() ); | |||
| final Iterator iterator = elemNames.iterator(); | |||
| final Iterator iterator = adders.keySet().iterator(); | |||
| while( iterator.hasNext() ) | |||
| { | |||
| final String propName = (String)iterator.next(); | |||
| final Method createMethod = (Method)creators.get( propName ); | |||
| final Method addMethod = (Method)adders.get( propName ); | |||
| // Determine and check the return type | |||
| Class type; | |||
| if( createMethod != null && addMethod != null ) | |||
| { | |||
| // Make sure the add method is more general than the create | |||
| // method | |||
| type = createMethod.getReturnType(); | |||
| final Class addType = addMethod.getParameterTypes()[ 0 ]; | |||
| if( !addType.isAssignableFrom( type ) ) | |||
| { | |||
| final String message = | |||
| REZ.getString( "incompatible-element-types.error", | |||
| m_class.getName(), | |||
| propName ); | |||
| throw new ConfigurationException( message ); | |||
| } | |||
| } | |||
| else if( createMethod != null ) | |||
| { | |||
| type = createMethod.getReturnType(); | |||
| } | |||
| else | |||
| { | |||
| type = addMethod.getParameterTypes()[ 0 ]; | |||
| } | |||
| final Class type = addMethod.getParameterTypes()[ 0 ]; | |||
| final boolean isTypedProp = ( propName.length() == 0 ); | |||
| if( isTypedProp && !type.isInterface() ) | |||
| { | |||
| @@ -144,7 +112,6 @@ class DefaultObjectConfigurer | |||
| final DefaultPropertyConfigurer configurer = | |||
| new DefaultPropertyConfigurer( m_allProps.size(), | |||
| type, | |||
| createMethod, | |||
| addMethod, | |||
| maxCount ); | |||
| m_allProps.add( configurer ); | |||
| @@ -224,45 +191,6 @@ class DefaultObjectConfigurer | |||
| return adders; | |||
| } | |||
| /** | |||
| * Find all 'create' methods, which return a non-primitive type, | |||
| * and take no parameters. | |||
| */ | |||
| private Map findCreators() | |||
| throws ConfigurationException | |||
| { | |||
| final Map creators = new HashMap(); | |||
| final List methodSet = new ArrayList(); | |||
| findMethodsWithPrefix( "create", methodSet ); | |||
| final Iterator iterator = methodSet.iterator(); | |||
| while( iterator.hasNext() ) | |||
| { | |||
| final Method method = (Method)iterator.next(); | |||
| final String methodName = method.getName(); | |||
| if( method.getReturnType().isPrimitive() || | |||
| method.getParameterTypes().length != 0 ) | |||
| { | |||
| continue; | |||
| } | |||
| // Extract element name | |||
| final String elemName = extractName( 6, methodName ); | |||
| // Add to the creators map | |||
| if( creators.containsKey( elemName ) ) | |||
| { | |||
| final String message = | |||
| REZ.getString( "multiple-creator-methods-for-element.error", | |||
| m_class.getName(), | |||
| methodName ); | |||
| throw new ConfigurationException( message ); | |||
| } | |||
| creators.put( elemName, method ); | |||
| } | |||
| return creators; | |||
| } | |||
| /** | |||
| * Enables content. | |||
| */ | |||
| @@ -300,7 +228,6 @@ class DefaultObjectConfigurer | |||
| m_contentConfigurer = | |||
| new DefaultPropertyConfigurer( m_allProps.size(), | |||
| type, | |||
| null, | |||
| method, | |||
| 1 ); | |||
| m_allProps.add( m_contentConfigurer ); | |||
| @@ -28,13 +28,11 @@ class DefaultPropertyConfigurer | |||
| private final int m_propIndex; | |||
| private final Class m_type; | |||
| private final Method m_createMethod; | |||
| private final Method m_addMethod; | |||
| private final int m_maxCount; | |||
| public DefaultPropertyConfigurer( final int propIndex, | |||
| final Class type, | |||
| final Method createMethod, | |||
| final Method addMethod, | |||
| final int maxCount ) | |||
| { | |||
| @@ -47,7 +45,6 @@ class DefaultPropertyConfigurer | |||
| { | |||
| m_type = type; | |||
| } | |||
| m_createMethod = createMethod; | |||
| m_addMethod = addMethod; | |||
| m_maxCount = maxCount; | |||
| } | |||
| @@ -60,44 +57,6 @@ class DefaultPropertyConfigurer | |||
| return m_type; | |||
| } | |||
| /** | |||
| * Creates a default value for this property. | |||
| */ | |||
| public Object createValue( final ConfigurationState state ) | |||
| throws ConfigurationException | |||
| { | |||
| if( null == m_createMethod ) | |||
| { | |||
| return null; | |||
| } | |||
| final DefaultConfigurationState defState = (DefaultConfigurationState)state; | |||
| // Make sure there isn't a pending object for this property | |||
| if( defState.getCreatedObject( m_propIndex ) != null ) | |||
| { | |||
| final String message = REZ.getString( "pending-property-value.error" ); | |||
| throw new ConfigurationException( message ); | |||
| } | |||
| try | |||
| { | |||
| // Create the value | |||
| final Object object = m_createMethod.invoke( defState.getObject(), null ); | |||
| defState.setCreatedObject( m_propIndex, object ); | |||
| return object; | |||
| } | |||
| catch( final InvocationTargetException ite ) | |||
| { | |||
| final Throwable cause = ite.getTargetException(); | |||
| throw new ConfigurationException( cause.getMessage(), cause ); | |||
| } | |||
| catch( final Exception e ) | |||
| { | |||
| throw new ConfigurationException( e.getMessage(), e ); | |||
| } | |||
| } | |||
| /** | |||
| * Adds a value for this property, to an object. | |||
| */ | |||
| @@ -112,13 +71,6 @@ class DefaultPropertyConfigurer | |||
| { | |||
| } | |||
| // Make sure the creator method was called, if necessary | |||
| if( pending == null && m_createMethod != null ) | |||
| { | |||
| final String message = REZ.getString( "must-be-element.error" ); | |||
| throw new ConfigurationException( message ); | |||
| } | |||
| defState.setCreatedObject( m_propIndex, null ); | |||
| // Check the property count | |||
| @@ -23,19 +23,6 @@ interface PropertyConfigurer | |||
| */ | |||
| Class getType(); | |||
| /** | |||
| * Creates a default value for this property. This value must be configured, | |||
| * and then attached to the object using {@link #addValue}. | |||
| * | |||
| * @param state The state object, representing the object being configured. | |||
| * @return An object which is assignable to the type returned by | |||
| * {@link #getType}. Returns null if this property does not | |||
| * need a default value. | |||
| * @throws ConfigurationException If the object cannot be created. | |||
| */ | |||
| Object createValue( ConfigurationState state ) | |||
| throws ConfigurationException; | |||
| /** | |||
| * Adds a value for this property, to an object. | |||
| * | |||
| @@ -3,10 +3,8 @@ extra-config-for-ref.error=A reference element can only include an "id" attribut | |||
| mismatch-ref-types.error=Could not convert reference "{0}" to the type expected for property "{1}". | |||
| incompatible-element-types.error=Incompatible creator and adder/setter methods found in class {0} for property "{1}". | |||
| multiple-adder-methods-for-element.error=Multiple add{1}() or set{1}() methods found in class {0}. | |||
| multiple-creator-methods-for-element.error=Multiple {1}() methods found in class {0}. | |||
| multiple-content-setter-methods.error=Multiple content setter methods found in class {0}. | |||
| pending-property-value.error=An object created using the creator method has not been set using the adder/setter method. | |||
| must-be-element.error=This property must be configured using a nested element. | |||
| too-many-values.error=Too many values for this property. | |||
| no-complex-type.error=Can not get complex type for non-primitive type {0}. | |||
| no-such-attribute.error=Element <{0}> does not support attribute "{1}". | |||