diff --git a/proposal/myrmidon/src/java/org/apache/antlib/core/Property.java b/proposal/myrmidon/src/java/org/apache/antlib/core/Property.java index 4e16e689c..646a57f63 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/core/Property.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/core/Property.java @@ -54,8 +54,8 @@ public class Property { try { - final TypeFactory typeFactory = getTypeFactory( DataType.class ); - final DataType value = (DataType)typeFactory.create( children[ i ].getName() ); + final String typeName = children[ i ].getName(); + final DataType value = (DataType)newInstance( DataType.class, typeName ); configure( value, children[ i ] ); setValue( value ); } diff --git a/proposal/myrmidon/src/java/org/apache/antlib/runtime/Facility.java b/proposal/myrmidon/src/java/org/apache/antlib/runtime/Facility.java index 0182c648c..c7c23f1d9 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/runtime/Facility.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/runtime/Facility.java @@ -49,15 +49,15 @@ public class Facility if( 1 == children.length ) { + final String typeName = children[ 0 ].getName(); try { - final TypeFactory typeFactory = getTypeFactory( AspectHandler.class ); - m_aspectHandler = (AspectHandler)typeFactory.create( children[ 0 ].getName() ); + m_aspectHandler = (AspectHandler)newInstance( AspectHandler.class, typeName ); } catch( final Exception e ) { final String message = - REZ.getString( "facility.no-create.error", children[ 0 ].getName() ); + REZ.getString( "facility.no-create.error", typeName ); throw new ConfigurationException( message, e ); } diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/framework/AbstractContainerTask.java b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/AbstractContainerTask.java index 6d6c71a6a..f0bfcacb1 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/framework/AbstractContainerTask.java +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/AbstractContainerTask.java @@ -107,6 +107,27 @@ public abstract class AbstractContainerTask getConfigurer().configure( object, name, value, getContext() ); } + /** + * Create an instance of type with specified type and in specified role. + */ + protected final Object newInstance( final Class roleType, final String typeName ) + throws TaskException + { + final TypeFactory typeFactory = getTypeFactory( roleType ); + try + { + return typeFactory.create( typeName ); + } + catch( final TypeException te ) + { + final String message = + REZ.getString( "container.no-create-type.error", + roleType.getName(), + typeName ); + throw new TaskException( message, te ); + } + } + /** * Locates a type factory. */ diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Resources.properties b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Resources.properties index f7ea1d837..b8b48a121 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Resources.properties +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Resources.properties @@ -2,6 +2,7 @@ container.null-value.error=Value ({0}) resolved to null. container.bad-resolve.error=Error resolving value ({0}). container.bad-config.error=Error converting value. container.no-factory.error=Could not locate the type factory for type "{0}". +container.no-create-type.error=Could not create instance of role "{0}" with type name "{1}". typedef.no-lib.error=Must specify the lib parameter. diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/framework/TypeInstanceTask.java b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/TypeInstanceTask.java index f492584d3..5eb6ccb1e 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/framework/TypeInstanceTask.java +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/TypeInstanceTask.java @@ -15,7 +15,6 @@ import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.configuration.DefaultConfiguration; import org.apache.myrmidon.api.TaskContext; import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.interfaces.type.TypeFactory; /** * This is the property "task" to declare a binding of a datatype to a name. @@ -64,8 +63,7 @@ public class TypeInstanceTask try { - final TypeFactory typeFactory = getTypeFactory( DataType.class ); - m_value = typeFactory.create( configuration.getName() ); + m_value = newInstance( DataType.class, configuration.getName() ); } catch( final Exception e ) {