adammurdoch    02/02/21 04:52:08

  Modified:    
proposal/myrmidon/src/testcases/org/apache/myrmidon/components/deployer
                        DefaultDeployerTest.java
               
proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer
                        DefaultConfigurerTest.java
               proposal/myrmidon/src/testcases/org/apache/myrmidon/components
                        AbstractComponentTest.java
               proposal/myrmidon/src/manifest builtin-ant-roles.xml
               proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/role
                        RoleManager.java
               proposal/myrmidon/src/java/org/apache/myrmidon/components/role
                        DefaultRoleManager.java Resources.properties
               
proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer
                        DefaultDeployer.java Deployment.java
                        Resources.properties
               
proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer
                        DefaultConfigurer.java
  Added:       
proposal/myrmidon/src/testcases/org/apache/myrmidon/components/role
                        DefaultRoleManagerTest.java
               proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/role
                        RoleException.java RoleInfo.java
  Log:
  Changes to RoleManager:
  
  * A class may now be explicitly associated with a role, rather than being
    implicit in the role name.
  
  * Added RoleInfo to bundle up role meta-info.
  
  * Reworked the methods of RoleManager.
  
  * Added test-cases for DefaultRoleManager.
  
  * Make tests compile again.
  
  Revision  Changes    Path
  1.1                  
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/role/DefaultRoleManagerTest.java
  
  Index: DefaultRoleManagerTest.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.txt file.
   */
  package org.apache.myrmidon.components.role;
  
  import org.apache.myrmidon.AbstractMyrmidonTest;
  import org.apache.myrmidon.api.Task;
  import org.apache.myrmidon.interfaces.role.RoleManager;
  import org.apache.myrmidon.interfaces.role.RoleInfo;
  import org.apache.myrmidon.interfaces.role.RoleException;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  
  /**
   * Test cases for the DefaultRoleManager.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/02/21 12:52:07 $
   */
  public class DefaultRoleManagerTest
      extends AbstractMyrmidonTest
  {
      private final static Resources REZ
          = ResourceManager.getPackageResources( DefaultRoleManagerTest.class );
  
      private RoleManager m_roleManager;
  
      public DefaultRoleManagerTest( String name )
      {
          super( name );
      }
  
      protected void setUp() throws Exception
      {
          m_roleManager = new DefaultRoleManager();
      }
  
      /**
       * Tests looking up a role by name, shorthand and type.
       */
      public void testLookup() throws Exception
      {
          final String roleName = "role-name";
          final String shorthand = "role-shorthand";
          final RoleInfo origRole = new RoleInfo( roleName, shorthand, 
Task.class );
          m_roleManager.addRole( origRole );
  
          // Lookup the role
          RoleInfo role = m_roleManager.getRole( roleName );
          assertTrue( origRole.equals(role) );
  
          // Lookup the role by shorthand
          role = m_roleManager.getRoleByShorthandName( shorthand );
          assertTrue( origRole.equals( role ) );
  
          // Lookup the role by type
          role = m_roleManager.getRoleByType( Task.class );
          assertTrue( origRole.equals( role ) );
  
          // Lookup an unknown role
          RoleInfo unknownRole = m_roleManager.getRole( "unknown" );
          assertNull( unknownRole );
  
          // Lookup an unknown shorthand
          unknownRole = m_roleManager.getRoleByShorthandName( "unknown" );
          assertNull( unknownRole );
  
          // Lookup an unknown role
          unknownRole = m_roleManager.getRoleByType( 
DefaultRoleManagerTest.class );
          assertNull( unknownRole );
      }
  
      /**
       * Tests inheriting roles from parent role manager.
       */
      public void testParent() throws Exception
      {
          final String roleName = "role-name";
          final String shorthand = "shorthand";
          final RoleInfo origRole = new RoleInfo( roleName, shorthand, 
Task.class );
          m_roleManager.addRole( origRole );
          final RoleManager roleManager = new DefaultRoleManager( m_roleManager 
);
  
          // Lookup by name
          RoleInfo roleInfo = roleManager.getRole( roleName );
          assertTrue( origRole.equals( roleInfo ) );
  
          // Lookup by shorthand
          roleInfo = roleManager.getRoleByShorthandName( shorthand );
          assertTrue( origRole.equals( roleInfo ) );
  
          // Lookup by type
          roleInfo = roleManager.getRoleByType( Task.class );
          assertTrue( origRole.equals( roleInfo ) );
      }
  
      /**
       * Tests overriding a role in a child role manager.
       */
      public void testOverrideName() throws Exception
      {
          final String roleName = "role-name";
          final String shorthand = "shorthand";
  
          // Add original role
          final RoleInfo origRole = new RoleInfo( roleName, shorthand, 
Task.class );
          m_roleManager.addRole( origRole );
  
          // Override role
          final RoleManager roleManager = new DefaultRoleManager( m_roleManager 
);
          final RoleInfo overrideNameRole = new RoleInfo( roleName, 
"shorthand1" );
          roleManager.addRole( overrideNameRole );
          final RoleInfo overrideShorthandRole = new RoleInfo( "role2", 
shorthand );
          roleManager.addRole( overrideShorthandRole );
          final RoleInfo overrideTypeRole = new RoleInfo( "role3", 
"shorthand3", Task.class );
          roleManager.addRole( overrideTypeRole );
  
          // Lookup role by name
          RoleInfo roleInfo = roleManager.getRole( roleName );
          assertTrue( overrideNameRole.equals( roleInfo ) );
  
          // Lookup role by shorthand
          roleInfo = roleManager.getRoleByShorthandName( shorthand );
          assertTrue( overrideShorthandRole.equals( roleInfo ) );
  
          // Lookup role by type
          roleInfo = roleManager.getRoleByType( Task.class );
          assertTrue( overrideTypeRole.equals( roleInfo ) );
      }
  
      /**
       * Tests adding duplicate roles.
       */
      public void testDuplicate() throws Exception
      {
          final String roleName = "role-name";
          final String shorthand = "shorthand";
          final RoleInfo origRole = new RoleInfo( roleName, shorthand, 
Task.class );
          m_roleManager.addRole( origRole );
  
          // Duplicate role name
          try
          {
              m_roleManager.addRole( new RoleInfo( roleName ) );
              fail();
          }
          catch( RoleException exc )
          {
              final String message = REZ.getString( "duplicate-role.error", 
roleName );
              assertSameMessage( message, exc );
          }
  
          // Duplicate shorthand
          try
          {
              m_roleManager.addRole( new RoleInfo( "another-role", shorthand ) 
);
              fail();
          }
          catch( RoleException exc )
          {
              final String message = REZ.getString( 
"duplicate-shorthand.error", shorthand );
              assertSameMessage( message, exc );
          }
  
          // Duplicate type
          try
          {
              m_roleManager.addRole( new RoleInfo( null, Task.class ) );
              fail();
          }
          catch( RoleException exc )
          {
              final String message = REZ.getString( "duplicate-type.error", 
Task.class.getName() );
              assertSameMessage( message, exc );
          }
      }
  
  }
  
  
  
  1.9       +4 -2      
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/deployer/DefaultDeployerTest.java
  
  Index: DefaultDeployerTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/deployer/DefaultDeployerTest.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DefaultDeployerTest.java  21 Feb 2002 11:06:41 -0000      1.8
  +++ DefaultDeployerTest.java  21 Feb 2002 12:52:07 -0000      1.9
  @@ -15,6 +15,7 @@
   import org.apache.myrmidon.interfaces.deployer.TypeDefinition;
   import org.apache.myrmidon.interfaces.deployer.TypeDeployer;
   import org.apache.myrmidon.interfaces.role.RoleManager;
  +import org.apache.myrmidon.interfaces.role.RoleInfo;
   import org.apache.myrmidon.interfaces.type.TypeFactory;
   import org.apache.myrmidon.interfaces.type.TypeManager;
   import org.apache.myrmidon.interfaces.type.TypeException;
  @@ -32,6 +33,7 @@
   {
       private static final String TEST_TYPE1_NAME = "test-type1";
       private static final String DATA_TYPE_ROLE = "data-type";
  +    private static final String CONVERTER_ROLE = "converter";
   
       private Deployer m_deployer;
       private RoleManager m_roleManager;
  @@ -54,8 +56,8 @@
   
           // Add some core roles
           m_roleManager = (RoleManager)getServiceManager().lookup( 
RoleManager.ROLE );
  -        m_roleManager.addNameRoleMapping( DATA_TYPE_ROLE, DataType.ROLE );
  -        m_roleManager.addNameRoleMapping( "converter", Converter.ROLE );
  +        m_roleManager.addRole( new RoleInfo( DataType.ROLE, DATA_TYPE_ROLE, 
DataType.class ) );
  +        m_roleManager.addRole( new RoleInfo( Converter.ROLE, CONVERTER_ROLE, 
Converter.class ) );
       }
   
       /**
  
  
  
  1.14      +33 -26    
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/DefaultConfigurerTest.java
  
  Index: DefaultConfigurerTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/DefaultConfigurerTest.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- DefaultConfigurerTest.java        21 Feb 2002 11:06:41 -0000      1.13
  +++ DefaultConfigurerTest.java        21 Feb 2002 12:52:07 -0000      1.14
  @@ -13,12 +13,15 @@
   import org.apache.avalon.excalibur.i18n.Resources;
   import org.apache.avalon.framework.configuration.ConfigurationException;
   import org.apache.avalon.framework.configuration.DefaultConfiguration;
  +import org.apache.avalon.framework.context.Context;
   import org.apache.myrmidon.api.TaskContext;
   import org.apache.myrmidon.components.AbstractComponentTest;
   import org.apache.myrmidon.components.workspace.DefaultTaskContext;
   import org.apache.myrmidon.framework.DataType;
   import org.apache.myrmidon.interfaces.configurer.Configurer;
  +import org.apache.myrmidon.interfaces.configurer.TaskContextAdapter;
   import org.apache.myrmidon.interfaces.role.RoleManager;
  +import org.apache.myrmidon.interfaces.role.RoleInfo;
   import org.apache.myrmidon.interfaces.type.DefaultTypeFactory;
   
   /**
  @@ -34,6 +37,7 @@
   
       private Configurer m_configurer;
       private DefaultTaskContext m_context;
  +    private Context m_adaptor;
   
       public DefaultConfigurerTest( String name )
       {
  @@ -55,6 +59,7 @@
           m_context = new DefaultTaskContext();
           final File baseDir = new File( "." ).getAbsoluteFile();
           m_context.setProperty( TaskContext.BASE_DIRECTORY, baseDir );
  +        m_adaptor = new TaskContextAdapter( m_context );
       }
   
       /**
  @@ -73,7 +78,7 @@
           final ConfigTest1 test = new ConfigTest1();
   
           // Configure the object
  -        m_configurer.configure( test, config, m_context );
  +        m_configurer.configure( test, config, m_adaptor );
   
           // Check result
           final ConfigTest1 expected = new ConfigTest1();
  @@ -102,7 +107,7 @@
           final ConfigTest10 test = new ConfigTest10();
   
           // Configure the object
  -        m_configurer.configure( test, config, m_context );
  +        m_configurer.configure( test, config, m_adaptor );
   
           // Check result
           final ConfigTest10 expected = new ConfigTest10();
  @@ -126,7 +131,7 @@
           // Configure the object
           try
           {
  -            m_configurer.configure( test, config, m_context );
  +            m_configurer.configure( test, config, m_adaptor );
               fail();
           }
           catch( final ConfigurationException ce )
  @@ -156,7 +161,7 @@
           final ConfigTest2 test = new ConfigTest2();
   
           // Configure the object
  -        m_configurer.configure( test, config, m_context );
  +        m_configurer.configure( test, config, m_adaptor );
   
           // Check result
           final ConfigTest2 expected = new ConfigTest2();
  @@ -185,7 +190,7 @@
           // Configure the object
           try
           {
  -            m_configurer.configure( test, config, m_context );
  +            m_configurer.configure( test, config, m_adaptor );
               fail();
           }
           catch( final ConfigurationException ce )
  @@ -209,7 +214,7 @@
           final ConfigTest1 test = new ConfigTest1();
   
           // Configure the object
  -        m_configurer.configure( test, config, m_context );
  +        m_configurer.configure( test, config, m_adaptor );
   
           // Check result
           final ConfigTest1 expected = new ConfigTest1();
  @@ -232,7 +237,7 @@
           // Configure the object
           try
           {
  -            m_configurer.configure( test, config, m_context );
  +            m_configurer.configure( test, config, m_adaptor );
               fail();
           }
           catch( final ConfigurationException ce )
  @@ -257,7 +262,7 @@
           m_context.setProperty( "prop-a", "other" );
   
           // Configure the object
  -        m_configurer.configure( test, config, m_context );
  +        m_configurer.configure( test, config, m_adaptor );
   
           // Check the configured object
           final ConfigTest1 expected = new ConfigTest1();
  @@ -279,7 +284,7 @@
           m_context.setProperty( "prop-a", "some value" );
   
           // Configure the object
  -        m_configurer.configure( test, config, m_context );
  +        m_configurer.configure( test, config, m_adaptor );
   
           // Check the configured object
           final ConfigTest1 expected = new ConfigTest1();
  @@ -303,7 +308,7 @@
           m_context.setProperty( "prop-a", "some value" );
   
           // Configure the object
  -        m_configurer.configure( test, config, m_context );
  +        m_configurer.configure( test, config, m_adaptor );
   
           // Check the configured object
           final ConfigTest1 expected = new ConfigTest1();
  @@ -329,7 +334,7 @@
           try
           {
               // Configure the object
  -            m_configurer.configure( test, config, m_context );
  +            m_configurer.configure( test, config, m_adaptor );
               fail();
           }
           catch( ConfigurationException e )
  @@ -354,7 +359,7 @@
           try
           {
               // Configure the object
  -            m_configurer.configure( test, config, m_context );
  +            m_configurer.configure( test, config, m_adaptor );
               fail();
           }
           catch( final ConfigurationException ce )
  @@ -380,7 +385,7 @@
           try
           {
               // Configure the object
  -            m_configurer.configure( test, config, m_context );
  +            m_configurer.configure( test, config, m_adaptor );
               fail();
           }
           catch( final ConfigurationException ce )
  @@ -415,7 +420,7 @@
           final ConfigTest6 test = new ConfigTest6();
   
           // Configure the object
  -        m_configurer.configure( test, config, m_context );
  +        m_configurer.configure( test, config, m_adaptor );
   
           final ConfigTest6 expected = new ConfigTest6();
           expected.add( new MyType1() );
  @@ -435,13 +440,14 @@
   
           // Set up the converter and role
           RoleManager roleMgr = (RoleManager)getServiceManager().lookup( 
RoleManager.ROLE );
  -        roleMgr.addNameRoleMapping( "my-role1", MyRole1.ROLE );
  +        final RoleInfo roleInfo = new RoleInfo("my-role1", MyRole1.class );
  +        roleMgr.addRole( roleInfo );
           registerConverter( StringToMyRole1Converter.class, String.class, 
MyRole1.class );
   
           final ConfigTest6 test = new ConfigTest6();
   
           // Configure the object
  -        m_configurer.configure( test, config, m_context );
  +        m_configurer.configure( test, config, m_adaptor );
   
           // Check result
           final ConfigTest6 expected = new ConfigTest6();
  @@ -465,7 +471,7 @@
           final ConfigTest7 test = new ConfigTest7();
   
           // Configure the object
  -        m_configurer.configure( test, config, m_context );
  +        m_configurer.configure( test, config, m_adaptor );
   
           final ConfigTest7 expected = new ConfigTest7();
           expected.add( child1 );
  @@ -489,7 +495,7 @@
           final ConfigTest8 test = new ConfigTest8();
   
           // Configure the object
  -        m_configurer.configure( test, config, m_context );
  +        m_configurer.configure( test, config, m_adaptor );
   
           final ConfigTest8 expected = new ConfigTest8();
           expected.addConfig( child1 );
  @@ -509,7 +515,7 @@
           final ConfigTest9 test = new ConfigTest9();
   
           // Configure the object
  -        m_configurer.configure( test, config, m_context );
  +        m_configurer.configure( test, config, m_adaptor );
   
           final ConfigTest9 expected = new ConfigTest9();
           expected.configure( config );
  @@ -532,7 +538,7 @@
           m_context.setProperty( "prop-a", "some indirect value" );
   
           // Configure the object
  -        m_configurer.configure( test, config, m_context );
  +        m_configurer.configure( test, config, m_adaptor );
   
           // Check the configured object
           final ConfigTest1 expected = new ConfigTest1();
  @@ -555,7 +561,7 @@
           // Configure the object
           try
           {
  -            m_configurer.configure( test, config, m_context );
  +            m_configurer.configure( test, config, m_adaptor );
               fail();
           }
           catch( ConfigurationException e )
  @@ -583,7 +589,7 @@
           // Configure the object
           try
           {
  -            m_configurer.configure( test, config, m_context );
  +            m_configurer.configure( test, config, m_adaptor );
               fail();
           }
           catch( ConfigurationException e )
  @@ -612,14 +618,15 @@
   
           // Add role mapping, and add to reference to context
           final RoleManager roleMgr = (RoleManager)getServiceManager().lookup( 
RoleManager.ROLE );
  -        roleMgr.addNameRoleMapping( "my-role1", MyRole1.class.getName() );
  +        final RoleInfo roleInfo = new RoleInfo( "my-role1", MyRole1.class );
  +        roleMgr.addRole( roleInfo );
           m_context.setProperty( "id", new MyType1() );
           m_context.setProperty( "id2", new MyType2() );
   
           final ConfigTest6 test = new ConfigTest6();
   
           // Configure the object
  -        m_configurer.configure( test, config, m_context );
  +        m_configurer.configure( test, config, m_adaptor );
   
           // Compare against expected value
           final ConfigTest6 expected = new ConfigTest6();
  @@ -644,7 +651,7 @@
           try
           {
               // Configure the object
  -            m_configurer.configure( test, config, m_context );
  +            m_configurer.configure( test, config, m_adaptor );
               fail();
           }
           catch( ConfigurationException e )
  @@ -675,7 +682,7 @@
           final ConfigTest3 test = new ConfigTest3();
   
           // Configure the object
  -        m_configurer.configure( test, config, m_context );
  +        m_configurer.configure( test, config, m_adaptor );
   
           // Test expected value
           final ConfigTest3 expected = new ConfigTest3();
  
  
  
  1.8       +6 -4      
jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/AbstractComponentTest.java
  
  Index: AbstractComponentTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/AbstractComponentTest.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- AbstractComponentTest.java        21 Feb 2002 11:06:40 -0000      1.7
  +++ AbstractComponentTest.java        21 Feb 2002 12:52:07 -0000      1.8
  @@ -10,11 +10,12 @@
   import java.util.ArrayList;
   import java.util.Iterator;
   import java.util.List;
  +import org.apache.aut.converter.Converter;
   import org.apache.avalon.framework.logger.LogEnabled;
   import org.apache.avalon.framework.logger.Logger;
   import org.apache.avalon.framework.service.DefaultServiceManager;
  -import org.apache.avalon.framework.service.ServiceManager;
   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.AbstractMyrmidonTest;
   import org.apache.myrmidon.components.configurer.DefaultConfigurer;
  @@ -25,14 +26,15 @@
   import org.apache.myrmidon.components.deployer.DefaultDeployer;
   import org.apache.myrmidon.components.extensions.DefaultExtensionManager;
   import org.apache.myrmidon.components.role.DefaultRoleManager;
  +import org.apache.myrmidon.components.service.DefaultAntServiceManager;
   import org.apache.myrmidon.components.type.DefaultTypeManager;
  -import org.apache.aut.converter.Converter;
   import org.apache.myrmidon.interfaces.configurer.Configurer;
   import org.apache.myrmidon.interfaces.converter.ConverterRegistry;
   import org.apache.myrmidon.interfaces.converter.MasterConverter;
   import org.apache.myrmidon.interfaces.deployer.Deployer;
   import org.apache.myrmidon.interfaces.extensions.ExtensionManager;
   import org.apache.myrmidon.interfaces.role.RoleManager;
  +import org.apache.myrmidon.interfaces.service.AntServiceManager;
   import org.apache.myrmidon.interfaces.type.DefaultTypeFactory;
   import org.apache.myrmidon.interfaces.type.TypeException;
   import org.apache.myrmidon.interfaces.type.TypeManager;
  @@ -115,8 +117,8 @@
           m_serviceManager.put( RoleManager.ROLE, component );
           components.add( component );
   
  -        component = new DefaultServiceManager();
  -        m_serviceManager.put( ServiceManager.ROLE, component );
  +        component = new DefaultAntServiceManager();
  +        m_serviceManager.put( AntServiceManager.ROLE, component );
           components.add( component );
   
           // Log enable the components
  
  
  
  1.9       +1 -1      
jakarta-ant/proposal/myrmidon/src/manifest/builtin-ant-roles.xml
  
  Index: builtin-ant-roles.xml
  ===================================================================
  RCS file: 
/home/cvs/jakarta-ant/proposal/myrmidon/src/manifest/builtin-ant-roles.xml,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- builtin-ant-roles.xml     15 Feb 2002 07:36:06 -0000      1.8
  +++ builtin-ant-roles.xml     21 Feb 2002 12:52:07 -0000      1.9
  @@ -4,7 +4,7 @@
       <role shorthand="listener" 
name="org.apache.myrmidon.listeners.ProjectListener"/>
       <role shorthand="aspect" 
name="org.apache.myrmidon.aspects.AspectHandler"/>
       <role shorthand="project-builder" 
name="org.apache.myrmidon.interfaces.builder.ProjectBuilder"/>
  -    <role shorthand="converter" 
name="org.apache.myrmidon.converter.Converter"/>
  +    <role shorthand="converter" name="org.apache.aut.converter.Converter"/>
       <role shorthand="configurer" 
name="org.apache.myrmidon.interfaces.configurer.Configurer"/>
       <role shorthand="exec-manager" 
name="org.apache.aut.nativelib.ExecManager"/>
       <role shorthand="file-system-manager" 
name="org.apache.aut.vfs.FileSystemManager"/>
  
  
  
  1.8       +19 -14    
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/role/RoleManager.java
  
  Index: RoleManager.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/role/RoleManager.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- RoleManager.java  21 Feb 2002 11:06:42 -0000      1.7
  +++ RoleManager.java  21 Feb 2002 12:52:07 -0000      1.8
  @@ -8,40 +8,45 @@
   package org.apache.myrmidon.interfaces.role;
   
   /**
  - * Interface to manage roles and mapping to shorthand names.
  + * Interface to manage roles.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
    * @author <a href="mailto:[EMAIL PROTECTED],org">Ricardo Rocha</a>
    * @author <a href="mailto:[EMAIL PROTECTED],org">Giacomo Pati</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
  - * @version CVS $Revision: 1.7 $ $Date: 2002/02/21 11:06:42 $
  + * @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
  + * @version CVS $Revision: 1.8 $ $Date: 2002/02/21 12:52:07 $
    */
   public interface RoleManager
   {
       String ROLE = RoleManager.class.getName();
   
       /**
  -     * Find Role name based on shorthand name.
  +     * Find role based on shorthand name.
        *
        * @param name the shorthand name
  -     * @return the role
  +     * @return the role, or null if the role cannot be found.
        */
  -    String getRoleForName( String name );
  +    RoleInfo getRoleByShorthandName( String name );
   
       /**
  -     * Find name based on role.
  +     * Find role based on role type.
        *
  -     * @param role the role
  -     * @return the name
  +     * @param type the role type.
  +     * @return the role, or null if the role cannot be found.
        */
  -    String getNameForRole( String role );
  +    RoleInfo getRoleByType( Class type );
   
       /**
  -     * Adds a role mapping.
  +     * Find role based on name.
        *
  -     * @param name the shorthand name.
  -     * @param role the role name.
  +     * @param name the role name
  +     * @return the role, or null if the role cannot be found.
        */
  -    void addNameRoleMapping( String name, String role )
  -        throws IllegalArgumentException;
  +    RoleInfo getRole( String name );
  +
  +    /**
  +     * Adds a role definition.
  +     */
  +    void addRole( RoleInfo role ) throws RoleException;
   }
  
  
  
  1.1                  
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/role/RoleException.java
  
  Index: RoleException.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.txt file.
   */
  package org.apache.myrmidon.interfaces.role;
  
  import org.apache.avalon.framework.CascadingException;
  
  /**
   * An exception thrown by the RoleManager.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/02/21 12:52:07 $
   */
  public class RoleException
      extends CascadingException
  {
      public RoleException( String s )
      {
          super( s );
      }
  
      public RoleException( String s, Throwable throwable )
      {
          super( s, throwable );
      }
  }
  
  
  
  1.1                  
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/role/RoleInfo.java
  
  Index: RoleInfo.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.txt file.
   */
  package org.apache.myrmidon.interfaces.role;
  
  
  
  /**
   * A role definition.  Role definitions are immutable.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/02/21 12:52:07 $
   */
  public final class RoleInfo
  {
      private final String m_name;
      private final String m_shorthand;
      private final Class m_type;
  
      /**
       * Creates a role definition.
       *
       * @param name The role name.
       */
      public RoleInfo( final String name )
      {
          m_name = name;
          m_shorthand = null;
          m_type = null;
      }
  
      /**
       * Creates a role definition.
       *
       * @param name The role name.
       * @param shorthand The role shorthand name.
       */
      public RoleInfo( final String name, final String shorthand )
      {
          m_name = name;
          m_shorthand = shorthand;
          m_type = null;
      }
  
      /**
       * Creates a role definition.
       *
       * @param name The role name.
       * @param shorthand The role shorthand name.  May be null.
       * @param type The role type.  May be null.
       */
      public RoleInfo( final String name, final String shorthand, final Class 
type )
      {
          m_name = name;
          m_shorthand = shorthand;
          m_type = type;
      }
  
      /**
       * Creates a role definition.  The role type's fully-qualified name
       * is used as the role name.
       */
      public RoleInfo( final String shorthand, final Class type )
      {
          m_name = type.getName();
          m_shorthand = shorthand;
          m_type = type;
      }
  
      /**
       * Compares a role to this role.
       */
      public boolean equals( final RoleInfo role )
      {
          if( role == null )
          {
              return false;
          }
          if( ! m_name.equals( role.m_name ) )
          {
              return false;
          }
          if( m_shorthand == null && role.m_shorthand != null )
          {
              return false;
          }
          if( m_shorthand != null && ! m_shorthand.equals( role.m_shorthand ) )
          {
              return false;
          }
          if( m_type != role.m_type )
          {
              return false;
          }
          return true;
      }
  
      /**
       * Returns this role's name.  This name uniquely identifies the role.
       */
      public String getName()
      {
          return m_name;
      }
  
      /**
       * Returns this role's shorthand name.
       *
       * @return The shorthand name, or null if this role has none.
       */
      public String getShorthand()
      {
          return m_shorthand;
      }
  
      /**
       * Returns this role's type.  All implementations of this role must be
       * assignable to this type.
       *
       * @return The role type, or null if this role has no type.
       */
      public Class getType()
      {
          return m_type;
      }
  }
  
  
  
  1.10      +78 -33    
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/role/DefaultRoleManager.java
  
  Index: DefaultRoleManager.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/role/DefaultRoleManager.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- DefaultRoleManager.java   6 Feb 2002 13:35:14 -0000       1.9
  +++ DefaultRoleManager.java   21 Feb 2002 12:52:07 -0000      1.10
  @@ -10,13 +10,15 @@
   import java.util.HashMap;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
  +import org.apache.myrmidon.interfaces.role.RoleException;
  +import org.apache.myrmidon.interfaces.role.RoleInfo;
   import org.apache.myrmidon.interfaces.role.RoleManager;
   
   /**
    * Interface to manage roles and mapping to names.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
  - * @version CVS $Revision: 1.9 $ $Date: 2002/02/06 13:35:14 $
  + * @version CVS $Revision: 1.10 $ $Date: 2002/02/21 12:52:07 $
    */
   public class DefaultRoleManager
       implements RoleManager
  @@ -27,11 +29,14 @@
       /** Parent <code>RoleManager</code> for nested resolution */
       private final RoleManager m_parent;
   
  -    /** Map for name to role mapping */
  -    private final HashMap m_names = new HashMap();
  +    /** Map from shorthand name -> RoleInfo. */
  +    private final HashMap m_shorthandMap = new HashMap();
   
  -    /** Map for role to name mapping */
  -    private final HashMap m_roles = new HashMap();
  +    /** Map from role name -> RoleInfo. */
  +    private final HashMap m_nameMap = new HashMap();
  +
  +    /** Map from role type -> RoleInfo. */
  +    private final HashMap m_typeMap = new HashMap();
   
       /**
        *  constructor--this RoleManager has no parent.
  @@ -53,66 +58,106 @@
       }
   
       /**
  -     * Find Role name based on shorthand name.
  +     * Find role based on shorthand name.
        *
        * @param name the shorthand name
  -     * @return the role
  +     * @return the role, or null if the role cannot be found.
        */
  -    public String getRoleForName( final String name )
  +    public RoleInfo getRoleByShorthandName( final String name )
       {
  -        final String role = (String)m_names.get( name );
  +        final RoleInfo role = (RoleInfo)m_shorthandMap.get( name );
   
           if( null == role && null != m_parent )
           {
  -            return m_parent.getRoleForName( name );
  +            return m_parent.getRoleByShorthandName( name );
           }
   
           return role;
       }
   
       /**
  -     * Find name based on role.
  +     * Find role based on role type.
        *
  -     * @param role the role
  -     * @return the name
  +     * @param type the role type.
  +     * @return the role, or null if the role cannot be found.
        */
  -    public String getNameForRole( final String role )
  +    public RoleInfo getRoleByType( final Class type )
       {
  -        final String name = (String)m_roles.get( role );
  +        final RoleInfo role = (RoleInfo)m_typeMap.get( type );
   
  -        if( null == name && null != m_parent )
  +        if( null == role && null != m_parent )
           {
  -            return m_parent.getNameForRole( name );
  +            return m_parent.getRoleByType( type );
           }
   
  -        return name;
  +        return role;
       }
   
       /**
  -     * Add a mapping between name and role
  +     * Find role based on name.
        *
  -     * @param name the shorthand name
  -     * @param role the role
  -     * @exception IllegalArgumentException if an name is already mapped to a 
different role
  +     * @param name the role name
  +     * @return the role, or null if the role cannot be found.
  +     */
  +    public RoleInfo getRole( final String name )
  +    {
  +        final RoleInfo role = (RoleInfo)m_nameMap.get( name );
  +
  +        if( null == role && null != m_parent )
  +        {
  +            return m_parent.getRole( name );
  +        }
  +
  +        return role;
  +    }
  +
  +    /**
  +     * Adds a role definition.
        */
  -    public void addNameRoleMapping( final String name, final String role )
  -        throws IllegalArgumentException
  +    public void addRole( final RoleInfo role ) throws RoleException
       {
  -        final String oldRole = (String)m_names.get( name );
  +        // Check for duplicate role names
  +        final String roleName = role.getName();
  +        RoleInfo oldRole = (RoleInfo)m_nameMap.get( roleName );
           if( null != oldRole && !oldRole.equals( role ) )
           {
  -            final String message = REZ.getString( "duplicate-name.error", 
oldRole );
  -            throw new IllegalArgumentException( message );
  +            final String message = REZ.getString( "duplicate-role.error", 
roleName );
  +            throw new RoleException( message );
           }
   
  -        final String oldName = (String)m_roles.get( role );
  -        if( null != oldName && !oldName.equals( name ) )
  +        // Check for duplicate shorthand names
  +        final String shorthand = role.getShorthand();
  +        if( shorthand != null )
           {
  -            final String message = REZ.getString( "duplicate-role.error", 
oldName );
  -            throw new IllegalArgumentException( message );
  +            oldRole = (RoleInfo)m_shorthandMap.get( shorthand );
  +            if( null != oldRole && !oldRole.equals( role ) )
  +            {
  +                final String message = REZ.getString( 
"duplicate-shorthand.error", shorthand );
  +                throw new RoleException( message );
  +            }
           }
   
  -        m_names.put( name, role );
  -        m_roles.put( role, name );
  +        // Check for duplicate types
  +        final Class roleType = role.getType();
  +        if( roleType != null )
  +        {
  +            oldRole = (RoleInfo)m_typeMap.get( roleType );
  +            if( null != oldRole && !oldRole.equals( role ) )
  +            {
  +                final String message = REZ.getString( 
"duplicate-type.error", roleType.getName() );
  +                throw new RoleException( message );
  +            }
  +        }
  +
  +        // Add the role to the maps
  +        m_nameMap.put( roleName, role );
  +        if( shorthand != null )
  +        {
  +            m_shorthandMap.put( shorthand, role );
  +        }
  +        if( roleType != null )
  +        {
  +            m_typeMap.put( roleType, role );
  +        }
       }
   }
  
  
  
  1.2       +3 -2      
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/role/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/role/Resources.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Resources.properties      29 Aug 2001 15:34:57 -0000      1.1
  +++ Resources.properties      21 Feb 2002 12:52:07 -0000      1.2
  @@ -1,2 +1,3 @@
  -duplicate-name.error=Name already mapped to another role ({0}).
  -duplicate-role.error=Role already mapped to another name ({0}).
  +duplicate-shorthand.error=Duplicate roles with shorthand name "{0}".
  +duplicate-type.error=Duplicate roles with type "{0}".
  +duplicate-role.error=Duplicate roles with name "{0}".
  
  
  
  1.28      +16 -17    
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/DefaultDeployer.java
  
  Index: DefaultDeployer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/DefaultDeployer.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- DefaultDeployer.java      21 Feb 2002 11:06:41 -0000      1.27
  +++ DefaultDeployer.java      21 Feb 2002 12:52:07 -0000      1.28
  @@ -24,6 +24,7 @@
   import org.apache.myrmidon.interfaces.deployer.DeploymentException;
   import org.apache.myrmidon.interfaces.deployer.TypeDefinition;
   import org.apache.myrmidon.interfaces.deployer.TypeDeployer;
  +import org.apache.myrmidon.interfaces.role.RoleInfo;
   import org.apache.myrmidon.interfaces.role.RoleManager;
   import org.apache.myrmidon.interfaces.service.AntServiceManager;
   import org.apache.myrmidon.interfaces.service.ServiceFactory;
  @@ -35,7 +36,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
  - * @version $Revision: 1.27 $ $Date: 2002/02/21 11:06:41 $
  + * @version $Revision: 1.28 $ $Date: 2002/02/21 12:52:07 $
    */
   public class DefaultDeployer
       extends AbstractLogEnabled
  @@ -146,12 +147,10 @@
                                  final ServiceDefinition definition )
           throws Exception
       {
  -        // Determine the service interface class name
  -        String serviceTypeName = getRoleForName( 
definition.getRoleShorthand() );
  -
  -        // Register the service factory
  +        final String roleShorthand = definition.getRoleShorthand();
  +        final Class serviceType = getRoleType( roleShorthand );
           final String factoryClassName = definition.getFactoryClass();
  -        handleType( deployment, ServiceFactory.class, serviceTypeName, 
factoryClassName );
  +        handleType( deployment, ServiceFactory.class, serviceType.getName(), 
factoryClassName );
       }
   
       /**
  @@ -206,8 +205,7 @@
               }
   
               // Deploy general-purpose type
  -            final String role = getRoleForName( roleShorthand );
  -            final Class roleType = deployment.getClassLoader().loadClass( 
role );
  +            final Class roleType = getRoleType( roleShorthand );
               handleType( deployment, roleType, typeName, className );
   
               if( getLogger().isDebugEnabled() )
  @@ -261,10 +259,13 @@
        */
       public void deployRole( final Deployment deployment,
                               final RoleDefinition roleDef )
  +        throws Exception
       {
           final String name = roleDef.getShortHand();
           final String role = roleDef.getRoleName();
  -        m_roleManager.addNameRoleMapping( name, role );
  +        final Class type = deployment.getClassLoader().loadClass( role );
  +        final RoleInfo roleInfo = new RoleInfo( role, name, type );
  +        m_roleManager.addRole( roleInfo );
   
           if( getLogger().isDebugEnabled() )
           {
  @@ -274,19 +275,17 @@
       }
   
       /**
  -     * Determines the role name from shorthand name.
  +     * Determines the type for a role, from its shorthand.
        */
  -    private String getRoleForName( final String name )
  +    private Class getRoleType( final String roleShorthand )
           throws DeploymentException
       {
  -        final String role = m_roleManager.getRoleForName( name );
  -
  -        if( null == role )
  +        final RoleInfo roleInfo =  m_roleManager.getRoleByShorthandName( 
roleShorthand );
  +        if( null == roleInfo )
           {
  -            final String message = REZ.getString( "unknown-role4name.error", 
name );
  +            final String message = REZ.getString( "unknown-role4name.error", 
roleShorthand );
               throw new DeploymentException( message );
           }
  -
  -        return role;
  +        return roleInfo.getType();
       }
   }
  
  
  
  1.22      +17 -7     
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/Deployment.java
  
  Index: Deployment.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/Deployment.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- Deployment.java   18 Feb 2002 08:37:00 -0000      1.21
  +++ Deployment.java   21 Feb 2002 12:52:07 -0000      1.22
  @@ -30,7 +30,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
  - * @version $Revision: 1.21 $ $Date: 2002/02/18 08:37:00 $
  + * @version $Revision: 1.22 $ $Date: 2002/02/21 12:52:07 $
    */
   class Deployment
       extends AbstractLogEnabled
  @@ -267,15 +267,25 @@
        * Deploys the roles from a role descriptor.
        */
       private void deployRoles( final RoleDescriptor descriptor )
  +        throws DeploymentException
       {
  -        final String message = REZ.getString( "url-deploy-roles.notice", 
descriptor.getUrl() );
  -        getLogger().info( message );
   
  -        final RoleDefinition[] definitions = descriptor.getDefinitions();
  -        for( int i = 0; i < definitions.length; i++ )
  +        try
           {
  -            final RoleDefinition definition = definitions[ i ];
  -            m_deployer.deployRole( this, definition );
  +            final String message = REZ.getString( "url-deploy-roles.notice", 
descriptor.getUrl() );
  +            getLogger().info( message );
  +
  +            final RoleDefinition[] definitions = descriptor.getDefinitions();
  +            for( int i = 0; i < definitions.length; i++ )
  +            {
  +                final RoleDefinition definition = definitions[ i ];
  +                m_deployer.deployRole( this, definition );
  +            }
  +        }
  +        catch( Exception e )
  +        {
  +            final String message = REZ.getString( "deploy-roles.error", 
descriptor.getUrl() );
  +            throw new DeploymentException( message, e );
           }
       }
   
  
  
  
  1.10      +1 -0      
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: 
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/Resources.properties,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Resources.properties      14 Feb 2002 02:07:02 -0000      1.9
  +++ Resources.properties      21 Feb 2002 12:52:07 -0000      1.10
  @@ -7,6 +7,7 @@
   
   deploy-from-classloader.error=Could not register types from ClassLoader.
   deploy-from-file.error=Could not register types from type library "{0}".
  +deploy-roles.error=Could not register roles from "{0}".
   deploy-types.error=Could not register types from "{0}".
   deploy-services.error=Could not register services from "{0}".
   deploy-converter.error=Could not register converter that converts from {0} 
to {1}.
  
  
  
  1.29      +5 -4      
jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer/DefaultConfigurer.java
  
  Index: DefaultConfigurer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/configurer/DefaultConfigurer.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- DefaultConfigurer.java    21 Feb 2002 11:06:40 -0000      1.28
  +++ DefaultConfigurer.java    21 Feb 2002 12:52:08 -0000      1.29
  @@ -25,6 +25,7 @@
   import org.apache.myrmidon.framework.DataType;
   import org.apache.myrmidon.interfaces.configurer.Configurer;
   import org.apache.myrmidon.interfaces.converter.MasterConverter;
  +import org.apache.myrmidon.interfaces.role.RoleInfo;
   import org.apache.myrmidon.interfaces.role.RoleManager;
   import org.apache.myrmidon.interfaces.type.TypeException;
   import org.apache.myrmidon.interfaces.type.TypeFactory;
  @@ -34,7 +35,7 @@
    * Class used to configure tasks.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
  - * @version $Revision: 1.28 $ $Date: 2002/02/21 11:06:40 $
  + * @version $Revision: 1.29 $ $Date: 2002/02/21 12:52:08 $
    */
   public class DefaultConfigurer
       extends AbstractLogEnabled
  @@ -468,7 +469,7 @@
       private PropertyConfigurer getConfigurerFromName( final ObjectConfigurer 
configurer,
                                                         final String name,
                                                         boolean ignoreRoleName 
)
  -        throws NoSuchPropertyException
  +        throws Exception
       {
           // Try a named property
           final NoSuchPropertyException exc;
  @@ -486,8 +487,8 @@
           final PropertyConfigurer propertyConfigurer = 
configurer.getTypedProperty();
           if( !ignoreRoleName )
           {
  -            final String roleShorthand = m_roleManager.getNameForRole( 
propertyConfigurer.getType().getName() );
  -            if( !name.equalsIgnoreCase( roleShorthand ) )
  +            final RoleInfo roleInfo = m_roleManager.getRoleByType( 
propertyConfigurer.getType() );
  +            if( roleInfo == null || !name.equalsIgnoreCase( 
roleInfo.getShorthand() ) )
               {
                   // Rethrow the original exception
                   throw exc;
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to