mcconnell    2002/07/26 09:29:11

  Modified:    assembly/src/java/org/apache/excalibur/meta
                        componentinfo.dtd
               assembly/src/java/org/apache/excalibur/meta/info/builder
                        Resources.properties XMLTypeCreator.java
  Added:       assembly/src/java/org/apache/excalibur/meta/info
                        Extension.java PhaseDescriptor.java
               assembly/src/java/org/apache/excalibur/meta/info/builder
                        ExtensionBuilder.java ExtensionCreator.java
                        SerializedExtensionCreator.java
                        XMLExtensionCreator.java
               
assembly/src/java/org/apache/excalibur/meta/info/builder/doc-files
                        ExtensionBuilder.gif
  Log:
  meta-info additions to provide support for Extension types
  
  Revision  Changes    Path
  1.2       +21 -1     
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/meta/componentinfo.dtd
  
  Index: componentinfo.dtd
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/meta/componentinfo.dtd,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- componentinfo.dtd 12 Jul 2002 07:58:14 -0000      1.1
  +++ componentinfo.dtd 26 Jul 2002 16:29:10 -0000      1.2
  @@ -28,8 +28,10 @@
   context      the context required by this component
   services     the services offered by this component
   dependencies the services that this component require to operate
  +dependencies the lifecycle phases that this component manages
  +
   -->
  -<!ELEMENT component-info (component, loggers?, context?, services?, 
dependencies?)>
  +<!ELEMENT component-info (component, loggers?, context?, services?, 
dependencies?, phases?)>
   <!--
     !ATTLIST component-info id ID #IMPLIED
             xmlns CDATA #FIXED 
"http://jakarta.apache.org/avalon/componentinfo_1_0.dtd";
  @@ -105,6 +107,24 @@
   <!ELEMENT dependency  (role?,service-ref,attributes?) >
     <!ATTLIST dependency optional CDATA #IMPLIED >
     <!ELEMENT role        (#PCDATA) >
  +
  +<!--
  +The phase element defines a lifecycle extension phase that this component 
provides.
  +It contains:
  +
  +name  the phase name.
  +interface  the client interface phase class element
  +attributes     Optional attributes about phase
  +-->
  +<!ELEMENT phase      (name,attributes?)>
  +  <!ATTLIST phase type CDATA #REQUIRED >
  +
  +<!--
  +The phases element contains a list of phases that this component provides.
  +It contains phase elements.
  +-->
  +<!ELEMENT phases    (phase*)>
  +
   
   <!--
   The loggers element contains a list of loggers that component uses.
  
  
  
  1.1                  
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/meta/info/Extension.java
  
  Index: Extension.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;
  
  import java.io.Serializable;
  import org.xml.sax.InputSource;
  import java.io.InputStream;
  
  import org.apache.excalibur.meta.ConfigurationBuilder;
  import org.apache.excalibur.meta.info.ComponentDescriptor;
  import org.apache.excalibur.meta.info.ContextDescriptor;
  import org.apache.excalibur.meta.info.DependencyDescriptor;
  import org.apache.excalibur.meta.info.LoggerDescriptor;
  import org.apache.excalibur.meta.info.ServiceDescriptor;
  import org.apache.excalibur.meta.info.ServiceDesignator;
  import org.apache.avalon.framework.configuration.Configuration;
  
  /**
   * This class contains the meta information about a particular
   * lifecycle extension type. It describes;
   *
   * <ul>
   *   <li>Human presentable meta data such as name, version, description etc
   *   useful when assembling the system.</li>
   *   <li>the context object capabilities that this extension requires</li>
   *   <li>the interfaces that this extensions supports</li>
   * </ul>
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
   * @version $Revision: 1.1 $ $Date: 2002/07/26 16:29:10 $
   */
  public class Extension extends Type
  {
      private final PhaseDescriptor[] m_phases;
  
      /**
       * Basic constructor that takes as parameters all parts.
       */
      public Extension( final ComponentDescriptor descriptor,
                            final LoggerDescriptor[] loggers,
                            final ContextDescriptor context,
                            final ServiceDescriptor[] services,
                            final DependencyDescriptor[] dependencies,
                            final PhaseDescriptor[] phases )
      {
          super( descriptor, loggers, context, services, dependencies );
  
          if( null == phases )
          {
              throw new NullPointerException( "phases" );
          }
          m_phases = phases;
      }
  
      /**
       * Return the phases supported by this extension.
       *
       * @return an array of phase descriptors.
       */
      public PhaseDescriptor[] getPhaseDescriptors()
      {
          return m_phases;
      }
  
     /**
      * Return a string representation of the type.
      * @return the stringified type
      */
      public String toString()
      {
          StringBuffer buffer = new StringBuffer();
          PhaseDescriptor[] phases = getPhaseDescriptors();
          for( int i=0; i<phases.length; i++ )
          {
              buffer.append( phases[i].getName() );
              if( i<(phases.length -1) )
                buffer.append( ", " );
          }
          return "Extension name: " + getInfo().getName() + " phases: " + 
buffer.toString();
      }
  }
  
  
  
  1.1                  
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/meta/info/PhaseDescriptor.java
  
  Index: PhaseDescriptor.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;
  
  import java.util.Properties;
  
  /**
   * A descriptor that describes a name and inteface of a lifecycle phase.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
   * @version $Revision: 1.1 $ $Date: 2002/07/26 16:29:10 $
   */
  public final class PhaseDescriptor extends Descriptor
  {
      /**
       * The name of the lifecycle phase.
       */
      private final String m_name;
  
      /**
       * The interface that represents the client view of the lifecycle phase.
       */
      private final String m_type;
  
      /**
       * Constructor a phase descriptor without attributes.
       * @param name the phase name
       * @param interface the phase type
       */
      public PhaseDescriptor( final String name,
                                   final String type )
      {
          this( name, type, null );
      }
  
      /**
       * Constructor a phase descriptor with attributes.
       * @param name the phase name
       * @param interface the phase type
       */
      public PhaseDescriptor( final String name,
                                   final String type,
                                   final Properties attributes )
      {
          super( attributes );
  
          if( null == name )
              throw new NullPointerException( "name" );
          if( null == type )
              throw new NullPointerException( "type" );
  
          m_name = name;
          m_type = type;
      }
  
      /**
       * Return the name of the lifecycle phase.
       *
       * @return the name the lifecycle phase.
       */
      public String getName()
      {
          return m_name;
      }
  
      /**
       * Return the classname of the interface for the lifecycle phase.
       *
       * @return the classname of the interface implemented by client components
       *   that the extension supports.
       */
      public String getClassname()
      {
          return m_type;
      }
  }
  
  
  
  1.2       +4 -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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Resources.properties      12 Jul 2002 17:01:39 -0000      1.1
  +++ Resources.properties      26 Jul 2002 16:29:11 -0000      1.2
  @@ -4,3 +4,7 @@
   builder.bad-toplevel-element.error=Error the component implemented by "{0}" 
has an invalid element at top level of component info descriptor. Expected: 
"component-info". 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}".
  +
  +builder.creating-extension.notice=Creating a Extension for class "{0}".
  +builder.created-extension.notice=Constructed Extension object for class {0} 
with {1} services, {2} dependencies, {3} context entries, and {4} phases.
  +
  
  
  
  1.5       +11 -11    
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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- XMLTypeCreator.java       20 Jul 2002 00:54:07 -0000      1.4
  +++ XMLTypeCreator.java       26 Jul 2002 16:29:11 -0000      1.5
  @@ -37,7 +37,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
    * @version $Revision$ $Date$
    */
  -public final class XMLTypeCreator
  +public class XMLTypeCreator
       extends AbstractLogEnabled
       implements TypeCreator
   {
  @@ -137,7 +137,7 @@
        * @return the created LoggerDescriptor
        * @throws ConfigurationException if an error occurs
        */
  -    private LoggerDescriptor[] buildLoggers( final Configuration 
configuration )
  +    protected LoggerDescriptor[] buildLoggers( final Configuration 
configuration )
           throws ConfigurationException
       {
           final Configuration[] elements = configuration.getChildren( "logger" 
);
  @@ -177,7 +177,7 @@
        * @return the created DependencyDescriptor
        * @throws ConfigurationException if an error occurs
        */
  -    private DependencyDescriptor[] buildDependencies( final String classname,
  +    protected DependencyDescriptor[] buildDependencies( final String 
classname,
                                                         final Configuration 
configuration )
           throws ConfigurationException
       {
  @@ -203,7 +203,7 @@
        * @return the created DependencyDescriptor
        * @throws ConfigurationException if an error occurs
        */
  -    private DependencyDescriptor buildDependency( final String classname,
  +    protected DependencyDescriptor buildDependency( final String classname,
                                                     final Configuration 
dependency )
           throws ConfigurationException
       {
  @@ -247,7 +247,7 @@
        * @return the created ContextDescriptor
        * @throws ConfigurationException if an error occurs
        */
  -    private ContextDescriptor buildContext( final Configuration context )
  +    protected ContextDescriptor buildContext( final Configuration context )
           throws ConfigurationException
       {
           final EntryDescriptor[] entrys =
  @@ -271,7 +271,7 @@
        * @return the created [EMAIL PROTECTED] EntryDescriptor}s
        * @throws ConfigurationException if an error occurs
        */
  -    private EntryDescriptor[] buildEntries( final Configuration[] entrySet )
  +    protected EntryDescriptor[] buildEntries( final Configuration[] entrySet 
)
           throws ConfigurationException
       {
           final ArrayList entrys = new ArrayList();
  @@ -292,7 +292,7 @@
        * @return the created [EMAIL PROTECTED] EntryDescriptor}
        * @throws ConfigurationException if an error occurs
        */
  -    private EntryDescriptor buildEntry( final Configuration config )
  +    protected EntryDescriptor buildEntry( final Configuration config )
           throws ConfigurationException
       {
           final String key = config.getAttribute( "key" );
  @@ -311,7 +311,7 @@
        * @return the created ServiceDescriptor
        * @throws ConfigurationException if an error occurs
        */
  -    private ServiceDescriptor[] buildServices( final Configuration 
servicesSet )
  +    protected ServiceDescriptor[] buildServices( final Configuration 
servicesSet )
           throws ConfigurationException
       {
           final Configuration[] elements = servicesSet.getChildren( "service" 
);
  @@ -367,7 +367,7 @@
        * @param config the attributes config
        * @return the Properties object representing attributes
        */
  -    private Properties buildAttributes( final Configuration config )
  +    protected Properties buildAttributes( final Configuration config )
           throws ConfigurationException
       {
           final Properties attributes = new Properties();
  @@ -391,7 +391,7 @@
        * @return the created ComponentDescriptor
        * @throws ConfigurationException if an error occurs
        */
  -    private ComponentDescriptor buildComponentDescriptor( final String 
classname,
  +    protected ComponentDescriptor buildComponentDescriptor( final String 
classname,
                                                             final 
Configuration component )
           throws ConfigurationException
       {
  
  
  
  1.1                  
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/meta/info/builder/ExtensionBuilder.java
  
  Index: ExtensionBuilder.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.Extension;
  
  /**
   * A ExtensionBuilder is responsible for building [EMAIL PROTECTED] Extension}
   * objects from Configuration objects. The format for Configuration object
   * is specified in the <a href="package-summary.html#external">package 
summary</a>.
   *
   * <p><b>UML</b></p>
   * <p><image src="doc-files/ExtensionBuilder.gif" border="0"/></p>
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
   * @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
   * @version $Revision: 1.1 $ $Date: 2002/07/26 16:29:10 $
   */
  public final class ExtensionBuilder
      extends AbstractLogEnabled
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( ExtensionBuilder.class );
  
      private final ExtensionCreator m_xmlExtensionCreator = 
createXMLExtensionCreator();
      private final ExtensionCreator m_serialExtensionCreator = new 
SerializedExtensionCreator();
  
      /**
       * Setup logging for all subcomponents
       */
      public void enableLogging( final Logger logger )
      {
          super.enableLogging( logger );
          setupLogger( m_serialExtensionCreator );
          if( null != m_xmlExtensionCreator )
          {
              setupLogger( m_xmlExtensionCreator );
          }
      }
  
      /**
       * Create a [EMAIL PROTECTED] Extension} object for specified Class.
       *
       * @param clazz The class of Component
       * @return the created Extension
       * @throws ConfigurationException if an error occurs
       */
      public Extension build( final Class clazz )
          throws Exception
      {
          return build( clazz.getName(), clazz.getClassLoader() );
      }
  
      /**
       * Create a [EMAIL PROTECTED] Extension} object for specified
       * classname, in specified ClassLoader.
       *
       * @param classname The classname of Component
       * @param classLoader the ClassLoader to load info from
       * @return the created Extension
       * @throws ConfigurationException if an error occurs
       */
      public Extension build( final String classname,
                                  final ClassLoader classLoader )
          throws Exception
      {
          final Extension info = buildFromSerDescriptor( classname, classLoader 
);
          if( null != info )
          {
              return info;
          }
          else
          {
              return buildFromXMLDescriptor( classname, classLoader );
          }
      }
  
      /**
       * Build Extension from the XML descriptor format.
       *
       * @param classname The classname of Component
       * @param classLoader the ClassLoader to load info from
       * @return the created Extension
       * @throws Exception if an error occurs
       */
      private Extension buildFromSerDescriptor( final String classname,
                                                    final ClassLoader 
classLoader )
          throws Exception
      {
          final String xinfo =
              classname.replace( '.', '/' ) + ".sinfo";
          final InputStream inputStream =
              classLoader.getResourceAsStream( xinfo );
          if( null == inputStream )
          {
              return null;
          }
  
          return m_serialExtensionCreator.createExtension( classname, 
inputStream );
      }
  
      /**
       * Build Extension from the XML descriptor format.
       *
       * @param classname The classname of Component
       * @param classLoader the ClassLoader to load info from
       * @return the created Extension
       * @throws Exception if an error occurs
       */
      private Extension buildFromXMLDescriptor( final String classname,
                                                    final ClassLoader 
classLoader )
          throws Exception
      {
          //
          // get the input stream for the .xinfo resource
          //
  
          final String xinfo =
              classname.replace( '.', '/' ) + ".xinfo";
          final InputStream inputStream =
              classLoader.getResourceAsStream( xinfo );
  
          if( null == inputStream )
          {
              //##############################################################//
              // Need to upgrade this to handle automated xinfo creation      //
              // using implemented interfaces for services, no dependecies,   //
              // no context, etc.                                             //
              //##############################################################//
  
              final String message =
                  REZ.getString( "builder.missing-info.error",
                                 classname );
              throw new Exception( message );
          }
  
          //
          // build the extension
          //
  
          final ExtensionCreator xmlExtensionCreator = getXMLExtensionCreator( 
classname );
          return xmlExtensionCreator.createExtension( classname, inputStream );
      }
  
      /**
       * Utility to get xml info builder, else throw
       * an exception if missing descriptor.
       *
       * @return the ExtensionCreator
       */
      private ExtensionCreator getXMLExtensionCreator( final String classname )
          throws Exception
      {
          if( null != m_xmlExtensionCreator )
          {
              return m_xmlExtensionCreator;
          }
          else
          {
              final String message =
                  REZ.getString( "builder.missing-xml-creator.error",
                                 classname );
              throw new Exception( message );
          }
      }
  
      /**
       * Utility to get XMLExtensionCreator if XML files are on
       * ClassPath.
       *
       * @return the XML [EMAIL PROTECTED] ExtensionCreator}
       */
      private static ExtensionCreator createXMLExtensionCreator()
      {
          ExtensionCreator xmlExtensionCreator = null;
          try
          {
              xmlExtensionCreator = new XMLExtensionCreator();
          }
          catch( final Exception e )
          {
              //Ignore it if ClassNot found due to no
              //XML Classes on classpath
          }
          return xmlExtensionCreator;
      }
  }
  
  
  
  1.1                  
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/meta/info/builder/ExtensionCreator.java
  
  Index: ExtensionCreator.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 org.apache.excalibur.meta.info.Extension;
  import java.io.InputStream;
  
  /**
   * Simple interface used to create [EMAIL PROTECTED] Extension}
   * from stream. This abstraction was primarily created so
   * that the Extension could be built from non-XML
   * sources and no XML classes need be in the classpath.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
   * @version $Revision: 1.1 $ $Date: 2002/07/26 16:29:10 $
   */
  public interface ExtensionCreator
  {
      /**
       * Create a [EMAIL PROTECTED] Extension} from stream
       *
       * @param classname the classname of extension implementation
       * @param input the input stream that the resource is loaded from
       * @return the newly created [EMAIL PROTECTED] Extension}
       * @throws Exception
       */
      Extension createExtension( String key, InputStream input )
          throws Exception;
  }
  
  
  
  1.1                  
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/meta/info/builder/SerializedExtensionCreator.java
  
  Index: SerializedExtensionCreator.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 org.apache.excalibur.meta.info.Extension;
  import java.io.InputStream;
  import java.io.ObjectInputStream;
  
  /**
   * Create [EMAIL PROTECTED] Extension} from stream made up of
   * serialized object.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
   * @version $Revision: 1.1 $ $Date: 2002/07/26 16:29:11 $
   */
  public class SerializedExtensionCreator
      implements ExtensionCreator
  {
      public Extension createExtension( final String key,
                                                final InputStream inputStream )
          throws Exception
      {
          final ObjectInputStream ois = new ObjectInputStream( inputStream );
          return (Extension)ois.readObject();
      }
  }
  
  
  
  1.1                  
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/meta/info/builder/XMLExtensionCreator.java
  
  Index: XMLExtensionCreator.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.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.ServiceDesignator;
  import org.apache.excalibur.meta.info.PhaseDescriptor;
  import org.apache.excalibur.meta.info.Extension;
  import org.apache.excalibur.meta.ConfigurationBuilder;
  import org.xml.sax.InputSource;
  
  /**
   * Handles internalization of an XML based description of a [EMAIL PROTECTED] 
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:[EMAIL PROTECTED]">Peter Donald</a>
   * @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
   * @version $Revision: 1.1 $ $Date: 2002/07/26 16:29:11 $
   */
  public class XMLExtensionCreator
      extends XMLTypeCreator
      implements ExtensionCreator
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( XMLExtensionCreator.class );
  
      /**
       * Create a [EMAIL PROTECTED] Extension} object for specified
       * classname, loaded from specified [EMAIL PROTECTED] InputStream}.
       *
       * @param classname The classname of the Extension
       * @param inputStream the InputStream to load Extension from
       * @return the created Extension
       * @throws Exception if an error occurs
       */
      public Extension createExtension( 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 [EMAIL PROTECTED] Extension} object for specified classname 
from
       * specified configuration data.
       *
       * @param classname The classname of Extension
       * @param info the Extension configuration
       * @return the created Extension
       * @throws ConfigurationException if an error occurs
       */
      private Extension build( final String classname, final Configuration info 
)
          throws Exception
      {
          if( getLogger().isDebugEnabled() )
          {
              final String message =
                  REZ.getString( "builder.creating-extension.notice",
                                 classname );
              getLogger().debug( message );
          }
  
          final String topLevelName = info.getName();
          if( !topLevelName.equals( "component-info" ) )
          {
              final String message =
                  REZ.getString( "builder.bad-toplevel-element.error",
                                 classname,
                                 topLevelName );
              throw new ConfigurationException( message );
          }
  
          Configuration configuration = null;
  
          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 = buildServices( configuration );
  
          configuration = info.getChild( "dependencies" );
          final DependencyDescriptor[] dependencies = buildDependencies( 
classname, configuration );
  
          configuration = info.getChild( "component" );
          final ComponentDescriptor descriptor =
              buildComponentDescriptor( classname, configuration );
  
          configuration = info.getChild( "phases" );
          final PhaseDescriptor[] phases =
              buildPhases( configuration );
  
          if( getLogger().isDebugEnabled() )
          {
              final String message =
                  REZ.getString( "builder.created-extension.notice", classname,
                                 new Integer( services.length ),
                                 new Integer( dependencies.length ),
                                 new Integer( context.getEntrys().length ),
                                 new Integer( phases.length ) );
              getLogger().debug( message );
          }
  
          return new Extension( descriptor, loggers, context, services, 
dependencies, phases );
      }
  
     /**
      * Utility function to create a set of phase descriptor from a 
configuration.
      * @param config a configuration containing 0..n phase elements
      * @return an array of phase descriptors
      * @exception Exception if a build error occurs
      */
      protected PhaseDescriptor[] buildPhases( Configuration config ) throws 
Exception
      {
          ArrayList list = new ArrayList();
          Configuration[] children = config.getChildren("phase");
          for( int i=0; i<children.length; i++ )
          {
              Configuration child = children[i];
              final String name = child.getChild("name").getValue();
              final String classname = child.getAttribute("type");
              final Properties attributes =
                  super.buildAttributes( child.getChild( "attributes" ) );
              list.add( new PhaseDescriptor( name, classname, attributes ) );
          }
          return (PhaseDescriptor[]) list.toArray( new PhaseDescriptor[0] );
      }
  
  }
  
  
  
  1.1                  
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/meta/info/builder/doc-files/ExtensionBuilder.gif
  
        <<Binary file>>
  
  

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

Reply via email to