mcconnell    2002/07/02 17:52:23

  Modified:    assembly/src/java/org/apache/excalibur/merlin/registry
                        Profile.java
  Log:
  replaced interface and impl with direct implementation
  
  Revision  Changes    Path
  1.2       +138 -41   
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/registry/Profile.java
  
  Index: Profile.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/registry/Profile.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Profile.java      1 Jul 2002 04:27:15 -0000       1.1
  +++ Profile.java      3 Jul 2002 00:52:23 -0000       1.2
  @@ -29,11 +29,14 @@
   import org.apache.avalon.excalibur.i18n.Resources;
   import org.apache.excalibur.configuration.ConfigurationUtil;
   import org.apache.avalon.framework.logger.Logger;
  +import org.apache.avalon.framework.logger.LogEnabled;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
  +import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.avalon.framework.activity.Initializable;
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.CascadingRuntimeException;
   import org.apache.avalon.framework.configuration.Configuration;
  +import org.apache.avalon.framework.configuration.DefaultConfiguration;
   import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
   import org.apache.avalon.framework.configuration.ConfigurationException;
   import org.apache.avalon.framework.context.Context;
  @@ -47,63 +50,157 @@
   import org.apache.excalibur.containerkit.metainfo.ServiceDescriptor;
   import org.apache.excalibur.containerkit.metainfo.DependencyDescriptor;
   import org.apache.excalibur.containerkit.metainfo.ServiceDesignator;
  +
   import org.apache.excalibur.containerkit.metadata.ComponentMetaData;
   import org.apache.excalibur.containerkit.metadata.DependencyMetaData;
   
  +import org.apache.excalibur.merlin.registry.Registry;
  +import org.apache.excalibur.merlin.registry.UnresolvedProviderException;
  +import org.apache.excalibur.configuration.ContextFactory;
  +import org.apache.excalibur.configuration.ConfigurationUtil;
   
   /**
  - * Interface that defines a set of constraints applied to a component type.
  + * The default implementation of a profile under which configuration, context
  + * and parameterization criteria is associated against a component type defintion.
  + *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Stephen McConnell</a>
    * @version $Revision$ $Date$
    */
  -public interface Profile
  +public class Profile extends ComponentMetaData 
   {
  +    private static String getAbstractName( Configuration profile )
  +    {
  +        return profile.getAttribute("name",null);
  +    }
  +
  +    private static DependencyMetaData[] getDependencyMetaData( 
  +      final DefaultRegistry registry, final ComponentType type ) 
  +      throws UnresolvedProviderException
  +    {
  +        Vector vector = new Vector();
  +        DependencyDescriptor[] deps = type.getComponentInfo().getDependencies();
  +        for( int i=0; i<deps.length; i++ )
  +        {
  +            final String role = deps[i].getRole();
  +            final Profile provider = registry.getCandidateProfile( deps[i] );
  +            DependencyMetaData data = new DependencyMetaData( 
  +               role, 
  +               provider.getName() 
  +            );
  +            vector.add( data );
  +        }
  +        return (DependencyMetaData[]) vector.toArray( new DependencyMetaData[0] );
  +    }
  +
  +
  +    private final ComponentType m_type;
  +
  +    private final Configuration m_profile;
  +
  +    private final DefaultRegistry m_registry;
  +
  +   /**
  +    * Creation of a default profile.
  +    * @param type the component type that this profile is qualifying
  +    */
  +    public Profile( final DefaultRegistry registry, final ComponentType type )
  +       throws ConfigurationException, UnresolvedProviderException
  +
  +    {
  +        this( registry, type, new DefaultConfiguration("profile") );
  +    }
  +
  +   /**
  +    * Creation of a profile of a component type. The 
  +    * configuration is a profile instance containing criteria for for the 
  +    * profiles default configuration, parameters and content.
  +    * 
  +    * @param type the component type that this profile is qualifying
  +    * @param profile a configuration instance possibly containing a context, 
  +    *   parameters and configuration element.
  +    * @param name the profile name
  +    */
  +    public Profile( 
  +      final DefaultRegistry registry, final ComponentType type, final Configuration 
profile )
  +      throws ConfigurationException, UnresolvedProviderException
  +    {
  +        super( 
  +          getAbstractName( profile ), 
  +          getDependencyMetaData( registry, type ), 
  +          Parameters.fromConfiguration( profile.getChild("paramerters") ),
  +          profile.getChild("configuration"),
  +          type.getComponentInfo() 
  +        );
  +        m_type = type;
  +        m_profile = profile;
  +        m_registry = registry;
  +        m_registry.install( this );
  +    }
   
      /**
  -    * Default role name for this interface.
  -    */
  -    static final String ROLE = Profile.class.getName();
  -
  -   /**
  -    * Returns the name of the component type profile.
  -    * @return the profile name
  -    */
  -    String getName();
  -
  -   /**
  -    * Returns the component type that this profile constrains.
  +    * Returns the component type bound to the profile.
       * @return the component type
       */
  -    ComponentType getComponentType();
  +    public ComponentType getComponentType()
  +    {
  +        return m_type;
  +    }
   
      /**
       * Returns the context to be supplied to an instance of the profile
       * @return the profile context object
       */
  -    Context getContext( Context parent );
  -
  -   /**
  -    * Returns the configuration to be supplied to an instance of the profile
  -    * @return the profile configuration object
  -    */
  -    Configuration getConfiguration();
  -
  -   /**
  -    * Returns the parameters to be supplied to an instance of the profile
  -    * @return the profile parameter object
  -    */
  -    Parameters getParameters();
  -
  -    /**
  -     * Returns all dependency metadata for the profile.
  -     * @return the dependency metadata array
  -     */
  -    public DependencyMetaData[] getDependencies();
  -
  -    /**
  -     * Returns dependency metadata for a name dependency.
  -     * @return the dependency metadata
  -     */
  -    public DependencyMetaData getDependency( String role );
  +    public Context getContext( Context parent )
  +    {
  +        try
  +        {
  +            Configuration criteria = m_profile.getChild("context");
  +            return ContextFactory.createContextFromConfiguration( parent, criteria 
);
  +        }
  +        catch( Throwable e )
  +        {
  +            throw new ProfileRuntimeException( 
  +              "Unexpected error while creating context.", e );
  +        }
  +
  +    }
  +    
  +    public String toString()
  +    {
  +        return "DefaultProfile name: '" + getName() + "' type: " + 
getComponentType();
  +    }
  +
  +   /**
  +    * Provide a textual report on the profile.
  +    * @return the formatted profile report
  +    */
  +    public String report()
  +    {
  +        StringBuffer buffer = new StringBuffer();
  +        buffer.append( "PROFILE REPORT\n" );
  +        buffer.append( "\n  name: " + getName() );
  +        buffer.append( "\n  type: " + getComponentType() );
  +        buffer.append( "\n  context: " + getContext( null ) );
  +        buffer.append( "\n  configuration: \n" + ConfigurationUtil.list( 
getConfiguration() ));
  +        buffer.append( "\n  parameters: " + getParameters() );
  +        buffer.append( "\n  dependecies" );
  +
  +        DependencyMetaData[] dependencies = getDependencies();
  +        if( dependencies.length == 0 )
  +        {
  +            buffer.append( " (none)\n\n" );
  +            return buffer.toString();
  +        }
  +
  +        for( int i=0; i<dependencies.length; i++ )
  +        {
  +            buffer.append( "\n  dependency " + i );
  +            buffer.append( "\n    role: " + dependencies[i].getRole() );
  +            buffer.append( "\n    provider: " + dependencies[i].getProviderName() );
  +        }
  +
  +        buffer.append( "\n\n" );
  +        return buffer.toString();
  +    }
   
   }
  
  
  

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

Reply via email to