donaldp 2002/06/12 19:23:26
Modified: container/src/java/org/apache/myrmidon/components/configurer
DefaultConfigurer.java
Log:
Rather than aquiring the services;
* RoleManager
* TypeManager
* Converter
at startup via Serviceable the component aquires the services from the
TaskContext. This means that the TypeManager in current scope is used rather
than the manager aquired at start of lifecycle.
Revision Changes Path
1.53 +32 -39
jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/configurer/DefaultConfigurer.java
Index: DefaultConfigurer.java
===================================================================
RCS file:
/home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/configurer/DefaultConfigurer.java,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -r1.52 -r1.53
--- DefaultConfigurer.java 9 Jun 2002 13:20:46 -0000 1.52
+++ DefaultConfigurer.java 13 Jun 2002 02:23:26 -0000 1.53
@@ -12,9 +12,6 @@
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
import org.apache.excalibur.converter.Converter;
import org.apache.excalibur.converter.ConverterException;
import org.apache.myrmidon.api.TaskContext;
@@ -37,32 +34,15 @@
*/
public class DefaultConfigurer
extends AbstractLogEnabled
- implements Configurer, ScopedService, Serviceable
+ implements Configurer, ScopedService
{
private static final Resources REZ =
ResourceManager.getPackageResources( DefaultConfigurer.class );
- ///Converter to use for converting between values
- private Converter m_converter;
-
- //TypeManager to use to create types in typed adders
- private TypeManager m_typeManager;
-
- //RoleManager to use to map from type names -> role shorthand
- private RoleManager m_roleManager;
-
///Cached object configurers. This is a map from Class to the
///ObjectConfigurer for that class.
private Map m_configurerCache = new HashMap();
- public void service( final ServiceManager serviceManager )
- throws ServiceException
- {
- m_converter = (Converter)serviceManager.lookup( Converter.ROLE );
- m_typeManager = (TypeManager)serviceManager.lookup( TypeManager.ROLE
);
- m_roleManager = (RoleManager)serviceManager.lookup( RoleManager.ROLE
);
- }
-
/**
* Creates an uninitialised child of this service.
*/
@@ -338,7 +318,7 @@
// Locate the configurer for the child element
final PropertyConfigurer childConfigurer =
- getConfigurerFromName( state.getConfigurer(), name, true, true );
+ getConfigurerFromName( state.getConfigurer(), name, true, true,
context );
// Create & configure the child element
final Object child =
@@ -385,7 +365,7 @@
// Locate the configurer for the property
final PropertyConfigurer configurer =
- getConfigurerFromName( state.getConfigurer(), name, false,
isAdder );
+ getConfigurerFromName( state.getConfigurer(), name, false,
isAdder, context );
// Resolve any props in the id
String id = context.resolveValue( unresolvedId ).toString();
@@ -402,9 +382,10 @@
final Class type = configurer.getType();
if( !type.isInstance( ref ) )
{
+ final Converter converter = (Converter)context.getService(
Converter.class );
try
{
- ref = m_converter.convert( type, ref, context );
+ ref = converter.convert( type, ref, context );
}
catch( ConverterException e )
{
@@ -428,7 +409,7 @@
{
// Set the value
final PropertyConfigurer property =
- getConfigurerFromName( state.getConfigurer(), name, false, false
);
+ getConfigurerFromName( state.getConfigurer(), name, false,
false, context );
setValue( property, state, value, context );
}
@@ -448,7 +429,8 @@
final Class type = setter.getType();
if( !type.isInstance( objValue ) )
{
- objValue = m_converter.convert( type, objValue, context );
+ final Converter converter = (Converter)context.getService(
Converter.class );
+ objValue = converter.convert( type, objValue, context );
}
// Set the value
@@ -494,12 +476,12 @@
if( childConfigurer == state.getConfigurer().getTypedProperty() )
{
// Typed property
- child = createTypedObject( name, type );
+ child = createTypedObject( name, type, context );
}
else
{
// Named property
- child = createNamedObject( type );
+ child = createNamedObject( type, context );
}
// Configure the object
@@ -509,7 +491,8 @@
// Convert the object, if necessary
if( !type.isInstance( child ) )
{
- child = m_converter.convert( type, child, context );
+ final Converter converter = (Converter)context.getService(
Converter.class );
+ child = converter.convert( type, child, context );
}
return child;
@@ -528,7 +511,8 @@
private PropertyConfigurer getConfigurerFromName( final ObjectConfigurer
configurer,
final String name,
boolean ignoreRoleName,
- final boolean isAdder )
+ final boolean isAdder,
+ final TaskContext
context )
throws Exception
{
// Try a named property
@@ -559,8 +543,10 @@
else
{
// Check the role name
+ final RoleManager roleManager =
+ (RoleManager)context.getService( RoleManager.class );
final String classname =
propertyConfigurer.getType().getName();
- final RoleInfo roleInfo =
m_roleManager.getRoleByInterface( classname );
+ final RoleInfo roleInfo =
roleManager.getRoleByInterface( classname );
if( roleInfo != null && name.equalsIgnoreCase(
roleInfo.getShortName() ) )
{
return propertyConfigurer;
@@ -575,13 +561,17 @@
/**
* Creates an instance for a named property.
*/
- private Object createNamedObject( final Class type )
+ private Object createNamedObject( final Class type,
+ final TaskContext context )
throws Exception
{
+ final RoleManager roleManager = (RoleManager)context.getService(
RoleManager.class );
+ final TypeManager typeManager = (TypeManager)context.getService(
TypeManager.class );
+
// Map the expected type to a role. If found, instantiate the
default
// type for that role
final RoleInfo roleInfo =
- m_roleManager.getRoleByInterface( type.getName() );
+ roleManager.getRoleByInterface( type.getName() );
if( roleInfo != null )
{
final String typeName = roleInfo.getDefaultTypeName();
@@ -589,7 +579,7 @@
{
// Create the instance
final TypeFactory factory =
- m_typeManager.getFactory( roleInfo.getInterfaceName() );
+ typeManager.getFactory( roleInfo.getInterfaceName() );
return factory.create( typeName );
}
}
@@ -609,16 +599,19 @@
* Creates an instance of the typed property.
*/
private Object createTypedObject( final String name,
- final Class type )
+ final Class type,
+ final TaskContext context )
throws Exception
{
+ final RoleManager roleManager = (RoleManager)context.getService(
RoleManager.class );
+ final TypeManager typeManager = (TypeManager)context.getService(
TypeManager.class );
+
// Map the expected type to a role. If found, attempt to create
// an instance
- final RoleInfo roleInfo =
- m_roleManager.getRoleByInterface( type.getName() );
+ final RoleInfo roleInfo = roleManager.getRoleByInterface(
type.getName() );
if( roleInfo != null )
{
- final TypeFactory factory = m_typeManager.getFactory(
roleInfo.getInterfaceName() );
+ final TypeFactory factory = typeManager.getFactory(
roleInfo.getInterfaceName() );
if( factory.canCreate( name ) )
{
return factory.create( name );
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>