* Reverted TypeManager to reference roles by name, rather than type. * DefaultTypeManager now uses the RoleManager to determine a role's type, to use for doing instanceof checks. * DefaultMasterConverter, InstantiatingServiceManager, and VfsManager no longer look up a TypeFactory in their service() method. * Added ROLE field to several interfaces. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271849 13f79535-47bb-0310-9956-ffa450edef68master
@@ -51,7 +51,7 @@ public class Facility | |||
final String typeName = children[ 0 ].getName(); | |||
try | |||
{ | |||
m_aspectHandler = (AspectHandler)newInstance( AspectHandler.class, typeName ); | |||
m_aspectHandler = (AspectHandler)newInstance( AspectHandler.ROLE, typeName ); | |||
} | |||
catch( final Exception e ) | |||
{ | |||
@@ -20,6 +20,8 @@ import org.apache.aut.vfs.FileSystemException; | |||
*/ | |||
public interface FileSystemProvider | |||
{ | |||
String ROLE = FileSystemProvider.class.getName(); | |||
/** | |||
* Sets the context for this file system provider. This method is called | |||
* before any of the other provider methods. | |||
@@ -25,6 +25,8 @@ package org.apache.myrmidon.api; | |||
*/ | |||
public interface Task | |||
{ | |||
String ROLE = Task.class.getName(); | |||
/** | |||
* Specify the context in which the task operates in. | |||
* The Task will use the TaskContext to receive information | |||
@@ -585,7 +585,7 @@ public class DefaultConfigurer | |||
if( typeName != null ) | |||
{ | |||
// Create the instance | |||
final TypeFactory factory = m_typeManager.getFactory( roleInfo.getType() ); | |||
final TypeFactory factory = m_typeManager.getFactory( roleInfo.getName() ); | |||
return factory.create( typeName ); | |||
} | |||
} | |||
@@ -613,7 +613,7 @@ public class DefaultConfigurer | |||
final RoleInfo roleInfo = m_roleManager.getRoleByType( type ); | |||
if( roleInfo != null ) | |||
{ | |||
final TypeFactory factory = m_typeManager.getFactory( roleInfo.getType() ); | |||
final TypeFactory factory = m_typeManager.getFactory( roleInfo.getName() ); | |||
if( factory.canCreate( name ) ) | |||
{ | |||
return factory.create( name ); | |||
@@ -621,7 +621,7 @@ public class DefaultConfigurer | |||
} | |||
// Use the generic 'data-type' role. | |||
final TypeFactory factory = m_typeManager.getFactory( DataType.class ); | |||
final TypeFactory factory = m_typeManager.getFactory( DataType.ROLE ); | |||
if( !factory.canCreate( name ) ) | |||
{ | |||
throw new NoSuchPropertyException(); | |||
@@ -19,7 +19,6 @@ import org.apache.avalon.framework.service.ServiceException; | |||
import org.apache.avalon.framework.service.ServiceManager; | |||
import org.apache.avalon.framework.service.Serviceable; | |||
import org.apache.myrmidon.interfaces.converter.ConverterRegistry; | |||
import org.apache.myrmidon.interfaces.type.TypeException; | |||
import org.apache.myrmidon.interfaces.type.TypeFactory; | |||
import org.apache.myrmidon.interfaces.type.TypeManager; | |||
@@ -37,7 +36,7 @@ public class DefaultMasterConverter | |||
ResourceManager.getPackageResources( DefaultMasterConverter.class ); | |||
private ConverterRegistry m_registry; | |||
private TypeFactory m_factory; | |||
private TypeManager m_typeManager; | |||
/** Map from converter name to Converter. */ | |||
private Map m_converters = new HashMap(); | |||
@@ -52,17 +51,7 @@ public class DefaultMasterConverter | |||
throws ServiceException | |||
{ | |||
m_registry = (ConverterRegistry)serviceManager.lookup( ConverterRegistry.ROLE ); | |||
final TypeManager typeManager = (TypeManager)serviceManager.lookup( TypeManager.ROLE ); | |||
try | |||
{ | |||
m_factory = typeManager.getFactory( Converter.class ); | |||
} | |||
catch( final TypeException te ) | |||
{ | |||
final String message = REZ.getString( "no-converter-factory.error" ); | |||
throw new ServiceException( message, te ); | |||
} | |||
m_typeManager = (TypeManager)serviceManager.lookup( TypeManager.ROLE ); | |||
} | |||
/** | |||
@@ -95,7 +84,8 @@ public class DefaultMasterConverter | |||
Converter converter = (Converter)m_converters.get( name ); | |||
if( converter == null ) | |||
{ | |||
converter = (Converter)m_factory.create( name ); | |||
final TypeFactory factory = m_typeManager.getFactory( Converter.ROLE ); | |||
converter = (Converter)factory.create( name ); | |||
m_converters.put( name, converter ); | |||
} | |||
@@ -1,5 +1,4 @@ | |||
convert.error=Could not convert from {0} to {1}. | |||
no-converter.error=Could not find an appropriate converter. | |||
bad-typemanager.error=Badly configured TypeManager missing converter definition. | |||
bad-return-type.error=Converter {0} returned an object of type {1} which is assignable to the expected type {2}. | |||
ambiguous-converter.error=More than one converter available for this conversion. |
@@ -148,7 +148,7 @@ public class DefaultDeployer | |||
final String roleShorthand = definition.getRoleShorthand(); | |||
final String roleName = getRole( roleShorthand ).getName(); | |||
final String factoryClassName = definition.getFactoryClass(); | |||
handleType( deployment, ServiceFactory.class, roleName, factoryClassName ); | |||
handleType( deployment, ServiceFactory.ROLE, roleName, factoryClassName ); | |||
} | |||
/** | |||
@@ -203,8 +203,8 @@ public class DefaultDeployer | |||
} | |||
// Deploy general-purpose type | |||
final Class roleType = getRole( roleShorthand ).getType(); | |||
handleType( deployment, roleType, typeName, className ); | |||
final String roleName = getRole( roleShorthand ).getName(); | |||
handleType( deployment, roleName, typeName, className ); | |||
if( getLogger().isDebugEnabled() ) | |||
{ | |||
@@ -219,15 +219,15 @@ public class DefaultDeployer | |||
* Handles a type definition. | |||
*/ | |||
private void handleType( final Deployment deployment, | |||
final Class roleType, | |||
final String roleName, | |||
final String typeName, | |||
final String className ) | |||
throws Exception | |||
{ | |||
// TODO - detect duplicates | |||
final DefaultTypeFactory factory = deployment.getFactory( roleType ); | |||
final DefaultTypeFactory factory = deployment.getFactory( roleName ); | |||
factory.addNameClassMapping( typeName, className ); | |||
m_typeManager.registerType( roleType, typeName, factory ); | |||
m_typeManager.registerType( roleName, typeName, factory ); | |||
} | |||
/** | |||
@@ -240,9 +240,9 @@ public class DefaultDeployer | |||
throws Exception | |||
{ | |||
m_converterRegistry.registerConverter( className, source, destination ); | |||
final DefaultTypeFactory factory = deployment.getFactory( Converter.class ); | |||
final DefaultTypeFactory factory = deployment.getFactory( Converter.ROLE ); | |||
factory.addNameClassMapping( className, className ); | |||
m_typeManager.registerType( Converter.class, className, factory ); | |||
m_typeManager.registerType( Converter.ROLE, className, factory ); | |||
if( getLogger().isDebugEnabled() ) | |||
{ | |||
@@ -110,14 +110,14 @@ class Deployment | |||
/** | |||
* Returns the type factory for a role. | |||
*/ | |||
public DefaultTypeFactory getFactory( final Class roleType ) | |||
public DefaultTypeFactory getFactory( final String roleName ) | |||
{ | |||
DefaultTypeFactory factory = (DefaultTypeFactory)m_factories.get( roleType ); | |||
DefaultTypeFactory factory = (DefaultTypeFactory)m_factories.get( roleName ); | |||
if( null == factory ) | |||
{ | |||
factory = new DefaultTypeFactory( m_classLoader ); | |||
m_factories.put( roleType, factory ); | |||
m_factories.put( roleName, factory ); | |||
} | |||
return factory; | |||
@@ -38,11 +38,11 @@ import org.apache.myrmidon.interfaces.embeddor.Embeddor; | |||
import org.apache.myrmidon.interfaces.executor.Executor; | |||
import org.apache.myrmidon.interfaces.extensions.ExtensionManager; | |||
import org.apache.myrmidon.interfaces.model.Project; | |||
import org.apache.myrmidon.interfaces.property.PropertyResolver; | |||
import org.apache.myrmidon.interfaces.role.RoleManager; | |||
import org.apache.myrmidon.interfaces.service.MultiSourceServiceManager; | |||
import org.apache.myrmidon.interfaces.type.TypeFactory; | |||
import org.apache.myrmidon.interfaces.type.TypeManager; | |||
import org.apache.myrmidon.interfaces.property.PropertyResolver; | |||
import org.apache.myrmidon.interfaces.workspace.Workspace; | |||
import org.apache.myrmidon.listeners.ProjectListener; | |||
@@ -119,7 +119,7 @@ public class DefaultEmbeddor | |||
final Parameters parameters ) | |||
throws Exception | |||
{ | |||
final TypeFactory factory = m_typeManager.getFactory( ProjectBuilder.class ); | |||
final TypeFactory factory = m_typeManager.getFactory( ProjectBuilder.ROLE ); | |||
final ProjectBuilder builder = (ProjectBuilder)factory.create( type ); | |||
setupObject( builder, m_workspaceServiceManager, parameters ); | |||
return builder; | |||
@@ -146,7 +146,7 @@ public class DefaultEmbeddor | |||
public ProjectListener createListener( String name ) | |||
throws Exception | |||
{ | |||
final TypeFactory factory = m_typeManager.getFactory( ProjectListener.class ); | |||
final TypeFactory factory = m_typeManager.getFactory( ProjectListener.ROLE ); | |||
return (ProjectListener)factory.create( name ); | |||
} | |||
@@ -97,7 +97,7 @@ public class DefaultExecutor | |||
{ | |||
try | |||
{ | |||
final TypeFactory factory = frame.getTypeManager().getFactory( Task.class ); | |||
final TypeFactory factory = frame.getTypeManager().getFactory( Task.ROLE ); | |||
return (Task)factory.create( name ); | |||
} | |||
catch( final TypeException te ) | |||
@@ -63,6 +63,7 @@ public class InstantiatingServiceManager | |||
private RoleManager m_roleManager; | |||
private ServiceManager m_serviceManager; | |||
private Parameters m_parameters; | |||
private TypeManager m_typeManager; | |||
public void parameterize( Parameters parameters ) throws ParameterException | |||
{ | |||
@@ -83,15 +84,7 @@ public class InstantiatingServiceManager | |||
{ | |||
m_serviceManager = manager; | |||
m_roleManager = (RoleManager)manager.lookup( RoleManager.ROLE ); | |||
final TypeManager typeManager = (TypeManager)manager.lookup( TypeManager.ROLE ); | |||
try | |||
{ | |||
m_typeFactory = typeManager.getFactory( ServiceFactory.class ); | |||
} | |||
catch( final TypeException e ) | |||
{ | |||
throw new ServiceException( e.getMessage(), e ); | |||
} | |||
m_typeManager = (TypeManager)manager.lookup( TypeManager.ROLE ); | |||
} | |||
/** | |||
@@ -129,14 +122,29 @@ public class InstantiatingServiceManager | |||
{ | |||
return true; | |||
} | |||
if( m_typeFactory.canCreate( serviceRole ) ) | |||
try | |||
{ | |||
return true; | |||
return getFactory().canCreate( serviceRole ); | |||
} | |||
catch( TypeException e ) | |||
{ | |||
// Throw away exception - yuck | |||
} | |||
return false; | |||
} | |||
/** | |||
* Locates the type factory to use to instantiate service factories. | |||
*/ | |||
private TypeFactory getFactory() throws TypeException | |||
{ | |||
if( m_typeFactory == null ) | |||
{ | |||
m_typeFactory = m_typeManager.getFactory( ServiceFactory.ROLE ); | |||
} | |||
return m_typeFactory; | |||
} | |||
/** | |||
* Locates a service instance. | |||
*/ | |||
@@ -169,7 +177,7 @@ public class InstantiatingServiceManager | |||
try | |||
{ | |||
// Create the factory | |||
final ServiceFactory factory = (ServiceFactory)m_typeFactory.create( serviceRole ); | |||
final ServiceFactory factory = (ServiceFactory)getFactory().create( serviceRole ); | |||
setupObject( factory ); | |||
// Create the service | |||
@@ -8,6 +8,13 @@ | |||
package org.apache.myrmidon.components.type; | |||
import java.util.HashMap; | |||
import org.apache.avalon.excalibur.i18n.ResourceManager; | |||
import org.apache.avalon.excalibur.i18n.Resources; | |||
import org.apache.avalon.framework.service.ServiceException; | |||
import org.apache.avalon.framework.service.ServiceManager; | |||
import org.apache.avalon.framework.service.Serviceable; | |||
import org.apache.myrmidon.interfaces.role.RoleInfo; | |||
import org.apache.myrmidon.interfaces.role.RoleManager; | |||
import org.apache.myrmidon.interfaces.type.TypeException; | |||
import org.apache.myrmidon.interfaces.type.TypeFactory; | |||
import org.apache.myrmidon.interfaces.type.TypeManager; | |||
@@ -19,14 +26,19 @@ import org.apache.myrmidon.interfaces.type.TypeManager; | |||
* @version $Revision$ $Date$ | |||
*/ | |||
public class DefaultTypeManager | |||
implements TypeManager | |||
implements TypeManager, Serviceable | |||
{ | |||
private final static Resources REZ | |||
= ResourceManager.getPackageResources( DefaultTypeManager.class ); | |||
///Parent type manager to inherit values from. | |||
private final DefaultTypeManager m_parent; | |||
///Maps role Class to MultiSourceTypeFactory. | |||
private final HashMap m_roleMap = new HashMap(); | |||
private RoleManager m_roleManager; | |||
public DefaultTypeManager() | |||
{ | |||
this( null ); | |||
@@ -35,21 +47,31 @@ public class DefaultTypeManager | |||
public DefaultTypeManager( final DefaultTypeManager parent ) | |||
{ | |||
m_parent = parent; | |||
if( m_parent != null ) | |||
{ | |||
m_roleManager = m_parent.m_roleManager; | |||
} | |||
} | |||
public void service( final ServiceManager serviceManager ) | |||
throws ServiceException | |||
{ | |||
m_roleManager = (RoleManager)serviceManager.lookup( RoleManager.ROLE ); | |||
} | |||
public void registerType( final Class role, | |||
public void registerType( final String roleName, | |||
final String shorthandName, | |||
final TypeFactory factory ) | |||
throws TypeException | |||
{ | |||
final MultiSourceTypeFactory msFactory = createFactory( role ); | |||
final MultiSourceTypeFactory msFactory = createFactory( roleName ); | |||
msFactory.register( shorthandName, factory ); | |||
} | |||
public TypeFactory getFactory( final Class role ) | |||
public TypeFactory getFactory( final String roleName ) | |||
throws TypeException | |||
{ | |||
return createFactory( role ); | |||
return createFactory( roleName ); | |||
} | |||
public TypeManager createChildTypeManager() | |||
@@ -57,29 +79,29 @@ public class DefaultTypeManager | |||
return new DefaultTypeManager( this ); | |||
} | |||
protected final MultiSourceTypeFactory lookupFactory( final Class role ) | |||
protected final MultiSourceTypeFactory lookupFactory( final String roleName ) | |||
{ | |||
return (MultiSourceTypeFactory)m_roleMap.get( role ); | |||
return (MultiSourceTypeFactory)m_roleMap.get( roleName ); | |||
} | |||
/** | |||
* Get a factory of appropriate role. | |||
* Create a Factory if none exists with same name. | |||
* | |||
* @param role the role name(must be name of work interface) | |||
* @param roleName the role name | |||
* @return the Factory for interface | |||
* @exception TypeException role does not specify accessible work interface | |||
*/ | |||
private MultiSourceTypeFactory createFactory( final Class role ) | |||
private MultiSourceTypeFactory createFactory( final String roleName ) | |||
throws TypeException | |||
{ | |||
MultiSourceTypeFactory factory = (MultiSourceTypeFactory)m_roleMap.get( role ); | |||
MultiSourceTypeFactory factory = (MultiSourceTypeFactory)m_roleMap.get( roleName ); | |||
if( null != factory ) | |||
{ | |||
return factory; | |||
} | |||
final MultiSourceTypeFactory parentFactory = getParentTypedFactory( role ); | |||
final MultiSourceTypeFactory parentFactory = getParentTypedFactory( roleName ); | |||
if( null != parentFactory ) | |||
{ | |||
factory = new MultiSourceTypeFactory( parentFactory ); | |||
@@ -88,19 +110,26 @@ public class DefaultTypeManager | |||
///If we haven't got factory try to create a new one | |||
if( null == factory ) | |||
{ | |||
factory = new MultiSourceTypeFactory( role ); | |||
// Lookup the role type | |||
final RoleInfo role = m_roleManager.getRole( roleName ); | |||
if( role == null ) | |||
{ | |||
final String message = REZ.getString( "unknown-role.error", roleName ); | |||
throw new TypeException( message ); | |||
} | |||
factory = new MultiSourceTypeFactory( role.getType() ); | |||
} | |||
m_roleMap.put( role, factory ); | |||
m_roleMap.put( roleName, factory ); | |||
return factory; | |||
} | |||
private MultiSourceTypeFactory getParentTypedFactory( final Class role ) | |||
private MultiSourceTypeFactory getParentTypedFactory( final String roleName ) | |||
{ | |||
if( null != m_parent ) | |||
{ | |||
return m_parent.lookupFactory( role ); | |||
return m_parent.lookupFactory( roleName ); | |||
} | |||
else | |||
{ | |||
@@ -82,7 +82,7 @@ public class MultiSourceTypeFactory | |||
// Create the object | |||
final Object object = factory.create( name ); | |||
if( !m_type.isInstance( object ) ) | |||
if( m_type != null && !m_type.isInstance( object ) ) | |||
{ | |||
final String message = REZ.getString( "mismatched-type.error", name, object.getClass().getName() ); | |||
throw new TypeException( message ); | |||
@@ -1,3 +1,7 @@ | |||
# DefaultTypeManager | |||
unknown-role.error=Cannot create a type factory for unknown role {0}. | |||
# MultiSourceTypeFactory | |||
no-instantiate.error=Unable to instantiate ({0}). | |||
no-mapping.error=Malconfigured factory, no classname for ({0}). | |||
no-factory.error=Failed to locate factory for {0}. | |||
@@ -310,7 +310,7 @@ public class DefaultWorkspace | |||
* @exception TaskException if an error occurs | |||
*/ | |||
private void executeTarget( final ProjectEntry entry, | |||
final String targetName ) | |||
final String targetName ) | |||
throws TaskException | |||
{ | |||
// Locate the target | |||
@@ -22,6 +22,8 @@ import org.apache.myrmidon.interfaces.executor.Executor; | |||
import org.apache.myrmidon.interfaces.type.TypeException; | |||
import org.apache.myrmidon.interfaces.type.TypeFactory; | |||
import org.apache.myrmidon.interfaces.type.TypeManager; | |||
import org.apache.myrmidon.interfaces.role.RoleInfo; | |||
import org.apache.myrmidon.interfaces.role.RoleManager; | |||
/** | |||
* This is the class that Task writers should extend to provide custom tasks. | |||
@@ -171,35 +173,69 @@ public abstract class AbstractContainerTask | |||
protected final Object newInstance( final Class roleType, final String typeName ) | |||
throws TaskException | |||
{ | |||
final TypeFactory typeFactory = getTypeFactory( roleType ); | |||
try | |||
{ | |||
final RoleInfo role = getRoleByType( roleType ); | |||
final TypeFactory typeFactory = getTypeFactory( role.getName() ); | |||
return typeFactory.create( typeName ); | |||
} | |||
catch( final TypeException te ) | |||
catch( Exception e ) | |||
{ | |||
final String message = | |||
REZ.getString( "container.no-create-type.error", | |||
roleType.getName(), | |||
typeName ); | |||
throw new TaskException( message, te ); | |||
REZ.getString( "container.no-create-type-for-type.error", roleType.getName(), typeName ); | |||
throw new TaskException( message, e ); | |||
} | |||
} | |||
/** | |||
* Create an instance of type with specified type and in specified role. | |||
*/ | |||
protected final Object newInstance( final String roleName, final String typeName ) | |||
throws TaskException | |||
{ | |||
try | |||
{ | |||
final TypeFactory typeFactory = getTypeFactory( roleName ); | |||
return typeFactory.create( typeName ); | |||
} | |||
catch( final Exception e ) | |||
{ | |||
final String message = | |||
REZ.getString( "container.no-create-type.error", roleName, typeName ); | |||
throw new TaskException( message, e ); | |||
} | |||
} | |||
/** | |||
* Looks up a role using the role type. | |||
*/ | |||
protected final RoleInfo getRoleByType( final Class roleType ) | |||
throws TaskException | |||
{ | |||
final RoleManager roleManager = (RoleManager)getService( RoleManager.class ); | |||
final RoleInfo role = roleManager.getRoleByType( roleType ); | |||
if( role == null ) | |||
{ | |||
final String message = REZ.getString( "container.unknown-role-type.error", roleType.getName() ); | |||
throw new TaskException( message ); | |||
} | |||
return role; | |||
} | |||
/** | |||
* Locates a type factory. | |||
*/ | |||
protected final TypeFactory getTypeFactory( final Class roleType ) | |||
protected final TypeFactory getTypeFactory( final String roleName ) | |||
throws TaskException | |||
{ | |||
final TypeManager typeManager = (TypeManager)getService( TypeManager.class ); | |||
try | |||
{ | |||
return typeManager.getFactory( roleType ); | |||
final TypeManager typeManager = (TypeManager)getService( TypeManager.class ); | |||
return typeManager.getFactory( roleName ); | |||
} | |||
catch( final TypeException te ) | |||
{ | |||
final String message = REZ.getString( "container.no-factory.error", roleType.getName() ); | |||
final String message = REZ.getString( "container.no-factory.error", roleName ); | |||
throw new TaskException( message, te ); | |||
} | |||
} | |||
@@ -1,8 +1,10 @@ | |||
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}". | |||
container.no-factory.error=Could not locate the type factory for role "{0}". | |||
container.no-create-type.error=Could not create an instance of role "{0}" with type name "{1}". | |||
container.no-create-type-for-type.error=Could not create an instance of class "{0}" with type name "{1}". | |||
container.unknown-role-type.error=Could not determine the role for class "{0}". | |||
typedef.no-lib.error=Must specify the lib parameter. | |||
@@ -61,7 +61,7 @@ public class TypeInstanceTask | |||
try | |||
{ | |||
m_value = newInstance( DataType.class, configuration.getName() ); | |||
m_value = newInstance( DataType.ROLE, configuration.getName() ); | |||
} | |||
catch( final Exception e ) | |||
{ | |||
@@ -7,19 +7,18 @@ | |||
*/ | |||
package org.apache.myrmidon.framework.factories; | |||
import org.apache.aut.vfs.FileSystemException; | |||
import org.apache.aut.vfs.impl.DefaultFileSystemManager; | |||
import org.apache.aut.vfs.provider.FileSystemProvider; | |||
import org.apache.aut.vfs.FileSystemException; | |||
import org.apache.avalon.excalibur.i18n.ResourceManager; | |||
import org.apache.avalon.excalibur.i18n.Resources; | |||
import org.apache.avalon.framework.activity.Disposable; | |||
import org.apache.avalon.framework.activity.Initializable; | |||
import org.apache.avalon.framework.service.Serviceable; | |||
import org.apache.avalon.framework.service.ServiceManager; | |||
import org.apache.avalon.framework.service.ServiceException; | |||
import org.apache.avalon.excalibur.i18n.ResourceManager; | |||
import org.apache.avalon.excalibur.i18n.Resources; | |||
import org.apache.myrmidon.interfaces.type.TypeManager; | |||
import org.apache.avalon.framework.service.ServiceManager; | |||
import org.apache.avalon.framework.service.Serviceable; | |||
import org.apache.myrmidon.interfaces.type.TypeFactory; | |||
import org.apache.myrmidon.interfaces.type.TypeException; | |||
import org.apache.myrmidon.interfaces.type.TypeManager; | |||
/** | |||
* The myrmidon FileSystemManager implementation. | |||
@@ -34,22 +33,14 @@ public class VfsManager | |||
private final static Resources REZ | |||
= ResourceManager.getPackageResources( VfsManager.class ); | |||
private TypeFactory m_typeFactory; | |||
private TypeManager m_typeManager; | |||
/** | |||
* Locate the services used by this service. | |||
*/ | |||
public void service( final ServiceManager serviceManager ) throws ServiceException | |||
{ | |||
final TypeManager typeManager = (TypeManager)serviceManager.lookup( TypeManager.ROLE ); | |||
try | |||
{ | |||
m_typeFactory = typeManager.getFactory( FileSystemProvider.class ); | |||
} | |||
catch( TypeException e ) | |||
{ | |||
throw new ServiceException( e.getMessage(), e ); | |||
} | |||
m_typeManager = (TypeManager)serviceManager.lookup( TypeManager.ROLE ); | |||
} | |||
/** | |||
@@ -57,14 +48,16 @@ public class VfsManager | |||
*/ | |||
public void initialize() throws Exception | |||
{ | |||
final TypeFactory factory = m_typeManager.getFactory( FileSystemProvider.ROLE ); | |||
// TODO - make this list configurable | |||
// Required providers | |||
addProvider( new String[] { "zip", "jar" }, "zip", false ); | |||
addProvider( factory, new String[]{"zip", "jar"}, "zip", false ); | |||
// Optional providers | |||
addProvider( new String[] { "smb" }, "smb", true ); | |||
addProvider( new String[] { "ftp" }, "ftp", true ); | |||
addProvider( factory, new String[]{"smb"}, "smb", true ); | |||
addProvider( factory, new String[]{"ftp"}, "ftp", true ); | |||
} | |||
/** | |||
@@ -79,13 +72,14 @@ public class VfsManager | |||
/** | |||
* Registers a file system provider. | |||
*/ | |||
public void addProvider( final String[] urlSchemes, | |||
final String providerName, | |||
final boolean ignoreIfNotPresent ) | |||
private void addProvider( final TypeFactory factory, | |||
final String[] urlSchemes, | |||
final String providerName, | |||
final boolean ignoreIfNotPresent ) | |||
throws FileSystemException | |||
{ | |||
// Create an instance | |||
if( ignoreIfNotPresent && ! m_typeFactory.canCreate( providerName ) ) | |||
if( ignoreIfNotPresent && !factory.canCreate( providerName ) ) | |||
{ | |||
return; | |||
} | |||
@@ -93,7 +87,7 @@ public class VfsManager | |||
final FileSystemProvider provider; | |||
try | |||
{ | |||
provider = (FileSystemProvider)m_typeFactory.create( providerName ); | |||
provider = (FileSystemProvider)factory.create( providerName ); | |||
} | |||
catch( Exception e ) | |||
{ | |||
@@ -14,6 +14,8 @@ package org.apache.myrmidon.interfaces.service; | |||
* | |||
* @author <a href="mailto:peter@apache.org">Peter Donald</a> | |||
* @version $Revision$ $Date$ | |||
* | |||
* @ant:role shorthand="service-factory" | |||
*/ | |||
public interface ServiceFactory | |||
{ | |||
@@ -20,18 +20,19 @@ public interface TypeManager | |||
/** | |||
* Registers a new type. | |||
* | |||
* @param roleType The role interface for the type. Objects created by the factory | |||
* must implement this interface. | |||
* @param roleName The role for the type. | |||
* @param shorthandName The shorthand name for the type. | |||
* @param factory The type factory. | |||
*/ | |||
void registerType( Class roleType, String shorthandName, TypeFactory factory ) | |||
void registerType( String roleName, String shorthandName, TypeFactory factory ) | |||
throws TypeException; | |||
/** | |||
* Returns the factory for a role. | |||
* | |||
* @param roleName The role for the type. | |||
*/ | |||
TypeFactory getFactory( Class roleType ) | |||
TypeFactory getFactory( String roleName ) | |||
throws TypeException; | |||
/** | |||
@@ -17,6 +17,8 @@ package org.apache.myrmidon.listeners; | |||
*/ | |||
public interface ProjectListener | |||
{ | |||
String ROLE = ProjectListener.class.getName(); | |||
/** | |||
* Notify the listener that a project is about to start. This method | |||
* is called for top-level projects only. | |||
@@ -31,16 +31,18 @@ public abstract class AbstractMyrmidonTest | |||
{ | |||
super( name ); | |||
final String baseDirProp = System.getProperty( "test.basedir" ); | |||
m_baseDir = new File( baseDirProp ); | |||
m_baseDir = getCanonicalFile( new File( baseDirProp ) ); | |||
String packagePath = getClass().getName(); | |||
int idx = packagePath.lastIndexOf( '.' ); | |||
packagePath = packagePath.substring( 0, idx ); | |||
packagePath = packagePath.replace( '.', File.separatorChar ); | |||
m_testBaseDir = new File( m_baseDir, packagePath ); | |||
m_testBaseDir = getCanonicalFile( new File( m_baseDir, packagePath ) ); | |||
} | |||
/** | |||
* Locates a test resource, and asserts that the resource exists | |||
* | |||
* @param name path of the resource, relative to this test's base directory. | |||
*/ | |||
protected File getTestResource( final String name ) | |||
{ | |||
@@ -49,6 +51,8 @@ public abstract class AbstractMyrmidonTest | |||
/** | |||
* Locates a test resource. | |||
* | |||
* @param name path of the resource, relative to this test's base directory. | |||
*/ | |||
protected File getTestResource( final String name, final boolean mustExist ) | |||
{ | |||
@@ -66,14 +70,23 @@ public abstract class AbstractMyrmidonTest | |||
return file; | |||
} | |||
/** | |||
* Locates the base directory for this test. | |||
*/ | |||
protected File getTestDirectory() | |||
{ | |||
return m_testBaseDir; | |||
} | |||
/** | |||
* Locates a test directory, creating it if it does not exist. | |||
* | |||
* @param name path of the directory, relative to this test's base directory. | |||
*/ | |||
protected File getTestDirectory( final String name ) | |||
{ | |||
File file = new File( m_testBaseDir, name ); | |||
file = getCanonicalFile( file ); | |||
assertTrue( "Test directory \"" + file + "\" does not exist or is not a directory.", | |||
file.isDirectory() || file.mkdirs() ); | |||
return file; | |||
@@ -22,18 +22,22 @@ import org.apache.myrmidon.components.configurer.DefaultConfigurer; | |||
import org.apache.myrmidon.components.converter.DefaultConverterRegistry; | |||
import org.apache.myrmidon.components.converter.DefaultMasterConverter; | |||
import org.apache.myrmidon.components.deployer.DefaultDeployer; | |||
import org.apache.myrmidon.components.executor.DefaultExecutor; | |||
import org.apache.myrmidon.components.extensions.DefaultExtensionManager; | |||
import org.apache.myrmidon.components.property.DefaultPropertyResolver; | |||
import org.apache.myrmidon.components.role.DefaultRoleManager; | |||
import org.apache.myrmidon.components.type.DefaultTypeManager; | |||
import org.apache.myrmidon.framework.DataType; | |||
import org.apache.myrmidon.interfaces.classloader.ClassLoaderManager; | |||
import org.apache.myrmidon.interfaces.configurer.Configurer; | |||
import org.apache.myrmidon.interfaces.converter.ConverterRegistry; | |||
import org.apache.myrmidon.interfaces.deployer.Deployer; | |||
import org.apache.myrmidon.interfaces.executor.Executor; | |||
import org.apache.myrmidon.interfaces.extensions.ExtensionManager; | |||
import org.apache.myrmidon.interfaces.property.PropertyResolver; | |||
import org.apache.myrmidon.interfaces.role.RoleInfo; | |||
import org.apache.myrmidon.interfaces.role.RoleManager; | |||
import org.apache.myrmidon.interfaces.service.ServiceFactory; | |||
import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | |||
import org.apache.myrmidon.interfaces.type.TypeManager; | |||
@@ -47,6 +51,10 @@ public abstract class AbstractComponentTest | |||
{ | |||
private DefaultServiceManager m_serviceManager; | |||
public static final String DATA_TYPE_ROLE = "data-type"; | |||
public static final String CONVERTER_ROLE = "converter"; | |||
public static final String SERVICE_FACTORY_ROLE = "service-factory"; | |||
public AbstractComponentTest( final String name ) | |||
{ | |||
super( name ); | |||
@@ -85,6 +93,10 @@ public abstract class AbstractComponentTest | |||
m_serviceManager.put( Deployer.ROLE, component ); | |||
components.add( component ); | |||
component = new DefaultExecutor(); | |||
m_serviceManager.put( Executor.ROLE, component ); | |||
components.add( component ); | |||
final DefaultClassLoaderManager classLoaderMgr = new DefaultClassLoaderManager(); | |||
classLoaderMgr.setBaseClassLoader( getClass().getClassLoader() ); | |||
m_serviceManager.put( ClassLoaderManager.ROLE, classLoaderMgr ); | |||
@@ -123,7 +135,15 @@ public abstract class AbstractComponentTest | |||
serviceable.service( m_serviceManager ); | |||
} | |||
} | |||
// Register some standard roles | |||
// Add some core roles | |||
final RoleManager roleManager = (RoleManager)getServiceManager().lookup( RoleManager.ROLE ); | |||
roleManager.addRole( new RoleInfo( DataType.ROLE, DATA_TYPE_ROLE, DataType.class ) ); | |||
roleManager.addRole( new RoleInfo( Converter.ROLE, CONVERTER_ROLE, Converter.class ) ); | |||
roleManager.addRole( new RoleInfo( ServiceFactory.ROLE, SERVICE_FACTORY_ROLE, ServiceFactory.class ) ); | |||
} | |||
return m_serviceManager; | |||
} | |||
@@ -149,7 +169,7 @@ public abstract class AbstractComponentTest | |||
/** | |||
* Utility method to register a type. | |||
*/ | |||
protected void registerType( final Class roleType, | |||
protected void registerType( final String roleName, | |||
final String typeName, | |||
final Class type ) | |||
throws Exception | |||
@@ -157,7 +177,7 @@ public abstract class AbstractComponentTest | |||
final ClassLoader loader = getClass().getClassLoader(); | |||
final DefaultTypeFactory factory = new DefaultTypeFactory( loader ); | |||
factory.addNameClassMapping( typeName, type.getName() ); | |||
getTypeManager().registerType( roleType, typeName, factory ); | |||
getTypeManager().registerType( roleName, typeName, factory ); | |||
} | |||
/** | |||
@@ -172,6 +192,6 @@ public abstract class AbstractComponentTest | |||
converterRegistry.registerConverter( converterClass.getName(), sourceClass.getName(), destClass.getName() ); | |||
DefaultTypeFactory factory = new DefaultTypeFactory( getClass().getClassLoader() ); | |||
factory.addNameClassMapping( converterClass.getName(), converterClass.getName() ); | |||
getTypeManager().registerType( Converter.class, converterClass.getName(), factory ); | |||
getTypeManager().registerType( Converter.ROLE, converterClass.getName(), factory ); | |||
} | |||
} |
@@ -401,7 +401,7 @@ public class DefaultConfigurerTest | |||
config.addChild( child ); | |||
registerRole( new RoleInfo( "myrole1", null, MyRole1.class, "default-type" ) ); | |||
registerType( MyRole1.class, "default-type", MyType1.class ); | |||
registerType( "myrole1", "default-type", MyType1.class ); | |||
final ConfigTestInterfaceAdder test = new ConfigTestInterfaceAdder(); | |||
@@ -487,8 +487,8 @@ public class DefaultConfigurerTest | |||
config.addChild( child1 ); | |||
config.addChild( child2 ); | |||
registerType( DataType.class, "my-type1", MyType1.class ); | |||
registerType( DataType.class, "my-type2", MyType2.class ); | |||
registerType( DataType.ROLE, "my-type1", MyType1.class ); | |||
registerType( DataType.ROLE, "my-type2", MyType2.class ); | |||
final ConfigTestTypedAdder test = new ConfigTestTypedAdder(); | |||
@@ -514,8 +514,8 @@ public class DefaultConfigurerTest | |||
// Register incompatible types with the same name, as data-type and myrole1. | |||
registerRole( new RoleInfo( "myrole1", "myrole1", MyRole1.class ) ); | |||
registerType( MyRole1.class, "my-type1", MyType1.class ); | |||
registerType( DataType.class, "my-type1", StringBuffer.class ); | |||
registerType( "myrole1", "my-type1", MyType1.class ); | |||
registerType( DataType.ROLE, "my-type1", StringBuffer.class ); | |||
final ConfigTestTypedAdderRole test = new ConfigTestTypedAdderRole(); | |||
@@ -540,7 +540,7 @@ public class DefaultConfigurerTest | |||
child.setAttribute( "prop", "some value" ); | |||
config.addChild( child ); | |||
registerType( DataType.class, "some-type", ConfigTestTypedAdderConversion.class ); | |||
registerType( DataType.ROLE, "some-type", ConfigTestTypedAdderConversion.class ); | |||
registerConverter( ObjectToMyRole1Converter.class, Object.class, MyRole1.class ); | |||
final ConfigTestTypedAdderConversion test = new ConfigTestTypedAdderConversion(); | |||
@@ -16,8 +16,6 @@ import org.apache.myrmidon.interfaces.deployer.ConverterDefinition; | |||
import org.apache.myrmidon.interfaces.deployer.Deployer; | |||
import org.apache.myrmidon.interfaces.deployer.TypeDefinition; | |||
import org.apache.myrmidon.interfaces.deployer.TypeDeployer; | |||
import org.apache.myrmidon.interfaces.role.RoleInfo; | |||
import org.apache.myrmidon.interfaces.role.RoleManager; | |||
import org.apache.myrmidon.interfaces.type.TypeException; | |||
import org.apache.myrmidon.interfaces.type.TypeFactory; | |||
@@ -30,11 +28,8 @@ public class DefaultDeployerTest | |||
extends AbstractComponentTest | |||
{ | |||
private static final String TEST_TYPE1_NAME = "test-type1"; | |||
private static final String DATA_TYPE_ROLE = "data-type"; | |||
private static final String CONVERTER_ROLE = "converter"; | |||
private Deployer m_deployer; | |||
private RoleManager m_roleManager; | |||
private Converter m_converter; | |||
public DefaultDeployerTest( final String name ) | |||
@@ -51,11 +46,6 @@ public class DefaultDeployerTest | |||
super.setUp(); | |||
m_deployer = (Deployer)getServiceManager().lookup( Deployer.ROLE ); | |||
m_converter = (Converter)getServiceManager().lookup( Converter.ROLE ); | |||
// Add some core roles | |||
m_roleManager = (RoleManager)getServiceManager().lookup( RoleManager.ROLE ); | |||
m_roleManager.addRole( new RoleInfo( DataType.ROLE, DATA_TYPE_ROLE, DataType.class ) ); | |||
m_roleManager.addRole( new RoleInfo( Converter.ROLE, CONVERTER_ROLE, Converter.class ) ); | |||
} | |||
/** | |||
@@ -81,7 +71,7 @@ public class DefaultDeployerTest | |||
typeDeployer.deployType( typeDef ); | |||
// Check the type has been registered | |||
final TypeFactory typeFactory = getTypeManager().getFactory( DataType.class ); | |||
final TypeFactory typeFactory = getTypeManager().getFactory( DataType.ROLE ); | |||
final Object result = typeFactory.create( typeName ); | |||
assertTrue( result instanceof TestType1 ); | |||
} | |||
@@ -137,7 +127,7 @@ public class DefaultDeployerTest | |||
private void assertTypesNotRegistered() throws Exception | |||
{ | |||
// Check the data-type | |||
TypeFactory typeFactory = getTypeManager().getFactory( DataType.class ); | |||
TypeFactory typeFactory = getTypeManager().getFactory( DataType.ROLE ); | |||
try | |||
{ | |||
typeFactory.create( TEST_TYPE1_NAME ); | |||
@@ -149,9 +139,9 @@ public class DefaultDeployerTest | |||
} | |||
// Check the custom role implementation | |||
typeFactory = getTypeManager().getFactory( TestRole1.class ); | |||
try | |||
{ | |||
typeFactory = getTypeManager().getFactory( TestRole1.ROLE ); | |||
typeFactory.create( TEST_TYPE1_NAME ); | |||
fail(); | |||
} | |||
@@ -179,12 +169,12 @@ public class DefaultDeployerTest | |||
private void assertTypesRegistered() throws Exception | |||
{ | |||
// Check the data-type | |||
TypeFactory typeFactory = getTypeManager().getFactory( DataType.class ); | |||
TypeFactory typeFactory = getTypeManager().getFactory( DataType.ROLE ); | |||
Object object = typeFactory.create( TEST_TYPE1_NAME ); | |||
assertTrue( object instanceof TestType1 ); | |||
// Check the custom role implementation | |||
typeFactory = getTypeManager().getFactory( TestRole1.class ); | |||
typeFactory = getTypeManager().getFactory( TestRole1.ROLE ); | |||
object = typeFactory.create( TEST_TYPE1_NAME ); | |||
assertTrue( object instanceof TestType1 ); | |||
@@ -140,6 +140,6 @@ public class InstantiatingServiceManagerTest | |||
final DefaultTypeFactory typeFactory = new DefaultTypeFactory( getClass().getClassLoader() ); | |||
typeFactory.addNameClassMapping( serviceRoleName, factoryClass.getName() ); | |||
final TypeManager typeManager = (TypeManager)getServiceManager().lookup( TypeManager.ROLE ); | |||
typeManager.registerType( ServiceFactory.class, serviceRoleName, typeFactory ); | |||
typeManager.registerType( ServiceFactory.ROLE, serviceRoleName, typeFactory ); | |||
} | |||
} |
@@ -31,16 +31,18 @@ public abstract class AbstractMyrmidonTest | |||
{ | |||
super( name ); | |||
final String baseDirProp = System.getProperty( "test.basedir" ); | |||
m_baseDir = new File( baseDirProp ); | |||
m_baseDir = getCanonicalFile( new File( baseDirProp ) ); | |||
String packagePath = getClass().getName(); | |||
int idx = packagePath.lastIndexOf( '.' ); | |||
packagePath = packagePath.substring( 0, idx ); | |||
packagePath = packagePath.replace( '.', File.separatorChar ); | |||
m_testBaseDir = new File( m_baseDir, packagePath ); | |||
m_testBaseDir = getCanonicalFile( new File( m_baseDir, packagePath ) ); | |||
} | |||
/** | |||
* Locates a test resource, and asserts that the resource exists | |||
* | |||
* @param name path of the resource, relative to this test's base directory. | |||
*/ | |||
protected File getTestResource( final String name ) | |||
{ | |||
@@ -49,6 +51,8 @@ public abstract class AbstractMyrmidonTest | |||
/** | |||
* Locates a test resource. | |||
* | |||
* @param name path of the resource, relative to this test's base directory. | |||
*/ | |||
protected File getTestResource( final String name, final boolean mustExist ) | |||
{ | |||
@@ -66,14 +70,23 @@ public abstract class AbstractMyrmidonTest | |||
return file; | |||
} | |||
/** | |||
* Locates the base directory for this test. | |||
*/ | |||
protected File getTestDirectory() | |||
{ | |||
return m_testBaseDir; | |||
} | |||
/** | |||
* Locates a test directory, creating it if it does not exist. | |||
* | |||
* @param name path of the directory, relative to this test's base directory. | |||
*/ | |||
protected File getTestDirectory( final String name ) | |||
{ | |||
File file = new File( m_testBaseDir, name ); | |||
file = getCanonicalFile( file ); | |||
assertTrue( "Test directory \"" + file + "\" does not exist or is not a directory.", | |||
file.isDirectory() || file.mkdirs() ); | |||
return file; | |||
@@ -22,18 +22,22 @@ import org.apache.myrmidon.components.configurer.DefaultConfigurer; | |||
import org.apache.myrmidon.components.converter.DefaultConverterRegistry; | |||
import org.apache.myrmidon.components.converter.DefaultMasterConverter; | |||
import org.apache.myrmidon.components.deployer.DefaultDeployer; | |||
import org.apache.myrmidon.components.executor.DefaultExecutor; | |||
import org.apache.myrmidon.components.extensions.DefaultExtensionManager; | |||
import org.apache.myrmidon.components.property.DefaultPropertyResolver; | |||
import org.apache.myrmidon.components.role.DefaultRoleManager; | |||
import org.apache.myrmidon.components.type.DefaultTypeManager; | |||
import org.apache.myrmidon.framework.DataType; | |||
import org.apache.myrmidon.interfaces.classloader.ClassLoaderManager; | |||
import org.apache.myrmidon.interfaces.configurer.Configurer; | |||
import org.apache.myrmidon.interfaces.converter.ConverterRegistry; | |||
import org.apache.myrmidon.interfaces.deployer.Deployer; | |||
import org.apache.myrmidon.interfaces.executor.Executor; | |||
import org.apache.myrmidon.interfaces.extensions.ExtensionManager; | |||
import org.apache.myrmidon.interfaces.property.PropertyResolver; | |||
import org.apache.myrmidon.interfaces.role.RoleInfo; | |||
import org.apache.myrmidon.interfaces.role.RoleManager; | |||
import org.apache.myrmidon.interfaces.service.ServiceFactory; | |||
import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | |||
import org.apache.myrmidon.interfaces.type.TypeManager; | |||
@@ -47,6 +51,10 @@ public abstract class AbstractComponentTest | |||
{ | |||
private DefaultServiceManager m_serviceManager; | |||
public static final String DATA_TYPE_ROLE = "data-type"; | |||
public static final String CONVERTER_ROLE = "converter"; | |||
public static final String SERVICE_FACTORY_ROLE = "service-factory"; | |||
public AbstractComponentTest( final String name ) | |||
{ | |||
super( name ); | |||
@@ -85,6 +93,10 @@ public abstract class AbstractComponentTest | |||
m_serviceManager.put( Deployer.ROLE, component ); | |||
components.add( component ); | |||
component = new DefaultExecutor(); | |||
m_serviceManager.put( Executor.ROLE, component ); | |||
components.add( component ); | |||
final DefaultClassLoaderManager classLoaderMgr = new DefaultClassLoaderManager(); | |||
classLoaderMgr.setBaseClassLoader( getClass().getClassLoader() ); | |||
m_serviceManager.put( ClassLoaderManager.ROLE, classLoaderMgr ); | |||
@@ -123,7 +135,15 @@ public abstract class AbstractComponentTest | |||
serviceable.service( m_serviceManager ); | |||
} | |||
} | |||
// Register some standard roles | |||
// Add some core roles | |||
final RoleManager roleManager = (RoleManager)getServiceManager().lookup( RoleManager.ROLE ); | |||
roleManager.addRole( new RoleInfo( DataType.ROLE, DATA_TYPE_ROLE, DataType.class ) ); | |||
roleManager.addRole( new RoleInfo( Converter.ROLE, CONVERTER_ROLE, Converter.class ) ); | |||
roleManager.addRole( new RoleInfo( ServiceFactory.ROLE, SERVICE_FACTORY_ROLE, ServiceFactory.class ) ); | |||
} | |||
return m_serviceManager; | |||
} | |||
@@ -149,7 +169,7 @@ public abstract class AbstractComponentTest | |||
/** | |||
* Utility method to register a type. | |||
*/ | |||
protected void registerType( final Class roleType, | |||
protected void registerType( final String roleName, | |||
final String typeName, | |||
final Class type ) | |||
throws Exception | |||
@@ -157,7 +177,7 @@ public abstract class AbstractComponentTest | |||
final ClassLoader loader = getClass().getClassLoader(); | |||
final DefaultTypeFactory factory = new DefaultTypeFactory( loader ); | |||
factory.addNameClassMapping( typeName, type.getName() ); | |||
getTypeManager().registerType( roleType, typeName, factory ); | |||
getTypeManager().registerType( roleName, typeName, factory ); | |||
} | |||
/** | |||
@@ -172,6 +192,6 @@ public abstract class AbstractComponentTest | |||
converterRegistry.registerConverter( converterClass.getName(), sourceClass.getName(), destClass.getName() ); | |||
DefaultTypeFactory factory = new DefaultTypeFactory( getClass().getClassLoader() ); | |||
factory.addNameClassMapping( converterClass.getName(), converterClass.getName() ); | |||
getTypeManager().registerType( Converter.class, converterClass.getName(), factory ); | |||
getTypeManager().registerType( Converter.ROLE, converterClass.getName(), factory ); | |||
} | |||
} |
@@ -401,7 +401,7 @@ public class DefaultConfigurerTest | |||
config.addChild( child ); | |||
registerRole( new RoleInfo( "myrole1", null, MyRole1.class, "default-type" ) ); | |||
registerType( MyRole1.class, "default-type", MyType1.class ); | |||
registerType( "myrole1", "default-type", MyType1.class ); | |||
final ConfigTestInterfaceAdder test = new ConfigTestInterfaceAdder(); | |||
@@ -487,8 +487,8 @@ public class DefaultConfigurerTest | |||
config.addChild( child1 ); | |||
config.addChild( child2 ); | |||
registerType( DataType.class, "my-type1", MyType1.class ); | |||
registerType( DataType.class, "my-type2", MyType2.class ); | |||
registerType( DataType.ROLE, "my-type1", MyType1.class ); | |||
registerType( DataType.ROLE, "my-type2", MyType2.class ); | |||
final ConfigTestTypedAdder test = new ConfigTestTypedAdder(); | |||
@@ -514,8 +514,8 @@ public class DefaultConfigurerTest | |||
// Register incompatible types with the same name, as data-type and myrole1. | |||
registerRole( new RoleInfo( "myrole1", "myrole1", MyRole1.class ) ); | |||
registerType( MyRole1.class, "my-type1", MyType1.class ); | |||
registerType( DataType.class, "my-type1", StringBuffer.class ); | |||
registerType( "myrole1", "my-type1", MyType1.class ); | |||
registerType( DataType.ROLE, "my-type1", StringBuffer.class ); | |||
final ConfigTestTypedAdderRole test = new ConfigTestTypedAdderRole(); | |||
@@ -540,7 +540,7 @@ public class DefaultConfigurerTest | |||
child.setAttribute( "prop", "some value" ); | |||
config.addChild( child ); | |||
registerType( DataType.class, "some-type", ConfigTestTypedAdderConversion.class ); | |||
registerType( DataType.ROLE, "some-type", ConfigTestTypedAdderConversion.class ); | |||
registerConverter( ObjectToMyRole1Converter.class, Object.class, MyRole1.class ); | |||
final ConfigTestTypedAdderConversion test = new ConfigTestTypedAdderConversion(); | |||
@@ -16,8 +16,6 @@ import org.apache.myrmidon.interfaces.deployer.ConverterDefinition; | |||
import org.apache.myrmidon.interfaces.deployer.Deployer; | |||
import org.apache.myrmidon.interfaces.deployer.TypeDefinition; | |||
import org.apache.myrmidon.interfaces.deployer.TypeDeployer; | |||
import org.apache.myrmidon.interfaces.role.RoleInfo; | |||
import org.apache.myrmidon.interfaces.role.RoleManager; | |||
import org.apache.myrmidon.interfaces.type.TypeException; | |||
import org.apache.myrmidon.interfaces.type.TypeFactory; | |||
@@ -30,11 +28,8 @@ public class DefaultDeployerTest | |||
extends AbstractComponentTest | |||
{ | |||
private static final String TEST_TYPE1_NAME = "test-type1"; | |||
private static final String DATA_TYPE_ROLE = "data-type"; | |||
private static final String CONVERTER_ROLE = "converter"; | |||
private Deployer m_deployer; | |||
private RoleManager m_roleManager; | |||
private Converter m_converter; | |||
public DefaultDeployerTest( final String name ) | |||
@@ -51,11 +46,6 @@ public class DefaultDeployerTest | |||
super.setUp(); | |||
m_deployer = (Deployer)getServiceManager().lookup( Deployer.ROLE ); | |||
m_converter = (Converter)getServiceManager().lookup( Converter.ROLE ); | |||
// Add some core roles | |||
m_roleManager = (RoleManager)getServiceManager().lookup( RoleManager.ROLE ); | |||
m_roleManager.addRole( new RoleInfo( DataType.ROLE, DATA_TYPE_ROLE, DataType.class ) ); | |||
m_roleManager.addRole( new RoleInfo( Converter.ROLE, CONVERTER_ROLE, Converter.class ) ); | |||
} | |||
/** | |||
@@ -81,7 +71,7 @@ public class DefaultDeployerTest | |||
typeDeployer.deployType( typeDef ); | |||
// Check the type has been registered | |||
final TypeFactory typeFactory = getTypeManager().getFactory( DataType.class ); | |||
final TypeFactory typeFactory = getTypeManager().getFactory( DataType.ROLE ); | |||
final Object result = typeFactory.create( typeName ); | |||
assertTrue( result instanceof TestType1 ); | |||
} | |||
@@ -137,7 +127,7 @@ public class DefaultDeployerTest | |||
private void assertTypesNotRegistered() throws Exception | |||
{ | |||
// Check the data-type | |||
TypeFactory typeFactory = getTypeManager().getFactory( DataType.class ); | |||
TypeFactory typeFactory = getTypeManager().getFactory( DataType.ROLE ); | |||
try | |||
{ | |||
typeFactory.create( TEST_TYPE1_NAME ); | |||
@@ -149,9 +139,9 @@ public class DefaultDeployerTest | |||
} | |||
// Check the custom role implementation | |||
typeFactory = getTypeManager().getFactory( TestRole1.class ); | |||
try | |||
{ | |||
typeFactory = getTypeManager().getFactory( TestRole1.ROLE ); | |||
typeFactory.create( TEST_TYPE1_NAME ); | |||
fail(); | |||
} | |||
@@ -179,12 +169,12 @@ public class DefaultDeployerTest | |||
private void assertTypesRegistered() throws Exception | |||
{ | |||
// Check the data-type | |||
TypeFactory typeFactory = getTypeManager().getFactory( DataType.class ); | |||
TypeFactory typeFactory = getTypeManager().getFactory( DataType.ROLE ); | |||
Object object = typeFactory.create( TEST_TYPE1_NAME ); | |||
assertTrue( object instanceof TestType1 ); | |||
// Check the custom role implementation | |||
typeFactory = getTypeManager().getFactory( TestRole1.class ); | |||
typeFactory = getTypeManager().getFactory( TestRole1.ROLE ); | |||
object = typeFactory.create( TEST_TYPE1_NAME ); | |||
assertTrue( object instanceof TestType1 ); | |||
@@ -140,6 +140,6 @@ public class InstantiatingServiceManagerTest | |||
final DefaultTypeFactory typeFactory = new DefaultTypeFactory( getClass().getClassLoader() ); | |||
typeFactory.addNameClassMapping( serviceRoleName, factoryClass.getName() ); | |||
final TypeManager typeManager = (TypeManager)getServiceManager().lookup( TypeManager.ROLE ); | |||
typeManager.registerType( ServiceFactory.class, serviceRoleName, typeFactory ); | |||
typeManager.registerType( ServiceFactory.ROLE, serviceRoleName, typeFactory ); | |||
} | |||
} |