Browse Source

Added a newInstance method to AbstractContainerTask to make it easier to create instances of a role with a specific type

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271330 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Donald 24 years ago
parent
commit
23083ead26
5 changed files with 28 additions and 8 deletions
  1. +2
    -2
      proposal/myrmidon/src/java/org/apache/antlib/core/Property.java
  2. +3
    -3
      proposal/myrmidon/src/java/org/apache/antlib/runtime/Facility.java
  3. +21
    -0
      proposal/myrmidon/src/java/org/apache/myrmidon/framework/AbstractContainerTask.java
  4. +1
    -0
      proposal/myrmidon/src/java/org/apache/myrmidon/framework/Resources.properties
  5. +1
    -3
      proposal/myrmidon/src/java/org/apache/myrmidon/framework/TypeInstanceTask.java

+ 2
- 2
proposal/myrmidon/src/java/org/apache/antlib/core/Property.java View File

@@ -54,8 +54,8 @@ public class Property
{ {
try 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 ] ); configure( value, children[ i ] );
setValue( value ); setValue( value );
} }


+ 3
- 3
proposal/myrmidon/src/java/org/apache/antlib/runtime/Facility.java View File

@@ -49,15 +49,15 @@ public class Facility


if( 1 == children.length ) if( 1 == children.length )
{ {
final String typeName = children[ 0 ].getName();
try 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 ) catch( final Exception e )
{ {
final String message = final String message =
REZ.getString( "facility.no-create.error", children[ 0 ].getName() );
REZ.getString( "facility.no-create.error", typeName );
throw new ConfigurationException( message, e ); throw new ConfigurationException( message, e );
} }




+ 21
- 0
proposal/myrmidon/src/java/org/apache/myrmidon/framework/AbstractContainerTask.java View File

@@ -107,6 +107,27 @@ public abstract class AbstractContainerTask
getConfigurer().configure( object, name, value, getContext() ); 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. * Locates a type factory.
*/ */


+ 1
- 0
proposal/myrmidon/src/java/org/apache/myrmidon/framework/Resources.properties View File

@@ -2,6 +2,7 @@ container.null-value.error=Value ({0}) resolved to null.
container.bad-resolve.error=Error resolving value ({0}). container.bad-resolve.error=Error resolving value ({0}).
container.bad-config.error=Error converting value. container.bad-config.error=Error converting value.
container.no-factory.error=Could not locate the type factory for type "{0}". 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. typedef.no-lib.error=Must specify the lib parameter.




+ 1
- 3
proposal/myrmidon/src/java/org/apache/myrmidon/framework/TypeInstanceTask.java View File

@@ -15,7 +15,6 @@ import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfiguration; import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.myrmidon.api.TaskContext; import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException; 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. * This is the property "task" to declare a binding of a datatype to a name.
@@ -64,8 +63,7 @@ public class TypeInstanceTask


try try
{ {
final TypeFactory typeFactory = getTypeFactory( DataType.class );
m_value = typeFactory.create( configuration.getName() );
m_value = newInstance( DataType.class, configuration.getName() );
} }
catch( final Exception e ) catch( final Exception e )
{ {


Loading…
Cancel
Save