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/embeddor DefaultEmbeddor.java
Date Sat, 23 Mar 2002 04:37:17 GMT
donaldp     02/03/22 20:37:17

  Modified:    proposal/myrmidon/src/test/org/apache/myrmidon/components
                        AbstractComponentTest.java
               proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/converter
                        ConverterRegistry.java
               proposal/myrmidon/src/java/org/apache/myrmidon/components/converter
                        DefaultMasterConverter.java
               proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor
                        DefaultEmbeddor.java
  Removed:     proposal/myrmidon/src/java/org/apache/myrmidon/components/converter
                        DefaultConverterRegistry.java
  Log:
  Merge DefaultConverterRegistry into DefaultMasterConverter
  
  Revision  Changes    Path
  1.18      +0 -3      jakarta-ant/proposal/myrmidon/src/test/org/apache/myrmidon/components/AbstractComponentTest.java
  
  Index: AbstractComponentTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/test/org/apache/myrmidon/components/AbstractComponentTest.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- AbstractComponentTest.java	21 Mar 2002 10:29:15 -0000	1.17
  +++ AbstractComponentTest.java	23 Mar 2002 04:37:16 -0000	1.18
  @@ -75,9 +75,6 @@
   
               Object component = createComponent( Converter.ROLE, DefaultMasterConverter.class
);
               m_serviceManager.put( Converter.ROLE, component );
  -            components.add( component );
  -
  -            component = createComponent( ConverterRegistry.ROLE, DefaultConverterRegistry.class
);
               m_serviceManager.put( ConverterRegistry.ROLE, component );
               components.add( component );
   
  
  
  
  1.7       +1 -11     jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/converter/ConverterRegistry.java
  
  Index: ConverterRegistry.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/converter/ConverterRegistry.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ConverterRegistry.java	21 Feb 2002 11:06:41 -0000	1.6
  +++ ConverterRegistry.java	23 Mar 2002 04:37:16 -0000	1.7
  @@ -11,21 +11,11 @@
    * Interface for registry for ConverterInfos.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.6 $ $Date: 2002/02/21 11:06:41 $
  + * @version $Revision: 1.7 $ $Date: 2002/03/23 04:37:16 $
    */
   public interface ConverterRegistry
   {
       String ROLE = ConverterRegistry.class.getName();
  -
  -    /**
  -     * Retrieve name of ConverterInfo that describes converter that converts
  -     * from source to destination.
  -     *
  -     * @param source the source classname
  -     * @param destination the destination classname
  -     * @return the className of converter or null if none available
  -     */
  -    String getConverterName( String source, String destination );
   
       /**
        * Register a converter
  
  
  
  1.25      +53 -10    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.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- DefaultMasterConverter.java	23 Mar 2002 04:21:32 -0000	1.24
  +++ DefaultMasterConverter.java	23 Mar 2002 04:37:16 -0000	1.25
  @@ -17,29 +17,34 @@
   import org.apache.avalon.framework.service.ServiceException;
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.avalon.framework.service.Serviceable;
  -import org.apache.myrmidon.interfaces.converter.ConverterRegistry;
   import org.apache.myrmidon.interfaces.type.TypeFactory;
   import org.apache.myrmidon.interfaces.type.TypeManager;
  +import org.apache.myrmidon.interfaces.converter.ConverterRegistry;
   
   /**
    * Converter engine to handle converting between types.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.24 $ $Date: 2002/03/23 04:21:32 $
  + * @version $Revision: 1.25 $ $Date: 2002/03/23 04:37:16 $
    */
   public class DefaultMasterConverter
  -    implements Converter, Serviceable
  +    implements Converter, ConverterRegistry, Serviceable
   {
       private final static Resources REZ =
           ResourceManager.getPackageResources( DefaultMasterConverter.class );
   
  -    private ConverterRegistry m_registry;
       private TypeManager m_typeManager;
   
       /** Map from converter name to Converter. */
       private Map m_converters = new HashMap();
   
       /**
  +     * This holds the mapping between source/destination
  +     * and converter name.
  +     */
  +    private final HashMap m_mapping = new HashMap();
  +
  +    /**
        * Retrieve relevent services needed to deploy.
        *
        * @param serviceManager the ServiceManager
  @@ -48,11 +53,31 @@
       public void service( final ServiceManager serviceManager )
           throws ServiceException
       {
  -        m_registry = (ConverterRegistry)serviceManager.lookup( ConverterRegistry.ROLE );
           m_typeManager = (TypeManager)serviceManager.lookup( TypeManager.ROLE );
       }
   
       /**
  +     * Register a converter
  +     *
  +     * @param className the className of converter
  +     * @param source the source classname
  +     * @param destination the destination classname
  +     */
  +    public void registerConverter( final String className,
  +                                   final String source,
  +                                   final String destination )
  +    {
  +        HashMap map = (HashMap)m_mapping.get( source );
  +        if( null == map )
  +        {
  +            map = new HashMap();
  +            m_mapping.put( source, map );
  +        }
  +
  +        map.put( destination, className );
  +    }
  +
  +    /**
        * Convert object to destination type.
        *
        * @param destination the destination type
  @@ -76,7 +101,7 @@
           try
           {
               // Search inheritance hierarchy for converter
  -            final String name = getConverterName( originalClass, destination );
  +            final String name = findConverter( originalClass, destination );
   
               // Create the converter
               Converter converter = (Converter)m_converters.get( name );
  @@ -126,8 +151,8 @@
        * Determine the name of the converter to use to convert between
        * original and destination classes.
        */
  -    private String getConverterName( final Class originalClass,
  -                                     final Class destination )
  +    private String findConverter( final Class originalClass,
  +                                  final Class destination )
           throws ConverterException
       {
           //TODO: Maybe we should search the destination classes hierarchy as well
  @@ -157,8 +182,8 @@
               }
   
               // Check if we can convert from current class to destination
  -            final String name = m_registry.getConverterName( clazz.getName(),
  -                                                             destination.getName() );
  +            final String name = getConverterClassname( clazz.getName(),
  +                                                       destination.getName() );
               if( name == null )
               {
                   continue;
  @@ -191,5 +216,23 @@
           // Could not find a converter
           final String message = REZ.getString( "no-converter.error" );
           throw new ConverterException( message );
  +    }
  +
  +    /**
  +     * Retrieve name of ConverterInfo that describes converter that converts
  +     * from source to destination.
  +     *
  +     * @param source the source classname
  +     * @param destination the destination classname
  +     * @return the className of converter or null if none available
  +     */
  +    private String getConverterClassname( final String source, final String destination
)
  +    {
  +        final HashMap map = (HashMap)m_mapping.get( source );
  +        if( null == map )
  +        {
  +            return null;
  +        }
  +        return (String)map.get( destination );
       }
   }
  
  
  
  1.35      +8 -5      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java
  
  Index: DefaultEmbeddor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- DefaultEmbeddor.java	15 Mar 2002 02:48:20 -0000	1.34
  +++ DefaultEmbeddor.java	23 Mar 2002 04:37:17 -0000	1.35
  @@ -30,7 +30,6 @@
   import org.apache.myrmidon.interfaces.builder.ProjectBuilder;
   import org.apache.myrmidon.interfaces.classloader.ClassLoaderManager;
   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.DeploymentException;
   import org.apache.myrmidon.interfaces.deployer.TypeDeployer;
  @@ -44,6 +43,7 @@
   import org.apache.myrmidon.interfaces.type.TypeFactory;
   import org.apache.myrmidon.interfaces.type.TypeManager;
   import org.apache.myrmidon.interfaces.workspace.Workspace;
  +import org.apache.myrmidon.interfaces.converter.ConverterRegistry;
   import org.apache.myrmidon.listeners.ProjectListener;
   
   /**
  @@ -51,7 +51,7 @@
    * Instantiate this to embed inside other applications.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.34 $ $Date: 2002/03/15 02:48:20 $
  + * @version $Revision: 1.35 $ $Date: 2002/03/23 04:37:17 $
    */
   public class DefaultEmbeddor
       extends AbstractLogEnabled
  @@ -253,9 +253,10 @@
           throws Exception
       {
           // Create the components
  -        createComponent( ConverterRegistry.class, PREFIX + "converter.DefaultConverterRegistry"
);
           createComponent( ExtensionManager.class, PREFIX + "extensions.DefaultExtensionManager"
);
  -        createComponent( Converter.class, PREFIX + "converter.DefaultMasterConverter" );
  +        final Object converter =
  +            createComponent( Converter.class, PREFIX + "converter.DefaultMasterConverter"
);
  +        m_serviceManager.put( ConverterRegistry.ROLE, converter );
           createComponent( Configurer.class, PREFIX + "configurer.DefaultConfigurer" );
           createComponent( TypeManager.class, PREFIX + "type.DefaultTypeManager" );
           createComponent( RoleManager.class, PREFIX + "role.DefaultRoleManager" );
  @@ -276,12 +277,14 @@
       /**
        * Creates a component.
        */
  -    private void createComponent( Class roleType, String defaultImpl )
  +    private Object createComponent( final Class roleType,
  +                                  final String defaultImpl )
           throws Exception
       {
           final Object component = createService( roleType, defaultImpl );
           m_serviceManager.put( roleType.getName(), component );
           m_components.add( component );
  +        return component;
       }
   
       /**
  
  
  

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