ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adammurd...@apache.org
Subject cvs commit: jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/service/test InstantiatingServiceManagerTestCase.java
Date Sun, 16 Jun 2002 04:15:27 GMT
adammurdoch    2002/06/15 21:15:27

  Modified:    container project.xml
               container/src/java/org/apache/myrmidon/components/embeddor
                        DefaultEmbeddor.java Resources.properties
               container/src/java/org/apache/myrmidon/components/service
                        InstantiatingServiceManager.java
               container/src/java/org/apache/myrmidon/interfaces/service
                        DefaultServiceFactory.java ServiceRegistry.java
               container/src/test/org/apache/myrmidon/components/service/test
                        InstantiatingServiceManagerTestCase.java
  Added:       container/src/conf ant-services.xml
  Log:
  * Changed DefaultEmbeddor to load service definitions from META-INF/ant-services.xml
    resource, instead of using a hardcoded list.  Currently only handles a single file,
    and does not do any validation.
  
  * Treat the root PropertyStore as a service.
  
  * Added ServiceRegistry.registerService( String[], Object ), which registers
    a service whose lifecycle is not managed by the container.
  
  Revision  Changes    Path
  1.11      +1 -0      jakarta-ant-myrmidon/container/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/project.xml,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- project.xml	16 May 2002 03:26:45 -0000	1.10
  +++ project.xml	16 Jun 2002 04:15:26 -0000	1.11
  @@ -21,6 +21,7 @@
                   <exclude name="org/apache/myrmidon/launcher/**" />
                   <exclude name="org/apache/myrmidon/interfaces/**" />
               </patternset>
  +            <metainf dir="src/conf" includes="*.xml"/>
           </jar>
           <jar>
               <id>myrmidon-container-api</id>
  
  
  
  1.1                  jakarta-ant-myrmidon/container/src/conf/ant-services.xml
  
  Index: ant-services.xml
  ===================================================================
  <services>
      <service classname="org.apache.myrmidon.components.role.DefaultRoleManager">
          <role name="org.apache.myrmidon.interfaces.role.RoleManager"/>
          <role name="org.apache.myrmidon.interfaces.role.RoleRegistry"/>
      </service>
      <service classname="org.apache.myrmidon.components.property.DefaultPropertyStore">
          <role name="org.apache.myrmidon.interfaces.property.PropertyStore"/>
      </service>
      <service classname="org.apache.myrmidon.components.extensions.DefaultExtensionManager">
          <role name="org.apache.myrmidon.interfaces.extensions.ExtensionManager"/>
      </service>
      <service classname="org.apache.myrmidon.components.type.DefaultTypeManager">
          <role name="org.apache.myrmidon.interfaces.type.TypeManager"/>
          <role name="org.apache.myrmidon.interfaces.type.TypeRegistry"/>
      </service>
      <service classname="org.apache.myrmidon.components.deployer.DefaultDeployer">
          <role name="org.apache.myrmidon.interfaces.deployer.Deployer"/>
      </service>
      <service classname="org.apache.myrmidon.components.configurer.DefaultConfigurer">
          <role name="org.apache.myrmidon.interfaces.configurer.Configurer"/>
      </service>
      <service classname="org.apache.myrmidon.components.library.DefaultLibraryManager">
          <role name="org.apache.myrmidon.interfaces.library.LibraryManager"/>
      </service>
      <service classname="org.apache.myrmidon.components.executor.DefaultExecutor">
          <role name="org.apache.myrmidon.interfaces.executor.Executor"/>
      </service>
      <service classname="org.apache.myrmidon.components.property.DefaultNameValidatorManager">
          <role name="org.apache.myrmidon.interfaces.property.NameValidatorManager"/>
      </service>
      <service classname="org.apache.myrmidon.components.event.DefaultTaskEventManager">
          <role name="org.apache.myrmidon.interfaces.event.TaskEventManager"/>
      </service>
      <service classname="org.apache.myrmidon.components.property.DefaultPropertyResolver">
          <role name="org.apache.myrmidon.interfaces.property.PropertyResolver"/>
      </service>
      <service classname="org.apache.myrmidon.components.converter.DefaultMasterConverter">
          <role name="org.apache.myrmidon.interfaces.converter.ConverterRegistry"/>
          <role name="org.apache.excalibur.converter.Converter"/>
      </service>
      <service classname="org.apache.myrmidon.components.builder.DefaultModelBuilder">
          <role name="org.apache.myrmidon.interfaces.builder.ModelBuilder"/>
      </service>
      <service classname="org.apache.myrmidon.components.builder.MasterProjectBuilder">
          <role name="org.apache.myrmidon.interfaces.builder.ProjectBuilder"/>
      </service>
  </services>
  
  
  1.99      +65 -115   jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java
  
  Index: DefaultEmbeddor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java,v
  retrieving revision 1.98
  retrieving revision 1.99
  diff -u -r1.98 -r1.99
  --- DefaultEmbeddor.java	15 Jun 2002 08:00:20 -0000	1.98
  +++ DefaultEmbeddor.java	16 Jun 2002 04:15:26 -0000	1.99
  @@ -8,6 +8,8 @@
   package org.apache.myrmidon.components.embeddor;
   
   import java.io.File;
  +import java.io.InputStream;
  +import java.net.URL;
   import java.util.Arrays;
   import java.util.Iterator;
   import java.util.Map;
  @@ -16,53 +18,42 @@
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.activity.Initializable;
   import org.apache.avalon.framework.activity.Startable;
  -import org.apache.avalon.framework.container.ContainerUtil;
  +import org.apache.avalon.framework.configuration.Configuration;
  +import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
   import org.apache.avalon.framework.context.Context;
   import org.apache.avalon.framework.context.ContextException;
   import org.apache.avalon.framework.context.Contextualizable;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
  -import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.avalon.framework.service.DefaultServiceManager;
   import org.apache.avalon.framework.service.ServiceManager;
  -import org.apache.excalibur.converter.Converter;
  +import org.apache.avalon.framework.container.ContainerUtil;
   import org.apache.myrmidon.Constants;
   import org.apache.myrmidon.api.TaskContext;
   import org.apache.myrmidon.api.TaskException;
   import org.apache.myrmidon.api.event.TaskListener;
   import org.apache.myrmidon.api.metadata.ModelElement;
   import org.apache.myrmidon.components.executor.DefaultExecutionFrame;
  -import org.apache.myrmidon.components.property.DefaultPropertyStore;
   import org.apache.myrmidon.components.service.InstantiatingServiceManager;
   import org.apache.myrmidon.components.workspace.DefaultWorkspace;
  -import org.apache.myrmidon.interfaces.builder.ModelBuilder;
   import org.apache.myrmidon.interfaces.builder.ProjectBuilder;
   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.deployer.TypeLibraryDeployer;
   import org.apache.myrmidon.interfaces.embeddor.Embeddor;
  -import org.apache.myrmidon.interfaces.event.TaskEventManager;
   import org.apache.myrmidon.interfaces.executor.ExecutionFrame;
  -import org.apache.myrmidon.interfaces.executor.Executor;
  -import org.apache.myrmidon.interfaces.extensions.ExtensionManager;
   import org.apache.myrmidon.interfaces.library.Library;
   import org.apache.myrmidon.interfaces.library.LibraryManager;
   import org.apache.myrmidon.interfaces.model.Project;
  -import org.apache.myrmidon.interfaces.property.NameValidatorManager;
  -import org.apache.myrmidon.interfaces.property.PropertyResolver;
   import org.apache.myrmidon.interfaces.property.PropertyStore;
  -import org.apache.myrmidon.interfaces.role.RoleInfo;
  -import org.apache.myrmidon.interfaces.role.RoleManager;
  -import org.apache.myrmidon.interfaces.role.RoleRegistry;
   import org.apache.myrmidon.interfaces.service.DefaultServiceFactory;
   import org.apache.myrmidon.interfaces.service.ServiceDescriptor;
   import org.apache.myrmidon.interfaces.service.ServiceFactory;
   import org.apache.myrmidon.interfaces.service.ServiceRegistry;
   import org.apache.myrmidon.interfaces.type.TypeFactory;
   import org.apache.myrmidon.interfaces.type.TypeManager;
  -import org.apache.myrmidon.interfaces.type.TypeRegistry;
   import org.apache.myrmidon.interfaces.workspace.ProjectDescriptor;
   import org.apache.myrmidon.interfaces.workspace.Workspace;
  +import org.xml.sax.InputSource;
   
   /**
    * Default implementation of Embeddor.
  @@ -78,9 +69,6 @@
       private static final Resources REZ =
           ResourceManager.getPackageResources( DefaultEmbeddor.class );
   
  -    /** Package containing the default component implementations. */
  -    private static final String PREFIX = "org.apache.myrmidon.components.";
  -
       /** Namespace for the container types */
       private static final String CONTAINER_TYPE_NAMESPACE = "myrmidon";
   
  @@ -89,7 +77,7 @@
       private LibraryManager m_libraryManager;
       private Configurer m_configurer;
   
  -    private final InstantiatingServiceManager m_serviceManager = new InstantiatingServiceManager();
  +    private InstantiatingServiceManager m_serviceManager;
   
       private Context m_context;
       private ExecutionFrame m_rootFrame;
  @@ -173,6 +161,8 @@
           throws Exception
       {
           // setup the root components
  +        m_serviceManager = new InstantiatingServiceManager( getLogger(), m_context );
  +        ContainerUtil.enableLogging( m_serviceManager, getLogger() );
           setupComponents();
   
           // locate the components we need
  @@ -276,128 +266,88 @@
       private void setupComponents()
           throws Exception
       {
  -        setupObject( m_serviceManager, m_serviceManager, null );
  -
           final ServiceRegistry registry = (ServiceRegistry)m_serviceManager.lookup( ServiceRegistry.ROLE
);
   
  -        // Create the role manager first.  It is used to validate the rest
  -        // of the services
  -        registerService( registry,
  -                         null, new String[]{RoleManager.ROLE, RoleRegistry.ROLE},
  -                         PREFIX + "role.DefaultRoleManager" );
  -        final RoleRegistry roleRegistry = (RoleRegistry)m_serviceManager.lookup( RoleRegistry.ROLE
);
  -
  -        // Create the other services
  -        registerService( registry,
  -                         roleRegistry,
  -                         new String[]{ExtensionManager.ROLE},
  -                         PREFIX + "extensions.DefaultExtensionManager" );
  -        registerService( registry,
  -                         roleRegistry,
  -                         new String[]{TypeManager.ROLE, TypeRegistry.ROLE},
  -                         PREFIX + "type.DefaultTypeManager" );
  -        registerService( registry,
  -                         roleRegistry,
  -                         new String[]{Deployer.ROLE},
  -                         PREFIX + "deployer.DefaultDeployer" );
  -        registerService( registry,
  -                         roleRegistry,
  -                         new String[]{LibraryManager.ROLE},
  -                         PREFIX + "library.DefaultLibraryManager" );
  -        registerService( registry,
  -                         roleRegistry,
  -                         new String[]{Executor.ROLE},
  -                         PREFIX + "executor.DefaultExecutor" );
  -        registerService( registry,
  -                         roleRegistry,
  -                         new String[]{NameValidatorManager.ROLE},
  -                         PREFIX + "property.DefaultNameValidatorManager" );
  -        registerService( registry,
  -                         roleRegistry,
  -                         new String[]{TaskEventManager.ROLE},
  -                         PREFIX + "event.DefaultTaskEventManager" );
  -
  -        // Skip validation for the following services, because the (default)
  -        // role manager complains about duplicate role definitions for them.
  -        // TODO - um, validate them
  -        registerService( registry,
  -                         null,
  -                         new String[]{PropertyResolver.ROLE},
  -                         PREFIX + "property.DefaultPropertyResolver" );
  -        registerService( registry,
  -                         null,
  -                         new String[]{Configurer.ROLE},
  -                         PREFIX + "configurer.DefaultConfigurer" );
  -        registerService( registry,
  -                         null,
  -                         new String[]{Converter.ROLE, ConverterRegistry.ROLE},
  -                         PREFIX + "converter.DefaultMasterConverter" );
  -        registerService( registry,
  -                         null,
  -                         new String[]{ModelBuilder.ROLE},
  -                         PREFIX + "builder.DefaultModelBuilder" );
  -        registerService( registry,
  -                         null,
  -                         new String[]{ProjectBuilder.ROLE},
  -                         PREFIX + "builder.MasterProjectBuilder" );
  +        // Register the services
  +        final Configuration config = loadServiceConfig();
  +        final Configuration[] serviceDefs = config.getChildren( "service" );
  +        for( int i = 0; i < serviceDefs.length; i++ )
  +        {
  +            final Configuration serviceDef = serviceDefs[ i ];
  +            registerService( registry, serviceDef );
  +        }
   
  -        m_serviceManager.put( Embeddor.ROLE, this );
  +        // Add this embeddor
  +        registry.registerService( new String[] { Embeddor.ROLE }, this );
  +    }
  +
  +    /**
  +     * Loads the service descriptor.
  +     */
  +    private Configuration loadServiceConfig()
  +        throws Exception
  +    {
  +        final URL url = getClass().getClassLoader().getResource( "META-INF/ant-services.xml"
);
  +        if( url == null )
  +        {
  +            final String message = REZ.getString( "embeddor.find-service-definitions.error"
);
  +            throw new Exception( message );
  +        }
  +        final InputStream instr = url.openStream();
  +        try
  +        {
  +            final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
  +            final InputSource inputSource = new InputSource( instr );
  +            inputSource.setSystemId( url.toExternalForm() );
  +            return builder.build( inputSource );
  +        }
  +        finally
  +        {
  +            instr.close();
  +        }
       }
   
       /**
        * Registers a service, and the roles that it provides.
        */
       private void registerService( final ServiceRegistry serviceRegistry,
  -                                  final RoleRegistry roleRegistry,
  -                                  final String[] roles,
  -                                  final String defaultImplClass )
  +                                  final Configuration serviceDef )
           throws Exception
       {
  -        // Register the roles
  -        if( roleRegistry != null )
  +        final String classname = serviceDef.getAttribute( "classname" );
  +        final Configuration[] roleElems = serviceDef.getChildren( "role" );
  +        final String[] roleNames = new String[ roleElems.length ];
  +        for( int j = 0; j < roleElems.length; j++ )
           {
  -            for( int i = 0; i < roles.length; i++ )
  -            {
  -                final String role = roles[ i ];
  -                final Class roleImplClass = Class.forName( role );
  -                roleRegistry.addRole( new RoleInfo( role, roleImplClass ) );
  -            }
  +            roleNames[ j ] = roleElems[ j ].getAttribute( "name" );
           }
   
  -        // Register the service
  -        final ServiceFactory factory = new DefaultServiceFactory( defaultImplClass, getClass().getClassLoader()
);
  -        final ServiceDescriptor descriptor = new ServiceDescriptor( roles, factory );
  -        serviceRegistry.registerService( descriptor );
  +        final ServiceFactory factory = new DefaultServiceFactory( classname, getClass().getClassLoader()
);
  +        registerService( serviceRegistry, roleNames, factory );
       }
   
       /**
  -     * Sets-up an object by running it through the log-enable, compose,
  -     * parameterise and initialise lifecycle stages.
  +     * Registers a service, and the roles that it provides.
  +     *
  +     * @todo need to register the roles.
        */
  -    private void setupObject( final Object object,
  -                              final ServiceManager serviceManager,
  -                              final Parameters parameters )
  +    private void registerService( final ServiceRegistry serviceRegistry,
  +                                  final String[] roles,
  +                                  final ServiceFactory factory )
           throws Exception
       {
  -        ContainerUtil.enableLogging( object, getLogger() );
  -        ContainerUtil.contextualize( object, m_context );
  -        ContainerUtil.service( object, serviceManager );
  -        if( parameters != null )
  -        {
  -            ContainerUtil.parameterize( object, parameters );
  -        }
  -        ContainerUtil.initialize( object );
  +        // Register the service
  +        final ServiceDescriptor descriptor = new ServiceDescriptor( roles, factory );
  +        serviceRegistry.registerService( descriptor );
       }
   
       /**
        * Creates a root property store.
        */
  -    private PropertyStore createBaseStore( final InstantiatingServiceManager serviceManager
)
  +    private PropertyStore createBaseStore( final ServiceManager serviceManager )
           throws Exception
       {
  -        final DefaultPropertyStore store = new DefaultPropertyStore();
  -        ContainerUtil.service( store, serviceManager );
  -        serviceManager.put( PropertyStore.ROLE, store );
  +        final PropertyStore store = (PropertyStore)serviceManager.lookup( PropertyStore.ROLE
);
   
           //Add system properties
           addToStore( store, System.getProperties() );
  
  
  
  1.8       +2 -1      jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/embeddor/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/embeddor/Resources.properties,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Resources.properties	15 Jun 2002 08:00:21 -0000	1.7
  +++ Resources.properties	16 Jun 2002 04:15:26 -0000	1.8
  @@ -1,2 +1,3 @@
   embeddor.corelib-count.notice=Deploying {0} core libraries.
  -embeddor.corelib-deployed.notice=Deploying library "{0}" with class-path: {1}.
  \ No newline at end of file
  +embeddor.corelib-deployed.notice=Deploying library "{0}" with class-path: {1}.
  +embeddor.find-service-definitions.error=Could not locate the services descriptor.
  \ No newline at end of file
  
  
  
  1.13      +70 -51    jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/service/InstantiatingServiceManager.java
  
  Index: InstantiatingServiceManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/service/InstantiatingServiceManager.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- InstantiatingServiceManager.java	15 Jun 2002 08:00:21 -0000	1.12
  +++ InstantiatingServiceManager.java	16 Jun 2002 04:15:26 -0000	1.13
  @@ -17,16 +17,15 @@
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.container.ContainerUtil;
   import org.apache.avalon.framework.context.Context;
  -import org.apache.avalon.framework.context.ContextException;
  -import org.apache.avalon.framework.context.Contextualizable;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
  +import org.apache.avalon.framework.logger.Logger;
   import org.apache.avalon.framework.service.ServiceException;
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.myrmidon.interfaces.role.RoleInfo;
   import org.apache.myrmidon.interfaces.role.RoleManager;
  +import org.apache.myrmidon.interfaces.service.ServiceDescriptor;
   import org.apache.myrmidon.interfaces.service.ServiceFactory;
   import org.apache.myrmidon.interfaces.service.ServiceRegistry;
  -import org.apache.myrmidon.interfaces.service.ServiceDescriptor;
   
   /**
    * A service manager implementation, which creates service instances on demand.
  @@ -49,7 +48,7 @@
    */
   public class InstantiatingServiceManager
       extends AbstractLogEnabled
  -    implements ServiceManager, Contextualizable, Disposable, ServiceRegistry
  +    implements ServiceManager, Disposable, ServiceRegistry
   {
       private static final Resources REZ =
           ResourceManager.getPackageResources( InstantiatingServiceManager.class );
  @@ -63,11 +62,14 @@
       /** The objects (services and factories) that this mgr is responsible for. */
       private final List m_objects = new ArrayList();
   
  -    private Context m_context;
  +    private Context m_serviceContext;
  +    private Logger m_serviceLogger;
   
  -    public void contextualize( final Context context ) throws ContextException
  +    public InstantiatingServiceManager( final Logger serviceLogger,
  +                                        final Context serviceContext )
       {
  -        m_context = context;
  +        m_serviceLogger = serviceLogger;
  +        m_serviceContext = serviceContext;
       }
   
       /**
  @@ -96,13 +98,22 @@
       }
   
       /**
  -     * Adds a service to this service manager.  This is a temporary method.
  -     *
  -     * @todo Get rid of this method - use ServiceRegistry instead.
  +     * Registers a service.  All lifecycle management is handled by the caller.
        */
  -    public void put( final String roleName, final Object service )
  +    public void registerService( final String[] roles,
  +                                 final Object service )
  +        throws ServiceException
       {
  -        m_services.put( roleName, service );
  +        // Do some validation before adding the service
  +        validateServiceRoles( roles );
  +        validateService( roles, service );
  +
  +        // Register the service
  +        for( int i = 0; i < roles.length; i++ )
  +        {
  +            final String role = roles[ i ];
  +            m_services.put( role, service );
  +        }
       }
   
       /**
  @@ -113,20 +124,7 @@
       {
           // Check for collisions with other services
           final String[] roles = descriptor.getRoles();
  -        for( int i = 0; i < roles.length; i++ )
  -        {
  -            final String role = roles[ i ];
  -            if( m_descriptors.containsKey( role ) )
  -            {
  -                final String message = REZ.getString( "duplicate-factory-for-role.error",
role );
  -                throw new ServiceException( message );
  -            }
  -            if( m_services.containsKey( role ) )
  -            {
  -                final String message = REZ.getString( "duplicate-service-for-role.error",
role );
  -                throw new ServiceException( message );
  -            }
  -        }
  +        validateServiceRoles( roles );
   
           // Run the factory through the lifecycle
           // TODO - should be doing this somewhere else?
  @@ -148,6 +146,27 @@
       }
   
       /**
  +     * Checks for collisions between existing services and a service being added.
  +     */
  +    private void validateServiceRoles( final String[] roles ) throws ServiceException
  +    {
  +        for( int i = 0; i < roles.length; i++ )
  +        {
  +            final String role = roles[ i ];
  +            if( m_descriptors.containsKey( role ) )
  +            {
  +                final String message = REZ.getString( "duplicate-factory-for-role.error",
role );
  +                throw new ServiceException( message );
  +            }
  +            if( m_services.containsKey( role ) )
  +            {
  +                final String message = REZ.getString( "duplicate-service-for-role.error",
role );
  +                throw new ServiceException( message );
  +            }
  +        }
  +    }
  +
  +    /**
        * Determines if this service manager contains a particular service.
        */
       public boolean hasService( final String serviceRole )
  @@ -230,11 +249,7 @@
               // Create, validate, and setup the service
               final Object service = descriptor.getFactory().createService();
               final String[] roles = descriptor.getRoles();
  -            for( int i = 0; i < roles.length; i++ )
  -            {
  -                final String role = roles[ i ];
  -                validateService( role, service );
  -            }
  +            validateService( roles, service );
   
               setupObject( service );
   
  @@ -257,29 +272,33 @@
       /**
        * Validates a newly create service
        */
  -    private void validateService( final String serviceRole,
  +    private void validateService( final String[] roles,
                                     final Object service )
           throws ServiceException
       {
  -        final RoleManager roleManager = (RoleManager)m_services.get( RoleManager.ROLE );
  -        if( roleManager == null )
  +        for( int i = 0; i < roles.length; i++ )
           {
  -            return;
  -        }
  +            final String role = roles[ i ];
  +            final RoleManager roleManager = (RoleManager)m_services.get( RoleManager.ROLE
);
  +            if( roleManager == null )
  +            {
  +                continue;
  +            }
   
  -        final RoleInfo roleInfo = roleManager.getRoleByInterface( serviceRole );
  -        if( roleInfo == null )
  -        {
  -            // TODO - should this be an error?
  -            return;
  -        }
  +            final RoleInfo roleInfo = roleManager.getRoleByInterface( role );
  +            if( roleInfo == null )
  +            {
  +                // TODO - should this be an error?
  +                continue;
  +            }
   
  -        final Class serviceType = roleInfo.getImplementationClass();
  -        if( serviceType != null && !serviceType.isInstance( service ) )
  -        {
  -            final String message = REZ.getString( "mismatched-service-type.error",
  -                                                  serviceRole, service.getClass().getName()
);
  -            throw new ServiceException( message );
  +            final Class serviceType = roleInfo.getImplementationClass();
  +            if( serviceType != null && !serviceType.isInstance( service ) )
  +            {
  +                final String message = REZ.getString( "mismatched-service-type.error",
  +                                                      role, service.getClass().getName()
);
  +                throw new ServiceException( message );
  +            }
           }
       }
   
  @@ -289,8 +308,8 @@
       private void setupObject( final Object object )
           throws Exception
       {
  -        ContainerUtil.enableLogging( object, getLogger() );
  -        ContainerUtil.contextualize( object, m_context );
  +        ContainerUtil.enableLogging( object, m_serviceLogger );
  +        ContainerUtil.contextualize( object, m_serviceContext );
           ContainerUtil.service( object, this );
           ContainerUtil.initialize( object );
           m_objects.add( object );
  
  
  
  1.2       +19 -5     jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/service/DefaultServiceFactory.java
  
  Index: DefaultServiceFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/service/DefaultServiceFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultServiceFactory.java	15 Jun 2002 07:54:54 -0000	1.1
  +++ DefaultServiceFactory.java	16 Jun 2002 04:15:27 -0000	1.2
  @@ -16,12 +16,21 @@
   public class DefaultServiceFactory
       implements ServiceFactory
   {
  -    private final String m_clasname;
  +    private final String m_classname;
       private final ClassLoader m_loader;
  +    private final Class m_class;
   
  -    public DefaultServiceFactory( final String clasname, final ClassLoader loader )
  +    public DefaultServiceFactory( final Class serviceClass )
       {
  -        m_clasname = clasname;
  +        m_class = serviceClass;
  +        m_classname = null;
  +        m_loader = null;
  +    }
  +
  +    public DefaultServiceFactory( final String classname, final ClassLoader loader )
  +    {
  +        m_class = null;
  +        m_classname = classname;
           m_loader = loader;
       }
   
  @@ -31,6 +40,11 @@
       public Object createService()
           throws Exception
       {
  -        return m_loader.loadClass( m_clasname).newInstance();
  +        Class clazz = m_class;
  +        if( clazz == null )
  +        {
  +            clazz = m_loader.loadClass( m_classname );
  +        }
  +        return clazz.newInstance();
       }
   }
  
  
  
  1.4       +19 -2     jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/service/ServiceRegistry.java
  
  Index: ServiceRegistry.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/service/ServiceRegistry.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ServiceRegistry.java	15 Jun 2002 08:00:21 -0000	1.3
  +++ ServiceRegistry.java	16 Jun 2002 04:15:27 -0000	1.4
  @@ -21,11 +21,28 @@
       String ROLE = ServiceRegistry.class.getName();
   
       /**
  -     * Register a service in runtime.
  +     * Registers a service.  All lifecycle management is handled by the
  +     * container:
  +     *
  +     * <ul>
  +     * <li>The service is instantiated using the factory provided in the
  +     * descriptor.
  +     * <li>The service is taken through the lifecycle stages (service,
  +     * contextualise, initialise, etc).
  +     * <li>The service is made available for use, under the roles specified
  +     * in the descriptor.
  +     * <li>The service instance is disposed when it is no longer needed.
  +     * </ul>
        *
        * @param serviceDescriptor The service to register.
        * @throws ServiceException if error registering factory.
        */
       void registerService( ServiceDescriptor serviceDescriptor )
  +        throws ServiceException;
  +
  +    /**
  +     * Registers a service.  All lifecycle management is handled by the caller.
  +     */
  +    void registerService( String[] roles, Object service )
           throws ServiceException;
   }
  
  
  
  1.11      +6 -5      jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/service/test/InstantiatingServiceManagerTestCase.java
  
  Index: InstantiatingServiceManagerTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/service/test/InstantiatingServiceManagerTestCase.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- InstantiatingServiceManagerTestCase.java	15 Jun 2002 08:00:22 -0000	1.10
  +++ InstantiatingServiceManagerTestCase.java	16 Jun 2002 04:15:27 -0000	1.11
  @@ -13,8 +13,9 @@
   import org.apache.myrmidon.components.AbstractComponentTest;
   import org.apache.myrmidon.components.role.DefaultRoleManager;
   import org.apache.myrmidon.components.service.InstantiatingServiceManager;
  -import org.apache.myrmidon.interfaces.role.RoleManager;
   import org.apache.myrmidon.interfaces.role.RoleInfo;
  +import org.apache.myrmidon.interfaces.role.RoleManager;
  +import org.apache.myrmidon.interfaces.role.RoleRegistry;
   import org.apache.myrmidon.interfaces.service.ServiceDescriptor;
   
   /**
  @@ -42,12 +43,12 @@
           throws Exception
       {
           // Set-up the service manager
  -        m_serviceManager = new InstantiatingServiceManager();
  +        m_serviceManager = new InstantiatingServiceManager( getLogger(), new DefaultContext()
);
           m_serviceManager.enableLogging( getLogger() );
  -        m_serviceManager.contextualize( new DefaultContext() );
   
           final DefaultRoleManager roleManager = new DefaultRoleManager();
  -        m_serviceManager.put( RoleManager.ROLE, roleManager );
  +        m_serviceManager.registerService( new String[] { RoleManager.ROLE,
  +                                                         RoleRegistry.ROLE }, roleManager
);
           roleManager.addRole( new RoleInfo( "test-service", TestService.class ) );
       }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message