git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271832 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -51,6 +51,58 @@ public class ClassicConfigurer | |||||
| m_converter = (Converter)serviceManager.lookup( Converter.ROLE ); | m_converter = (Converter)serviceManager.lookup( Converter.ROLE ); | ||||
| } | } | ||||
| /** | |||||
| * Configure an object based on a configuration in a particular context. | |||||
| * This configuring can be done in different ways for different | |||||
| * configurers. | |||||
| * | |||||
| * The implementation of this method should only use the methods | |||||
| * specified by the supplied class. It is an error for the specified | |||||
| * class not to be a base class or interface compatible with specified | |||||
| * object. | |||||
| * | |||||
| * @param object the object | |||||
| * @param clazz the Class object to use during configuration | |||||
| * @param configuration the configuration | |||||
| * @param context the Context | |||||
| * @exception ConfigurationException if an error occurs | |||||
| */ | |||||
| public void configureElement( Object object, | |||||
| Class clazz, | |||||
| Configuration configuration, | |||||
| TaskContext context ) | |||||
| throws ConfigurationException | |||||
| { | |||||
| throw new UnsupportedOperationException(); | |||||
| } | |||||
| /** | |||||
| * Configure named attribute of object in a particular context. | |||||
| * This configuring can be done in different ways for different | |||||
| * configurers. | |||||
| * | |||||
| * The implementation of this method should only use the methods | |||||
| * specified by the supplied class. It is an error for the specified | |||||
| * class not to be a base class or interface compatible with specified | |||||
| * object. | |||||
| * | |||||
| * @param object the object | |||||
| * @param clazz the Class object to use during configuration | |||||
| * @param name the attribute name | |||||
| * @param value the attribute value | |||||
| * @param context the Context | |||||
| * @exception ConfigurationException if an error occurs | |||||
| */ | |||||
| public void configureAttribute( Object object, | |||||
| Class clazz, | |||||
| String name, | |||||
| String value, | |||||
| TaskContext context ) | |||||
| throws ConfigurationException | |||||
| { | |||||
| throw new UnsupportedOperationException(); | |||||
| } | |||||
| /** | /** | ||||
| * Configure a task based on a configuration in a particular context. | * Configure a task based on a configuration in a particular context. | ||||
| * This configuring can be done in different ways for different | * This configuring can be done in different ways for different | ||||
| @@ -65,8 +117,8 @@ public class ClassicConfigurer | |||||
| * @exception ConfigurationException if an error occurs | * @exception ConfigurationException if an error occurs | ||||
| */ | */ | ||||
| public void configureElement( final Object object, | public void configureElement( final Object object, | ||||
| final Configuration configuration, | |||||
| final TaskContext context ) | |||||
| final Configuration configuration, | |||||
| final TaskContext context ) | |||||
| throws ConfigurationException | throws ConfigurationException | ||||
| { | { | ||||
| if( DEBUG ) | if( DEBUG ) | ||||
| @@ -106,7 +158,7 @@ public class ClassicConfigurer | |||||
| getLogger().debug( message ); | getLogger().debug( message ); | ||||
| } | } | ||||
| configureAttribute( object, name, value, context ); | |||||
| doConfigureAttribute( object, name, value, context ); | |||||
| } | } | ||||
| final Configuration[] children = configuration.getChildren(); | final Configuration[] children = configuration.getChildren(); | ||||
| @@ -122,7 +174,7 @@ public class ClassicConfigurer | |||||
| getLogger().debug( message ); | getLogger().debug( message ); | ||||
| } | } | ||||
| configureElement( object, child, context ); | |||||
| doConfigureElement( object, child, context ); | |||||
| } | } | ||||
| final String content = configuration.getValue( null ); | final String content = configuration.getValue( null ); | ||||
| @@ -155,12 +207,12 @@ public class ClassicConfigurer | |||||
| * @exception ConfigurationException if an error occurs | * @exception ConfigurationException if an error occurs | ||||
| */ | */ | ||||
| public void configureAttribute( final Object object, | public void configureAttribute( final Object object, | ||||
| final String name, | |||||
| final String value, | |||||
| final TaskContext context ) | |||||
| final String name, | |||||
| final String value, | |||||
| final TaskContext context ) | |||||
| throws ConfigurationException | throws ConfigurationException | ||||
| { | { | ||||
| configureAttribute( object, name, value, context ); | |||||
| doConfigureAttribute( object, name, value, context ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -179,10 +231,10 @@ public class ClassicConfigurer | |||||
| setValue( object, "addContent", content, context ); | setValue( object, "addContent", content, context ); | ||||
| } | } | ||||
| private void configureAttribute( final Object object, | |||||
| final String name, | |||||
| final String value, | |||||
| final TaskContext context ) | |||||
| private void doConfigureAttribute( final Object object, | |||||
| final String name, | |||||
| final String value, | |||||
| final TaskContext context ) | |||||
| throws ConfigurationException | throws ConfigurationException | ||||
| { | { | ||||
| final String methodName = getMethodNameFor( name ); | final String methodName = getMethodNameFor( name ); | ||||
| @@ -431,9 +483,9 @@ public class ClassicConfigurer | |||||
| return sb.toString(); | return sb.toString(); | ||||
| } | } | ||||
| private void configureElement( final Object object, | |||||
| final Configuration configuration, | |||||
| final TaskContext context ) | |||||
| private void doConfigureElement( final Object object, | |||||
| final Configuration configuration, | |||||
| final TaskContext context ) | |||||
| throws ConfigurationException | throws ConfigurationException | ||||
| { | { | ||||
| final String name = configuration.getName(); | final String name = configuration.getName(); | ||||
| @@ -474,7 +526,7 @@ public class ClassicConfigurer | |||||
| try | try | ||||
| { | { | ||||
| final Object created = method.invoke( object, new Object[ 0 ] ); | final Object created = method.invoke( object, new Object[ 0 ] ); | ||||
| configureElement( created, configuration, context ); | |||||
| doConfigureElement( created, configuration, context ); | |||||
| } | } | ||||
| catch( final ConfigurationException ce ) | catch( final ConfigurationException ce ) | ||||
| { | { | ||||
| @@ -498,7 +550,7 @@ public class ClassicConfigurer | |||||
| final Class clazz = method.getParameterTypes()[ 0 ]; | final Class clazz = method.getParameterTypes()[ 0 ]; | ||||
| final Object created = clazz.newInstance(); | final Object created = clazz.newInstance(); | ||||
| configureElement( created, configuration, context ); | |||||
| doConfigureElement( created, configuration, context ); | |||||
| method.invoke( object, new Object[]{created} ); | method.invoke( object, new Object[]{created} ); | ||||
| } | } | ||||
| catch( final ConfigurationException ce ) | catch( final ConfigurationException ce ) | ||||
| @@ -78,14 +78,23 @@ public class DefaultConfigurer | |||||
| * @exception ConfigurationException if an error occurs | * @exception ConfigurationException if an error occurs | ||||
| */ | */ | ||||
| public void configureElement( final Object object, | public void configureElement( final Object object, | ||||
| final Configuration configuration, | |||||
| final TaskContext context ) | |||||
| final Configuration configuration, | |||||
| final TaskContext context ) | |||||
| throws ConfigurationException | |||||
| { | |||||
| configureElement( object, object.getClass(), configuration, context ); | |||||
| } | |||||
| public void configureElement( final Object object, | |||||
| final Class clazz, | |||||
| final Configuration configuration, | |||||
| final TaskContext context ) | |||||
| throws ConfigurationException | throws ConfigurationException | ||||
| { | { | ||||
| try | try | ||||
| { | { | ||||
| // Configure the object | // Configure the object | ||||
| configureObject( object, configuration, context ); | |||||
| configureObject( object, clazz, configuration, context ); | |||||
| } | } | ||||
| catch( final ReportableConfigurationException e ) | catch( final ReportableConfigurationException e ) | ||||
| { | { | ||||
| @@ -109,6 +118,7 @@ public class DefaultConfigurer | |||||
| * @throws Exception On error | * @throws Exception On error | ||||
| */ | */ | ||||
| private void configureObject( final Object object, | private void configureObject( final Object object, | ||||
| final Class clazz, | |||||
| final Configuration configuration, | final Configuration configuration, | ||||
| final TaskContext context ) | final TaskContext context ) | ||||
| throws Exception | throws Exception | ||||
| @@ -122,7 +132,7 @@ public class DefaultConfigurer | |||||
| { | { | ||||
| // Start configuration of the object | // Start configuration of the object | ||||
| final String elemName = configuration.getName(); | final String elemName = configuration.getName(); | ||||
| final ObjectConfigurer configurer = getConfigurer( object.getClass() ); | |||||
| final ObjectConfigurer configurer = getConfigurer( clazz ); | |||||
| final ConfigurationState state = configurer.startConfiguration( object ); | final ConfigurationState state = configurer.startConfiguration( object ); | ||||
| // Set each of the attributes | // Set each of the attributes | ||||
| @@ -140,7 +150,7 @@ public class DefaultConfigurer | |||||
| { | { | ||||
| final String message = | final String message = | ||||
| REZ.getString( "no-such-attribute.error", elemName, name ); | REZ.getString( "no-such-attribute.error", elemName, name ); | ||||
| throw new ReportableConfigurationException( message ); | |||||
| throw new ReportableConfigurationException( message ); | |||||
| } | } | ||||
| catch( final Exception ce ) | catch( final Exception ce ) | ||||
| { | { | ||||
| @@ -218,13 +228,34 @@ public class DefaultConfigurer | |||||
| * @exception ConfigurationException if an error occurs | * @exception ConfigurationException if an error occurs | ||||
| */ | */ | ||||
| public void configureAttribute( final Object object, | public void configureAttribute( final Object object, | ||||
| final String name, | |||||
| final String value, | |||||
| final TaskContext context ) | |||||
| final String name, | |||||
| final String value, | |||||
| final TaskContext context ) | |||||
| throws ConfigurationException | |||||
| { | |||||
| configureAttribute( object, object.getClass(), name, value, context ); | |||||
| } | |||||
| /** | |||||
| * Configure named attribute of object in a particular context. | |||||
| * This configuring can be done in different ways for different | |||||
| * configurers. | |||||
| * | |||||
| * @param object the object | |||||
| * @param name the attribute name | |||||
| * @param value the attribute value | |||||
| * @param context the Context | |||||
| * @exception ConfigurationException if an error occurs | |||||
| */ | |||||
| public void configureAttribute( final Object object, | |||||
| final Class clazz, | |||||
| final String name, | |||||
| final String value, | |||||
| final TaskContext context ) | |||||
| throws ConfigurationException | throws ConfigurationException | ||||
| { | { | ||||
| // Locate the configurer for this object | // Locate the configurer for this object | ||||
| final ObjectConfigurer configurer = getConfigurer( object.getClass() ); | |||||
| final ObjectConfigurer configurer = getConfigurer( clazz ); | |||||
| // TODO - this ain't right, the validation is going to be screwed up | // TODO - this ain't right, the validation is going to be screwed up | ||||
| final ConfigurationState state = configurer.startConfiguration( object ); | final ConfigurationState state = configurer.startConfiguration( object ); | ||||
| @@ -471,7 +502,8 @@ public class DefaultConfigurer | |||||
| } | } | ||||
| // Configure the object | // Configure the object | ||||
| configureObject( child, element, context ); | |||||
| final Object object = child; | |||||
| configureObject( object, object.getClass(), element, context ); | |||||
| // Convert the object, if necessary | // Convert the object, if necessary | ||||
| if( !type.isInstance( child ) ) | if( !type.isInstance( child ) ) | ||||
| @@ -48,4 +48,50 @@ public interface Configurer | |||||
| */ | */ | ||||
| void configureAttribute( Object object, String name, String value, TaskContext context ) | void configureAttribute( Object object, String name, String value, TaskContext context ) | ||||
| throws ConfigurationException; | throws ConfigurationException; | ||||
| /** | |||||
| * Configure an object based on a configuration in a particular context. | |||||
| * This configuring can be done in different ways for different | |||||
| * configurers. | |||||
| * | |||||
| * The implementation of this method should only use the methods | |||||
| * specified by the supplied class. It is an error for the specified | |||||
| * class not to be a base class or interface compatible with specified | |||||
| * object. | |||||
| * | |||||
| * @param object the object | |||||
| * @param clazz the Class object to use during configuration | |||||
| * @param configuration the configuration | |||||
| * @param context the Context | |||||
| * @exception ConfigurationException if an error occurs | |||||
| */ | |||||
| void configureElement( Object object, | |||||
| Class clazz, | |||||
| Configuration configuration, | |||||
| TaskContext context ) | |||||
| throws ConfigurationException; | |||||
| /** | |||||
| * Configure named attribute of object in a particular context. | |||||
| * This configuring can be done in different ways for different | |||||
| * configurers. | |||||
| * | |||||
| * The implementation of this method should only use the methods | |||||
| * specified by the supplied class. It is an error for the specified | |||||
| * class not to be a base class or interface compatible with specified | |||||
| * object. | |||||
| * | |||||
| * @param object the object | |||||
| * @param clazz the Class object to use during configuration | |||||
| * @param name the attribute name | |||||
| * @param value the attribute value | |||||
| * @param context the Context | |||||
| * @exception ConfigurationException if an error occurs | |||||
| */ | |||||
| void configureAttribute( Object object, | |||||
| Class clazz, | |||||
| String name, | |||||
| String value, | |||||
| TaskContext context ) | |||||
| throws ConfigurationException; | |||||
| } | } | ||||