mcconnell    2003/07/05 21:07:52

  Modified:    merlin/composition/src/java/org/apache/avalon/composition/model/impl
                        DefaultCompositionModel.java
                        DefaultContainmentModel.java
                        DefaultDeploymentModel.java DefaultModel.java
                        DefaultSystemContext.java Resources.properties
  Log:
  Add parameterization handling to the deployment model and improve the configuration 
handling code.
  
  Revision  Changes    Path
  1.4       +2 -2      
avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultCompositionModel.java
  
  Index: DefaultCompositionModel.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultCompositionModel.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultCompositionModel.java      6 Jul 2003 03:00:25 -0000       1.3
  +++ DefaultCompositionModel.java      6 Jul 2003 04:07:52 -0000       1.4
  @@ -222,6 +222,6 @@
   
       public String toString()
       {
  -        return "[composition model: " + getPath() + getName() + "]";
  +        return "[composition model: " + getFQN() + "]";
       }
   }
  
  
  
  1.5       +2 -2      
avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModel.java
  
  Index: DefaultContainmentModel.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModel.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultContainmentModel.java      6 Jul 2003 03:00:25 -0000       1.4
  +++ DefaultContainmentModel.java      6 Jul 2003 04:07:52 -0000       1.5
  @@ -301,6 +301,6 @@
   
       public String toString()
       {
  -        return "[containment model: " + getPath() + getName() + "]";
  +        return "[containment model: " + getFQN() + "]";
       }
   }
  
  
  
  1.5       +184 -39   
avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultDeploymentModel.java
  
  Index: DefaultDeploymentModel.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultDeploymentModel.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultDeploymentModel.java       6 Jul 2003 03:00:25 -0000       1.4
  +++ DefaultDeploymentModel.java       6 Jul 2003 04:07:52 -0000       1.5
  @@ -51,6 +51,8 @@
   package org.apache.avalon.composition.model.impl;
   
   import java.io.File;
  +import java.util.Properties;
  +import java.util.Enumeration;
   
   import org.apache.avalon.composition.model.DeploymentModel;
   import org.apache.avalon.composition.model.ClassLoaderModel;
  @@ -61,6 +63,8 @@
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.DefaultConfiguration;
   import org.apache.avalon.framework.configuration.Configurable;
  +import org.apache.avalon.framework.parameters.Parameters;
  +import org.apache.avalon.framework.parameters.Parameterizable;
   import org.apache.avalon.framework.logger.Logger;
   import org.apache.avalon.meta.data.DeploymentProfile;
   import org.apache.avalon.meta.info.Type;
  @@ -104,9 +108,9 @@
       // mutable state
       //==============================================================
   
  -    private Configuration m_config = null;
  +    private Configuration m_config;
   
  -    private boolean m_configurationReplacementPolicy = false;
  +    private Parameters m_parameters;
   
       //==============================================================
       // constructor
  @@ -154,12 +158,39 @@
                 profile.getClassname() );
           }
           m_type = m_classLoaderModel.getTypeRepository().getType( m_class );
  +
  +        if( isConfigurable() )
  +        {
  +            final Configuration defaults = m_type.getConfiguration();
  +            final Configuration explicit = m_profile.getConfiguration();
  +            final Configuration consolidated = 
  +              consolidateConfigurations( explicit, defaults );
  +            if( consolidated != null )
  +            {
  +                m_config = consolidated;
  +            }
  +            else
  +            {
  +                m_config = EMPTY_CONFIGURATION;
  +            }
  +        }
  +
  +        if( isParameterizable() )
  +        {
  +            final Parameters parameters = m_profile.getParameters();
  +            if( parameters != null )
  +            {
  +                m_parameters = parameters;
  +            }
  +            else
  +            {
  +                m_parameters = Parameters.EMPTY_PARAMETERS;
  +            }
  +        }
       }
   
       //==============================================================
  -    // implementation
  -    //
  -    // expose everything needed to create a new appliance instance
  +    // DeploymentModel
       //==============================================================
   
       public Type getType()
  @@ -177,12 +208,124 @@
       }
   
      /**
  +    * Rest if the component type backing the model is 
  +    * parameterizable.
  +    *
  +    * @param return TRUE if the compoent type is parameterizable
  +    *   otherwise FALSE
  +    */
  +    public boolean isParameterizable()
  +    {
  +        return Parameters.class.isAssignableFrom( getDeploymentClass() );
  +    }
  +
  +   /**
  +    * Set the parameters to the supplied value.  The supplied 
  +    * parameters value will replace the existing parameters value.
  +    *
  +    * @param parameters the supplied parameters value
  +    * @exception IllegalStateException if the component type backing the 
  +    *   model does not implement the parameteriazable interface
  +    * @exception NullPointerException if the supplied parameters are null
  +    */
  +    public void setParameters( Parameters parameters )
  +    {
  +        setParameters( parameters, true );
  +    }
  +
  +   /**
  +    * Set the parameters to the supplied value.  The supplied 
  +    * parameters value may suppliment or replace the existing 
  +    * parameters value.
  +    *
  +    * @param parameters the supplied parameters
  +    * @param policy if TRUE the supplied parameters replaces the current
  +    *   parameters value otherwise the existing and supplied values
  +    *   are aggregrated
  +    * @exception IllegalStateException if the component type backing the 
  +    *   model does not implement the parameteriazable interface
  +    * @exception NullPointerException if the supplied parameters are null
  +    */
  +    public void setParameters( Parameters parameters, boolean policy )
  +      throws IllegalStateException
  +    {
  +        if( !isParameterizable() )
  +        {
  +            final String error = 
  +              REZ.getString( 
  +                "deployment.parameters.irrational", 
  +                getDeploymentClass().getName(), 
  +                this.toString() );
  +            throw new IllegalStateException( error );
  +        }
  +
  +        if( parameters == null )
  +        {
  +            throw new NullPointerException( "parameters" );
  +        }
  +
  +        if( policy )
  +        {
  +            Properties props = Parameters.toProperties( m_parameters );
  +            Properties suppliment = Parameters.toProperties( parameters );
  +            Enumeration enum = suppliment.propertyNames();
  +            while( enum.hasMoreElements() )
  +            {
  +                String name = (String) enum.nextElement();
  +                String value = suppliment.getProperty( name );
  +                if( value == null )
  +                {
  +                    props.remove( name );
  +                }
  +                else
  +                {
  +                    props.setProperty( name, value );
  +                }
  +            }
  +            m_parameters = Parameters.fromProperties( props );
  +        }
  +        else
  +        {        
  +            m_parameters = parameters;
  +        }
  +    }
  +
  +   /**
  +    * Return the configuration to be applied to the component.
  +    * The implementation returns the current configuration state.
  +    * If the the component type does not implementation the 
  +    * Configurable interface, the implementation returns null. 
  +    *
  +    * @return the qualified configuration
  +    */
  +    public Parameters getParameters()
  +    {
  +        return m_parameters;
  +    }
  +
  +   /**
  +    * Rest if the component type backing the model is 
  +    * configurable.
  +    *
  +    * @param return TRUE if the component type is configurable
  +    *   otherwise FALSE
  +    */
  +    public boolean isConfigurable()
  +    {
  +        return Configurable.class.isAssignableFrom( getDeploymentClass() );
  +    }
  +
  +   /**
       * Set the configuration to the supplied value.  The supplied 
       * configuration will replace the existing configuration.
       *
       * @param config the supplied configuration
  +    * @exception IllegalStateException if the component type backing the 
  +    *   model does not implement the configurable interface
  +    * @exception NullPointerException if the supplied configuration is null
       */
       public void setConfiguration( Configuration config )
  +      throws IllegalStateException, NullPointerException
       {
           setConfiguration( config, true );
       }
  @@ -196,11 +339,36 @@
       *   configuration otherwise the resoved configuration shall be layed above
       *   the configuration supplied with the profile which in turn is layer above 
       *   the type default configuration (if any)
  +    * @exception IllegalStateException if the component type backing the 
  +    *   model does not implement the configurable interface
  +    * @exception NullPointerException if the supplied configuration is null
       */
       public void setConfiguration( Configuration config, boolean policy )
  +      throws IllegalStateException, NullPointerException
       {
  -        m_config = config;
  -        m_configurationReplacementPolicy = policy;
  +        if( !isConfigurable() )
  +        {
  +            final String error = 
  +              REZ.getString( 
  +                "deployment.configuration.irrational", 
  +                getDeploymentClass().getName(), 
  +                this.toString() );
  +            throw new IllegalStateException( error );
  +        }
  +
  +        if( config == null )
  +        {
  +            throw new NullPointerException( "config" );
  +        }
  +
  +        if( policy )
  +        {
  +            m_config = consolidateConfigurations( config, m_config );
  +        }
  +        else
  +        {
  +            m_config = config;
  +        }
       }
   
      /**
  @@ -213,34 +381,15 @@
       */
       public Configuration getConfiguration()
       {
  -        if( Configurable.class.isAssignableFrom( getDeploymentClass() ) )
  -        {
  -            if( m_configurationReplacementPolicy ) 
  -            {
  -                if( m_config != null )
  -                {
  -                    return m_config;
  -                }
  -                else
  -                {
  -                    return EMPTY_CONFIGURATION;
  -                }
  -            }
  -            else
  -            {
  -                final Configuration defaults = m_type.getConfiguration();
  -                final Configuration explicit = m_profile.getConfiguration();
  -                Configuration consolidated = consolidateConfigurations( explicit, 
defaults );
  -                return consolidateConfigurations( m_config, consolidated );
  -            }
  -        }
  -        else
  -        {
  -            return null;
  -        }
  +        return m_config;
       }
   
  -    private Configuration consolidateConfigurations( final Configuration primary, 
final Configuration defaults )
  +    //==============================================================
  +    // implementation
  +    //==============================================================
  +
  +    private Configuration consolidateConfigurations( 
  +      final Configuration primary, final Configuration defaults )
       {
           if( primary == null )
           {
  @@ -259,12 +408,8 @@
           }
       }
   
  -    //==============================================================
  -    // protected implementation
  -    //==============================================================
  -
       public String toString()
       {
  -        return "[deployment model : " + getPath() + getName() + "]";
  +        return "[deployment model : " + getFQN() + "]";
       }
   }
  
  
  
  1.3       +6 -1      
avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultModel.java
  
  Index: DefaultModel.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultModel.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultModel.java 6 Jul 2003 03:00:25 -0000       1.2
  +++ DefaultModel.java 6 Jul 2003 04:07:52 -0000       1.3
  @@ -146,6 +146,11 @@
           return m_logger;
       }
   
  +    protected String getFQN()
  +    {
  +        return getPath() + getName();
  +    }
  +
       public String toString()
       {
           return "[model: " + getPath() + getName() + "]";
  
  
  
  1.3       +3 -16     
avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultSystemContext.java
  
  Index: DefaultSystemContext.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/DefaultSystemContext.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultSystemContext.java 6 Jul 2003 03:00:25 -0000       1.2
  +++ DefaultSystemContext.java 6 Jul 2003 04:07:52 -0000       1.3
  @@ -66,7 +66,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
    * @version $Revision$ $Date$
    */
  -public class DefaultSystemContext extends DefaultContext implements SystemContext
  +public class DefaultSystemContext implements SystemContext
   {
       //==============================================================
       // static
  @@ -97,20 +97,6 @@
       */
       public DefaultSystemContext( File base, Repository repository )
       {
  -        this( base, repository, null );
  -    }
  -
  -   /**
  -    * Creation of a new system context.
  -    *
  -    * @param base the base directory from which relative references 
  -    *   within a classpath or library directive shall be resolved
  -    * @param repository a resource repository to be used when resolving 
  -    *   resource directives
  -    */
  -    public DefaultSystemContext( File base, Repository repository, Map map )
  -    {
  -        super( map );
           if( base == null )
           {
               throw new NullPointerException( "base" );
  @@ -125,6 +111,7 @@
                 REZ.getString( "system.context.base.not-a-directory.error", base  );
               throw new IllegalArgumentException( error );
           }
  +
           m_base = base;
           m_repository = repository;
       }
  
  
  
  1.4       +2 -0      
avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/model/impl/Resources.properties,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Resources.properties      6 Jul 2003 03:00:25 -0000       1.3
  +++ Resources.properties      6 Jul 2003 04:07:52 -0000       1.4
  @@ -19,6 +19,8 @@
   containment.unknown-profile-class.error=Unknown profile class: {1} in {0}.
   
   # DefaultDeploymentModel
  +deployment.parameters.irrational=Illegal attempt to set a parameter value for a 
component type '{0}' that is not parameterizable in the model: {1}.
  +deployment.configuration.irrational=Illegal attempt to set a cofiguration value for 
a component type '{0}' that is not confiurable in the model: {1}.
   
   # DefaultModel
   created=created: {0}
  
  
  

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

Reply via email to