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/converter Converter.java
Date Sun, 03 Jun 2001 06:10:07 GMT
donaldp     01/06/02 23:10:07

  Modified:    proposal/myrmidon/src/java/org/apache/ant/modules/basic
                        Property.java
               proposal/myrmidon/src/java/org/apache/myrmidon/api
                        DataType.java Task.java
               proposal/myrmidon/src/java/org/apache/myrmidon/components/converter
                        DefaultMasterConverter.java
               proposal/myrmidon/src/java/org/apache/myrmidon/components/executor
                        DefaultExecutor.java
               proposal/myrmidon/src/java/org/apache/myrmidon/components/type
                        DefaultTypeManager.java TypeFactory.java
                        TypeManager.java
               proposal/myrmidon/src/java/org/apache/myrmidon/converter
                        Converter.java
  Added:       proposal/myrmidon/src/java/org/apache/myrmidon/components/type
                        MultiSourceTypeFactory.java
  Removed:     proposal/myrmidon/src/java/org/apache/myrmidon/components/type
                        TypedComponentSelector.java
  Log:
  Converted TypeManager so that types no longer have to implement Avalons 'Component' interface.
  
  Revision  Changes    Path
  1.12      +10 -4     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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Property.java	2001/06/02 14:28:40	1.11
  +++ Property.java	2001/06/03 06:10:03	1.12
  @@ -9,7 +9,6 @@
   
   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 +21,8 @@
   import org.apache.myrmidon.components.configurer.Configurer;
   import org.apache.myrmidon.components.converter.MasterConverter;
   import org.apache.myrmidon.components.type.TypeManager;
  +import org.apache.myrmidon.components.type.TypeException;
  +import org.apache.myrmidon.components.type.TypeFactory;
   
   /**
    * This is the property "task" to declare a binding of a datatype to a name.
  @@ -35,7 +36,7 @@
       private String              m_name;
       private Object              m_value;
       private boolean             m_localScope     = true;
  -    private ComponentSelector   m_selector;
  +    private TypeFactory         m_factory;
       private MasterConverter     m_converter;
       private Configurer          m_configurer;
   
  @@ -44,7 +45,12 @@
       {
           m_configurer = (Configurer)componentManager.lookup( Configurer.ROLE );
           final TypeManager typeManager = (TypeManager)componentManager.lookup( TypeManager.ROLE
);
  -        m_selector = (ComponentSelector)typeManager.lookup( DataType.ROLE + "Selector"
);
  +        
  +        try { m_factory = typeManager.getFactory( DataType.ROLE ); }
  +        catch( final TypeException te )
  +        {
  +            throw new ComponentException( "Unable to retrieve factory from TypeManager",
te );
  +        }
   
           m_converter = (MasterConverter)componentManager.lookup( MasterConverter.ROLE );
       }
  @@ -121,7 +127,7 @@
   
               try
               {
  -                final DataType value = (DataType)m_selector.select( child.getName() );
  +                final DataType value = (DataType)m_factory.create( child.getName() );
                   setValue( value );
                   m_configurer.configure( value, child, getContext() );
               }
  
  
  
  1.2       +0 -3      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/api/DataType.java
  
  Index: DataType.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/api/DataType.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DataType.java	2001/06/02 14:28:42	1.1
  +++ DataType.java	2001/06/03 06:10:04	1.2
  @@ -7,8 +7,6 @@
    */
   package org.apache.myrmidon.api;
   
  -import org.apache.avalon.framework.component.Component;
  -
   /**
    * Base class for those classes that can appear inside the build file
    * as stand alone data types.  
  @@ -16,7 +14,6 @@
    * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
    */
   public interface DataType
  -    extends Component
   {
       String ROLE = "org.apache.myrmidon.api.DataType";
   }
  
  
  
  1.5       +0 -3      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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Task.java	2001/06/02 08:26:53	1.4
  +++ Task.java	2001/06/03 06:10:04	1.5
  @@ -7,8 +7,6 @@
    */
   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.
    * 
  @@ -26,7 +24,6 @@
    * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
    */
   public interface Task
  -    extends Component
   {
       String ROLE = "org.apache.myrmidon.api.Task";
   
  
  
  
  1.3       +11 -6     jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/converter/DefaultMasterConverter.java
  
  Index: DefaultMasterConverter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/converter/DefaultMasterConverter.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultMasterConverter.java	2001/06/03 05:14:47	1.2
  +++ DefaultMasterConverter.java	2001/06/03 06:10:04	1.3
  @@ -9,11 +9,12 @@
   
   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.context.Context;
   import org.apache.avalon.framework.logger.AbstractLoggable;
   import org.apache.myrmidon.components.converter.MasterConverter;
  +import org.apache.myrmidon.components.type.TypeException;
  +import org.apache.myrmidon.components.type.TypeFactory;
   import org.apache.myrmidon.components.type.TypeManager;
   import org.apache.myrmidon.converter.Converter;
   import org.apache.myrmidon.converter.ConverterException;
  @@ -30,7 +31,7 @@
       private final static boolean DEBUG                = false;
   
       private ConverterRegistry    m_registry;
  -    private ComponentSelector    m_selector;
  +    private TypeFactory          m_factory;
   
       /**
        * Retrieve relevent services needed to deploy.
  @@ -44,7 +45,11 @@
           m_registry = (ConverterRegistry)componentManager.lookup( ConverterRegistry.ROLE
);
   
           final TypeManager typeManager = (TypeManager)componentManager.lookup( TypeManager.ROLE
);
  -        m_selector = (ComponentSelector)typeManager.lookup( Converter.ROLE + "Selector"
);
  +        try { m_factory = typeManager.getFactory( Converter.ROLE ); }
  +        catch( final TypeException te )
  +        {
  +            throw new ComponentException( "Unable to retrieve factory from TypeManager",
te );
  +        }
       }
   
       /**
  @@ -86,7 +91,7 @@
           try
           {
               //TODO: Start caching converters instead of repeatedly instantiating em.
  -            final Converter converter = (Converter)m_selector.select( name );
  +            final Converter converter = (Converter)m_factory.create( name );
   
   
               if( DEBUG )
  @@ -96,10 +101,10 @@
   
               return converter.convert( destination, original, context );
           }
  -        catch( final ComponentException ce )
  +        catch( final TypeException te )
           {
               throw new ConverterException( "Badly configured TypeManager missing " +
  -                                          "converter definition" );
  +                                          "converter definition", te );
           }
       }
   }
  
  
  
  1.8       +11 -6     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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DefaultExecutor.java	2001/06/02 14:28:43	1.7
  +++ DefaultExecutor.java	2001/06/03 06:10:05	1.8
  @@ -12,7 +12,6 @@
   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;
  @@ -27,6 +26,8 @@
   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.TypeException;
  +import org.apache.myrmidon.components.type.TypeFactory;
   import org.apache.myrmidon.components.type.TypeManager;
   
   public class DefaultExecutor
  @@ -34,7 +35,7 @@
       implements Executor, Composable
   {
       private Configurer           m_configurer;
  -    private ComponentSelector    m_selector;
  +    private TypeFactory          m_factory;
   
       private ComponentManager     m_componentManager;
   
  @@ -53,7 +54,11 @@
           m_configurer = (Configurer)componentManager.lookup( Configurer.ROLE );
   
           final TypeManager typeManager = (TypeManager)componentManager.lookup( TypeManager.ROLE
);
  -        m_selector = (ComponentSelector)typeManager.lookup( Task.ROLE + "Selector" );
  +        try { m_factory = typeManager.getFactory( Task.ROLE ); }
  +        catch( final TypeException te )
  +        {
  +            throw new ComponentException( "Unable to retrieve factory from TypeManager",
te );
  +        }
       }
   
       public void execute( final Configuration taskData, final TaskContext context )
  @@ -88,11 +93,11 @@
       {
           try
           {
  -            return (Task)m_selector.select( name );
  +            return (Task)m_factory.create( name );
           }
  -        catch( final ComponentException ce )
  +        catch( final TypeException te )
           {
  -            throw new TaskException( "Unable to create task " + name, ce );
  +            throw new TaskException( "Unable to create task " + name, te );
           }
       }
   
  
  
  
  1.5       +42 -58    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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultTypeManager.java	2001/06/03 05:31:17	1.4
  +++ DefaultTypeManager.java	2001/06/03 06:10:05	1.5
  @@ -8,9 +8,6 @@
   package org.apache.myrmidon.components.type;
   
   import java.util.HashMap;
  -import org.apache.avalon.framework.component.Component;
  -import org.apache.avalon.framework.component.ComponentException;
  -import org.apache.avalon.framework.component.ComponentSelector;
   
   /**
    * The interface that is used to manage types.
  @@ -21,80 +18,68 @@
       implements TypeManager
   {
       ///Parent type manager to inherit values from.
  -    private final TypeManager  m_parent;
  +    private final DefaultTypeManager  m_parent;
   
  -    ///Maps role to TypedComponentSelector.
  -    private final HashMap      m_roleMap      = new HashMap();
  +    ///Maps role to MultiSourceTypeFactory.
  +    private final HashMap             m_roleMap      = new HashMap();
   
       public DefaultTypeManager()
       {
           this( null );
       }
   
  -    public DefaultTypeManager( final TypeManager parent )
  +    public DefaultTypeManager( final DefaultTypeManager parent )
       {
           m_parent = parent;
       }
   
  -    public Component lookup( final String role )
  -        throws ComponentException
  +    public void registerType( final String role, 
  +                              final String shorthandName, 
  +                              final TypeFactory factory ) 
  +        throws TypeException
       {
  -        if( role.endsWith( "Selector" ) )
  -        {
  -           return createSelector( role );
  -        }
  -        else
  -        {
  -            throw new ComponentException( "Unable to provide implementation for '" + 
  -                                          role + "'" );
  -        }
  +        final MultiSourceTypeFactory msFactory = createFactory( role + "Selector" );
  +        msFactory.register( shorthandName, factory );
       }
   
  -    public void release( final Component component )
  +    public TypeFactory getFactory( final String role )
  +        throws TypeException
       {
  +        return createFactory( role + "Selector" );
       }
   
  -    public void registerType( final String role, 
  -                              final String shorthandName, 
  -                              final TypeFactory factory ) 
  -        throws Exception
  +    protected final MultiSourceTypeFactory lookupFactory( final String role )
       {
  -        final TypedComponentSelector selector = createSelector( role + "Selector" );
  -        selector.register( shorthandName, factory );
  +        return (MultiSourceTypeFactory)m_roleMap.get( role );
       }
   
       /**
  -     * Get a selector of appropriate role.
  -     * Create a Selector if none exists with same name.
  +     * 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)
  -     * @return the Selector for interface
  -     * @exception ComponentException if role exists and not a selector, role does not 
  -     *            specify accessible work interface, or 
  +     * @return the Factory for interface
  +     * @exception TypeException role does not specify accessible work interface 
        */
  -    private TypedComponentSelector createSelector( final String role )
  -        throws ComponentException
  +    private MultiSourceTypeFactory createFactory( final String role )
  +        throws TypeException
       {
  -        TypedComponentSelector selector = (TypedComponentSelector)m_roleMap.get( role );
  -        if( null != selector ) 
  +        MultiSourceTypeFactory factory = (MultiSourceTypeFactory)m_roleMap.get( role );
  +        if( null != factory ) 
           {
  -            return selector;
  +            return factory;
           }
   
  -        if( null != m_parent )
  +        final MultiSourceTypeFactory parentFactory = getParentTypedFactory( role );   
   
  +        if( null != parentFactory )
           {
  -            final TypedComponentSelector parentSelector = getTypedSelector( m_parent, role
);
  -
  -            if( null != parentSelector )
  -            {
  -                selector = new TypedComponentSelector( parentSelector );
  -            }
  +            factory = new MultiSourceTypeFactory( parentFactory );
           }
   
  -        ///If we haven't goa selector try to create a new one
  -        if( null == selector )
  +        ///If we haven't goa factory try to create a new one
  +        if( null == factory )
           {
  -            //Precondition that role.endsWith( "Selector" )
  +            //Precondition that role.endsWith( "Factory" )
               final int length = role.length() - 8;
               final String workInterface = role.substring( 0, length );
   
  @@ -102,30 +87,29 @@
               {
                   //TODO: Should we use ContextClassLoader here ??? Or perhaps try that on
failure??
                   final Class clazz = Class.forName( workInterface );
  -                selector = new TypedComponentSelector( clazz );
  +                factory = new MultiSourceTypeFactory( clazz );
               }
               catch( final Exception e )
               {
  -                throw new ComponentException( "Role '" + role + "' does not specify " +
  -                                              "accessible work interface" );
  +                throw new TypeException( "Role '" + role + "' does not specify " +
  +                                         "accessible work interface" );
               }
           }        
   
  -        m_roleMap.put( role, selector );
  +        m_roleMap.put( role, factory );
   
  -        return selector;
  +        return factory;
       }
   
  -    private TypedComponentSelector getTypedSelector( final TypeManager typeManager, 
  -                                                     final String role )
  +    private MultiSourceTypeFactory getParentTypedFactory( final String role )
       {
  -        try
  +        if( null != m_parent )
           {
  -            return (TypedComponentSelector)typeManager.lookup( role );
  +            return m_parent.lookupFactory( role );
  +        }
  +        else
  +        {       
  +            return null;
           }
  -        catch( final ComponentException ce ) {}
  -        catch( final ClassCastException cce ) {}
  -        
  -        return null;
       }
   }
  
  
  
  1.2       +5 -5      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/type/TypeFactory.java
  
  Index: TypeFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/type/TypeFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TypeFactory.java	2001/06/03 05:31:17	1.1
  +++ TypeFactory.java	2001/06/03 06:10:05	1.2
  @@ -8,19 +8,19 @@
   package org.apache.myrmidon.components.type;
   
   /**
  - * Create a component based on role and hint.
  + * Create an instance on name.
    *
    * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
  - * @version CVS $Revision: 1.1 $ $Date: 2001/06/03 05:31:17 $
  + * @version CVS $Revision: 1.2 $ $Date: 2001/06/03 06:10:05 $
    */
   public interface TypeFactory
   {
       /**
  -     * Create a Component with appropriate name.
  +     * Create a type instance based on name.
        *
        * @param name the name
  -     * @return the created component
  -     * @exception ComponentException if an error occurs
  +     * @return the type instance
  +     * @exception TypeException if an error occurs
        */
       Object create( String name )
           throws TypeException;
  
  
  
  1.4       +5 -3      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/type/TypeManager.java
  
  Index: TypeManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/type/TypeManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TypeManager.java	2001/06/03 05:31:17	1.3
  +++ TypeManager.java	2001/06/03 06:10:05	1.4
  @@ -8,7 +8,6 @@
   package org.apache.myrmidon.components.type;
   
   import org.apache.avalon.framework.component.Component;
  -import org.apache.avalon.framework.component.ComponentManager;
   
   /**
    * The interface that is used to manage types.
  @@ -16,10 +15,13 @@
    * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
    */
   public interface TypeManager
  -    extends Component, ComponentManager
  +    extends Component
   {
       String ROLE = "org.apache.myrmidon.components.type.TypeManager";
   
       void registerType( String role, String shorthandName, TypeFactory factory )
  -        throws Exception;
  +        throws TypeException;
  +
  +    TypeFactory getFactory( String role )
  +        throws TypeException;
   }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/type/MultiSourceTypeFactory.java
  
  Index: MultiSourceTypeFactory.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.myrmidon.components.type;
  
  import java.util.HashMap;
  
  /**
   * This factory acts as a proxy to set of object factorys.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public class MultiSourceTypeFactory
      implements TypeFactory               
  {
      ///Parent Selector
      private final MultiSourceTypeFactory  m_parent;
  
      ///Map of name->factory list
      private final HashMap                 m_factorys = new HashMap();
  
      ///Type expected to be created from factorys
      private final Class                   m_type;
  
      public MultiSourceTypeFactory( final Class type )
      {
          m_type = type;
          m_parent = null;
      }
  
      public MultiSourceTypeFactory( final MultiSourceTypeFactory parent )
      {
          m_type = parent.getType();
          m_parent = parent;
      }
  
      /**
       * Populate the ComponentSelector.
       */
      public void register( final String name, final TypeFactory factory )
      {
          m_factorys.put( name, factory );
      }
  
      /**
       * Create a type instance based on name.
       *
       * @param name the name
       * @return the type instance
       * @exception TypeException if an error occurs
       */
      public Object create( final String name )
          throws TypeException
      {
          TypeFactory factory = getTypeFactory( name );
  
          if( null == factory && null != m_parent ) 
          {
              m_parent.getTypeFactory( name );
          }
  
          if( null == factory ) return null;
          else
          {
              final Object object = factory.create( name );
  
              if( !m_type.isInstance( object ) )
              {
                  throw new TypeException( "Object '" + name + "' is not of " +
                                           "correct Type (" + m_type.getName() + ")" );
              }
  
              return object;
          }
      }
  
      /**
       * Retrieve type managed by selector.
       * Used by other instances of TypedComponentSelector.
       *
       * @return the type class
       */
      protected final Class getType()
      {
          return m_type;
      }
  
      protected final TypeFactory getTypeFactory( final String name )
      {
          return (TypeFactory)m_factorys.get( name );
      }
  }
  
  
  
  1.2       +0 -2      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/converter/Converter.java
  
  Index: Converter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/converter/Converter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Converter.java	2001/06/02 14:28:43	1.1
  +++ Converter.java	2001/06/03 06:10:06	1.2
  @@ -7,7 +7,6 @@
    */
   package org.apache.myrmidon.converter;
   
  -import org.apache.avalon.framework.component.Component;
   import org.apache.avalon.framework.context.Context;
   
   /**
  @@ -16,7 +15,6 @@
    * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
    */
   public interface Converter
  -    extends Component
   {
       String ROLE = "org.apache.myrmidon.converter.Converter";
   
  
  
  

Mime
View raw message