ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/embeddor/test DefaultEmbeddorTest.java
Date Sun, 30 Jun 2002 06:57:57 GMT
donaldp     2002/06/29 23:57:57

  Modified:    container/src/java/org/apache/myrmidon/components/embeddor
                        DefaultEmbeddor.java
               container/src/java/org/apache/myrmidon/interfaces
                        EmbeddedAnt.java
               container/src/java/org/apache/myrmidon/interfaces/embeddor
                        Embeddor.java
               container/src/test/org/apache/myrmidon/components/embeddor/test
                        DefaultEmbeddorTest.java
  Log:
  Allow you to pass in TaskContext when creating a TaskListener from Embeddor.
  
  Revision  Changes    Path
  1.110     +49 -25    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.109
  retrieving revision 1.110
  diff -u -r1.109 -r1.110
  --- DefaultEmbeddor.java	30 Jun 2002 06:36:35 -0000	1.109
  +++ DefaultEmbeddor.java	30 Jun 2002 06:57:56 -0000	1.110
  @@ -51,6 +51,7 @@
   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.TypeException;
   import org.apache.myrmidon.interfaces.type.TypeFactory;
   import org.apache.myrmidon.interfaces.type.TypeManager;
   import org.apache.myrmidon.interfaces.type.TypeRegistry;
  @@ -75,10 +76,8 @@
       /** Namespace for the container types */
       private static final String CONTAINER_TYPE_NAMESPACE = "myrmidon";
   
  -    private Deployer m_deployer;
       private TypeManager m_typeManager;
       private LibraryManager m_libraryManager;
  -    private Configurer m_configurer;
   
       private InstantiatingServiceManager m_serviceManager;
   
  @@ -109,17 +108,8 @@
                                     final TaskContext context )
           throws Exception
       {
  -        ProjectBuilder builder;
  -        if( null != context )
  -        {
  -            builder =
  -                (ProjectBuilder)context.getService( ProjectBuilder.class );
  -        }
  -        else
  -        {
  -            builder =
  -                (ProjectBuilder)m_serviceManager.lookup( ProjectBuilder.ROLE );
  -        }
  +        final ProjectBuilder builder =
  +            (ProjectBuilder)getService( context, ProjectBuilder.class );
           /*       final TypeFactory factory = m_typeManager.getFactory( ModelBuilder.ROLE
);
                  final ModelBuilder modelBuilder =
                      (ModelBuilder)factory.create( project.getType() );
  @@ -162,19 +152,35 @@
       /**
        * Creates a task listener.
        */
  -    public TaskListener createListener( final ModelElement model )
  +    public TaskListener setupListener( final ModelElement model,
  +                                       final TaskContext context )
           throws Exception
       {
           // Create the listener, contextualise it, and then configure it using
           // the supplied model.
  -        final TypeFactory factory =
  -            m_typeManager.getFactory( TaskListener.ROLE );
  -        final TaskListener listener = (TaskListener)factory.create( model.getName() );
  -        listener.contextualize( m_rootContext );
  -        m_configurer.configureElement( listener, model, m_rootContext );
  +        final TaskListener listener = createListener( context, model.getName() );
  +        final TaskContext actualContext = getTaskContext( context );
  +
  +        listener.contextualize( actualContext );
  +
  +        final Configurer configurer =
  +            (Configurer)getService( context, Configurer.class );
  +
  +        configurer.configureElement( listener, model, actualContext );
           return listener;
       }
   
  +    private TaskListener createListener( final TaskContext context,
  +                                         final String name )
  +        throws TaskException, TypeException
  +    {
  +        final TypeManager typeManager =
  +            (TypeManager)getService( context, TypeManager.class );
  +        final TypeFactory factory =
  +            typeManager.getFactory( TaskListener.ROLE );
  +        return (TaskListener)factory.create( name );
  +    }
  +
       /**
        * Initialize the system.
        *
  @@ -205,9 +211,7 @@
           m_serviceManager.registerService( new String[]{Embeddor.ROLE}, this );
   
           // locate the components we need
  -        m_deployer = (Deployer)m_serviceManager.lookup( Deployer.ROLE );
           m_libraryManager = (LibraryManager)m_serviceManager.lookup( LibraryManager.ROLE
);
  -        m_configurer = (Configurer)m_serviceManager.lookup( Configurer.ROLE );
   
           // create the root execution frame
           m_rootFrame = new DefaultExecutionFrame( "", new File( "." ), m_serviceManager
);
  @@ -222,7 +226,9 @@
           final ClassLoader containerClassLoader = getClass().getClassLoader();
           final Library containerLib =
               m_libraryManager.createLibrary( containerClassLoader );
  -        m_deployer.deployTypes( containerLib, CONTAINER_TYPE_NAMESPACE, m_rootContext );
  +
  +        final Deployer deployer = (Deployer)getService( null, Deployer.class );
  +        deployer.deployTypes( containerLib, CONTAINER_TYPE_NAMESPACE, m_rootContext );
   
           // Deploy all core type libraries in the lib directory
           final Library[] coreLibs = m_libraryManager.getCoreLibraries();
  @@ -248,7 +254,7 @@
                   getLogger().debug( message );
               }
   
  -            m_deployer.deployTypes( library, library.getName(), m_rootContext );
  +            deployer.deployTypes( library, library.getName(), m_rootContext );
           }
       }
   
  @@ -269,7 +275,6 @@
           m_serviceManager.dispose();
   
           // Ditch everything
  -        m_deployer = null;
           m_context = null;
       }
   
  @@ -401,6 +406,25 @@
               final String key = (String)keys.next();
               final Object value = map.get( key );
               store.setProperty( key, value );
  +        }
  +    }
  +
  +    private Object getService( final TaskContext context,
  +                               final Class roleClass )
  +        throws TaskException
  +    {
  +        return getTaskContext( context ).getService( roleClass );
  +    }
  +
  +    private TaskContext getTaskContext( final TaskContext context )
  +    {
  +        if( null != context )
  +        {
  +            return context;
  +        }
  +        else
  +        {
  +            return m_rootContext;
           }
       }
   }
  
  
  
  1.31      +2 -2      jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/EmbeddedAnt.java
  
  Index: EmbeddedAnt.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/EmbeddedAnt.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- EmbeddedAnt.java	20 Jun 2002 06:01:00 -0000	1.30
  +++ EmbeddedAnt.java	30 Jun 2002 06:57:56 -0000	1.31
  @@ -288,7 +288,7 @@
               else
               {
                   final ModelElement model = (ModelElement)obj;
  -                listener = embeddor.createListener( model );
  +                listener = embeddor.setupListener( model, null );
               }
               eventManager.addTaskListener( listener );
           }
  
  
  
  1.28      +4 -2      jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/embeddor/Embeddor.java
  
  Index: Embeddor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/embeddor/Embeddor.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- Embeddor.java	30 Jun 2002 06:36:36 -0000	1.27
  +++ Embeddor.java	30 Jun 2002 06:57:56 -0000	1.28
  @@ -44,10 +44,12 @@
        * Creates a task listener.
        *
        * @param model The model to use to create and configure the listener.
  +     * @param context The context in which you build listener (and thus which
  +     *                Listeners are available). May be null.
        * @return the listener.
        * @throws Exception If the listener could not be created.
        */
  -    TaskListener createListener( ModelElement model )
  +    TaskListener setupListener( ModelElement model, TaskContext context )
           throws Exception;
   
       /**
  
  
  
  1.38      +2 -2      jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/embeddor/test/DefaultEmbeddorTest.java
  
  Index: DefaultEmbeddorTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/embeddor/test/DefaultEmbeddorTest.java,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- DefaultEmbeddorTest.java	30 Jun 2002 06:36:36 -0000	1.37
  +++ DefaultEmbeddorTest.java	30 Jun 2002 06:57:56 -0000	1.38
  @@ -108,7 +108,7 @@
       public void testCreateListener() throws Exception
       {
           final ModelElement model = new ModelElement( "default", "?:?:?" );
  -        final TaskListener listener = getEmbeddor().createListener( model );
  +        final TaskListener listener = getEmbeddor().setupListener( model, null );
           assertNotNull( listener );
       }
   
  
  
  

--
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