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/proposal/myrmidon/src/java/org/apache/myrmidon/components/type DefaultComponentFactory.java DefaultTypeManager.java TypedComponentSelector.java
Date Sat, 02 Jun 2001 08:26:54 GMT
donaldp     01/06/02 01:26:54

  Modified:    proposal/myrmidon/src/java/org/apache/ant/modules/basic
                        Property.java
               proposal/myrmidon/src/java/org/apache/ant/modules/core
                        RegisterDataType.java RegisterTasklet.java
               proposal/myrmidon/src/java/org/apache/myrmidon/api Task.java
               proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer
                        DefaultTskDeployer.java
               proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor
                        MyrmidonEmbeddor.java
               proposal/myrmidon/src/java/org/apache/myrmidon/components/executor
                        DefaultExecutor.java
               proposal/myrmidon/src/java/org/apache/myrmidon/components/type
                        DefaultComponentFactory.java
                        DefaultTypeManager.java TypedComponentSelector.java
  Log:
  Integrate type so that tasks/datatypes are access via TypeManager rather than through individual
Registrys scattered through classes.
  
  Revision  Changes    Path
  1.10      +7 -6      jakarta-ant/proposal/myrmidon/src/java/org/apache/ant/modules/basic/Property.java
  
  Index: Property.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/ant/modules/basic/Property.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Property.java	2001/05/31 17:19:38	1.9
  +++ Property.java	2001/06/02 08:26:52	1.10
  @@ -11,9 +11,9 @@
   import org.apache.myrmidon.api.TaskException;
   import org.apache.ant.convert.Converter;
   import org.apache.ant.tasklet.DataType;
  -import org.apache.ant.tasklet.engine.DataTypeEngine;
   import org.apache.avalon.framework.component.ComponentException;
   import org.apache.avalon.framework.component.ComponentManager;
  +import org.apache.avalon.framework.component.ComponentSelector;
   import org.apache.avalon.framework.component.Composable;
   import org.apache.avalon.framework.configuration.Configurable;
   import org.apache.avalon.framework.configuration.Configuration;
  @@ -22,6 +22,7 @@
   import org.apache.myrmidon.api.AbstractTask;
   import org.apache.myrmidon.api.TaskContext;
   import org.apache.myrmidon.components.configurer.Configurer;
  +import org.apache.myrmidon.components.type.TypeManager;
   
   /**
    * This is the property "task" to declare a binding of a datatype to a name.
  @@ -35,7 +36,7 @@
       protected String              m_name;
       protected Object              m_value;
       protected boolean             m_localScope     = true;
  -    protected DataTypeEngine      m_engine;
  +    protected ComponentSelector   m_selector;
       protected Converter           m_converter;
       protected Configurer          m_configurer;
   
  @@ -43,10 +44,10 @@
           throws ComponentException
       {
           m_configurer = (Configurer)componentManager.lookup( Configurer.ROLE );
  +        final TypeManager typeManager = (TypeManager)componentManager.lookup( TypeManager.ROLE
);
  +        m_selector = 
  +            (ComponentSelector)typeManager.lookup( "org.apache.ant.tasklet.DataTypeSelector"
);
   
  -        m_engine = (DataTypeEngine)componentManager.
  -            lookup( "org.apache.ant.tasklet.engine.DataTypeEngine" );
  -
           m_converter = (Converter)componentManager.lookup( "org.apache.ant.convert.Converter"
);
       }
   
  @@ -122,7 +123,7 @@
   
               try
               {
  -                final DataType value = m_engine.createDataType( child.getName() );
  +                final DataType value = (DataType)m_selector.select( child.getName() );
                   setValue( value );
                   m_configurer.configure( value, child, getContext() );
               }
  
  
  
  1.6       +14 -9     jakarta-ant/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterDataType.java
  
  Index: RegisterDataType.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterDataType.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- RegisterDataType.java	2001/05/29 12:06:09	1.5
  +++ RegisterDataType.java	2001/06/02 08:26:53	1.6
  @@ -8,10 +8,9 @@
   package org.apache.ant.modules.core;
   
   import java.net.URL;
  -import org.apache.avalon.framework.camelot.DefaultLocator;
   import org.apache.avalon.framework.camelot.DeploymentException;
  -import org.apache.avalon.framework.camelot.RegistryException;
   import org.apache.myrmidon.api.TaskException;
  +import org.apache.myrmidon.components.type.DefaultComponentFactory;
   
   /**
    * Method to register a single datatype.
  @@ -19,16 +18,16 @@
    * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
    */
   public class RegisterDataType
  -    extends AbstractResourceRegisterer
  +    extends AbstractTypeDefinition
   {
       protected void registerResource( final String name,
  -                                     final String classname,
  +                                     final String className,
                                        final URL url )
  -        throws TaskException, RegistryException
  +        throws TaskException
       {
  -        if( null == classname )
  +        if( null == className )
           {
  -            try { m_tskDeployer.deployDataType( name, url.toString(), url ); }
  +            try { getDeployer().deployDataType( name, url.toString(), url ); }
               catch( final DeploymentException de )
               {
                   throw new TaskException( "Failed deploying " + name + " from " + url, de
);
  @@ -36,8 +35,14 @@
           }
           else
           {
  -            final DefaultLocator locator = new DefaultLocator( classname, url );
  -            m_dataTypeEngine.getRegistry().register( name, locator );
  +            final DefaultComponentFactory factory = 
  +                new DefaultComponentFactory( new URL[] { url } );
  +            factory.addNameClassMapping( name, className );
  +            try { getTypeManager().registerType( "org.apache.ant.tasklet.DataType", name,
factory ); }
  +            catch( final Exception e )
  +            {
  +                throw new TaskException( "Failed registering " + name + " from " + url,
e );
  +            }
           }
       }
   }
  
  
  
  1.7       +18 -12    jakarta-ant/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterTasklet.java
  
  Index: RegisterTasklet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterTasklet.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- RegisterTasklet.java	2001/05/29 12:06:10	1.6
  +++ RegisterTasklet.java	2001/06/02 08:26:53	1.7
  @@ -8,27 +8,27 @@
   package org.apache.ant.modules.core;
   
   import java.net.URL;
  -import org.apache.myrmidon.api.TaskException;
  -import org.apache.avalon.framework.camelot.DefaultLocator;
   import org.apache.avalon.framework.camelot.DeploymentException;
  -import org.apache.avalon.framework.camelot.RegistryException;
  +import org.apache.myrmidon.api.Task;
  +import org.apache.myrmidon.api.TaskException;
  +import org.apache.myrmidon.components.type.DefaultComponentFactory;
   
   /**
    * Method to register a single tasklet.
    *
    * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
    */
  -public class RegisterTasklet 
  -    extends AbstractResourceRegisterer
  +public class RegisterTasklet
  +    extends AbstractTypeDefinition
   {
  -    protected void registerResource( final String name, 
  -                                     final String classname, 
  +    protected void registerResource( final String name,
  +                                     final String className,
                                        final URL url )
  -        throws TaskException, RegistryException 
  +        throws TaskException
       {
  -        if( null == classname )
  +        if( null == className )
           {
  -            try { m_tskDeployer.deployTask( name, url.toString(), url ); }
  +            try { getDeployer().deployTask( name, url.toString(), url ); }
               catch( final DeploymentException de )
               {
                   throw new TaskException( "Failed deploying " + name + " from " + url, de
);
  @@ -36,8 +36,14 @@
           }
           else
           {
  -            final DefaultLocator locator = new DefaultLocator( classname, url );
  -            m_engine.getRegistry().register( name, locator ); 
  +            final DefaultComponentFactory factory = 
  +                new DefaultComponentFactory( new URL[] { url } );
  +            factory.addNameClassMapping( name, className );
  +            try { getTypeManager().registerType( Task.ROLE, name, factory ); }
  +            catch( final Exception e )
  +            {
  +                throw new TaskException( "Failed registering " + name + " from " + url,
e );
  +            }
           }
       }
   }
  
  
  
  1.4       +3 -0      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/api/Task.java
  
  Index: Task.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/api/Task.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Task.java	2001/06/02 06:58:12	1.3
  +++ Task.java	2001/06/02 08:26:53	1.4
  @@ -7,6 +7,8 @@
    */
   package org.apache.myrmidon.api;
   
  +import org.apache.avalon.framework.component.Component;
  +
   /**
    * This is the interface that tasks implement to be executed in Myrmidon runtime.
    * 
  @@ -24,6 +26,7 @@
    * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
    */
   public interface Task
  +    extends Component
   {
       String ROLE = "org.apache.myrmidon.api.Task";
   
  
  
  
  1.5       +12 -13    jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/DefaultTskDeployer.java
  
  Index: DefaultTskDeployer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/DefaultTskDeployer.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultTskDeployer.java	2001/06/02 06:58:12	1.4
  +++ DefaultTskDeployer.java	2001/06/02 08:26:53	1.5
  @@ -52,8 +52,8 @@
   {
       private final static String   TSKDEF_FILE     = "TASK-LIB/taskdefs.xml";
   
  -    private Registry              m_dataTypeRegistry;
  -    private Registry              m_taskRegistry;
  +    //private Registry              m_dataTypeRegistry;
  +    //private Registry              m_taskRegistry;
       private Registry              m_converterRegistry;
       private ConverterRegistry     m_converterInfoRegistry;
       private TypeManager           m_typeManager;
  @@ -77,8 +77,8 @@
           throws ComponentException
       {
           //UGLY HACK alert !!!
  -        final Executor executor = (Executor)componentManager.lookup( Executor.ROLE );
  -        m_taskRegistry = executor.getRegistry();
  +        //final Executor executor = (Executor)componentManager.lookup( Executor.ROLE );
  +        //m_taskRegistry = executor.getRegistry();
   
           final ConverterEngine converterEngine = (ConverterEngine)componentManager.
               lookup( "org.apache.ant.convert.engine.ConverterEngine" );
  @@ -86,11 +86,10 @@
           m_converterInfoRegistry = converterEngine.getInfoRegistry();
           m_converterRegistry = converterEngine.getRegistry();
   
  -        final DataTypeEngine dataTypeEngine = (DataTypeEngine)componentManager.
  -            lookup( "org.apache.ant.tasklet.engine.DataTypeEngine" );
  +        //final DataTypeEngine dataTypeEngine = (DataTypeEngine)componentManager.
  +        //lookup( "org.apache.ant.tasklet.engine.DataTypeEngine" );
  +        //m_dataTypeRegistry = dataTypeEngine.getRegistry();
   
  -        m_dataTypeRegistry = dataTypeEngine.getRegistry();
  -
           m_typeManager = (TypeManager)componentManager.lookup( TypeManager.ROLE );
       }
   
  @@ -277,7 +276,7 @@
       {
           final String name = task.getAttribute( "name" );
           final String className = task.getAttribute( "classname" );
  -
  +        /*
           final DefaultLocator info = new DefaultLocator( className, url );
   
           try { m_taskRegistry.register( name, info ); }
  @@ -286,7 +285,7 @@
               throw new DeploymentException( "Error registering " + name + " due to " + re,
                                              re );
           }
  -
  +        */
           factory.addNameClassMapping( name, className );
           
           try { m_typeManager.registerType( Task.ROLE, name, factory ); }
  @@ -305,7 +304,7 @@
       {
           final String name = datatype.getAttribute( "name" );
           final String className = datatype.getAttribute( "classname" );
  -
  +/*
           final DefaultLocator info = new DefaultLocator( className, url );
   
           try { m_dataTypeRegistry.register( name, info ); }
  @@ -314,9 +313,9 @@
               throw new DeploymentException( "Error registering " + name + " due to " + re,
                                              re );
           }
  -
  +*/
           factory.addNameClassMapping( name, className );
  -        try { m_typeManager.registerType( Task.ROLE, name, factory ); }
  +        try { m_typeManager.registerType( "org.apache.ant.tasklet.DataType", name, factory
); }
           catch( final Exception e )
           {
               throw new DeploymentException( "Error registering " + name + " due to " + e,
e );
  
  
  
  1.13      +6 -6      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/MyrmidonEmbeddor.java
  
  Index: MyrmidonEmbeddor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/MyrmidonEmbeddor.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- MyrmidonEmbeddor.java	2001/06/02 06:58:12	1.12
  +++ MyrmidonEmbeddor.java	2001/06/02 08:26:54	1.13
  @@ -236,12 +236,18 @@
           component = getParameter( "org.apache.ant.convert.engine.ConverterEngine" );
           m_converterEngine = (ConverterEngine)createComponent( component, ConverterEngine.class
);
   
  +        component = getParameter( Configurer.ROLE );
  +        m_configurer = (Configurer)createComponent( component, Configurer.class );
  +
           component = getParameter( "org.apache.ant.tasklet.engine.DataTypeEngine" );
           m_dataTypeEngine = (DataTypeEngine)createComponent( component, DataTypeEngine.class
);
   
           component = getParameter( TypeManager.ROLE );
           m_typeManager = (TypeManager)createComponent( component, TypeManager.class );
   
  +        component = getParameter( TskDeployer.ROLE );
  +        m_deployer = (TskDeployer)createComponent( component, TskDeployer.class );
  +
           component = getParameter( Executor.ROLE );
           m_executor = (Executor)createComponent( component, Executor.class );
   
  @@ -250,12 +256,6 @@
   
           component = getParameter( ProjectBuilder.ROLE );
           m_builder =(ProjectBuilder)createComponent( component, ProjectBuilder.class );
  -
  -        component = getParameter( TskDeployer.ROLE );
  -        m_deployer = (TskDeployer)createComponent( component, TskDeployer.class );
  -
  -        component = getParameter( Configurer.ROLE );
  -        m_configurer = (Configurer)createComponent( component, Configurer.class );
       }
   
       /**
  
  
  
  1.5       +19 -11    jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/executor/DefaultExecutor.java
  
  Index: DefaultExecutor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/executor/DefaultExecutor.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultExecutor.java	2001/05/31 17:20:15	1.4
  +++ DefaultExecutor.java	2001/06/02 08:26:54	1.5
  @@ -20,6 +20,7 @@
   import org.apache.avalon.framework.component.Component;
   import org.apache.avalon.framework.component.ComponentException;
   import org.apache.avalon.framework.component.ComponentManager;
  +import org.apache.avalon.framework.component.ComponentSelector;
   import org.apache.avalon.framework.component.Composable;
   import org.apache.avalon.framework.component.DefaultComponentManager;
   import org.apache.avalon.framework.configuration.Configurable;
  @@ -34,20 +35,22 @@
   import org.apache.myrmidon.api.TaskException;
   import org.apache.myrmidon.api.TaskException;
   import org.apache.myrmidon.components.configurer.Configurer;
  +import org.apache.myrmidon.components.type.TypeManager;
   
   public class DefaultExecutor
       extends AbstractLoggable
       implements Executor, Composable
   {
  -    private Factory              m_factory;
  -    private Registry             m_registry   = new DefaultRegistry( Locator.class );
  +    //private Factory              m_factory;
  +    //private Registry             m_registry   = new DefaultRegistry( Locator.class );
       private Configurer           m_configurer;
  +    private ComponentSelector    m_selector;
   
       private ComponentManager     m_componentManager;
   
       public Registry getRegistry()
       {
  -        return m_registry;
  +        return null;//m_registry;
       }
   
       /**
  @@ -61,10 +64,12 @@
       {
           //cache CM so it can be used while executing tasks
           m_componentManager = componentManager;
  +        //m_factory = (Factory)componentManager.lookup( "org.apache.avalon.framework.camelot.Factory"
);
   
  -        m_factory = (Factory)componentManager.lookup( "org.apache.avalon.framework.camelot.Factory"
);
  -
           m_configurer = (Configurer)componentManager.lookup( Configurer.ROLE );
  +
  +        final TypeManager typeManager = (TypeManager)componentManager.lookup( TypeManager.ROLE
);
  +        m_selector = (ComponentSelector)typeManager.lookup( Task.ROLE + "Selector" );
       }
   
       public void execute( final Configuration taskData, final TaskContext context )
  @@ -99,17 +104,20 @@
       {
           try
           {
  -            final Locator locator = (Locator)m_registry.getInfo( name, Locator.class );
  -            return (Task)m_factory.create( locator, Task.class );
  +            return (Task)m_selector.select( name );
  +            //final Locator locator = (Locator)m_registry.getInfo( name, Locator.class
);
  +            //return (Task)m_factory.create( locator, Task.class );
           }
  -        catch( final RegistryException re )
  +        catch( final ComponentException ce )
           {
  -            throw new TaskException( "Unable to locate task " + name, re );
  +            throw new TaskException( "Unable to create task " + name, ce );
           }
  -        catch( final FactoryException fe )
  +/*        catch( final RegistryException re )
           {
  -            throw new TaskException( "Unable to create task " + name, fe );
  +            throw new TaskException( "Unable to locate task " + name, re );
           }
  +        catch( final FactoryException fe )
  +*/
       }
   
       private void doConfigure( final Task task,
  
  
  
  1.2       +2 -2      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/type/DefaultComponentFactory.java
  
  Index: DefaultComponentFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/type/DefaultComponentFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultComponentFactory.java	2001/05/31 17:21:48	1.1
  +++ DefaultComponentFactory.java	2001/06/02 08:26:54	1.2
  @@ -17,7 +17,7 @@
    * Create a component based on name.
    *
    * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
  - * @version CVS $Revision: 1.1 $ $Date: 2001/05/31 17:21:48 $
  + * @version CVS $Revision: 1.2 $ $Date: 2001/06/02 08:26:54 $
    */
   public class DefaultComponentFactory
       implements ComponentFactory
  @@ -36,7 +36,7 @@
   
       public DefaultComponentFactory( final URL[] urls )
       {
  -        this( urls, null );
  +        this( urls, Thread.currentThread().getContextClassLoader() );
       }
   
       public DefaultComponentFactory( final URL[] urls, final ClassLoader parent )
  
  
  
  1.3       +12 -6     jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/type/DefaultTypeManager.java
  
  Index: DefaultTypeManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/type/DefaultTypeManager.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultTypeManager.java	2001/06/02 06:58:12	1.2
  +++ DefaultTypeManager.java	2001/06/02 08:26:54	1.3
  @@ -39,10 +39,9 @@
       public Component lookup( final String role )
           throws ComponentException
       {
  -        final ComponentSelector selector = (ComponentSelector)m_roleMap.get( role );
  -        if( null != selector )
  +        if( role.endsWith( "Selector" ) )
           {
  -            return selector;
  +           return createSelector( role );
           }
           else
           {
  @@ -60,7 +59,7 @@
                                 final ComponentFactory factory ) 
           throws Exception
       {
  -        final TypedComponentSelector selector = createSelector( role );
  +        final TypedComponentSelector selector = createSelector( role + "Selector" );
           selector.register( shorthandName, factory );
       }
   
  @@ -77,7 +76,10 @@
           throws ComponentException
       {
           TypedComponentSelector selector = (TypedComponentSelector)m_roleMap.get( role );
  -        if( null != selector ) return selector;
  +        if( null != selector ) 
  +        {
  +            return selector;
  +        }
   
           if( null != m_parent )
           {
  @@ -92,10 +94,14 @@
           ///If we haven't goa selector try to create a new one
           if( null == selector )
           {
  +            //Precondition that role.endsWith( "Selector" )
  +            final int length = role.length() - 8;
  +            final String workInterface = role.substring( 0, length );
  +
               try
               {
                   //TODO: Should we use ContextClassLoader here ??? Or perhaps try that on
failure??
  -                final Class clazz = Class.forName( role );
  +                final Class clazz = Class.forName( workInterface );
                   selector = new TypedComponentSelector( clazz );
               }
               catch( final Exception e )
  
  
  
  1.3       +1 -1      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/type/TypedComponentSelector.java
  
  Index: TypedComponentSelector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/type/TypedComponentSelector.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TypedComponentSelector.java	2001/06/02 05:47:28	1.2
  +++ TypedComponentSelector.java	2001/06/02 08:26:54	1.3
  @@ -64,7 +64,7 @@
   
           if( null != component )
           {
  -            if( m_type.isInstance( component ) )
  +            if( !m_type.isInstance( component ) )
               {
                   throw new ComponentException( "Implementation of " + name + " is not of
" +
                                                 "correct type (" + m_type.getClass().getName()
+ ")" );
  
  
  

Mime
View raw message