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/java/org/apache/myrmidon/components/role DefaultRoleManager.java
Date Sun, 09 Jun 2002 13:20:47 GMT
donaldp     2002/06/09 06:20:47

  Modified:    container/src/java/org/apache/myrmidon/interfaces/role
                        RoleInfo.java RoleManager.java
               framework/src/java/org/apache/myrmidon/framework
                        AbstractTypeDef.java AbstractContainerTask.java
               container/src/java/org/apache/myrmidon/components/workspace
                        DefaultTaskContext.java
               container/src/java/org/apache/myrmidon/components/configurer
                        DefaultConfigurer.java ClassicConfigurer.java
               container/src/java/org/apache/myrmidon/components/role
                        DefaultRoleManager.java
  Log:
  Reworked RoleManager so that it explicitly uses terms InterfaceName and ShortName.
  
  This has the aim of reducing the arbitrary nature of whether or not to use short name or
long name as part of role string.
  
  Revision  Changes    Path
  1.8       +21 -12    jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/role/RoleInfo.java
  
  Index: RoleInfo.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/role/RoleInfo.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- RoleInfo.java	9 Jun 2002 09:47:33 -0000	1.7
  +++ RoleInfo.java	9 Jun 2002 13:20:46 -0000	1.8
  @@ -15,7 +15,7 @@
    * A role definition.  Role definitions are immutable.
    *
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
  - * @version $Revision: 1.7 $ $Date: 2002/06/09 09:47:33 $
  + * @version $Revision: 1.8 $ $Date: 2002/06/09 13:20:46 $
    */
   public final class RoleInfo
   {
  @@ -25,7 +25,7 @@
       /** The classname of the custom type deployer for this role. */
       public static final String ATTRIBUTE_CUSTOM_TYPE_DEPLOYER = "type-deployer";
   
  -    private final String m_name;
  +    private final String m_shortName;
       private final Class m_type;
       private final Map m_attributes;
       private final Map m_readOnlyAttributes;
  @@ -35,9 +35,9 @@
        *
        * @see #RoleInfo( String, Class, Map )
        */
  -    public RoleInfo( final String name )
  +    public RoleInfo( final String shortName )
       {
  -        this( name, null, null );
  +        this( shortName, null, null );
       }
   
       /**
  @@ -45,23 +45,23 @@
        *
        * @see #RoleInfo( String, Class, Map )
        */
  -    public RoleInfo( final String name, final Class type )
  +    public RoleInfo( final String shortName, final Class type )
       {
  -        this( name, type, null );
  +        this( shortName, type, null );
       }
   
       /**
        * Creates a role definition.
        *
  -     * @param name The role name.
  +     * @param shortName The role name.
        * @param type The role implementation class.  May be null.
        * @param attributes Additional meta-information for the role.  May be null.
        */
  -    public RoleInfo( final String name,
  +    public RoleInfo( final String shortName,
                        final Class type,
                        final Map attributes )
       {
  -        m_name = name;
  +        m_shortName = shortName;
           m_type = type;
           if( attributes == null || attributes.size() == 0 )
           {
  @@ -86,7 +86,7 @@
           {
               return false;
           }
  -        if( !m_name.equals( role.m_name ) )
  +        if( !m_shortName.equals( role.m_shortName ) )
           {
               return false;
           }
  @@ -101,9 +101,18 @@
        * Provides this role's name, which uniquely identifies the role.
        * @return The role name.
        */
  -    public String getName()
  +    public String getShortName()
       {
  -        return m_name;
  +        return m_shortName;
  +    }
  +
  +    /**
  +     * Provides this role's name, which uniquely identifies the role.
  +     * @return The role name.
  +     */
  +    public String getInterfaceName()
  +    {
  +        return m_type.getName();
       }
   
       /**
  
  
  
  1.12      +7 -7      jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/role/RoleManager.java
  
  Index: RoleManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/role/RoleManager.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- RoleManager.java	25 Apr 2002 01:41:50 -0000	1.11
  +++ RoleManager.java	9 Jun 2002 13:20:46 -0000	1.12
  @@ -15,7 +15,7 @@
    * @author <a href="mailto:giacomo@apache,org">Giacomo Pati</a>
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
  - * @version CVS $Revision: 1.11 $ $Date: 2002/04/25 01:41:50 $
  + * @version CVS $Revision: 1.12 $ $Date: 2002/06/09 13:20:46 $
    */
   public interface RoleManager
   {
  @@ -23,18 +23,18 @@
       String ROLE = RoleManager.class.getName();
   
       /**
  -     * Find role based on role implementation class.
  +     * Find role based on name.
        *
  -     * @param type the role type.
  +     * @param name the role name
        * @return the role, or null if the role cannot be found.
        */
  -    RoleInfo getRoleByImplementationClass( Class type );
  +    RoleInfo getRoleByShortName( String name );
   
       /**
  -     * Find role based on name.
  +     * Find role based on classname.
        *
  -     * @param name the role name
  +     * @param classname the classname
        * @return the role, or null if the role cannot be found.
        */
  -    RoleInfo getRole( String name );
  +    RoleInfo getRoleByInterface( String classname );
   }
  
  
  
  1.10      +18 -1     jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/AbstractTypeDef.java
  
  Index: AbstractTypeDef.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/AbstractTypeDef.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- AbstractTypeDef.java	22 May 2002 07:44:02 -0000	1.9
  +++ AbstractTypeDef.java	9 Jun 2002 13:20:46 -0000	1.10
  @@ -15,12 +15,14 @@
   import org.apache.myrmidon.framework.file.Path;
   import org.apache.myrmidon.interfaces.library.Library;
   import org.apache.myrmidon.interfaces.library.LibraryManager;
  +import org.apache.myrmidon.interfaces.role.RoleInfo;
  +import org.apache.myrmidon.interfaces.role.RoleManager;
   
   /**
    * Abstract task to extend to define a type.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.9 $ $Date: 2002/05/22 07:44:02 $
  + * @version $Revision: 1.10 $ $Date: 2002/06/09 13:20:46 $
    */
   public abstract class AbstractTypeDef
       extends AbstractContainerTask
  @@ -80,6 +82,21 @@
           {
               throw new TaskException( e.getMessage(), e );
           }
  +    }
  +
  +    /**
  +     * Retrieve the shortname for the specified role.
  +     *
  +     * @param role the role name
  +     * @return the shortname
  +     * @throws TaskException if unable to lcoate role
  +     */
  +    protected String getShortNameForRole( final String role )
  +        throws TaskException
  +    {
  +        final RoleManager roleManager = (RoleManager)getService( RoleManager.class );
  +        final RoleInfo roleInfo = roleManager.getRoleByInterface( role );
  +        return roleInfo.getShortName();
       }
   
       /**
  
  
  
  1.7       +6 -5      jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/AbstractContainerTask.java
  
  Index: AbstractContainerTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/AbstractContainerTask.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- AbstractContainerTask.java	23 May 2002 01:50:26 -0000	1.6
  +++ AbstractContainerTask.java	9 Jun 2002 13:20:46 -0000	1.7
  @@ -7,8 +7,8 @@
    */
   package org.apache.myrmidon.framework;
   
  -import org.apache.aut.converter.Converter;
  -import org.apache.aut.converter.ConverterException;
  +import org.apache.excalibur.converter.Converter;
  +import org.apache.excalibur.converter.ConverterException;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
   import org.apache.myrmidon.api.AbstractTask;
  @@ -29,7 +29,7 @@
    * This is the class that Task writers should extend to provide custom tasks.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.6 $ $Date: 2002/05/23 01:50:26 $
  + * @version $Revision: 1.7 $ $Date: 2002/06/09 13:20:46 $
    */
   public abstract class AbstractContainerTask
       extends AbstractTask
  @@ -180,7 +180,7 @@
           try
           {
               final RoleInfo role = getRoleByType( roleType );
  -            final TypeFactory typeFactory = getTypeFactory( role.getName() );
  +            final TypeFactory typeFactory = getTypeFactory( role.getShortName() );
               return typeFactory.create( typeName );
           }
           catch( Exception e )
  @@ -217,7 +217,8 @@
           throws TaskException
       {
           final RoleManager roleManager = (RoleManager)getService( RoleManager.class );
  -        final RoleInfo role = roleManager.getRoleByImplementationClass( roleType );
  +        final RoleInfo role =
  +            roleManager.getRoleByInterface( roleType.getName() );
           if( role == null )
           {
               final String message = REZ.getString( "container.unknown-role-type.error",
roleType.getName() );
  
  
  
  1.51      +4 -1      jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/workspace/DefaultTaskContext.java
  
  Index: DefaultTaskContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/workspace/DefaultTaskContext.java,v
  retrieving revision 1.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- DefaultTaskContext.java	28 May 2002 02:04:14 -0000	1.50
  +++ DefaultTaskContext.java	9 Jun 2002 13:20:46 -0000	1.51
  @@ -29,7 +29,7 @@
    * Default implementation of TaskContext.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.50 $ $Date: 2002/05/28 02:04:14 $
  + * @version $Revision: 1.51 $ $Date: 2002/06/09 13:20:46 $
    */
   public class DefaultTaskContext
       implements TaskContext
  @@ -126,6 +126,7 @@
           final ServiceManager serviceManager = m_frame.getServiceManager();
           try
           {
  +/*
               // Map the service class to the role name for that service
               final RoleManager roleManager = (RoleManager)serviceManager.lookup( RoleManager.ROLE
);
               final RoleInfo roleInfo = roleManager.getRoleByImplementationClass( clazz );
  @@ -140,7 +141,9 @@
               {
                   roleName = classname;
               }
  +*/
   
  +            final String roleName = classname;
               // Lookup the service by role name.  Note that this will chain
               // up to parent ServiceManagers (if any)
               if( serviceManager.hasService( roleName ) )
  
  
  
  1.52      +13 -10    jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/configurer/DefaultConfigurer.java
  
  Index: DefaultConfigurer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/configurer/DefaultConfigurer.java,v
  retrieving revision 1.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- DefaultConfigurer.java	23 May 2002 09:18:09 -0000	1.51
  +++ DefaultConfigurer.java	9 Jun 2002 13:20:46 -0000	1.52
  @@ -9,14 +9,14 @@
   
   import java.util.HashMap;
   import java.util.Map;
  -import org.apache.aut.converter.Converter;
  -import org.apache.aut.converter.ConverterException;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.avalon.framework.service.ServiceException;
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.avalon.framework.service.Serviceable;
  +import org.apache.excalibur.converter.Converter;
  +import org.apache.excalibur.converter.ConverterException;
   import org.apache.myrmidon.api.TaskContext;
   import org.apache.myrmidon.api.metadata.ModelElement;
   import org.apache.myrmidon.api.metadata.ModelException;
  @@ -32,7 +32,7 @@
    * Class used to configure tasks.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.51 $ $Date: 2002/05/23 09:18:09 $
  + * @version $Revision: 1.52 $ $Date: 2002/06/09 13:20:46 $
    * @ant.type type="configurer" name="default"
    */
   public class DefaultConfigurer
  @@ -559,9 +559,9 @@
                   else
                   {
                       // Check the role name
  -                    final RoleInfo roleInfo =
  -                        m_roleManager.getRoleByImplementationClass( propertyConfigurer.getType()
);
  -                    if( roleInfo != null && name.equalsIgnoreCase( roleInfo.getName()
) )
  +                    final String classname = propertyConfigurer.getType().getName();
  +                    final RoleInfo roleInfo = m_roleManager.getRoleByInterface( classname
);
  +                    if( roleInfo != null && name.equalsIgnoreCase( roleInfo.getShortName()
) )
                       {
                           return propertyConfigurer;
                       }
  @@ -580,14 +580,16 @@
       {
           // Map the expected type to a role.  If found, instantiate the default
           // type for that role
  -        final RoleInfo roleInfo = m_roleManager.getRoleByImplementationClass( type );
  +        final RoleInfo roleInfo =
  +            m_roleManager.getRoleByInterface( type.getName() );
           if( roleInfo != null )
           {
               final String typeName = roleInfo.getDefaultTypeName();
               if( typeName != null )
               {
                   // Create the instance
  -                final TypeFactory factory = m_typeManager.getFactory( roleInfo.getName()
);
  +                final TypeFactory factory =
  +                    m_typeManager.getFactory( roleInfo.getInterfaceName() );
                   return factory.create( typeName );
               }
           }
  @@ -612,10 +614,11 @@
       {
           // Map the expected type to a role.  If found, attempt to create
           // an instance
  -        final RoleInfo roleInfo = m_roleManager.getRoleByImplementationClass( type );
  +        final RoleInfo roleInfo =
  +            m_roleManager.getRoleByInterface( type.getName() );
           if( roleInfo != null )
           {
  -            final TypeFactory factory = m_typeManager.getFactory( roleInfo.getName() );
  +            final TypeFactory factory = m_typeManager.getFactory( roleInfo.getInterfaceName()
);
               if( factory.canCreate( name ) )
               {
                   return factory.create( name );
  
  
  
  1.15      +2 -2      jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/configurer/ClassicConfigurer.java
  
  Index: ClassicConfigurer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/configurer/ClassicConfigurer.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- ClassicConfigurer.java	23 May 2002 01:50:25 -0000	1.14
  +++ ClassicConfigurer.java	9 Jun 2002 13:20:46 -0000	1.15
  @@ -10,8 +10,6 @@
   import java.lang.reflect.InvocationTargetException;
   import java.lang.reflect.Method;
   import java.util.ArrayList;
  -import org.apache.aut.converter.Converter;
  -import org.apache.aut.converter.ConverterException;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
  @@ -19,6 +17,8 @@
   import org.apache.avalon.framework.service.ServiceException;
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.avalon.framework.service.Serviceable;
  +import org.apache.excalibur.converter.Converter;
  +import org.apache.excalibur.converter.ConverterException;
   import org.apache.myrmidon.api.TaskContext;
   import org.apache.myrmidon.api.TaskException;
   import org.apache.myrmidon.api.metadata.ModelElement;
  
  
  
  1.14      +13 -11    jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/role/DefaultRoleManager.java
  
  Index: DefaultRoleManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/role/DefaultRoleManager.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- DefaultRoleManager.java	25 Apr 2002 01:41:50 -0000	1.13
  +++ DefaultRoleManager.java	9 Jun 2002 13:20:47 -0000	1.14
  @@ -19,7 +19,7 @@
    * Interface to manage roles and mapping to names.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version CVS $Revision: 1.13 $ $Date: 2002/04/25 01:41:50 $
  + * @version CVS $Revision: 1.14 $ $Date: 2002/06/09 13:20:47 $
    */
   public class DefaultRoleManager
       implements RoleManager, RoleRegistry
  @@ -58,16 +58,16 @@
       /**
        * Find role based on role type.
        *
  -     * @param type the role type.
  +     * @param classname the role type.
        * @return the role, or null if the role cannot be found.
        */
  -    public RoleInfo getRoleByImplementationClass( final Class type )
  +    public RoleInfo getRoleByInterface( final String classname )
       {
  -        final RoleInfo role = (RoleInfo)m_typeMap.get( type );
  +        final RoleInfo role = (RoleInfo)m_typeMap.get( classname );
   
           if( null == role && null != m_parent )
           {
  -            return m_parent.getRoleByImplementationClass( type );
  +            return m_parent.getRoleByInterface( classname );
           }
   
           return role;
  @@ -79,13 +79,13 @@
        * @param name the role name
        * @return the role, or null if the role cannot be found.
        */
  -    public RoleInfo getRole( final String name )
  +    public RoleInfo getRoleByShortName( final String name )
       {
           final RoleInfo role = (RoleInfo)m_nameMap.get( name );
   
           if( null == role && null != m_parent )
           {
  -            return m_parent.getRole( name );
  +            return m_parent.getRoleByShortName( name );
           }
   
           return role;
  @@ -97,7 +97,7 @@
       public void addRole( final RoleInfo role ) throws RoleException
       {
           // Check for duplicate role names
  -        final String roleName = role.getName();
  +        final String roleName = role.getShortName();
           RoleInfo oldRole = (RoleInfo)m_nameMap.get( roleName );
           if( null != oldRole && !oldRole.equals( role ) )
           {
  @@ -109,10 +109,12 @@
           final Class roleImplClass = role.getImplementationClass();
           if( roleImplClass != null )
           {
  -            oldRole = (RoleInfo)m_typeMap.get( roleImplClass );
  +            final String classname = roleImplClass.getName();
  +            oldRole = (RoleInfo)m_typeMap.get( classname );
               if( null != oldRole && !oldRole.equals( role ) )
               {
  -                final String message = REZ.getString( "duplicate-type.error", roleImplClass.getName()
);
  +                final String message =
  +                    REZ.getString( "duplicate-type.error", classname );
                   throw new RoleException( message );
               }
           }
  @@ -121,7 +123,7 @@
           m_nameMap.put( roleName, role );
           if( roleImplClass != null )
           {
  -            m_typeMap.put( roleImplClass, role );
  +            m_typeMap.put( roleImplClass.getName(), role );
           }
       }
   }
  
  
  

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