* Embeddor now creates a ServiceManager component. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271312 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -25,6 +25,8 @@ import org.apache.myrmidon.interfaces.deployer.DeploymentException; | |||
| import org.apache.myrmidon.interfaces.deployer.TypeDefinition; | |||
| import org.apache.myrmidon.interfaces.deployer.TypeDeployer; | |||
| import org.apache.myrmidon.interfaces.role.RoleManager; | |||
| import org.apache.myrmidon.interfaces.service.ServiceFactory; | |||
| import org.apache.myrmidon.interfaces.service.ServiceManager; | |||
| import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | |||
| import org.apache.myrmidon.interfaces.type.TypeManager; | |||
| @@ -50,6 +52,7 @@ public class DefaultDeployer | |||
| /** Map from ClassLoader to the deployer for that class loader. */ | |||
| private final Map m_classLoaderDeployers = new HashMap(); | |||
| private ServiceManager m_ServiceManager; | |||
| /** | |||
| * Retrieve relevent services needed to deploy. | |||
| @@ -64,6 +67,7 @@ public class DefaultDeployer | |||
| m_typeManager = (TypeManager)componentManager.lookup( TypeManager.ROLE ); | |||
| m_roleManager = (RoleManager)componentManager.lookup( RoleManager.ROLE ); | |||
| m_classLoaderManager = (ClassLoaderManager)componentManager.lookup( ClassLoaderManager.ROLE ); | |||
| m_ServiceManager = (ServiceManager)componentManager.lookup( ServiceManager.ROLE ); | |||
| } | |||
| /** | |||
| @@ -135,6 +139,21 @@ public class DefaultDeployer | |||
| return deployment; | |||
| } | |||
| /** | |||
| * Deploys a service. | |||
| */ | |||
| public void deployService( final Deployment deployment, | |||
| final ServiceDefinition definition ) | |||
| throws Exception | |||
| { | |||
| // Determine the service interface class name | |||
| String serviceTypeName = getRoleForName( definition.getRoleShorthand() ); | |||
| // Register the service factory | |||
| final String factoryClassName = definition.getFactoryClass(); | |||
| handleType( deployment, ServiceFactory.class, serviceTypeName, factoryClassName ); | |||
| } | |||
| /** | |||
| * Handles a type definition. | |||
| */ | |||
| @@ -187,7 +206,16 @@ public class DefaultDeployer | |||
| } | |||
| // Deploy general-purpose type | |||
| handleType( deployment, roleShorthand, typeName, className ); | |||
| final String role = getRoleForName( roleShorthand ); | |||
| final Class roleType = deployment.getClassLoader().loadClass( role ); | |||
| handleType( deployment, roleType, typeName, className ); | |||
| if( getLogger().isDebugEnabled() ) | |||
| { | |||
| final String message = | |||
| REZ.getString( "register-type.notice", roleShorthand, typeName ); | |||
| getLogger().debug( message ); | |||
| } | |||
| } | |||
| } | |||
| @@ -195,24 +223,15 @@ public class DefaultDeployer | |||
| * Handles a type definition. | |||
| */ | |||
| private void handleType( final Deployment deployment, | |||
| final String roleShorthand, | |||
| final Class roleType, | |||
| final String typeName, | |||
| final String className ) | |||
| throws Exception | |||
| { | |||
| // TODO - detect duplicates | |||
| final String role = getRoleForName( roleShorthand ); | |||
| final Class roleType = deployment.getClassLoader().loadClass( role ); | |||
| final DefaultTypeFactory factory = deployment.getFactory( roleType ); | |||
| factory.addNameClassMapping( typeName, className ); | |||
| m_typeManager.registerType( roleType, typeName, factory ); | |||
| if( getLogger().isDebugEnabled() ) | |||
| { | |||
| final String message = | |||
| REZ.getString( "register-type.notice", roleShorthand, typeName ); | |||
| getLogger().debug( message ); | |||
| } | |||
| } | |||
| /** | |||
| @@ -270,5 +289,4 @@ public class DefaultDeployer | |||
| return role; | |||
| } | |||
| } | |||
| @@ -136,11 +136,19 @@ class Deployment | |||
| public void deployAll() | |||
| throws DeploymentException | |||
| { | |||
| // Deploy types | |||
| for( int i = 0; i < m_descriptors.length; i++ ) | |||
| { | |||
| TypeDescriptor descriptor = m_descriptors[ i ]; | |||
| deployTypes( descriptor ); | |||
| } | |||
| // Deploy services | |||
| for( int i = 0; i < m_services.length; i++ ) | |||
| { | |||
| final ServiceDescriptor descriptor = m_services[ i ]; | |||
| deployServices( descriptor ); | |||
| } | |||
| } | |||
| /** | |||
| @@ -295,4 +303,30 @@ class Deployment | |||
| } | |||
| } | |||
| /** | |||
| * Deploys all services from a typelib descriptor. | |||
| */ | |||
| private void deployServices( final ServiceDescriptor descriptor ) | |||
| throws DeploymentException | |||
| { | |||
| try | |||
| { | |||
| final String message = REZ.getString( "url-deploy-services.notice", descriptor.getUrl() ); | |||
| getLogger().info( message ); | |||
| // Deploy the services | |||
| final ServiceDefinition[] definitions = descriptor.getDefinitions(); | |||
| for( int i = 0; i < definitions.length; i++ ) | |||
| { | |||
| final ServiceDefinition definition = definitions[ i ]; | |||
| m_deployer.deployService( this, definition ); | |||
| } | |||
| } | |||
| catch( Exception e ) | |||
| { | |||
| final String message = REZ.getString( "deploy-services.error", descriptor.getUrl() ); | |||
| throw new DeploymentException( message, e ); | |||
| } | |||
| } | |||
| } | |||
| @@ -3,10 +3,12 @@ register-type.notice=Registered type {0}/{1}. | |||
| register-role.notice=Registered role {0} with shorthand name {1}. | |||
| url-deploy-types.notice=Registering types from "{0}". | |||
| url-deploy-roles.notice=Registering roles from "{0}". | |||
| url-deploy-services.notice=Registering services from "{0}". | |||
| deploy-from-classloader.error=Could not register types from ClassLoader. | |||
| deploy-from-file.error=Could not register types from type library "{0}". | |||
| deploy-types.error=Could not register types from "{0}". | |||
| deploy-services.error=Could not register services from "{0}". | |||
| deploy-converter.error=Could not register converter that converts from {0} to {1}. | |||
| deploy-type.error=Could not register type {0}/{1}. | |||
| unknown-role4name.error=Unknown role "{0}". | |||
| @@ -45,9 +45,21 @@ class ServiceDescriptorBuilder | |||
| throw new DeploymentException( message ); | |||
| } | |||
| // TODO - populate the descriptor | |||
| // Build the descriptor | |||
| final ServiceDescriptor descriptor = new ServiceDescriptor( url ); | |||
| return new ServiceDescriptor( url ); | |||
| // Add the service definitions | |||
| final Configuration[] elements = config.getChildren(); | |||
| for( int i = 0; i < elements.length; i++ ) | |||
| { | |||
| final Configuration element = elements[ i ]; | |||
| final String roleShorthand = element.getName(); | |||
| final String factoryClassName = element.getAttribute( "factory" ); | |||
| final ServiceDefinition definition = new ServiceDefinition( roleShorthand, factoryClassName, config ); | |||
| descriptor.addDefinition( definition ); | |||
| } | |||
| return descriptor; | |||
| } | |||
| catch( Exception e ) | |||
| { | |||
| @@ -38,6 +38,7 @@ 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.role.RoleManager; | |||
| import org.apache.myrmidon.interfaces.service.ServiceManager; | |||
| import org.apache.myrmidon.interfaces.type.TypeFactory; | |||
| import org.apache.myrmidon.interfaces.type.TypeManager; | |||
| import org.apache.myrmidon.interfaces.workspace.Workspace; | |||
| @@ -245,6 +246,7 @@ public class DefaultEmbeddor | |||
| createComponent( Deployer.class, PREFIX + "deployer.DefaultDeployer" ); | |||
| createComponent( ClassLoaderManager.class, PREFIX + "deployer.DefaultClassLoaderManager" ); | |||
| createComponent( Executor.class, PREFIX + "executor.AspectAwareExecutor" ); | |||
| createComponent( ServiceManager.class, PREFIX + "service.DefaultServiceManager" ); | |||
| } | |||
| /** | |||