donaldp 02/03/12 03:14:44
Modified:
proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer
ClassicConfigurer.java DefaultConfigurer.java
proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/configurer
Configurer.java
Log:
Add some extra methods to configurer interface that allows you to pass in the
class/interface to use during configuring process. This makes it dead simple to
support facades
Revision Changes Path
1.10 +69 -17
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer/ClassicConfigurer.java
Index: ClassicConfigurer.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer/ClassicConfigurer.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- ClassicConfigurer.java 12 Mar 2002 10:33:54 -0000 1.9
+++ ClassicConfigurer.java 12 Mar 2002 11:14:43 -0000 1.10
@@ -52,6 +52,58 @@
}
/**
+ * 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.
* This configuring can be done in different ways for different
* configurers.
@@ -65,8 +117,8 @@
* @exception ConfigurationException if an error occurs
*/
public void configureElement( final Object object,
- final Configuration configuration,
- final TaskContext context )
+ final Configuration configuration,
+ final TaskContext context )
throws ConfigurationException
{
if( DEBUG )
@@ -106,7 +158,7 @@
getLogger().debug( message );
}
- configureAttribute( object, name, value, context );
+ doConfigureAttribute( object, name, value, context );
}
final Configuration[] children = configuration.getChildren();
@@ -122,7 +174,7 @@
getLogger().debug( message );
}
- configureElement( object, child, context );
+ doConfigureElement( object, child, context );
}
final String content = configuration.getValue( null );
@@ -155,12 +207,12 @@
* @exception ConfigurationException if an error occurs
*/
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, name, value, context );
+ doConfigureAttribute( object, name, value, context );
}
/**
@@ -179,10 +231,10 @@
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
{
final String methodName = getMethodNameFor( name );
@@ -431,9 +483,9 @@
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
{
final String name = configuration.getName();
@@ -474,7 +526,7 @@
try
{
final Object created = method.invoke( object, new Object[ 0 ] );
- configureElement( created, configuration, context );
+ doConfigureElement( created, configuration, context );
}
catch( final ConfigurationException ce )
{
@@ -498,7 +550,7 @@
final Class clazz = method.getParameterTypes()[ 0 ];
final Object created = clazz.newInstance();
- configureElement( created, configuration, context );
+ doConfigureElement( created, configuration, context );
method.invoke( object, new Object[]{created} );
}
catch( final ConfigurationException ce )
1.40 +43 -11
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer/DefaultConfigurer.java
Index: DefaultConfigurer.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer/DefaultConfigurer.java,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- DefaultConfigurer.java 12 Mar 2002 10:33:54 -0000 1.39
+++ DefaultConfigurer.java 12 Mar 2002 11:14:43 -0000 1.40
@@ -33,7 +33,7 @@
* Class used to configure tasks.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
- * @version $Revision: 1.39 $ $Date: 2002/03/12 10:33:54 $
+ * @version $Revision: 1.40 $ $Date: 2002/03/12 11:14:43 $
* @ant:type type="configurer" name="default"
*/
public class DefaultConfigurer
@@ -78,14 +78,23 @@
* @exception ConfigurationException if an error occurs
*/
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
{
try
{
// Configure the object
- configureObject( object, configuration, context );
+ configureObject( object, clazz, configuration, context );
}
catch( final ReportableConfigurationException e )
{
@@ -109,6 +118,7 @@
* @throws Exception On error
*/
private void configureObject( final Object object,
+ final Class clazz,
final Configuration configuration,
final TaskContext context )
throws Exception
@@ -122,7 +132,7 @@
{
// Start configuration of the object
final String elemName = configuration.getName();
- final ObjectConfigurer configurer = getConfigurer(
object.getClass() );
+ final ObjectConfigurer configurer = getConfigurer( clazz );
final ConfigurationState state = configurer.startConfiguration(
object );
// Set each of the attributes
@@ -140,7 +150,7 @@
{
final String message =
REZ.getString( "no-such-attribute.error", elemName,
name );
- throw new ReportableConfigurationException( message );
+ throw new ReportableConfigurationException( message );
}
catch( final Exception ce )
{
@@ -218,13 +228,34 @@
* @exception ConfigurationException if an error occurs
*/
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
{
// 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
final ConfigurationState state = configurer.startConfiguration(
object );
@@ -471,7 +502,8 @@
}
// Configure the object
- configureObject( child, element, context );
+ final Object object = child;
+ configureObject( object, object.getClass(), element, context );
// Convert the object, if necessary
if( !type.isInstance( child ) )
1.11 +47 -1
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/configurer/Configurer.java
Index: Configurer.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/configurer/Configurer.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Configurer.java 12 Mar 2002 10:33:54 -0000 1.10
+++ Configurer.java 12 Mar 2002 11:14:44 -0000 1.11
@@ -15,7 +15,7 @@
* Class used to configure tasks.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
- * @version $Revision: 1.10 $ $Date: 2002/03/12 10:33:54 $
+ * @version $Revision: 1.11 $ $Date: 2002/03/12 11:14:44 $
* @ant:role shorthand="configurer"
*/
public interface Configurer
@@ -47,5 +47,51 @@
* @exception ConfigurationException if an error occurs
*/
void configureAttribute( Object object, String name, String value,
TaskContext context )
+ 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;
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>