You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by ad...@apache.org on 2002/07/04 15:17:23 UTC

cvs commit: jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/library Library.java

adammurdoch    2002/07/04 06:17:23

  Modified:    container/src/java/org/apache/myrmidon/components/deployer
                        DefaultDeployer.java Resources.properties
               container/src/java/org/apache/myrmidon/components/library
                        DefaultLibrary.java DefaultLibraryManager.java
                        Resources.properties
               container/src/java/org/apache/myrmidon/interfaces/library
                        Library.java
  Added:       container/src/java/org/apache/myrmidon/components/library
                        DefinitionBuilder.java RoleDefinitionBuilder.java
                        TypeDefinitionBuilder.java
  Removed:     container/src/java/org/apache/myrmidon/components/deployer
                        DefaultTypeLibraryDeployer.java
                        DescriptorBuilder.java RoleDescriptorBuilder.java
                        TypeDescriptorBuilder.java
  Log:
  - Added Library.getRoles() and getTypes(), which provide access
    to the contents of the library's descriptors.
  - Moved antlib descriptor parsing from DefaultDeployer to
    DefaultLibraryManager (and simplified it somewhat).
  - Side effect is that type and role info for an antlib is now
    cached, since DefaultLibraryManager caches the Library objects.
  
  Revision  Changes    Path
  1.54      +38 -48    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.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- DefaultDeployer.java	27 Jun 2002 05:13:34 -0000	1.53
  +++ DefaultDeployer.java	4 Jul 2002 13:17:22 -0000	1.54
  @@ -7,9 +7,9 @@
    */
   package org.apache.myrmidon.components.deployer;
   
  +import java.util.Arrays;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
  -import org.apache.avalon.framework.container.ContainerUtil;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.avalon.framework.service.ServiceException;
   import org.apache.avalon.framework.service.ServiceManager;
  @@ -20,13 +20,12 @@
   import org.apache.myrmidon.interfaces.deployer.DeploymentException;
   import org.apache.myrmidon.interfaces.deployer.TypeDefinition;
   import org.apache.myrmidon.interfaces.library.Library;
  +import org.apache.myrmidon.interfaces.role.RoleInfo;
   import org.apache.myrmidon.interfaces.role.RoleManager;
   import org.apache.myrmidon.interfaces.role.RoleRegistry;
  -import org.apache.myrmidon.interfaces.role.RoleInfo;
  -import java.util.Arrays;
   
   /**
  - * This class deploys roles, types and services from a typelib.
  + * This class deploys roles and types from a typelib.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
  @@ -63,44 +62,6 @@
       }
   
       /**
  -     * Creates a deployer for a library.
  -     */
  -    private DefaultTypeLibraryDeployer createDeployer( final Library library )
  -        throws DeploymentException
  -    {
  -        try
  -        {
  -            final DefaultTypeLibraryDeployer deployer =
  -                new DefaultTypeLibraryDeployer( library.getClassLoader() );
  -            ContainerUtil.enableLogging( deployer, getLogger() );
  -            deployer.loadDescriptors( library.getClassPath() );
  -
  -            // Deploy the roles
  -            // TODO - need to defer this
  -
  -            if( getLogger().isDebugEnabled() )
  -            {
  -                final String message =
  -                    REZ.getString( "url-deploy-roles.notice", Arrays.asList( library.getClassPath() ) );
  -                getLogger().debug( message );
  -            }
  -
  -            final RoleInfo[] roles = deployer.getRoles();
  -            for( int i = 0; i < roles.length; i++ )
  -            {
  -                deployRole( roles[ i ] );
  -            }
  -
  -            return deployer;
  -        }
  -        catch( final Exception e )
  -        {
  -            final String message = REZ.getString( "deploy-from-library.error", library.getName() );
  -            throw new DeploymentException( message, e );
  -        }
  -    }
  -
  -    /**
        * Deploys all the types from a library.
        */
       public void deployTypes( final Library library,
  @@ -108,7 +69,7 @@
                                final TaskContext context )
           throws DeploymentException
       {
  -        final DefaultTypeLibraryDeployer deployer = createDeployer( library );
  +        deployRoles( library );
   
           if( getLogger().isDebugEnabled() )
           {
  @@ -117,7 +78,7 @@
               getLogger().debug( message );
           }
   
  -        final TypeDefinition[] types = deployer.getTypes();
  +        final TypeDefinition[] types = library.getTypes();
           for( int i = 0; i < types.length; i++ )
           {
               deployType( namespace, types[ i ], context );
  @@ -135,8 +96,10 @@
                               final TaskContext context )
           throws DeploymentException
       {
  -        final DefaultTypeLibraryDeployer deployer = createDeployer( library );
  -        final TypeDefinition[] types = deployer.getTypes();
  +        // TODO - should deploy only the role being used
  +        deployRoles( library );
  +
  +        final TypeDefinition[] types = library.getTypes();
           try
           {
               // Locate the definition for the type
  @@ -158,7 +121,6 @@
               final String message = REZ.getString( "deploy-type.error", roleName, typeName );
               throw new DeploymentException( message, e );
           }
  -
       }
   
       /**
  @@ -184,6 +146,34 @@
           {
               final String message = REZ.getString( "deploy-type.error",
                                                     typeDef.getRole(), typeDef.getName() );
  +            throw new DeploymentException( message, e );
  +        }
  +    }
  +
  +    /**
  +     * Deploys the roles defined by a library
  +     */
  +    private void deployRoles( final Library library )
  +        throws DeploymentException
  +    {
  +        try
  +        {
  +            if( getLogger().isDebugEnabled() )
  +            {
  +                final String message =
  +                    REZ.getString( "url-deploy-roles.notice", Arrays.asList( library.getClassPath() ) );
  +                getLogger().debug( message );
  +            }
  +
  +            final RoleInfo[] roles = library.getRoles();
  +            for( int i = 0; i < roles.length; i++ )
  +            {
  +                deployRole( roles[ i ] );
  +            }
  +        }
  +        catch( final Exception e )
  +        {
  +            final String message = REZ.getString( "deploy-from-library.error", library.getName() );
               throw new DeploymentException( message, e );
           }
       }
  
  
  
  1.19      +1 -14     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.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- Resources.properties	25 Jun 2002 07:34:02 -0000	1.18
  +++ Resources.properties	4 Jul 2002 13:17:22 -0000	1.19
  @@ -2,24 +2,11 @@
   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}".
   
   deploy-from-library.error=Could not deploy types from 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}.
   deploy-type.error=Could not register type {0}/{1}.
  -typedef.no-classname.error=Must specify the classname parameter.
   typedef.no-name.error=Must specify name parameter.
   typedef.no-role.error=Must specify type parameter.
   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}.
  -type-descriptor-version.error=Type library descriptor version {0} is incompatible with current version {1}.
  -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}".
  -build-descriptor.error=Could not load descriptor "{0}".
  \ No newline at end of file
  +missing-roleinfo.error=Unable to locate role "{0}".
  \ No newline at end of file
  
  
  
  1.3       +26 -2     jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/library/DefaultLibrary.java
  
  Index: DefaultLibrary.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/library/DefaultLibrary.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultLibrary.java	25 Jun 2002 07:13:28 -0000	1.2
  +++ DefaultLibrary.java	4 Jul 2002 13:17:22 -0000	1.3
  @@ -10,6 +10,8 @@
   import java.net.URL;
   import org.apache.avalon.excalibur.extension.Extension;
   import org.apache.myrmidon.interfaces.library.Library;
  +import org.apache.myrmidon.interfaces.role.RoleInfo;
  +import org.apache.myrmidon.interfaces.deployer.TypeDefinition;
   
   /**
    * The default library implementation.
  @@ -25,18 +27,24 @@
       private final ClassLoader m_classLoader;
       private final URL[] m_classpath;
       private final Library[] m_parentLibs;
  +    private final RoleInfo[] m_roles;
  +    private final TypeDefinition[] m_types;
   
       public DefaultLibrary( final String name,
                              final Extension[] extensions,
                              final ClassLoader classLoader,
                              final URL[] classpath,
  -                           final Library[] parentLibs )
  +                           final Library[] parentLibs,
  +                           final RoleInfo[] roles,
  +                           final TypeDefinition[] types )
       {
           m_name = name;
           m_extensions = extensions;
           m_classLoader = classLoader;
           m_classpath = classpath;
           m_parentLibs = parentLibs;
  +        m_roles = roles;
  +        m_types = types;
       }
   
       /**
  @@ -78,5 +86,21 @@
       public URL[] getClassPath()
       {
           return m_classpath;
  +    }
  +
  +    /**
  +     * Returns the roles defined in this library.
  +     */
  +    public RoleInfo[] getRoles()
  +    {
  +        return m_roles;
  +    }
  +
  +    /**
  +     * Returns the types defined in this library.
  +     */
  +    public TypeDefinition[] getTypes()
  +    {
  +        return m_types;
       }
   }
  
  
  
  1.12      +35 -7     jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/library/DefaultLibraryManager.java
  
  Index: DefaultLibraryManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/library/DefaultLibraryManager.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- DefaultLibraryManager.java	27 Jun 2002 23:39:47 -0000	1.11
  +++ DefaultLibraryManager.java	4 Jul 2002 13:17:22 -0000	1.12
  @@ -17,6 +17,7 @@
   import java.util.HashSet;
   import java.util.Map;
   import java.util.Set;
  +import java.util.List;
   import java.util.jar.Manifest;
   import org.apache.aut.nativelib.PathUtil;
   import org.apache.avalon.excalibur.extension.Extension;
  @@ -31,6 +32,8 @@
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.avalon.framework.service.Serviceable;
   import org.apache.myrmidon.interfaces.ComponentException;
  +import org.apache.myrmidon.interfaces.deployer.TypeDefinition;
  +import org.apache.myrmidon.interfaces.role.RoleInfo;
   import org.apache.myrmidon.interfaces.extensions.ExtensionManager;
   import org.apache.myrmidon.interfaces.library.Library;
   import org.apache.myrmidon.interfaces.library.LibraryManager;
  @@ -54,6 +57,9 @@
       private Library m_rootLibrary;
       private ClassLoader m_rootClassLoader;
       private Library[] m_coreLibraries;
  +    private final DefinitionBuilder m_roleBuilder = new RoleDefinitionBuilder();
  +    private final DefinitionBuilder m_typeBuilder = new TypeDefinitionBuilder();
  +
   
       /**
        * Map from Jar file to the Library for that file.
  @@ -193,11 +199,7 @@
               prependClassPath( loader, classPath );
           }
           final URL[] libClassPath = (URL[])classPath.toArray( new URL[ classPath.size() ] );
  -        return new DefaultLibrary( name,
  -                                   extensions,
  -                                   classLoader,
  -                                   libClassPath,
  -                                   new Library[ 0 ] );
  +        return buildLibrary( name, extensions, classLoader, libClassPath, new Library[ 0 ] );
       }
   
       /**
  @@ -241,7 +243,33 @@
               name = extns[ 0 ].getExtensionName();
           }
   
  -        return new DefaultLibrary( name, extns, classLoader, urls, parentLibraries );
  +        return buildLibrary( name, extns, classLoader, urls, parentLibraries );
  +    }
  +
  +    /**
  +     * Builds a Library impl, after assembling the role and type definitions
  +     * for the library.
  +     *
  +     * @todo Defer building all the role and type info until it is needed
  +     */
  +    private Library buildLibrary( final String name,
  +                                  final Extension[] extensions,
  +                                  final ClassLoader classLoader,
  +                                  final URL[] classPath,
  +                                  final Library[] parents )
  +        throws Exception
  +    {
  +        final List roles = m_roleBuilder.build( classLoader, classPath );
  +        final RoleInfo[] roleDefs = (RoleInfo[])roles.toArray( new RoleInfo[ roles.size() ] );
  +        final List types = m_typeBuilder.build( classLoader, classPath );
  +        final TypeDefinition[] typeDefs = (TypeDefinition[])types.toArray( new TypeDefinition[ types.size() ] );
  +        return new DefaultLibrary( name,
  +                                   extensions,
  +                                   classLoader,
  +                                   classPath,
  +                                   parents,
  +                                   roleDefs,
  +                                   typeDefs );
       }
   
       /**
  
  
  
  1.5       +12 -0     jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/library/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/library/Resources.properties,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Resources.properties	22 May 2002 07:26:25 -0000	1.4
  +++ Resources.properties	4 Jul 2002 13:17:22 -0000	1.5
  @@ -1,6 +1,18 @@
  +# DefaultLibraryManager
   no-file.error=Could not find library "{0}".
   load-library.error=Could not load Type Library "{0}".
   get-classpath-for-loader.error=Could not determine the class-path for a ClassLoader.
   create-classloader-for-files.error=Could not create a ClassLoader for {0}.
   dependency-cycle.error=Cycle in dependencies for library "{0}".
   unsatisfied.extension.error=Library "{0}" requires unknown extension "{1}" ( version {2}).
  +
  +# DefinitionBuilder
  +build-descriptor.error=Could not load descriptor "{0}".
  +role-descriptor-no-version.error=Role descriptor does not have a version attribute.
  +role-descriptor-version.error=Role descriptor version {0} is incompatible with expected version {1}.
  +role-no-name.error=Role definition does not have a name attribute.
  +role-no-interface.error=Role definition "{0}" does not have an interface attribute.
  +type-descriptor-no-version.error=Type descriptor does not have a version attribute.
  +type-descriptor-version.error=Type descriptor version {0} is incompatible with expected version {1}.
  +multi-types-element.error=Type descriptor contains multiple top-level <types/> elements.
  +type-no-impl.error=Type definition does not have an impl attribute.
  \ No newline at end of file
  
  
  
  1.1                  jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/library/DefinitionBuilder.java
  
  Index: DefinitionBuilder.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.library;
  
  import java.util.List;
  import java.util.ArrayList;
  import java.net.URL;
  import java.io.FileNotFoundException;
  import org.apache.avalon.framework.CascadingException;
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.myrmidon.interfaces.builder.ModelBuilder;
  import org.apache.myrmidon.components.builder.DefaultModelBuilder;
  import org.apache.myrmidon.api.metadata.ModelElement;
  
  /**
   * Assembles type/role definitions from the descriptors contained in a library.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/07/04 13:17:22 $
   */
  abstract class DefinitionBuilder
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( DefinitionBuilder.class );
  
      private final ModelBuilder m_builder = new DefaultModelBuilder();
  
      /**
       * Returns the name of the descriptor resource.
       */
      protected abstract String getDescriptorName();
  
      /**
       * Builds the definitions from a parsed descriptor.
       * @param model The parsed descriptor.
       * @param classLoader The classloader for the library.
       * @param definitions The list to add the definitions to.
       */
      protected abstract void build( ModelElement model, ClassLoader classLoader, List definitions )
          throws Exception;
  
      /**
       * Builds the definitions contained in the given library.
       * @param classLoader The library classloader.
       * @param classPath The library classpath.
       * @return A list of the definitions.
       */
      public List build( final ClassLoader classLoader,
                         final URL[] classPath )
          throws Exception
      {
          final ArrayList definitions = new ArrayList();
  
          // Locate all the descriptors
          final ArrayList descriptorUrls = locateResources( getDescriptorName(), classPath );
  
          // Parse each descriptor in turn
          final int size = descriptorUrls.size();
          for( int i = 0; i < size; i++ )
          {
              final String url = (String)descriptorUrls.get( i );
  
              // Parse the file
              try
              {
                  final ModelElement model = m_builder.build( url );
                  build( model, classLoader, definitions );
              }
              catch( final Exception e )
              {
                  final String message = REZ.getString( "build-descriptor.error", url );
                  throw new CascadingException( message, e );
              }
          }
  
          return definitions;
      }
  
      /**
       * Locates all resources of a particular name in the given classpath.
       */
      private ArrayList locateResources( final String resource, final URL[] searchPath )
          throws Exception
      {
          final ArrayList resourceUrls = new ArrayList();
          for( int i = 0; i < searchPath.length; i++ )
          {
              final URL url = searchPath[ i ];
  
              // Build the URL for the resource
              final String systemID;
              if( url.getFile().endsWith( "/" ) )
              {
                  systemID = url + resource;
              }
              else
              {
                  systemID = "jar:" + url + "!/" + resource;
              }
  
              try
              {
                  // Probe the resource
                  final URL resourceUrl = new URL( systemID );
                  resourceUrl.openStream().close();
  
                  // Add to the list
                  resourceUrls.add( systemID );
              }
              catch( final FileNotFoundException e )
              {
                  // Ignore
              }
          }
          return resourceUrls;
      }
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/library/RoleDefinitionBuilder.java
  
  Index: RoleDefinitionBuilder.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.library;
  
  import java.util.HashMap;
  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.myrmidon.api.metadata.ModelElement;
  import org.apache.myrmidon.interfaces.role.RoleInfo;
  
  /**
   * Assembles role definitions from role descriptors.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/07/04 13:17:22 $
   */
  class RoleDefinitionBuilder
      extends DefinitionBuilder
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( RoleDefinitionBuilder.class );
  
      private static final Version ROLE_DESCRIPTOR_VERSION = new Version( 1, 0, 0 );
  
      /**
       * Returns the name of the descriptor resource.
       */
      protected String getDescriptorName()
      {
          return "META-INF/ant-roles.xml";
      }
  
      /**
       * Builds the definitions from a parsed descriptor.
       */
      protected void build( final ModelElement model,
                            final ClassLoader classLoader,
                            final List definitions )
          throws Exception
      {
          // Check version
          final String versionString = model.getAttribute( "version" );
          if( versionString == null )
          {
              final String message = REZ.getString( "role-descriptor-no-version.error" );
              throw new Exception( message );
          }
          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 ModelElement[] children = model.getChildren( "role" );
          for( int i = 0; i < children.length; i++ )
          {
              final ModelElement child = children[ i ];
  
              final String shortName = child.getAttribute( "name" );
              if( shortName == null )
              {
                  final String message = REZ.getString( "role-no-name.error" );
                  throw new Exception( message );
              }
  
              final String className = child.getAttribute( "interface" );
              if( className == null )
              {
                  final String message = REZ.getString( "role-no-interface.error", shortName );
                  throw new Exception( message );
              }
  
              final Class roleType = classLoader.loadClass( className );
  
              final Map attrMap = new HashMap();
              final String[] attrs = child.getAttributeNames();
              for( int j = 0; j < attrs.length; j++ )
              {
                  final String attr = attrs[ j ];
                  Object value = child.getAttribute( attr );
                  if( attr.equals( RoleInfo.ATTRIBUTE_CUSTOM_TYPE_DEPLOYER ) )
                  {
                      value = classLoader.loadClass( (String)value ).newInstance();
                  }
                  attrMap.put( attr, value );
              }
              attrMap.remove( "name" );
              attrMap.remove( "interface" );
  
              final RoleInfo roleInfo = new RoleInfo( shortName, roleType, attrMap );
              definitions.add( roleInfo );
          }
      }
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/library/TypeDefinitionBuilder.java
  
  Index: TypeDefinitionBuilder.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.library;
  
  import java.util.HashMap;
  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.myrmidon.api.metadata.ModelElement;
  import org.apache.myrmidon.interfaces.deployer.TypeDefinition;
  import org.apache.myrmidon.interfaces.type.DefaultTypeFactory;
  import org.apache.myrmidon.interfaces.type.TypeFactory;
  import org.apache.myrmidon.interfaces.type.TypeManager;
  
  /**
   * Builds type definitions from type descriptors.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/07/04 13:17:22 $
   */
  class TypeDefinitionBuilder
      extends DefinitionBuilder
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( TypeDefinitionBuilder.class );
  
      private static final Version TYPE_DESCRIPTOR_VERSION = new Version( 1, 0, 0 );
  
      /**
       * Returns the name of the descriptor resource.
       */
      protected String getDescriptorName()
      {
          return "META-INF/ant-types.xml";
      }
  
      /**
       * Builds the definitions from a parsed descriptor.
       */
      protected void build( final ModelElement model,
                            final ClassLoader classLoader,
                            final List definitions )
          throws Exception
      {
          // Check version
          final String versionString = model.getAttribute( "version" );
          if( versionString == null )
          {
              final String message = REZ.getString( "type-descriptor-no-version.error" );
              throw new Exception( message );
          }
          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 Exception( message );
          }
  
          // Extract each of the types elements
          final ModelElement[] children = model.getChildren( "types" );
          if( 1 != children.length )
          {
              final String message =
                  REZ.getString( "multi-types-element.error" );
              throw new Exception( message );
          }
          final ModelElement[] typeEntries = children[ 0 ].getChildren();
          for( int i = 0; i < typeEntries.length; i++ )
          {
              final ModelElement typeEntry = typeEntries[ i ];
              final TypeDefinition typeDef = createTypeDefinition( typeEntry, classLoader );
              definitions.add( typeDef );
          }
      }
  
      /**
       * Creates a type definition.
       */
      private TypeDefinition createTypeDefinition( final ModelElement element,
                                                   final ClassLoader classLoader )
          throws Exception
      {
          final String roleName = element.getName();
          final String className = element.getAttribute( "impl" );
          if( className == null )
          {
              final String message = REZ.getString( "type-no-impl.error" );
              throw new Exception( message );
          }
          String typeName = element.getAttribute( "name" );
          if( typeName == null )
          {
              typeName = className.replace( TypeManager.NAMESPACE_SEPARATOR, '_' );
          }
  
          // Create type factory
          final TypeFactory factory = new DefaultTypeFactory( typeName, className, classLoader );
  
          // Extract other meta-info
          final String[] attributes = element.getAttributeNames();
          final Map attrs = new HashMap();
          for( int i = 0; i < attributes.length; i++ )
          {
              final String name = attributes[ i ];
              attrs.put( name, element.getAttribute( name ) );
          }
  
          return new TypeDefinition( typeName, roleName, factory, attrs );
      }
  }
  
  
  
  1.3       +13 -1     jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/library/Library.java
  
  Index: Library.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/library/Library.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Library.java	25 Jun 2002 07:13:28 -0000	1.2
  +++ Library.java	4 Jul 2002 13:17:23 -0000	1.3
  @@ -9,6 +9,8 @@
   
   import java.net.URL;
   import org.apache.avalon.excalibur.extension.Extension;
  +import org.apache.myrmidon.interfaces.role.RoleInfo;
  +import org.apache.myrmidon.interfaces.deployer.TypeDefinition;
   
   /**
    * This interface represents a library of Java classes, and deployable types.
  @@ -45,4 +47,14 @@
        * Returns the class-path for the library.
        */
       URL[] getClassPath();
  +
  +    /**
  +     * Returns the roles defined in this library.
  +     */
  +    RoleInfo[] getRoles();
  +
  +    /**
  +     * Returns the types defined in this library.
  +     */
  +    TypeDefinition[] getTypes();
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>