avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon-sandbox/merlin/meta/src/java/org/apache/avalon/meta/model/builder XMLProfileCreator.java
Date Thu, 24 Apr 2003 12:43:31 GMT
mcconnell    2003/04/24 05:43:31

  Modified:    merlin/meta project.xml
               merlin/meta/src/java/org/apache/avalon/meta/info/builder
                        XMLTypeCreator.java
               merlin/meta/src/java/org/apache/avalon/meta/model/builder
                        XMLProfileCreator.java
  Log:
  Updated profile creation to be component based (simplying the approach for specialized profile
types).
  
  Revision  Changes    Path
  1.3       +1 -1      avalon-sandbox/merlin/meta/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/meta/project.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- project.xml	29 Mar 2003 06:56:46 -0000	1.2
  +++ project.xml	24 Apr 2003 12:43:31 -0000	1.3
  @@ -4,7 +4,7 @@
     <extend>${basedir}/../project.xml</extend>
     <groupId>avalon</groupId>
     <id>avalon-meta</id>
  -  <name>Meta</name>
  +  <name>Meta Model</name>
     <package>org.apache.avalon.meta</package>
   
     <currentVersion>1.0</currentVersion>
  
  
  
  1.6       +2 -2      avalon-sandbox/merlin/meta/src/java/org/apache/avalon/meta/info/builder/XMLTypeCreator.java
  
  Index: XMLTypeCreator.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/meta/src/java/org/apache/avalon/meta/info/builder/XMLTypeCreator.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XMLTypeCreator.java	15 Apr 2003 03:05:41 -0000	1.5
  +++ XMLTypeCreator.java	24 Apr 2003 12:43:31 -0000	1.6
  @@ -382,7 +382,7 @@
        * @return the created ServiceDescriptor
        * @throws ConfigurationException if an error occurs
        */
  -    protected ServiceDescriptor buildService( final Configuration service )
  +    public ServiceDescriptor buildService( final Configuration service )
           throws ConfigurationException
       {
           ReferenceDescriptor reference = createReference( service.getAttribute( "type" )
);
  
  
  
  1.3       +49 -44    avalon-sandbox/merlin/meta/src/java/org/apache/avalon/meta/model/builder/XMLProfileCreator.java
  
  Index: XMLProfileCreator.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/meta/src/java/org/apache/avalon/meta/model/builder/XMLProfileCreator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XMLProfileCreator.java	20 Apr 2003 12:26:27 -0000	1.2
  +++ XMLProfileCreator.java	24 Apr 2003 12:43:31 -0000	1.3
  @@ -61,6 +61,7 @@
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
   import org.apache.avalon.framework.configuration.DefaultConfiguration;
  +import org.apache.avalon.framework.context.DefaultContext;
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.avalon.meta.model.ModelRuntimeException;
   import org.apache.avalon.meta.model.LoggingDirective;
  @@ -72,6 +73,8 @@
   import org.apache.avalon.meta.model.Profile;
   import org.apache.avalon.meta.model.Mode;
   import org.apache.avalon.meta.ConfigurationBuilder;
  +import org.apache.avalon.meta.info.DependencyDescriptor;
  +import org.apache.avalon.meta.info.ServiceDescriptor;
   import org.apache.avalon.meta.info.Type;
   import org.apache.avalon.meta.info.builder.XMLTypeCreator;
   import org.apache.excalibur.configuration.CascadingConfiguration;
  @@ -119,35 +122,20 @@
       */
       public XMLProfileCreator( Class base )
       {
  -        m_clazz = base;
  -        try
  +        if( base == null )
           {
  -            m_base = base.getConstructor( 
  -             new Class[]
  -             {
  -              String.class, 
  -              Parameters.class,
  -              Configuration.class,
  -              ContextDirective.class,
  -              LoggingDirective.class,
  -              Type.class,
  -              Mode.class
  -             }
  -           );
  -        }
  -        catch( Throwable e )
  -        {
  -           throw new RuntimeException( e.toString() );
  +            throw new NullPointerException( "base" );
           }
  +        m_clazz = base;
       }
   
      /**
  -    * Returns the constructor to use when using a custom profile class.
  -    * @return the custom profile constructor
  +    * Returns the base profile class.
  +    * @return the custom profile class
       */
  -    protected Constructor getConstructor()
  +    protected Class getBaseClass()
       {
  -        return m_base;
  +        return m_clazz;
       }
   
       /**
  @@ -208,6 +196,7 @@
       {
           return buildProfile( type, config, defaults, Mode.EXPLICIT );
       }
  +
       /**
        * Create an array of {@link Profile} object for specified type from
        * specified configuration data associated with a single type.
  @@ -232,8 +221,7 @@
   
           for( int i = 0; i < profiles.length; i++ )
           {
  -            vector.add( buildProfile(
  -                type, profiles[ i ], Mode.PACKAGED ) );
  +            vector.add( buildProfile( type, profiles[ i ], Mode.PACKAGED ) );
           }
   
           return (Profile[])vector.toArray( (Object[]) Array.newInstance( m_clazz, 0 ) );
  @@ -247,7 +235,7 @@
       }
   
       private Profile buildProfile(
  -        Type type, Configuration profile, Configuration defaults, Mode mode )
  +        Type type, Configuration config, Configuration custom, Mode mode )
           throws Exception
       {
   
  @@ -255,30 +243,31 @@
           // create the logging categories for this profile
           //
   
  -        final String name = profile.getAttribute( "name" );
  +        final String name = config.getAttribute( "name" );
   
           LoggingDirective categories =
               createLoggingDirective(
  -                name, profile.getChild( "categories" ) );
  +                name, config.getChild( "categories" ) );
   
           //
           // build the profile directives
           //
   
           final Parameters params =
  -            Parameters.fromConfiguration( profile.getChild( "parameters" ) );
  -        final ContextDirective context =
  -            createContextDirective( profile.getChild( "context" ) );
  +            Parameters.fromConfiguration( config.getChild( "parameters" ) );
  +        final ContextDirective contextDirective =
  +            createContextDirective( config.getChild( "context" ) );
   
  -        Configuration config = null;
  -        if( defaults == null )
  +        Configuration configuration = null;
  +        if( custom == null )
           {
  -            config = profile.getChild( "configuration" );
  +            configuration = config.getChild( "configuration" );
           }
           else
           {
  -            Configuration base = profile.getChild( "configuration" );
  -            config = new CascadingConfiguration( defaults, base );
  +            configuration = 
  +              new CascadingConfiguration( 
  +               custom, config.getChild( "configuration" ) );
           }
   
           //
  @@ -287,9 +276,17 @@
   
           try
           {
  -            return (Profile) getConstructor().newInstance(
  -              new Object[]{
  -                name, params, config, context, categories, type, mode } );
  +            Profile profile = (Profile) m_clazz.newInstance();
  +            DefaultContext context = new DefaultContext();
  +            context.put( Profile.NAME_KEY, name );
  +            context.put( Profile.PARAMETERS_KEY, params );
  +            context.put( Profile.CONFIGURATION_KEY, configuration );
  +            context.put( Profile.CONTEXT_KEY, contextDirective );
  +            context.put( Profile.CATEGORIES_KEY, categories );
  +            context.put( Profile.TYPE_KEY, type );
  +            context.put( Profile.MODE_KEY, mode );
  +            profile.contextualize( context );
  +            return profile;
           }
           catch( Throwable e )
           {
  @@ -301,7 +298,7 @@
   
       private Profile createImplicitProfile( Type type ) throws Exception
       {
  -        ContextDirective context =
  +        ContextDirective contextDirective =
               new ContextDirective( null, new Import[ 0 ], new Entry[ 0 ] );
           final Configuration defaults =
               new DefaultConfiguration( "default", null );
  @@ -310,13 +307,21 @@
   
           try
           {
  -            return (Profile) getConstructor().newInstance(
  -              new Object[]{ null, null, defaults, context, categories, type, Mode.IMPLICIT
} );
  +            Profile profile = (Profile) m_clazz.newInstance();
  +            DefaultContext context = new DefaultContext();
  +            context.put( Profile.CONFIGURATION_KEY, defaults );
  +            context.put( Profile.CONTEXT_KEY, contextDirective );
  +            context.put( Profile.CATEGORIES_KEY, categories );
  +            context.put( Profile.TYPE_KEY, type );
  +            context.put( Profile.MODE_KEY, Mode.IMPLICIT );
  +            profile.contextualize( context );
  +            return profile;
           }
           catch( Throwable e )
           {
               final String error = 
  -              "Unexpected error while attempting to build implicit profile using class:
" + m_base;
  +              "Unexpected error while attempting to build implicit profile using class:
" 
  +              + m_base;
               throw new ModelRuntimeException( error, e );
           }
       }
  @@ -517,7 +522,7 @@
        * @return the category directive
        * @throws ConfigurationException if an error occurs
        */
  -    protected Category createCategory( Configuration config )
  +    public Category createCategory( Configuration config )
           throws ConfigurationException
       {
           return createCategory( null, config );
  
  
  

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


Mime
View raw message