avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/meta/info/builder BlockBuilder.java XMLBlockCreator.java Resources.properties XMLTypeCreator.java
Date Thu, 15 Aug 2002 04:14:50 GMT
mcconnell    2002/08/14 21:14:50

  Modified:    assembly build.xml
               assembly/demo/src/java/org/apache/excalibur/playground
                        ComplexComponent.java DemoManager.java
                        DemoManager.xinfo
               assembly/src/etc kernel.xml
               assembly/src/java/org/apache/excalibur/merlin/assembly
                        ContainerManager.java TypeManager.java
                        TypeRegistry.java
               assembly/src/java/org/apache/excalibur/merlin/resource
                        DefaultLifestyleManager.java
               assembly/src/java/org/apache/excalibur/meta
                        ConfigurationBuilder.java
               assembly/src/java/org/apache/excalibur/meta/info/builder
                        Resources.properties XMLTypeCreator.java
  Added:       assembly/src/java/org/apache/excalibur/container/lifecycle
                        package.html
               assembly/src/java/org/apache/excalibur/merlin/toolkit
                        GenericBlockContext.java
               assembly/src/java/org/apache/excalibur/meta blockinfo.dtd
               assembly/src/java/org/apache/excalibur/meta/info/builder
                        BlockBuilder.java XMLBlockCreator.java
  Log:
  Addition of support for Phoenix block assembly and Phoenix to Merlin
  migration tools.
  
  Revision  Changes    Path
  1.42      +12 -1     jakarta-avalon-excalibur/assembly/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/build.xml,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- build.xml	14 Aug 2002 10:46:29 -0000	1.41
  +++ build.xml	15 Aug 2002 04:14:49 -0000	1.42
  @@ -105,6 +105,7 @@
         <srcfiles dir="${src.dir}/java">
            <include name="**/merlin/**/*.*"/>
            <include name="**/excalibur/container/**/*.*"/>
  +         <include name="**/avalon/phoenix/**/*.*"/>
         </srcfiles>
         <srcfiles dir="${etc}">
            <include name="${project.manifest}"/>
  @@ -125,6 +126,7 @@
         </javac>
         <copy todir="${build}/main">
           <fileset dir="${src.dir}/java">
  +          <exclude name="org/apache/excalibur/meta/**/*"/>
             <include name="**/merlin/**/*.xml"/>
             <include name="**/merlin/**/*.properties"/>
             <include name="**/merlin/**/*.xinfo"/>
  @@ -133,8 +135,17 @@
           </fileset>
         </copy>
         <jar jarfile="${dist.dir}/${merlin.jar}" 
  -         basedir="${build}/main" manifest="${etc}/${project.manifest}"/>
  +         basedir="${build}/main" manifest="${etc}/${project.manifest}" 
  +         excludes="org/apache/excalibur/merlin/toolkit/**"/>
  +
  +      <!-- need to seperate next action out into a different build environment -->
  +
  +      <jar jarfile="${dist.dir}/tools.jar" 
  +         basedir="${build}/main" 
  +         includes="org/apache/excalibur/merlin/toolkit/**/*"/>
  +
     </target>
  +
   
     <target name="meta.context" depends="prepare">
       <mkdir dir="dist"/>
  
  
  
  1.9       +3 -1      jakarta-avalon-excalibur/assembly/demo/src/java/org/apache/excalibur/playground/ComplexComponent.java
  
  Index: ComplexComponent.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/demo/src/java/org/apache/excalibur/playground/ComplexComponent.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ComplexComponent.java	12 Aug 2002 17:38:20 -0000	1.8
  +++ ComplexComponent.java	15 Aug 2002 04:14:49 -0000	1.9
  @@ -141,7 +141,9 @@
           if( getLogger().isDebugEnabled() )
             getLogger().debug("dispose");
   
  -        m_simple = null;
  +        
  +        m_manager.release( m_simple );
  +        m_manager.release( m_basic );
           m_manager = null;
       }
   
  
  
  
  1.7       +12 -4     jakarta-avalon-excalibur/assembly/demo/src/java/org/apache/excalibur/playground/DemoManager.java
  
  Index: DemoManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/demo/src/java/org/apache/excalibur/playground/DemoManager.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DemoManager.java	14 Aug 2002 10:46:29 -0000	1.6
  +++ DemoManager.java	15 Aug 2002 04:14:49 -0000	1.7
  @@ -33,25 +33,33 @@
       public void create( Object target, Context context ) throws Exception
       {
           if( target instanceof Demonstratable )
  -          ((Demonstratable)target).demo( "create id: " + System.identityHashCode( this
) );
  +          ((Demonstratable)target).demo( "create id: " 
  +             + System.identityHashCode( this ) 
  +             + ", " + Thread.currentThread() );
       }
   
       public void destroy( Object target, Context context )
       {
           if( target instanceof Demonstratable )
  -          ((Demonstratable)target).demo( "destroy id: " + System.identityHashCode( this
) );
  +          ((Demonstratable)target).demo( "destroy id: " 
  +             + System.identityHashCode( this ) 
  +             + ", " + Thread.currentThread() );
       }
   
       public void access( Object target, Context context ) throws Exception
       {
           if( target instanceof Demonstratable )
  -          ((Demonstratable)target).demo( "access id: " + System.identityHashCode( this
) );
  +          ((Demonstratable)target).demo( "access id: " 
  +             + System.identityHashCode( this ) 
  +             + ", " + Thread.currentThread() );
       }
   
       public void release( Object target, Context context )
       {
           if( target instanceof Demonstratable )
  -          ((Demonstratable)target).demo( "release id: " + System.identityHashCode( this
) );
  +          ((Demonstratable)target).demo( "release id: " 
  +             + System.identityHashCode( this ) 
  +             + ", " + Thread.currentThread() );
       }
   
       //=======================================================================
  
  
  
  1.7       +1 -1      jakarta-avalon-excalibur/assembly/demo/src/java/org/apache/excalibur/playground/DemoManager.xinfo
  
  Index: DemoManager.xinfo
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/demo/src/java/org/apache/excalibur/playground/DemoManager.xinfo,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DemoManager.xinfo	14 Aug 2002 03:03:34 -0000	1.6
  +++ DemoManager.xinfo	15 Aug 2002 04:14:49 -0000	1.7
  @@ -14,7 +14,7 @@
     <component>
       <name>demonstratable</name>
       <attributes>
  -      <attribute key="avalon:lifestyle" value="transient"/>
  +      <attribute key="avalon:lifestyle" value="thread"/>
       </attributes>
     </component>
   
  
  
  
  1.34      +1 -0      jakarta-avalon-excalibur/assembly/src/etc/kernel.xml
  
  Index: kernel.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/etc/kernel.xml,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- kernel.xml	13 Aug 2002 03:57:56 -0000	1.33
  +++ kernel.xml	15 Aug 2002 04:14:49 -0000	1.34
  @@ -165,6 +165,7 @@
   
            </component>
   
  +
            <!--
            Demonstration of a component that contains an embedded kernel that programatically
            adds a container or two, and a new component type.  To enable this demo - change
the 
  
  
  
  1.1                  jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/container/lifecycle/package.html
  
  Index: package.html
  ===================================================================
  <body>
  Container independent interfaces and classes supporting component lifecycle extension.
  </body>
  
  
  
  1.20      +19 -2     jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/ContainerManager.java
  
  Index: ContainerManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/ContainerManager.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- ContainerManager.java	14 Aug 2002 10:46:29 -0000	1.19
  +++ ContainerManager.java	15 Aug 2002 04:14:49 -0000	1.20
  @@ -210,6 +210,8 @@
       */
       private DeploymentHelper m_deployment;
   
  +    private File m_home;
  +
       //===================================================================
       // constructor
       //===================================================================
  @@ -263,6 +265,7 @@
       public void contextualize( Context context ) throws ContextException
       {
           m_context = context;
  +        m_home = (File) context.get("avalon:home");
           super.contextualize( context );
           try
           {
  @@ -808,11 +811,25 @@
           if( resource != null )
             return resource;
   
  +        //
  +        // add some Phoenix specific stuff so we can work around context expected
  +        // on a BlockContext without having to modify the xinfo file
  +        //
  +
  +        DefaultContext c = new DefaultContext( context );
  +        c.put("name", profile.getName() );
  +        c.put("block.name", getPath().replace('/','.').substring(1) + "." + profile.getName()
);
  +        c.put("app.home", m_home );
  +
  +        //
  +        // continue on with resource creation
  +        //
  +
           try
           {
               LifestyleManager lifestyles = getLifestyleManager();
               LifestyleHandler handler =
  -              lifestyles.getHandler( this, m_deployment, m_helper, profile, context );
  +              lifestyles.getHandler( this, m_deployment, m_helper, profile, c );
               DefaultResource res = 
                 new DefaultResource( getPath(), profile, context, handler );
               res.enableLogging( getLocalLogger().getChildLogger( "resource" ) );
  
  
  
  1.10      +2 -2      jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/TypeManager.java
  
  Index: TypeManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/TypeManager.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TypeManager.java	14 Aug 2002 03:03:35 -0000	1.9
  +++ TypeManager.java	15 Aug 2002 04:14:49 -0000	1.10
  @@ -294,7 +294,7 @@
                               final String path = name.substring( 0, name.indexOf( ".class"
) );
                               try
                               {
  -                                m_types.addType( path );
  +                                m_types.addBlock( path );
                               }
                               catch( Throwable e )
                               {
  
  
  
  1.7       +29 -1     jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/TypeRegistry.java
  
  Index: TypeRegistry.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/TypeRegistry.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TypeRegistry.java	14 Aug 2002 03:03:35 -0000	1.6
  +++ TypeRegistry.java	15 Aug 2002 04:14:49 -0000	1.7
  @@ -25,6 +25,7 @@
   import org.apache.excalibur.meta.info.PhaseDescriptor;
   import org.apache.excalibur.meta.info.ExtensionDescriptor;
   import org.apache.excalibur.meta.info.builder.TypeBuilder;
  +import org.apache.excalibur.meta.info.builder.BlockBuilder;
   import org.apache.excalibur.merlin.model.Profile;
   import org.apache.excalibur.meta.verifier.ComponentVerifier;
   import org.apache.excalibur.configuration.ConfigurationUtil;
  @@ -45,6 +46,8 @@
   
       private TypeBuilder m_typeBuilder = new TypeBuilder();
   
  +    private BlockBuilder m_blockBuilder = new BlockBuilder();
  +
       private ClassLoader m_classloader;
   
      /**
  @@ -77,6 +80,7 @@
           m_classloader = loader;
           super.enableLogging( logger );
           m_typeBuilder.enableLogging( logger.getChildLogger("component") );
  +        m_blockBuilder.enableLogging( logger.getChildLogger("block") );
           getLogger().debug("type registry established");
       }
   
  @@ -117,6 +121,30 @@
           }
           return type;
       }
  +
  +   /**
  +    * Register a potential supplier component block.  The implementation will
  +    * create a component type instance for the entry if not already known and 
  +    * return the existing or new instance to the invoking client.
  +    *
  +    * @param classname the component class name
  +    * @return the component type
  +    */
  +    public Type addBlock( String path ) throws Exception
  +    {
  +        final String classname = path.replace('/','.');
  +
  +        getLogger().info("block: " + classname );
  +        Type type = getType( classname );
  +        if( type == null )
  +        {
  +            type = m_blockBuilder.build( classname, m_classloader );
  +            verify( type );
  +            register( type );
  +        }
  +        return type;
  +    }
  +
   
       private void verify( Type type ) throws Exception
       {
  
  
  
  1.4       +5 -6      jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/resource/DefaultLifestyleManager.java
  
  Index: DefaultLifestyleManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/resource/DefaultLifestyleManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultLifestyleManager.java	14 Aug 2002 10:46:29 -0000	1.3
  +++ DefaultLifestyleManager.java	15 Aug 2002 04:14:49 -0000	1.4
  @@ -115,11 +115,10 @@
               // per-thread lifestyle handler not implemented
               //
   
  -            final String error = 
  -              "PerThread lifestyle policy in profile: '" 
  -              + manager.getPath() + "/" + profile.getName()
  -              + "' unavailable.";
  -            throw new IllegalArgumentException( error );
  +            ThreadLocalLifestyleHandler handler = 
  +              new ThreadLocalLifestyleHandler( manager, deployment, helper, profile, context
);
  +            handler.enableLogging( getLogger() );
  +            return handler;
           }
           else if( policy.equalsIgnoreCase( "pooled" ) ) 
           {
  @@ -131,7 +130,7 @@
                 "Pooled lifestyle policy in profile: '" 
                 + manager.getPath() + "/" + profile.getName()
                 + "' unavailable.";
  -            throw new IllegalArgumentException( error );
  +            throw new UnsupportedOperationException( error );
           }
           else
           {
  
  
  
  1.1                  jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/toolkit/GenericBlockContext.java
  
  Index: GenericBlockContext.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.excalibur.merlin.toolkit;
  
  import java.io.File;
  import java.util.Map;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.DefaultContext;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.phoenix.BlockContext;
  
  /**
   * Block context that can be used by external containers the need to deal 
   * with existing Phoenix block implementations that include direct references to 
   * the BlockContext interface.  External containers can use this class as an 
   * alternative implementation that is independent of the Phoenix framework.
   *
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   */
  public class GenericBlockContext extends DefaultContext
      implements BlockContext
  {
  
      public GenericBlockContext( Map map, Context context )
      {
          super( map, context );    
      }
  
      /**
       * Base directory.
       *
       * @return the base directory
       */
      public File getBaseDirectory()
      {
          try
          {
              return (File) super.get( APP_HOME_DIR );
          }
          catch( Throwable e )
          {
              throw new RuntimeException( e.toString() );
          }
      }
  
      /**
       * Retrieve name of block.
       *
       * @return the name of block
       */
      public String getName()
      {
          try
          {
              return (String) super.get( NAME );
          }
          catch( Throwable e )
          {
              throw new RuntimeException( e.toString() );
          }
      }
  
      /**
       * Retrieve logger coresponding to named category.
       *
       * @return the logger
       * @deprecated This allows block writers to "break-out" of their logging
       *             hierarchy which is considered bad form. Replace by
       *             Logger.getChildLogger(String) where original logger is aquired
       *             via AbstractLogEnabled.
       * @exception UnsupportedOperationException is always thrown
       */
      public Logger getLogger( String name )
      {
          throw new UnsupportedOperationException("getLogger");
      }
  }
  
  
  
  1.4       +4 -1      jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/meta/ConfigurationBuilder.java
  
  Index: ConfigurationBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/meta/ConfigurationBuilder.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ConfigurationBuilder.java	5 Aug 2002 12:39:38 -0000	1.3
  +++ ConfigurationBuilder.java	15 Aug 2002 04:14:49 -0000	1.4
  @@ -34,6 +34,9 @@
           new DTDInfo( "-//AVALON/Component Type DTD Version 1.0//EN",
                        "http://jakarta.apache.org/avalon/type_1_0.dtd",
                        "org/apache/excalibur/meta/type.dtd" ),
  +        new DTDInfo( "-//PHOENIX/Block Info DTD Version 1.0//EN",
  +                     "http://jakarta.apache.org/avalon/type_1_0.dtd",
  +                     "org/apache/excalibur/meta/blockinfo.dtd" ),
       };
   
       private static final DTDResolver c_resolver =
  
  
  
  1.1                  jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/meta/blockinfo.dtd
  
  Index: blockinfo.dtd
  ===================================================================
  <!--
  
     This is the DTD defining the Phoenix BlockInfo 1.0
     descriptor (XML) file format/syntax.
  
     Author: Peter Donald <peter@apache.org>
  
     A BlockInfo is an XML file used to describe Blocks and located side-by-side with
     the Block .class file. It describes the services the Block requires to operate,
     the services the Block is capable of offerring other Blocks and other support
     meta data.
  
     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.
  
    -->
  
  <!--
  The blockinfo is the document root, it defines:
  
  block	     the specifc details about this block
  services     the services offered by this block
  dependencies the services that this block require to operate
  -->
  <!ELEMENT blockinfo (block, services?, management-access-points?, dependencies?)>
  <!ATTLIST blockinfo id ID #IMPLIED
            xmlns CDATA #FIXED "http://jakarta.apache.org/phoenix/blockinfo_1_0.dtd" >
  
  <!--
  The block element describes the block, it defines:
  
  name	        the human readable name of block type. Must be a string
               containing alphanumeric characters, '.', '_' and starting
               with a letter.
  version	     the version of the block in (in the format #.#.#, #.# or # where
               # is a integer
  schema-type  string representing the type of schema information available
               to validate block configuration
  -->
  <!ELEMENT block          (name?,version)>
    <!ELEMENT name         (#PCDATA) >
    <!ELEMENT version      (#PCDATA) >
    <!ELEMENT schema-type  (#PCDATA) >
  
  <!--
  The service element describes a service that the block
  can provide to other blocks, or this block depends upon.
  It defines:
  
  name         the name of the service. This must be equal to the class name of the
               interface that defines the service.
  version	     the version of the block in (in the format #.#.#, #.# or # where
               # is a integer
  -->
  <!ELEMENT service   EMPTY >
    <!ATTLIST service
         name CDATA #REQUIRED
         version CDATA #IMPLIED
    >
  
  <!--
  The service dependency describes a service that the block
  requires. It defines:
  
  role         the role of the service. This is the value that is used to lookup the
               service in the ComponentManager. If not provided it defaults to the
               value specified in the name attribute of service element
  service	     the service that is required
  -->
  <!ELEMENT dependency  (role?,service) >
    <!ELEMENT role        (#PCDATA) >
  
  <!--
  The services element contains a list of services that this Block supports.
  It contains service elements.
  -->
  <!ELEMENT services    (service*)>
  
  <!--
  The services element contains a list of services that this
  Block exports to the Management system. It contains service
  elements.
  -->
  <!ELEMENT management-access-points    (service*)>
  
  <!--
  The dependencies element contains a list of services that this Block requires.
  It contains dependency elements.
  -->
  <!ELEMENT dependencies    (dependency*)>
  
  
  
  1.5       +1 -0      jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/meta/info/builder/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/meta/info/builder/Resources.properties,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Resources.properties	14 Aug 2002 02:59:02 -0000	1.4
  +++ Resources.properties	15 Aug 2002 04:14:49 -0000	1.5
  @@ -2,6 +2,7 @@
   builder.creating-info.notice=Creating a Type from class "{0}".
   builder.created-info.notice=Constructed Type from class {0} with {1} services, {2} dependencies,
{3} context entries, {4} loggers, and {5} extended phases depedencies.
   builder.bad-toplevel-element.error=Error the component implemented by "{0}" has an invalid
element at top level of component info descriptor. Expected: "type". Actual: "{1}"
  +builder.bad-toplevel-block-element.error=Error the component implemented by "{0}" has an
invalid element at top level of component info descriptor. Expected: "blockinfo". Actual:
"{1}"
   builder.missing-info.error=Unable to locate resource from which to load info for component
implemented by class "{0}".
   builder.missing-xml-creator.error=Unable to create XMLTypeCreator, usually due to not having
XML classes on Classpath. Thus unable to lookup XML descriptor for component type "{0}".
   
  
  
  
  1.10      +3 -3      jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/meta/info/builder/XMLTypeCreator.java
  
  Index: XMLTypeCreator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/meta/info/builder/XMLTypeCreator.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- XMLTypeCreator.java	14 Aug 2002 02:59:02 -0000	1.9
  +++ XMLTypeCreator.java	15 Aug 2002 04:14:50 -0000	1.10
  @@ -391,7 +391,7 @@
        * @return the created ServiceDescriptor
        * @throws ConfigurationException if an error occurs
        */
  -    private ServiceDescriptor buildService( final Configuration service )
  +    protected ServiceDescriptor buildService( final Configuration service )
           throws ConfigurationException
       {
           Configuration serviceRef = service.getChild( "service-ref", false );
  @@ -450,7 +450,7 @@
        * @param version the version string
        * @return the created Version object
        */
  -    private Version buildVersion( final String version )
  +    protected Version buildVersion( final String version )
       {
           return Version.getVersion( version );
       }
  
  
  
  1.1                  jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/meta/info/builder/BlockBuilder.java
  
  Index: BlockBuilder.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.excalibur.meta.info.builder;
  
  import java.io.InputStream;
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.excalibur.meta.info.Type;
  
  /**
   * A BlockBuilder provides backwards compatibility with Phoenix blocks.
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   * @version $Revision: 1.1 $ $Date: 2002/08/15 04:14:49 $
   */
  public final class BlockBuilder
      extends AbstractLogEnabled
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( BlockBuilder.class );
  
      private final TypeCreator m_xmlBlockCreator = new XMLBlockCreator();
      private final TypeCreator m_xmlTypeCreator = new XMLTypeCreator();
  
      /**
       * Setup logging for all subcomponents
       */
      public void enableLogging( final Logger logger )
      {
          super.enableLogging( logger );
          if( null != m_xmlBlockCreator )
          {
              setupLogger( m_xmlBlockCreator );
              setupLogger( m_xmlTypeCreator );
          }
      }
  
      /**
       * Create a {@link Type} object for specified Class.
       *
       * @param clazz The class of Component
       * @return the created Type
       * @throws ConfigurationException if an error occurs
       */
      public Type build( final Class clazz )
          throws Exception
      {
          return build( clazz.getName(), clazz.getClassLoader() );
      }
  
      /**
       * Create a {@link Type} object for specified
       * classname, in specified ClassLoader.
       *
       * @param classname The classname of block
       * @param classLoader the ClassLoader to load info from
       * @return the created Type
       * @throws ConfigurationException if an error occurs
       */
      public Type build( final String classname,
                                  final ClassLoader classLoader )
          throws Exception
      {
          //
          // get the input stream for the .xinfo resource
          //
  
          final String xtype =
              classname.replace( '.', '/' ) + ".xtype";
          InputStream input =
              classLoader.getResourceAsStream( xtype );
          if( null == input )
          {
              final String xinfo =
                 classname.replace( '.', '/' ) + ".xinfo";
              input =
                 classLoader.getResourceAsStream( xinfo );
              if( null == input )
              {
                  final String message =
                    REZ.getString( "builder.missing-info.error",
                                 classname );
                  throw new Exception( message );
              }
              else
              {
                  //
                  // build the type
                  //
  
                  return m_xmlBlockCreator.createType( classname, input );
  
              }
          }
          else
          {
              return m_xmlTypeCreator.createType( classname, input );
          }
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/meta/info/builder/XMLBlockCreator.java
  
  Index: XMLBlockCreator.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.excalibur.meta.info.builder;
  
  import java.io.InputStream;
  import java.util.ArrayList;
  import java.util.Properties;
  import org.apache.excalibur.configuration.ConfigurationUtil;
  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.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.excalibur.meta.info.ComponentDescriptor;
  import org.apache.excalibur.meta.info.Type;
  import org.apache.excalibur.meta.info.ContextDescriptor;
  import org.apache.excalibur.meta.info.DependencyDescriptor;
  import org.apache.excalibur.meta.info.EntryDescriptor;
  import org.apache.excalibur.meta.info.LoggerDescriptor;
  import org.apache.excalibur.meta.info.ServiceDescriptor;
  import org.apache.excalibur.meta.info.ReferenceDescriptor;
  import org.apache.excalibur.meta.info.PhaseDescriptor;
  import org.apache.excalibur.meta.info.ExtensionDescriptor;
  import org.apache.excalibur.meta.ConfigurationBuilder;
  import org.xml.sax.InputSource;
  
  /**
   * Handles internalization of an XML based description of a {@link Type}
   * from a Configuration object. The format for Configuration object
   * is specified in the <a href="package-summary.html#external">package summary</a>.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   * @version $Revision: 1.1 $ $Date: 2002/08/15 04:14:49 $
   */
  public class XMLBlockCreator
      extends XMLTypeCreator
      implements TypeCreator
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( XMLBlockCreator.class );
  
      /**
       * Create a {@link Type} object for specified
       * classname, loaded from specified {@link InputStream}.
       *
       * @param implementationKey The classname of Component
       * @param inputStream the InputStream to load Type from
       * @return the created Type
       * @throws Exception if an error occurs
       */
      public Type createType( String implementationKey,
                                                InputStream inputStream  )
          throws Exception
      {
          if( inputStream == null ) 
            throw new NullPointerException("input");
  
          final InputSource input = new InputSource( inputStream );
          final String classname = implementationKey;
          final Configuration xinfo = ConfigurationBuilder.build( input );
          return build( classname, xinfo );
      }
  
      /**
       * Create a {@link Type} object for specified classname from
       * specified configuration data.
       *
       * @param classname The classname of Component
       * @param info the Type configuration
       * @return the created Type
       * @throws ConfigurationException if an error occurs
       */
      private Type build( final String classname, final Configuration info )
          throws Exception
      {
          if( getLogger().isDebugEnabled() )
          {
              final String message =
                  REZ.getString( "builder.creating-info.notice",
                                 classname );
              getLogger().debug( message );
          }
  
          final String topLevelName = info.getName();
          if( !topLevelName.equals( "type" ) )
          {
              if( !topLevelName.equals( "blockinfo" ) )
              {
                  final String message =
                      REZ.getString( "builder.bad-toplevel-block-element.error",
                                 classname,
                                 topLevelName );
                  throw new ConfigurationException( message );
              }
          }
  
          Configuration configuration = null;
  
          configuration = info.getChild( "block" );
          final ComponentDescriptor descriptor =
              buildComponentDescriptor( classname, configuration );
  
          configuration = info.getChild( "loggers" );
          final LoggerDescriptor[] loggers = buildLoggers( configuration );
  
          configuration = info.getChild( "context" );
          final ContextDescriptor context = buildContext( configuration );
  
          configuration = info.getChild( "services" );
          final ServiceDescriptor[] services = buildBlockServices( configuration );
  
          configuration = info.getChild( "dependencies" );
          final DependencyDescriptor[] dependencies = buildDependencies( classname, configuration
);
  
          configuration = info.getChild( "stages" );
          final PhaseDescriptor[] phases = buildPhases( configuration );
  
          configuration = info.getChild( "extensions" );
          final ExtensionDescriptor[] extensions = buildExtensions( configuration );
  
          if( getLogger().isInfoEnabled() )
          {
              final String message =
                  REZ.getString( "builder.created-facility.notice",
                                 classname,
                                 new Integer( services.length ),
                                 new Integer( dependencies.length ),
                                 new Integer( context.getEntrys().length ),
                                 new Integer( loggers.length ),
                                 new Integer( phases.length ),
                                 new Integer( extensions.length ) );
              getLogger().info( message );
          }
  
          return new Type( 
            descriptor, loggers, context, services, dependencies, phases, extensions );
      }
  
      /**
       * A utility method to build an array of {@link ServiceDescriptor}
       * objects from specified configuraiton.
       *
       * @param servicesSet the services configuration
       * @return the created ServiceDescriptor
       * @throws ConfigurationException if an error occurs
       */
      protected ServiceDescriptor[] buildBlockServices( final Configuration servicesSet )
          throws ConfigurationException
      {
          final Configuration[] elements = servicesSet.getChildren( "service" );
          final ArrayList services = new ArrayList();
  
          for( int i = 0; i < elements.length; i++ )
          {
              final ServiceDescriptor service = buildBlockService( elements[ i ] );
              services.add( service );
          }
  
          return (ServiceDescriptor[])services.toArray( new ServiceDescriptor[ 0 ] );
      }
  
  
      /**
       * A utility method to build a <code>ServiceDescriptor</code>
       * object from specified configuraiton data.
       *
       * @param service the service Configuration
       * @return the created ServiceDescriptor
       * @throws ConfigurationException if an error occurs
       */
      protected ServiceDescriptor buildBlockService( final Configuration service )
          throws ConfigurationException
      {
          final ReferenceDescriptor designator = buildReferenceDescriptor( service );
          final Properties attributes =
              buildAttributes( service.getChild( "attributes" ) );
          return new ServiceDescriptor( designator, attributes );
      }
  
      /**
       * A utility method to build a {@link ReferenceDescriptor}
       * object from specified configuraiton data.
       *
       * @param service the service Configuration
       * @return the created ReferenceDescriptor
       * @throws ConfigurationException if an error occurs
       */
      protected ReferenceDescriptor buildReferenceDescriptor( final Configuration service
)
          throws ConfigurationException
      {
          final String type = service.getAttribute( "name" );
          final String versionString = service.getAttribute( "version", "1.0" );
          final Version version = buildVersion( versionString );
          return new ReferenceDescriptor( type, version );
      }
  
      /**
       * A utility method to build a {@link DependencyDescriptor}
       * object from specified configuraiton.
       *
       * @param classname The classname of Component (used for logging purposes)
       * @param dependency the dependency configuration
       * @return the created DependencyDescriptor
       * @throws ConfigurationException if an error occurs
       */
      protected DependencyDescriptor buildDependency( final String classname,
                                                    final Configuration dependency )
          throws ConfigurationException
      {
  
          Configuration serviceRef = dependency.getChild( "service" );
          final ReferenceDescriptor service =
              buildReferenceDescriptor( serviceRef );
          final boolean optional =
              dependency.getAttributeAsBoolean( "optional", false );
          final Properties attributes =
              buildAttributes( dependency.getChild( "attributes" ) );
          String role = dependency.getChild( "role" ).getValue( null );
  
          //default to name of service if role unspecified
          if( null == role )
          {
              role = service.getClassname();
          }
          else
          {
              //If role is specified and it is the same as
              //service name then warn that it is redundent.
              if( role.equals( service.getClassname() ) )
              {
                  final String message =
                      REZ.getString( "builder.redundent-role.notice",
                                     classname,
                                     role );
                  getLogger().warn( message );
              }
          }
  
          return new DependencyDescriptor( role, service, optional, attributes );
      }
  
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message