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/framework/src/java/org/apache/myrmidon/framework DataType.java
Date Tue, 25 Jun 2002 07:34:02 GMT
adammurdoch    2002/06/25 00:34:02

  Modified:    container/src/java/org/apache/myrmidon/components/deployer
                        CompoundTypeDeployer.java DefaultDeployer.java
                        DefaultTypeLibraryDeployer.java
                        DescriptorBuilder.java Resources.properties
                        RoleDescriptorBuilder.java
                        TypeDescriptorBuilder.java
               container/src/java/org/apache/myrmidon/interfaces/role
                        RoleInfo.java RoleManager.java
               container/src/test/org/apache/myrmidon/components/role/test
                        DefaultRoleManagerTestCase.java
               framework/src/java/org/apache/myrmidon/framework
                        DataType.java
  Log:
  Dropped the restriction that data-types have to implement the DataType interface:
  
  - Added 'generic-role' attribute to role meta-info.  If this is set, the
    deployer ignores the role's interface name, and maps the role to
    java.lang.Object instead.
  - Switched this flag on for DataType.
  - More tidy-up of deployer internals (improve error reporting, mostly).
  
  Revision  Changes    Path
  1.11      +6 -18     jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/CompoundTypeDeployer.java
  
  Index: CompoundTypeDeployer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/CompoundTypeDeployer.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- CompoundTypeDeployer.java	24 Jun 2002 01:50:01 -0000	1.10
  +++ CompoundTypeDeployer.java	25 Jun 2002 07:34:02 -0000	1.11
  @@ -98,28 +98,16 @@
                   throw new ComponentException( message );
               }
   
  -            // Instantiate the custom type deployer for this role
  -            final String typeDeployerClassName = (String)role.getAttributes().get( RoleInfo.ATTRIBUTE_CUSTOM_TYPE_DEPLOYER
);
  -            if( typeDeployerClassName != null )
  -            {
  -                try
  -                {
  -                    final ClassLoader classLoader = role.getImplementationClass().getClassLoader();
  -                    final Class typeDeployerClass = classLoader.loadClass( typeDeployerClassName
);
  -                    deployer = (TypeDeployer)typeDeployerClass.newInstance();
  -                }
  -                catch( final Exception e )
  -                {
  -                    final String message = REZ.getString( "create-type-deployer.error",
roleName );
  -                    throw new ComponentException( message, e );
  -                }
  -            }
  -            else
  +            // Locate the custom type deployer for this role
  +            deployer = (TypeDeployer)role.getAttributes().get( RoleInfo.ATTRIBUTE_CUSTOM_TYPE_DEPLOYER
);
  +            if( deployer == null )
               {
                   deployer = m_defaultDeployer;
               }
  +
               m_deployers.put( roleName, deployer );
           }
  +
           return deployer;
       }
   }
  
  
  
  1.52      +2 -2      jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/DefaultDeployer.java
  
  Index: DefaultDeployer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/DefaultDeployer.java,v
  retrieving revision 1.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- DefaultDeployer.java	24 Jun 2002 07:03:48 -0000	1.51
  +++ DefaultDeployer.java	25 Jun 2002 07:34:02 -0000	1.52
  @@ -201,7 +201,7 @@
               final String debugMessage =
                   REZ.getString( "register-role.notice",
                                  roleInfo.getShortName(),
  -                               roleInfo.getImplementationClass().getName() );
  +                               roleInfo.getInterfaceName() );
               getLogger().debug( debugMessage );
           }
       }
  
  
  
  1.15      +18 -4     jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/DefaultTypeLibraryDeployer.java
  
  Index: DefaultTypeLibraryDeployer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/DefaultTypeLibraryDeployer.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- DefaultTypeLibraryDeployer.java	24 Jun 2002 07:03:48 -0000	1.14
  +++ DefaultTypeLibraryDeployer.java	25 Jun 2002 07:34:02 -0000	1.15
  @@ -14,11 +14,14 @@
   import java.util.Map;
   import javax.xml.parsers.SAXParser;
   import javax.xml.parsers.SAXParserFactory;
  +import org.apache.avalon.excalibur.i18n.ResourceManager;
  +import org.apache.avalon.excalibur.i18n.Resources;
  +import org.apache.avalon.framework.CascadingException;
   import org.apache.avalon.framework.configuration.SAXConfigurationHandler;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
  -import org.apache.myrmidon.interfaces.type.ClassLoaderTypeFactory;
   import org.apache.myrmidon.interfaces.deployer.TypeDefinition;
   import org.apache.myrmidon.interfaces.role.RoleInfo;
  +import org.apache.myrmidon.interfaces.type.ClassLoaderTypeFactory;
   import org.xml.sax.XMLReader;
   
   /**
  @@ -33,6 +36,9 @@
   class DefaultTypeLibraryDeployer
       extends AbstractLogEnabled
   {
  +    private static final Resources REZ =
  +        ResourceManager.getPackageResources( DefaultTypeLibraryDeployer.class );
  +
       private static final String TYPE_DESCRIPTOR_NAME = "META-INF/ant-types.xml";
       private static final String ROLE_DESCRIPTOR_NAME = "META-INF/ant-roles.xml";
   
  @@ -138,8 +144,16 @@
               final String url = (String)urls.get( i );
   
               // Parse the file
  -            parser.parse( url );
  -            builder.parseDescriptor( handler.getConfiguration(), url, this, definitions
);
  +            try
  +            {
  +                parser.parse( url );
  +                builder.parseDescriptor( handler.getConfiguration(), this, definitions
);
  +            }
  +            catch( final Exception e )
  +            {
  +                final String message = REZ.getString( "build-descriptor.error", url );
  +                throw new CascadingException( message, e );
  +            }
           }
   
           return definitions;
  
  
  
  1.5       +3 -5      jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/DescriptorBuilder.java
  
  Index: DescriptorBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/DescriptorBuilder.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DescriptorBuilder.java	24 Jun 2002 07:03:49 -0000	1.4
  +++ DescriptorBuilder.java	25 Jun 2002 07:34:02 -0000	1.5
  @@ -7,9 +7,8 @@
    */
   package org.apache.myrmidon.components.deployer;
   
  -import org.apache.myrmidon.interfaces.deployer.DeploymentException;
  -import org.apache.avalon.framework.configuration.Configuration;
   import java.util.List;
  +import org.apache.avalon.framework.configuration.Configuration;
   
   /**
    * Builds a descriptor.
  @@ -23,8 +22,7 @@
        * Builds a descriptor from a set of configuration.
        */
       void parseDescriptor( Configuration model,
  -                          String descriptorUrl,
                             DefaultTypeLibraryDeployer deployer,
                             List definitions )
  -        throws DeploymentException;
  +        throws Exception;
   }
  
  
  
  1.18      +4 -5      jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/Resources.properties,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- Resources.properties	9 Jun 2002 13:25:40 -0000	1.17
  +++ Resources.properties	25 Jun 2002 07:34:02 -0000	1.18
  @@ -1,5 +1,5 @@
   register-type.notice=Registered type {0}/{1}.
  -register-role.notice=Registered role {0} with class name {1}.
  +register-role.notice=Registered role {0} with interface name {1}.
   url-deploy-types.notice=Registering types from "{0}".
   url-deploy-roles.notice=Registering roles from "{0}".
   url-deploy-services.notice=Registering services from "{0}".
  @@ -16,11 +16,10 @@
   converterdef.no-source.error=Must specify the source-type parameter.
   converterdef.no-destination.error=Must specify the destination-type parameter.
   role-descriptor-version.error=Role descriptor version {0} is incompatible with current
version {1}.
  -build-role-descriptor.error=Could not build role descriptor from "{0}".
   type-descriptor-version.error=Type library descriptor version {0} is incompatible with
current version {1}.
  -build-type-descriptor.error=Could not build type library descriptor from "{0}".
  -multi-types-element.error=Library descriptor "{0}" contains multiple top-level <types/>
elements.
  +multi-types-element.error=Library descriptor contains multiple top-level <types/>
elements.
   service-descriptor-version.error=Service descriptor version {0} is incompatible with current
version {1}.
   build-service-descriptor.error=Could not build service descriptor from "{0}".
   create-type-deployer.error=Could not create the type deployer for role "{0}".
  -missing-roleinfo.error=Unable to locate RoleInfo for role "{0}".
  \ No newline at end of file
  +missing-roleinfo.error=Unable to locate RoleInfo for role "{0}".
  +build-descriptor.error=Could not load descriptor "{0}".
  \ No newline at end of file
  
  
  
  1.12      +40 -36    jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/RoleDescriptorBuilder.java
  
  Index: RoleDescriptorBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/RoleDescriptorBuilder.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- RoleDescriptorBuilder.java	24 Jun 2002 07:03:49 -0000	1.11
  +++ RoleDescriptorBuilder.java	25 Jun 2002 07:34:02 -0000	1.12
  @@ -8,13 +8,12 @@
   package org.apache.myrmidon.components.deployer;
   
   import java.util.HashMap;
  -import java.util.Map;
   import java.util.List;
  +import java.util.Map;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
   import org.apache.avalon.framework.Version;
   import org.apache.avalon.framework.configuration.Configuration;
  -import org.apache.myrmidon.interfaces.deployer.DeploymentException;
   import org.apache.myrmidon.interfaces.role.RoleInfo;
   
   /**
  @@ -35,49 +34,54 @@
        * Builds a descriptor from a set of configuration.
        */
       public void parseDescriptor( final Configuration model,
  -                                 final String url,
                                    final DefaultTypeLibraryDeployer deployer,
                                    final List definitions )
  -        throws DeploymentException
  +        throws Exception
       {
  -        try
  +        // Check version
  +        final String versionString = model.getAttribute( "version" );
  +        final Version version = Version.getVersion( versionString );
  +        if( !ROLE_DESCRIPTOR_VERSION.complies( version ) )
  +        {
  +            final String message = REZ.getString( "role-descriptor-version.error",
  +                                                  version, ROLE_DESCRIPTOR_VERSION );
  +            throw new Exception( message );
  +        }
  +
  +        // Extract each of the role elements
  +        final Configuration[] types = model.getChildren( "role" );
  +        for( int i = 0; i < types.length; i++ )
           {
  -            // Check version
  -            final String versionString = model.getAttribute( "version" );
  -            final Version version = Version.getVersion( versionString );
  -            if( !ROLE_DESCRIPTOR_VERSION.complies( version ) )
  +            final Configuration type = types[ i ];
  +            final String shortName = type.getAttribute( "name" );
  +            final String className = type.getAttribute( "interface" );
  +            final boolean isGenericRole = type.getAttributeAsBoolean( "generic-role", false
);
  +            final Class roleType;
  +            if( isGenericRole )
               {
  -                final String message = REZ.getString( "role-descriptor-version.error",
  -                                                      version, ROLE_DESCRIPTOR_VERSION
);
  -                throw new DeploymentException( message );
  +                roleType = Object.class;
               }
  -
  -            // Extract each of the role elements
  -            final Configuration[] types = model.getChildren( "role" );
  -            for( int i = 0; i < types.length; i++ )
  +            else
               {
  -                final Configuration type = types[ i ];
  -                final String shortName = type.getAttribute( "name" );
  -                final String className = type.getAttribute( "interface" );
  -                final Class roleType = deployer.getClassLoader().loadClass( className );
  -                final Map attrMap = new HashMap();
  -                final String[] attrs = type.getAttributeNames();
  -                for( int j = 0; j < attrs.length; j++ )
  +                roleType = deployer.getClassLoader().loadClass( className );
  +            }
  +            final Map attrMap = new HashMap();
  +            final String[] attrs = type.getAttributeNames();
  +            for( int j = 0; j < attrs.length; j++ )
  +            {
  +                final String attr = attrs[ j ];
  +                Object value = type.getAttribute( attr);
  +                if( attr.equals( RoleInfo.ATTRIBUTE_CUSTOM_TYPE_DEPLOYER ) )
                   {
  -                    String attr = attrs[ j ];
  -                    attrMap.put( attr, type.getAttribute( attr) );
  +                    value = deployer.getClassLoader().loadClass( (String)value ).newInstance();
                   }
  -                attrMap.remove( "name" );
  -                attrMap.remove( "interface" );
  -
  -                final RoleInfo roleInfo = new RoleInfo( shortName, roleType, attrMap );
  -                definitions.add( roleInfo );
  +                attrMap.put( attr, value );
               }
  -        }
  -        catch( final Exception e )
  -        {
  -            final String message = REZ.getString( "build-role-descriptor.error", url );
  -            throw new DeploymentException( message, e );
  +            attrMap.remove( "name" );
  +            attrMap.remove( "interface" );
  +
  +            final RoleInfo roleInfo = new RoleInfo( shortName, roleType, attrMap );
  +            definitions.add( roleInfo );
           }
       }
   }
  
  
  
  1.11      +24 -35    jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/TypeDescriptorBuilder.java
  
  Index: TypeDescriptorBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/deployer/TypeDescriptorBuilder.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- TypeDescriptorBuilder.java	24 Jun 2002 07:03:49 -0000	1.10
  +++ TypeDescriptorBuilder.java	25 Jun 2002 07:34:02 -0000	1.11
  @@ -8,13 +8,12 @@
   package org.apache.myrmidon.components.deployer;
   
   import java.util.HashMap;
  -import java.util.Map;
   import java.util.List;
  +import java.util.Map;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
   import org.apache.avalon.framework.Version;
   import org.apache.avalon.framework.configuration.Configuration;
  -import org.apache.myrmidon.interfaces.deployer.DeploymentException;
   import org.apache.myrmidon.interfaces.deployer.TypeDefinition;
   import org.apache.myrmidon.interfaces.type.ClassLoaderTypeFactory;
   import org.apache.myrmidon.interfaces.type.TypeManager;
  @@ -37,45 +36,35 @@
        * Builds a descriptor from a set of configuration.
        */
       public void parseDescriptor( final Configuration model,
  -                                 final String url,
                                    final DefaultTypeLibraryDeployer deployer,
                                    final List definitions )
  -        throws DeploymentException
  +        throws Exception
       {
  -        try
  +        // Check version
  +        final String versionString = model.getAttribute( "version" );
  +        final Version version = Version.getVersion( versionString );
  +        if( !TYPE_DESCRIPTOR_VERSION.complies( version ) )
           {
  -            // Check version
  -            final String versionString = model.getAttribute( "version" );
  -            final Version version = Version.getVersion( versionString );
  -            if( !TYPE_DESCRIPTOR_VERSION.complies( version ) )
  -            {
  -                final String message =
  -                    REZ.getString( "type-descriptor-version.error",
  -                                                      version, TYPE_DESCRIPTOR_VERSION
);
  -                throw new DeploymentException( message );
  -            }
  -
  -            // Extract each of the types elements
  -            final Configuration[] children = model.getChildren( "types" );
  -            if( 1 != children.length )
  -            {
  -                final String message =
  -                    REZ.getString( "multi-types-element.error", url );
  -                throw new DeploymentException( message );
  -            }
  -            final Configuration[] typeEntries = children[ 0 ].getChildren();
  -            for( int i = 0; i < typeEntries.length; i++ )
  -            {
  -                final Configuration typeEntry = typeEntries[ i ];
  -                final TypeDefinition typeDef = createTypeDefinition( typeEntry, deployer
);
  -                definitions.add( typeDef );
  -            }
  +            final String message =
  +                REZ.getString( "type-descriptor-version.error",
  +                               version, TYPE_DESCRIPTOR_VERSION );
  +            throw new Exception( message );
           }
  -        catch( Exception e )
  +
  +        // Extract each of the types elements
  +        final Configuration[] children = model.getChildren( "types" );
  +        if( 1 != children.length )
           {
               final String message =
  -                REZ.getString( "build-type-descriptor.error", url );
  -            throw new DeploymentException( message, e );
  +                REZ.getString( "multi-types-element.error" );
  +            throw new Exception( message );
  +        }
  +        final Configuration[] typeEntries = children[ 0 ].getChildren();
  +        for( int i = 0; i < typeEntries.length; i++ )
  +        {
  +            final Configuration typeEntry = typeEntries[ i ];
  +            final TypeDefinition typeDef = createTypeDefinition( typeEntry, deployer );
  +            definitions.add( typeDef );
           }
       }
   
  
  
  
  1.9       +2 -2      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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- RoleInfo.java	9 Jun 2002 13:20:46 -0000	1.8
  +++ RoleInfo.java	25 Jun 2002 07:34:02 -0000	1.9
  @@ -22,7 +22,7 @@
       /** The type name of the default implementation for this role. */
       public static final String ATTRIBUTE_DEFAULT_TYPE = "default-type";
   
  -    /** The classname of the custom type deployer for this role. */
  +    /** The custom type deployer for this role. */
       public static final String ATTRIBUTE_CUSTOM_TYPE_DEPLOYER = "type-deployer";
   
       private final String m_shortName;
  
  
  
  1.13      +2 -2      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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- RoleManager.java	9 Jun 2002 13:20:46 -0000	1.12
  +++ RoleManager.java	25 Jun 2002 07:34:02 -0000	1.13
  @@ -23,7 +23,7 @@
       String ROLE = RoleManager.class.getName();
   
       /**
  -     * Find role based on name.
  +     * Find role based on short name.
        *
        * @param name the role name
        * @return the role, or null if the role cannot be found.
  
  
  
  1.7       +6 -8      jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/role/test/DefaultRoleManagerTestCase.java
  
  Index: DefaultRoleManagerTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/components/role/test/DefaultRoleManagerTestCase.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DefaultRoleManagerTestCase.java	9 Jun 2002 13:13:54 -0000	1.6
  +++ DefaultRoleManagerTestCase.java	25 Jun 2002 07:34:02 -0000	1.7
  @@ -62,8 +62,7 @@
           assertNull( unknownRole );
   
           // Lookup an unknown role
  -        final String name = DefaultRoleManagerTestCase.class.getName();
  -        unknownRole = m_roleManager.getRoleByInterface( name );
  +        unknownRole = m_roleManager.getRoleByInterface( "unknown" );
           assertNull( unknownRole );
       }
   
  @@ -80,11 +79,11 @@
   
           // Lookup by name
           RoleInfo roleInfo = roleManager.getRoleByShortName( roleName );
  -        assertTrue( origRole.equals( roleInfo ) );
  +        assertSame( origRole, roleInfo );
   
           // Lookup by type
           roleInfo = roleManager.getRoleByInterface( roleType.getName() );
  -        assertTrue( origRole.equals( roleInfo ) );
  +        assertSame( origRole, roleInfo );
       }
   
       /**
  @@ -108,11 +107,11 @@
   
           // Lookup role by name
           RoleInfo roleInfo = roleManager.getRoleByShortName( roleName );
  -        assertTrue( overrideNameRole.equals( roleInfo ) );
  +        assertSame( overrideNameRole, roleInfo );
   
           // Lookup role by type
           roleInfo = roleManager.getRoleByInterface( roleType.getName() );
  -        assertTrue( overrideTypeRole.equals( roleInfo ) );
  +        assertSame( overrideTypeRole, roleInfo );
       }
   
       /**
  @@ -149,5 +148,4 @@
               assertSameMessage( message, exc );
           }
       }
  -
   }
  
  
  
  1.5       +2 -1      jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/DataType.java
  
  Index: DataType.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/DataType.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DataType.java	9 Jun 2002 13:08:30 -0000	1.4
  +++ DataType.java	25 Jun 2002 07:34:02 -0000	1.5
  @@ -8,12 +8,13 @@
   package org.apache.myrmidon.framework;
   
   /**
  - * Base class for those classes that can appear inside the build file
  + * Marker interface for those classes that can appear inside the build file
    * as stand alone data types.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
    * @ant.role name="data-type"
    *           type-deployer="org.apache.myrmidon.framework.DataTypeDeployer"
  + *           generic-role="true"
    */
   public interface DataType
   {
  
  
  

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