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-spi/src/java/org/apache/avalon/meta/model Profile.java
Date Thu, 24 Apr 2003 12:44:30 GMT
mcconnell    2003/04/24 05:44:30

  Modified:    merlin/meta-spi/src/java/org/apache/avalon/meta/model
                        Profile.java
  Log:
  Updated profile creation to be component based (simplying the approach for specialized profile
types).
  
  Revision  Changes    Path
  1.4       +136 -125  avalon-sandbox/merlin/meta-spi/src/java/org/apache/avalon/meta/model/Profile.java
  
  Index: Profile.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/meta-spi/src/java/org/apache/avalon/meta/model/Profile.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Profile.java	20 Apr 2003 12:46:25 -0000	1.3
  +++ Profile.java	24 Apr 2003 12:44:29 -0000	1.4
  @@ -51,10 +51,17 @@
   package org.apache.avalon.meta.model;
   
   import java.io.Serializable;
  +import java.util.ArrayList;
   
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.DefaultConfiguration;
  +import org.apache.avalon.framework.context.Context;
  +import org.apache.avalon.framework.context.ContextException;
  +import org.apache.avalon.framework.context.Contextualizable;
   import org.apache.avalon.framework.parameters.Parameters;
  +import org.apache.avalon.meta.info.DependencyDescriptor;
  +import org.apache.avalon.meta.info.ReferenceDescriptor;
  +import org.apache.avalon.meta.info.ServiceDescriptor;
   import org.apache.avalon.meta.info.Type;
   import org.apache.excalibur.configuration.CascadingConfiguration;
   import org.apache.excalibur.configuration.ConfigurationUtil;
  @@ -134,187 +141,115 @@
    * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
    * @version $Revision$ $Date$
    */
  -public class Profile implements Serializable
  +public class Profile implements Serializable, Contextualizable
   {
  +    public static final String NAME_KEY = "urn:meta:profile.name";
  +    public static final String TYPE_KEY = "urn:meta:profile.type"; 
  +    public static final String CATEGORIES_KEY = "urn:meta:profile.categories"; 
  +    public static final String MODE_KEY = "urn:meta:profile.mode"; 
  +    public static final String PARAMETERS_KEY = "urn:meta:profile.parameters"; 
  +    public static final String CONFIGURATION_KEY = "urn:meta:profile.configuration"; 
  +    public static final String CONTEXT_KEY = "urn:meta:profile.context"; 
   
       /**
        * The name of the component profile. This is an
        * abstract name used during assembly.
        */
  -    private final String m_name;
  +    private String m_name;
   
       /**
        * The assigned logging categories.
        */
  -    private final LoggingDirective m_categories;
  +    private LoggingDirective m_categories;
   
       /**
        * The info object for component type.
        */
  -    private final Type m_type;
  +    private Type m_type;
   
       /**
        * The parameters for component (if any).
        */
  -    private final Parameters m_parameters;
  +    private Parameters m_parameters;
   
       /**
        * The configuration for component (if any).
        */
  -    private final Configuration m_configuration;
  +    private Configuration m_configuration;
   
       /**
        * The configuration for component (if any).
        */
  -    private final ContextDirective m_context;
  +    private ContextDirective m_context;
   
       /**
        * The creation mode.
        */
  -    private final Mode m_mode;
  +    private Mode m_mode;
   
       /**
        * The activation policy.
        */
       private transient boolean m_activation = false;
   
  -    /**
  -     * Create an explicit Profile instance.
  -     *
  -     * @param name the abstract name of the profile
  -     * @param type the type of component that this profile qualifies
  -     * @param categories the logging categoories descriptor
  -     */
  -    public Profile( final String name,
  -                    final Type type,
  -                    final LoggingDirective categories )
  +    //--------------------------------------------------------------------------
  +    // lifecycle
  +    //--------------------------------------------------------------------------
  +
  +    public void contextualize( Context context ) throws ContextException
       {
  -        this( name, null, null, null, categories, type, Mode.EXPLICIT );
  +        m_type = (Type) context.get( TYPE_KEY );
  +        m_categories = (LoggingDirective) context.get( CATEGORIES_KEY );
  +        m_mode = (Mode) context.get( MODE_KEY );
  +
  +        setName( context );
  +        setContext( context );
  +        setParameters( context );
  +        setConfiguration( context );
       }
   
  +    //--------------------------------------------------------------------------
  +    // implementation
  +    //--------------------------------------------------------------------------
  +
       /**
  -     * Create a Profile instance without parameters.
  +     * Return the type info for component.
        *
  -     * @param name the abstract name of the profile
  -     * @param configuration the configuration instance to use during type instantiation
  -     * @param context the context instance to use during type instantiation
  -     * @param categories the logging categories descriptor
  -     * @param type the type of component that this profile qualifies
  -     * @param mode the creation mode (either IMPLICIT, PACKAGED, or EXPLICIT)
  +     * @return the info for component type.
        */
  -    public Profile( final String name,
  -                    final Configuration configuration,
  -                    final ContextDirective context,
  -                    final LoggingDirective categories,
  -                    final Type type,
  -                    final Mode mode )
  +    public Type getType()
       {
  -        this( name, null, configuration, context, categories, type, mode );
  +        return m_type;
       }
   
       /**
  -     * Create an explicit Profile instance without parameters.
  -     *
  -     * @param name the abstract name of profile
  -     * @param activation the profile activation policy
  -     * @param template the profile to use as a template
  +     * Get the block virtual services.
  +     * @return the block virtual services
        */
  -    public Profile( final String name, final Profile template )
  +    public ServiceDescriptor[] getServices()
       {
  -        this(
  -            name,
  -            template.getParameters(),
  -            template.getConfiguration(),
  -            template.getContext(),
  -            template.getCategories(),
  -            template.getType(),
  -            Mode.EXPLICIT
  -        );
  +        return m_type.getServices();
       }
   
       /**
  -     * Create a Profile instance.
  +     * Retrieve a service with a particular reference.
        *
  -     * @param name the abstract name of component meta data instance
  -     * @param parameters the parameters instance to use during type instantiation
  -     * @param configuration the configuration instance to use during type instantiation
  -     * @param context the context instance to use during type instantiation
  -     * @param categories the logging categories descriptor
  -     * @param type the type of component that this profile qualifies
  -     * @param mode the creation mode (either IMPLICIT, PACKAGED, or EXPLICIT)
  -     */
  -    public Profile( final String name,
  -                    final Parameters parameters,
  -                    final Configuration configuration,
  -                    final ContextDirective context,
  -                    final LoggingDirective categories,
  -                    final Type type,
  -                    final Mode mode )
  +     * @param reference a service reference descriptor
  +     * @return the service descriptor or null if it does not exist
  +     */
  +    public ServiceDescriptor getService( final ReferenceDescriptor reference )
       {
  -        if( null == type )
  -        {
  -            throw new NullPointerException( "type" );
  -        }
  -
  -        if( null == name )
  -        {
  -            m_name = type.getInfo().getName();
  -        }
  -        else
  -        {
  -            m_name = name;
  -        }
  -
  -        if( null == categories )
  -        {
  -            throw new NullPointerException( "categories" );
  -        }
  -
  -        if( null == mode )
  -        {
  -            throw new NullPointerException( "mode" );
  -        }
  -
  -        m_parameters = parameters;
  -        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( configuration, parent );
  -            }
  -            else
  -            {
  -                m_configuration = parent;
  -            }
  -        }
  -        else
  -        {
  -            if( configuration != null )
  -            {
  -                m_configuration = configuration;
  -            }
  -            else
  -            {
  -                m_configuration = new DefaultConfiguration( "configuration", "Profile.class"
);
  -            }
  -        }
  +        return m_type.getService( reference );
       }
   
       /**
  -     * Return the type info for component.
  -     *
  -     * @return the info for component type.
  +     * Get the block virtual dependencies.
  +     * @return the block virtual dependecies
        */
  -    public Type getType()
  -    {
  -        return m_type;
  -    }
  +     public DependencyDescriptor[] getDependencies()
  +     {
  +         return m_type.getDependencies();
  +     }
   
       /**
        * Return the name of component metadata instance.
  @@ -418,5 +353,81 @@
       public boolean getActivationPolicy()
       {
           return m_activation;
  +    }
  +
  +    private void setParameters( Context context )
  +    {
  +        try
  +        {
  +            m_parameters = (Parameters) context.get( PARAMETERS_KEY );
  +        }
  +        catch( ContextException e )
  +        {
  +            // ignore
  +        }
  +    }
  +
  +    private void setContext( Context context )
  +    {
  +        try
  +        {
  +            m_context = (ContextDirective) context.get( CONTEXT_KEY );
  +        }
  +        catch( ContextException e )
  +        {
  +            // ignore
  +        }
  +    }
  +
  +    private void setName( Context context )
  +    {
  +        try
  +        {
  +            m_name = (String) context.get( NAME_KEY );
  +        }
  +        catch( ContextException e )
  +        {
  +            m_name = m_type.getInfo().getName();
  +        }
  +    }
  +
  +    private void setConfiguration( Context context )
  +    {
  +        try
  +        {
  +            Configuration config = 
  +              (Configuration) context.get( CONFIGURATION_KEY );
  +            Configuration parent = m_type.getConfiguration();
  +
  +            if( parent != null )
  +            {
  +                if( config != null )
  +                {
  +                    m_configuration = 
  +                      new CascadingConfiguration( config, parent );
  +                }
  +                else
  +                {
  +                    m_configuration = parent;
  +                }
  +            }
  +            else
  +            {
  +                 m_configuration = config;
  +            }
  +        }
  +        catch( ContextException e )
  +        {
  +            Configuration config = m_type.getConfiguration();
  +            if( config != null )
  +            {
  +                m_configuration = config;
  +            }
  +            else
  +            {
  +                m_configuration = 
  +                  new DefaultConfiguration( "configuration", "Profile.class" );
  +            }
  +        }
       }
   }
  
  
  

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


Mime
View raw message