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/antlib/src/java/org/apache/antlib/template TemplateTaskFactory.java
Date Thu, 04 Jul 2002 13:12:21 GMT
adammurdoch    2002/07/04 06:12:21

  Modified:    container/src/test/org/apache/myrmidon/components/type/test
                        DefaultTypeManagerTestCase.java
               container/src/test/org/apache/myrmidon/interfaces/type/test
                        TypeFactoryTestCase.java
               container/src/java/org/apache/myrmidon/interfaces/type
                        ClassLoaderTypeFactory.java DefaultTypeFactory.java
                        ReloadingTypeFactory.java TypeManager.java
                        TypeRegistry.java
               antlib/src/java/org/apache/antlib/template
                        TemplateTaskFactory.java
  Log:
  - Some Javadoc fixes for the TypeFactory impls.
  - Changed DefaultTypeFactory so that it only creates instances of
    a single type.
  
  Revision  Changes    Path
  1.12      +6 -5      jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/type/test/DefaultTypeManagerTestCase.java
  
  Index: DefaultTypeManagerTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/type/test/DefaultTypeManagerTestCase.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- DefaultTypeManagerTestCase.java	30 Jun 2002 11:09:11 -0000	1.11
  +++ DefaultTypeManagerTestCase.java	4 Jul 2002 13:12:20 -0000	1.12
  @@ -10,12 +10,13 @@
   import org.apache.avalon.excalibur.i18n.Resources;
   import org.apache.myrmidon.components.AbstractComponentTest;
   import org.apache.myrmidon.components.type.DefaultTypeManager;
  +import org.apache.myrmidon.interfaces.role.RoleInfo;
  +import org.apache.myrmidon.interfaces.type.ClassLoaderTypeFactory;
   import org.apache.myrmidon.interfaces.type.DefaultTypeFactory;
   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;
  -import org.apache.myrmidon.interfaces.role.RoleInfo;
   
   /**
    * Test cases for the DefaultTypeManager
  @@ -281,9 +282,9 @@
           final Class individualClass = TYPE_CLASS2;
   
           // Create a set of types to register (all names map to Type1).
  -        DefaultTypeFactory factory = new DefaultTypeFactory();
  -        factory.addNameClassMapping( TYPE_NAME1, groupClass );
  -        factory.addNameClassMapping( TYPE_NAME2, groupClass );
  +        ClassLoaderTypeFactory factory = new ClassLoaderTypeFactory( groupClass.getClassLoader()
);
  +        factory.addNameClassMapping( TYPE_NAME1, groupClass.getName() );
  +        factory.addNameClassMapping( TYPE_NAME2, groupClass.getName() );
   
           // Register the factory
           m_typeRegistry.registerTypes( TEST_ROLE, groupNs, factory );
  
  
  
  1.5       +2 -3      jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/interfaces/type/test/TypeFactoryTestCase.java
  
  Index: TypeFactoryTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/interfaces/type/test/TypeFactoryTestCase.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TypeFactoryTestCase.java	22 May 2002 07:36:23 -0000	1.4
  +++ TypeFactoryTestCase.java	4 Jul 2002 13:12:20 -0000	1.5
  @@ -45,8 +45,7 @@
           throws Exception
       {
           // Make sure an instance of the expected class is created
  -        final DefaultTypeFactory factory = new DefaultTypeFactory();
  -        factory.addNameClassMapping( TYPE_NAME2, TYPE_CLASS2 );
  +        final DefaultTypeFactory factory = new DefaultTypeFactory( TYPE_NAME2, TYPE_CLASS2
);
   
           final Object type = factory.create( TYPE_NAME2 );
           final Class typeClass = type.getClass();
  
  
  
  1.3       +2 -2      jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/type/ClassLoaderTypeFactory.java
  
  Index: ClassLoaderTypeFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/type/ClassLoaderTypeFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ClassLoaderTypeFactory.java	23 May 2002 09:18:40 -0000	1.2
  +++ ClassLoaderTypeFactory.java	4 Jul 2002 13:12:20 -0000	1.3
  @@ -23,7 +23,7 @@
       implements TypeFactory
   {
       private static final Resources REZ =
  -        ResourceManager.getPackageResources( DefaultTypeFactory.class );
  +        ResourceManager.getPackageResources( ClassLoaderTypeFactory.class );
   
       ///A Map of shortnames to classnames
       private final HashMap m_classNames = new HashMap();
  
  
  
  1.16      +36 -33    jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/type/DefaultTypeFactory.java
  
  Index: DefaultTypeFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/type/DefaultTypeFactory.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- DefaultTypeFactory.java	23 May 2002 09:18:40 -0000	1.15
  +++ DefaultTypeFactory.java	4 Jul 2002 13:12:20 -0000	1.16
  @@ -7,13 +7,11 @@
    */
   package org.apache.myrmidon.interfaces.type;
   
  -import java.util.HashMap;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
   
   /**
  - * A {@link TypeFactory} implementation that creates instances using classes
  - * from the same classloader.
  + * A {@link TypeFactory} implementation that creates instances of a single type.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
    * @version CVS $Revision$ $Date$
  @@ -23,34 +21,42 @@
   {
       private static final Resources REZ =
           ResourceManager.getPackageResources( DefaultTypeFactory.class );
  -
  -    /** A Map from type name to implementing Class. */
  -    private final HashMap m_typeMap = new HashMap();
  -
  -    /**
  -     * Creates a factory, with no type mappings.
  -     */
  -    public DefaultTypeFactory()
  -    {
  -    }
  +    private final String m_name;
  +    private Class m_implClass;
  +    private final ClassLoader m_classLoader;
  +    private final String m_implClassName;
   
       /**
  -     * Creates a factory, with a single type mapping.  Additional mappings
  -     * can be added using {@link #addNameClassMapping}.
  +     * Creates a factory, that creates instances of the given type.
  +     *
  +     * @param name The type name.
  +     * @param implClass The implementing class.  Must be public and have a
  +     *        public no-args constructor.
        */
       public DefaultTypeFactory( final String name, final Class implClass )
       {
  -        addNameClassMapping( name, implClass );
  +        m_name = name;
  +        m_implClass = implClass;
  +        m_implClassName = implClass.getName();
  +        m_classLoader = null;
       }
   
       /**
  -     * Map a type name to the Class that implements the type.
  +     * Creates a factory, that creates instances of the given type.
  +     *
        * @param name The type name.
  -     * @param implClass The implementing Class.
  +     * @param implClass The name of the implementing class.  Must be public
  +     *        and have a public no-args constructor.
  +     * @param classLoader The ClassLoader to use to load the implementing class.
        */
  -    public void addNameClassMapping( final String name, final Class implClass )
  -    {
  -        m_typeMap.put( name, implClass );
  +    public DefaultTypeFactory( final String name,
  +                               final String implClass,
  +                               final ClassLoader classLoader )
  +    {
  +        m_name = name;
  +        m_implClass = null;
  +        m_implClassName = implClass;
  +        m_classLoader = classLoader;
       }
   
       /**
  @@ -58,7 +64,7 @@
        */
       public boolean canCreate( final String name )
       {
  -        return ( getClassForType( name ) != null );
  +        return m_name.equals( name );
       }
   
       /**
  @@ -67,9 +73,7 @@
       public Object create( final String name )
           throws TypeException
       {
  -        // Determine the name of the class to instantiate
  -        final Class clazz = getClassForType( name );
  -        if( null == clazz )
  +        if( !m_name.equals( name ) )
           {
               final String message = REZ.getString( "no-mapping.error", name );
               throw new TypeException( message );
  @@ -78,17 +82,16 @@
           // Instantiate the object
           try
           {
  -            return clazz.newInstance();
  +            if( m_implClass == null)
  +            {
  +                m_implClass = m_classLoader.loadClass( m_implClassName );
  +            }
  +            return m_implClass.newInstance();
           }
           catch( final Exception e )
           {
  -            final String message = REZ.getString( "no-instantiate.error", name, clazz.getName()
);
  +            final String message = REZ.getString( "no-instantiate.error", m_name, m_implClassName
);
               throw new TypeException( message, e );
           }
  -    }
  -
  -    private Class getClassForType( final String name )
  -    {
  -        return (Class)m_typeMap.get( name );
       }
   }
  
  
  
  1.5       +2 -2      jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/type/ReloadingTypeFactory.java
  
  Index: ReloadingTypeFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/type/ReloadingTypeFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ReloadingTypeFactory.java	22 May 2002 07:36:23 -0000	1.4
  +++ ReloadingTypeFactory.java	4 Jul 2002 13:12:21 -0000	1.5
  @@ -52,7 +52,7 @@
       }
   
       /**
  -     * @see DefaultTypeFactory
  +     * @see ClassLoaderTypeFactory
        */
       protected ClassLoader getClassLoader()
       {
  
  
  
  1.20      +2 -2      jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/type/TypeManager.java
  
  Index: TypeManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/type/TypeManager.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- TypeManager.java	30 Jun 2002 11:09:11 -0000	1.19
  +++ TypeManager.java	4 Jul 2002 13:12:21 -0000	1.20
  @@ -8,7 +8,7 @@
   package org.apache.myrmidon.interfaces.type;
   
   /**
  - * This interface is used to lookup type factories.
  + * This interface is used to create instances of types.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
    * @author <a href="mailto:darrell@apache.org">Darrell DeBoer</a>
  
  
  
  1.3       +2 -2      jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/type/TypeRegistry.java
  
  Index: TypeRegistry.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/type/TypeRegistry.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TypeRegistry.java	30 Jun 2002 11:09:11 -0000	1.2
  +++ TypeRegistry.java	4 Jul 2002 13:12:21 -0000	1.3
  @@ -48,7 +48,7 @@
           throws TypeException;
   
       /**
  -     * Returns the factory for a role.
  +     * Returns the factory for types of a role.
        *
        * @param roleName The role for the type.
        * @return The TypeFactory for the named role.
  
  
  
  1.2       +2 -2      jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/template/TemplateTaskFactory.java
  
  Index: TemplateTaskFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/template/TemplateTaskFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TemplateTaskFactory.java	28 Jun 2002 09:02:07 -0000	1.1
  +++ TemplateTaskFactory.java	4 Jul 2002 13:12:21 -0000	1.2
  @@ -11,7 +11,7 @@
   import org.apache.myrmidon.interfaces.type.TypeException;
   
   /**
  - * 
  + * A {@link TypeFactory} that creates template tasks.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
    * @version $Revision$ $Date$
  
  
  

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