mcconnell    2002/11/26 09:12:14

  Modified:    assembly/src/test/org/apache/avalon/assembly/profile
                        ProfileManagerTestCase.java
               meta/src/java/org/apache/avalon/meta type.dtd
               meta/src/java/org/apache/avalon/meta/info Type.java
               meta/src/java/org/apache/avalon/meta/info/builder
                        SerializedTypeCreator.java TypeBuilder.java
                        TypeCreator.java XMLTypeCreator.java
               meta/src/java/org/apache/avalon/meta/model Profile.java
  Added:       meta/src/java/org/apache/avalon/meta/info/builder
                        TypeFactory.java
  Log:
  Updating the assembly and meta content to bring it closer to the 
excalibur/info
  model in preparation for some sort of convergence.
  
  Revision  Changes    Path
  1.3       +1 -1      
avalon-sandbox/assembly/src/test/org/apache/avalon/assembly/profile/ProfileManagerTestCase.java
  
  Index: ProfileManagerTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/assembly/src/test/org/apache/avalon/assembly/profile/ProfileManagerTestCase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ProfileManagerTestCase.java       25 Nov 2002 11:36:22 -0000      1.2
  +++ ProfileManagerTestCase.java       26 Nov 2002 17:12:14 -0000      1.3
  @@ -121,7 +121,7 @@
           }
           catch( Throwable e )
           {
  -            System.out.println("failure to resolve extension handler profile 
for : " + ref );
  +            System.out.println("failure to resolve extension handler profile 
for : " + reference );
               e.printStackTrace();
               assertTrue( false );
           }
  
  
  
  1.2       +8 -9      
avalon-sandbox/meta/src/java/org/apache/avalon/meta/type.dtd
  
  Index: type.dtd
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/meta/src/java/org/apache/avalon/meta/type.dtd,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- type.dtd  24 Nov 2002 12:58:26 -0000      1.1
  +++ type.dtd  26 Nov 2002 17:12:14 -0000      1.2
  @@ -23,18 +23,17 @@
   <!--
   A type element is the document root, it defines:
   
  -info         the specific details about this component type
  -loggers      the loggers used by this component type
  -context      the context required by this component type
  -services     the services offered by this component type
  -dependencies the services that this component type require to operate
  -stages       the lifecycle stage extensions that this component type is 
depenent on
  -extensions   the lifecycle extensions that this component type provides
  -controls     the set of management control points
  +info           the specific details about this component type
  +loggers        the loggers used by this component type
  +context        the context required by this component type
  +services       the services offered by this component type
  +dependencies   the services that this component type require to operate
  +stages         the lifecycle stage extensions that this component type is 
depenent on
  +extensions     the lifecycle extensions that this component type provides
   
   -->
   
  -<!ELEMENT type ( (component|info), loggers?, context?, services?, 
dependencies?, stages?, extensions?)>
  +<!ELEMENT type ( info, loggers?, context?, services?, dependencies?, 
stages?, extensions?)>
   
   <!--
   The info element describes the component, it defines:
  
  
  
  1.2       +40 -2     
avalon-sandbox/meta/src/java/org/apache/avalon/meta/info/Type.java
  
  Index: Type.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/meta/src/java/org/apache/avalon/meta/info/Type.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Type.java 24 Nov 2002 12:58:26 -0000      1.1
  +++ Type.java 26 Nov 2002 17:12:14 -0000      1.2
  @@ -120,6 +120,40 @@
                    final ExtensionDescriptor[] extensions )
           throws NullPointerException
       {
  +        this( descriptor, loggers, context, services, dependencies, stages, 
extensions, null );
  +    }
  +
  +    /**
  +     * Creation of a new Type instance using a supplied component descriptor,
  +     * logging, cotext, services, depedencies, stages and extension 
descriptors.
  +     * @param descriptor a component descriprot that contains information 
about
  +     *   the component type
  +     * @param loggers a set of logger descriptors the declare the logging 
channels
  +     *   required by the type
  +     * @param context a component context descriptor that declares the 
context type
  +     *   and context entry key and value classnames
  +     * @param services a set of service descriprors that detail the service 
that
  +     *   this component type is capable of supplying
  +     * @param dependencies a set of depedency descriprors that detail the 
service
  +     *   that this component type is depedent on
  +     * @param stages a set of stage descriprors that detail the extensiuon 
stage
  +     *   interfaces that this component requires a handler for
  +     * @param extensions a set of lifecycle extension capabilities that this
  +     *   componet can provide to its container during the process of stage
  +     *   suppier resolution
  +     * @exception NullPointerException if the descriptor, loggers, context, 
services,
  +     *   dependencies, stages, or extensions argument is null
  +     */
  +    public Type( final InfoDescriptor descriptor,
  +                 final LoggerDescriptor[] loggers,
  +                 final ContextDescriptor context,
  +                 final ServiceDescriptor[] services,
  +                 final DependencyDescriptor[] dependencies,
  +                 final StageDescriptor[] stages,
  +                 final ExtensionDescriptor[] extensions,
  +                 final Configuration defaults )
  +        throws NullPointerException
  +    {
           if( null == descriptor )
           {
               throw new NullPointerException( "descriptor" );
  @@ -156,6 +190,7 @@
           m_dependencies = dependencies;
           m_stages = stages;
           m_extensions = extensions;
  +        m_configuration = defaults;
       }
   
       /**
  @@ -293,8 +328,10 @@
        * @exception Exception if an error occurs while marchalling the default
        *   confiugration for the type
        */
  -    public Configuration getConfiguration( ClassLoader loader ) throws 
Exception
  +    //public Configuration getConfiguration( ClassLoader loader ) throws 
Exception
  +    public Configuration getConfiguration()
       {
  +        /*
           if( m_loaded )
           {
               return m_configuration;
  @@ -314,6 +351,7 @@
               m_configuration = ConfigurationBuilder.build( source );
               m_loaded = true;
           }
  +        */
           return m_configuration;
       }
   
  
  
  
  1.2       +2 -1      
avalon-sandbox/meta/src/java/org/apache/avalon/meta/info/builder/SerializedTypeCreator.java
  
  Index: SerializedTypeCreator.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/meta/src/java/org/apache/avalon/meta/info/builder/SerializedTypeCreator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SerializedTypeCreator.java        24 Nov 2002 12:58:27 -0000      1.1
  +++ SerializedTypeCreator.java        26 Nov 2002 17:12:14 -0000      1.2
  @@ -80,4 +80,5 @@
           final ObjectInputStream ois = new ObjectInputStream( inputStream );
           return (Type)ois.readObject();
       }
  +
   }
  
  
  
  1.2       +88 -15    
avalon-sandbox/meta/src/java/org/apache/avalon/meta/info/builder/TypeBuilder.java
  
  Index: TypeBuilder.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/meta/src/java/org/apache/avalon/meta/info/builder/TypeBuilder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TypeBuilder.java  24 Nov 2002 12:58:27 -0000      1.1
  +++ TypeBuilder.java  26 Nov 2002 17:12:14 -0000      1.2
  @@ -54,6 +54,11 @@
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
   import org.apache.avalon.meta.info.Type;
  +import org.apache.avalon.framework.configuration.Configuration;
  +import org.apache.avalon.framework.configuration.DefaultConfiguration;
  +import org.apache.avalon.framework.configuration.ConfigurationException;
  +import org.apache.avalon.meta.ConfigurationBuilder;
  +import org.xml.sax.InputSource;
   
   /**
    * A TypeBuilder is responsible for building [EMAIL PROTECTED] Type}
  @@ -71,7 +76,7 @@
       private static final Resources REZ =
           ResourceManager.getPackageResources( TypeBuilder.class );
   
  -    private final TypeCreator m_xmlTypeCreator = createXMLTypeCreator();
  +    private final TypeFactory m_xmlTypeFactory = createxmlTypeFactory();
       private final TypeCreator m_serialTypeCreator = new 
SerializedTypeCreator();
   
       /**
  @@ -147,14 +152,17 @@
                                            final ClassLoader classLoader )
           throws Exception
       {
  +
  +        final TypeFactory xmlTypeFactory = getXMLTypeFactory( classname );
  +
           //
           // get the input stream for the .xinfo resource
           //
   
  -        final String xinfo =
  +        final String path =
               classname.replace( '.', '/' ) + ".xinfo";
           final InputStream inputStream =
  -            classLoader.getResourceAsStream( xinfo );
  +            classLoader.getResourceAsStream( path );
   
           if( null == inputStream )
           {
  @@ -164,12 +172,77 @@
               throw new Exception( message );
           }
   
  +        final InputSource inputSource = new InputSource( inputStream );
  +        final Configuration xinfo = ConfigurationBuilder.build( inputSource 
);
  +
  +        final String xdefaults =
  +            classname.replace( '.', '/' ) + ".xconfig";
  +        final InputStream defaultsStream =
  +            classLoader.getResourceAsStream( xdefaults );
  +
  +        Configuration defaults;
  +        if( defaultsStream != null )
  +        {
  +            final InputSource defaultsSource = new InputSource( 
defaultsStream );
  +            defaults = resolveConfiguration( classLoader, 
ConfigurationBuilder.build( defaultsSource ) );
  +        }
  +        else
  +        {
  +            defaults = new DefaultConfiguration( "configuration", (String) 
null );
  +        }
  +
           //
           // build the type
           //
   
  -        final TypeCreator xmlTypeCreator = getXMLTypeCreator( classname );
  -        return xmlTypeCreator.createType( classname, inputStream );
  +        return xmlTypeFactory.createType( classname, xinfo, defaults );
  +    }
  +
  +    private Configuration resolveConfiguration( ClassLoader classloader, 
Configuration config ) 
  +      throws Exception
  +    {
  +        if( config == null )
  +        {
  +            throw new NullPointerException("config");
  +        }
  +        String src = config.getAttribute( "src", null );
  +        if( src == null )
  +        {
  +            return config;
  +        }
  +        else
  +        {
  +            if( src.startsWith( "resource://" ) )
  +            {
  +                final String url = src.substring( 11 );
  +                final InputStream stream =
  +                    classloader.getResourceAsStream( url );
  +                if( null == stream )
  +                {
  +                    final String error =
  +                        "Requested configuration source does not exist: " + 
src;
  +                    throw new ConfigurationException( error );
  +                }
  +                final InputSource source = new InputSource( stream );
  +                return resolveConfiguration( 
  +                  classloader, ConfigurationBuilder.build( source ) );
  +            }
  +            else
  +            {
  +                try
  +                {
  +                    return resolveConfiguration( 
  +                      classloader, ConfigurationBuilder.build( src ) );
  +                }
  +                catch( Throwable e )
  +                {
  +                    final String error =
  +                        "Unexpected exception while attempting to resolve 
configuration from src : "
  +                        + src;
  +                    throw new ConfigurationException( error, e );
  +                }
  +            }
  +        }
       }
   
       /**
  @@ -178,12 +251,12 @@
        *
        * @return the TypeCreator
        */
  -    private TypeCreator getXMLTypeCreator( final String classname )
  +    private TypeFactory getXMLTypeFactory( final String classname )
           throws Exception
       {
  -        if( null != m_xmlTypeCreator )
  +        if( null != m_xmlTypeFactory )
           {
  -            return m_xmlTypeCreator;
  +            return m_xmlTypeFactory;
           }
           else
           {
  @@ -195,23 +268,23 @@
       }
   
       /**
  -     * Utility to get XMLTypeCreator if XML files are on
  +     * Utility to get xmlTypeFactory if XML files are on
        * ClassPath.
        *
  -     * @return the XML [EMAIL PROTECTED] TypeCreator}
  +     * @return the XML [EMAIL PROTECTED] TypeFactory}
        */
  -    private static TypeCreator createXMLTypeCreator()
  +    private static TypeFactory createxmlTypeFactory()
       {
  -        TypeCreator xmlTypeCreator = null;
  +        TypeFactory xmlTypeFactory = null;
           try
           {
  -            xmlTypeCreator = new XMLTypeCreator();
  +            xmlTypeFactory = new XMLTypeCreator();
           }
           catch( final Exception e )
           {
               //Ignore it if ClassNot found due to no
               //XML Classes on classpath
           }
  -        return xmlTypeCreator;
  +        return xmlTypeFactory;
       }
   }
  
  
  
  1.2       +2 -1      
avalon-sandbox/meta/src/java/org/apache/avalon/meta/info/builder/TypeCreator.java
  
  Index: TypeCreator.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/meta/src/java/org/apache/avalon/meta/info/builder/TypeCreator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TypeCreator.java  24 Nov 2002 12:58:27 -0000      1.1
  +++ TypeCreator.java  26 Nov 2002 17:12:14 -0000      1.2
  @@ -74,4 +74,5 @@
        */
       Type createType( String key, InputStream input )
           throws Exception;
  +
   }
  
  
  
  1.2       +7 -8      
avalon-sandbox/meta/src/java/org/apache/avalon/meta/info/builder/XMLTypeCreator.java
  
  Index: XMLTypeCreator.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/meta/src/java/org/apache/avalon/meta/info/builder/XMLTypeCreator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XMLTypeCreator.java       24 Nov 2002 12:58:27 -0000      1.1
  +++ XMLTypeCreator.java       26 Nov 2002 17:12:14 -0000      1.2
  @@ -82,7 +82,7 @@
    */
   public class XMLTypeCreator
       extends XMLServiceCreator
  -    implements TypeCreator
  +    implements TypeFactory
   {
       private static final Resources REZ =
           ResourceManager.getPackageResources( XMLTypeCreator.class );
  @@ -91,12 +91,12 @@
        * Create a [EMAIL PROTECTED] Type} object for specified
        * classname, loaded from specified [EMAIL PROTECTED] InputStream}.
        *
  -     * @param implementationKey The classname of Component
  +     * @param classname 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,
  +    public Type createType( String classname,
                               InputStream inputStream )
           throws Exception
       {
  @@ -106,9 +106,8 @@
           }
   
           final InputSource input = new InputSource( inputStream );
  -        final String classname = implementationKey;
           final Configuration xinfo = ConfigurationBuilder.build( input );
  -        return build( classname, xinfo );
  +        return createType( classname, xinfo, (Configuration) null );
       }
   
       /**
  @@ -120,7 +119,7 @@
        * @return the created Type
        * @throws Exception if an error occurs
        */
  -    private Type build( final String classname, final Configuration info )
  +    public Type createType( final String classname, final Configuration 
info, final Configuration defaults )
           throws Exception
       {
           final String topLevelName = info.getName();
  @@ -169,7 +168,7 @@
           final ExtensionDescriptor[] extensions = buildExtensions( 
configuration );
   
           return new Type(
  -            descriptor, loggers, context, services, dependencies, phases, 
extensions );
  +            descriptor, loggers, context, services, dependencies, phases, 
extensions, defaults );
       }
   
       /**
  
  
  
  1.1                  
avalon-sandbox/meta/src/java/org/apache/avalon/meta/info/builder/TypeFactory.java
  
  Index: TypeFactory.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and
      "Apache Software Foundation"  must not be used to endorse or promote
      products derived  from this  software without  prior written
      permission. For written permission, please contact [EMAIL PROTECTED]
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.avalon.meta.info.builder;
  
  import java.io.InputStream;
  import org.apache.avalon.meta.info.Type;
  import org.apache.avalon.framework.configuration.Configuration;
  
  /**
   * Simple interface used to create [EMAIL PROTECTED] Type}
   * from stream. This abstraction was primarily created so
   * that the Type could be built from non-XML
   * sources and no XML classes need be in the classpath.
   *
   * @author <a href="mailto:avalon-dev@jakarta.apache.org";>Avalon Development 
Team</a>
   * @version $Revision: 1.1 $ $Date: 2002/11/26 17:12:14 $
   */
  public interface TypeFactory extends TypeCreator
  {
  
      /**
       * Create a [EMAIL PROTECTED] Type} using a supplied type configuration 
and default configuration 
       *
       * @param path the class resource name of component type that we are 
looking up
       * @param xinfo the configuration fragment for the type
       * @param xinfo the configuration fragment for the default configuration
       * @return the newly created [EMAIL PROTECTED] Type}
       * @exception Exception if an error occurs
       */
      Type createType( String path, Configuration xinfo, Configuration defaults 
)
          throws Exception;
  
  }
  
  
  
  1.2       +26 -77    
avalon-sandbox/meta/src/java/org/apache/avalon/meta/model/Profile.java
  
  Index: Profile.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/meta/src/java/org/apache/avalon/meta/model/Profile.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Profile.java      24 Nov 2002 12:58:28 -0000      1.1
  +++ Profile.java      26 Nov 2002 17:12:14 -0000      1.2
  @@ -54,6 +54,7 @@
   import java.io.Serializable;
   import org.apache.avalon.framework.configuration.Configurable;
   import org.apache.avalon.framework.configuration.Configuration;
  +import org.apache.avalon.framework.configuration.DefaultConfiguration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.excalibur.configuration.CascadingConfiguration;
  @@ -286,11 +287,34 @@
           }
   
           m_parameters = parameters;
  -        m_configuration = configuration;
           m_categories = categories;
           m_type = type;
           m_context = context;
           m_mode = mode;
  +
  +        Configuration parent = m_type.getConfiguration();
  +        if( parent != null )
  +        {
  +            if( configuration != null )
  +            {
  +                m_configuration = new CascadingConfiguration( parent, 
configuration );
  +            }
  +            else
  +            {
  +                m_configuration = parent;
  +            }
  +        }
  +        else
  +        {
  +            if( configuration != null )
  +            {
  +                m_configuration = configuration;
  +            }
  +            else
  +            {
  +                m_configuration = new DefaultConfiguration( "configuration", 
null );
  +            }
  +        }
       }
   
       /**
  @@ -351,81 +375,6 @@
       public Configuration getConfiguration()
       {
           return m_configuration;
  -    }
  -
  -    /**
  -     * Return the derived Configuration for the profile as a
  -     * [EMAIL PROTECTED] CascadingConfiguration}. The primary configuration
  -     * is either the base configuration of a configuration referenced
  -     * by the attribute <code>src</code> and the default configuration
  -     * is resolved from the &lt;classname&gt;.xconfig resourse.
  -     *
  -     * @param classloader the classloader to use
  -     * @return the Configuration for profile.
  -     * @exception Exception if an error occurs while resolving the 
configuration
  -     */
  -    public Configuration getConfiguration( ClassLoader classloader ) throws 
Exception
  -    {
  -        if( m_config != null )
  -        {
  -            return m_config;
  -        }
  -
  -        final Class type = classloader.loadClass(
  -            getType().getInfo().getClassname() );
  -        if( !Configurable.class.isAssignableFrom( type ) )
  -        {
  -            return null;
  -        }
  -
  -        final Configuration defaults = getType().getConfiguration( 
classloader );
  -        Configuration base = null;
  -        if( getConfiguration().getAttribute( "src", null ) != null )
  -        {
  -            String src = getConfiguration().getAttribute( "src" );
  -            if( src.startsWith( "resource://" ) )
  -            {
  -                final String url = src.substring( 11 );
  -                final InputStream stream =
  -                    classloader.getResourceAsStream( url );
  -                if( null == stream )
  -                {
  -                    final String error =
  -                        "Requested configuration source does not exist: " + 
src;
  -                    throw new ConfigurationException( error );
  -                }
  -                final InputSource source = new InputSource( stream );
  -                base = ConfigurationBuilder.build( source );
  -            }
  -            else
  -            {
  -                try
  -                {
  -                    base = ConfigurationBuilder.build( src );
  -                }
  -                catch( Throwable e )
  -                {
  -                    final String error =
  -                        "Unexpected exception while attempting to resolve 
configuration from src : "
  -                        + src;
  -                    throw new ConfigurationException( error );
  -                }
  -            }
  -        }
  -        else
  -        {
  -            base = getConfiguration();
  -        }
  -
  -        if( null == defaults )
  -        {
  -            m_config = base;
  -        }
  -        else
  -        {
  -            m_config = new CascadingConfiguration( base, defaults );
  -        }
  -        return m_config;
       }
   
       /**
  
  
  

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

Reply via email to