svn commit: rev 31048 - in avalon/trunk/runtime/composition: api/src/java/org/apache/avalon/composition/data impl/src/java/org/apache/avalon/composition/data/builder impl/src/java/org/apache/avalon/composition/model/impl

[email protected]
Newsgroups gmane.comp.jakarta.avalon.cvs
Message-ID <[email protected]>
Author: niclas
Date: Sat Jul 31 10:21:49 2004
New Revision: 31048

Modified:
   avalon/trunk/runtime/composition/api/src/java/org/apache/avalon/composition/data/TargetDirective.java
   avalon/trunk/runtime/composition/impl/src/java/org/apache/avalon/composition/data/builder/XMLTargetsCreator.java
   avalon/trunk/runtime/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultComponentModel.java
   avalon/trunk/runtime/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModel.java
Log:
Added Parameters override support in composition.

Modified: avalon/trunk/runtime/composition/api/src/java/org/apache/avalon/composition/data/TargetDirective.java
==============================================================================
--- avalon/trunk/runtime/composition/api/src/java/org/apache/avalon/composition/data/TargetDirective.java	(original)
+++ avalon/trunk/runtime/composition/api/src/java/org/apache/avalon/composition/data/TargetDirective.java	Sat Jul 31 10:21:49 2004
@@ -20,6 +20,7 @@
 import java.io.Serializable;
 
 import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.parameters.Parameters;
 
 import org.apache.avalon.logging.data.CategoriesDirective;
 
@@ -48,6 +49,11 @@
     private final Configuration m_config;
 
     /**
+     * The parameters.
+     */
+    private final Parameters m_params;
+
+    /**
      * The configuration.
      */
     private final CategoriesDirective m_categories;
@@ -67,19 +73,43 @@
      * @param path target path
      * @param configuration the configuration 
      * @param categories the logging category directives 
+     * @param profile a security profile
+     */
+    public TargetDirective( 
+      final String path, 
+      final Configuration configuration, 
+      final CategoriesDirective categories,
+      final String profile )
+    {
+        this( path, configuration, null, categories, profile );
+    }
+
+    /**
+     * Create a new Target instance.
+     *
+     * @param path target path
+     * @param configuration the configuration 
+     * @param parameters the parameters
+     * @param categories the logging category directives 
+     * @param profile a security profile
+     *
+     * @since 2.1.0
      */
     public TargetDirective( 
       final String path, 
       final Configuration configuration, 
+      final Parameters parameters, 
       final CategoriesDirective categories,
       final String profile )
     {
         m_path = path;
         m_config = configuration;
+        m_params = parameters;
         m_categories = categories;
         m_profile = profile;
     }
 
+
     //========================================================================
     // implementation
     //========================================================================
@@ -105,6 +135,16 @@
     }
 
     /**
+     * Return the target parameters.
+     *
+     * @return the target parameters
+     */
+    public Parameters getParameters()
+    {
+        return m_params;
+    }
+
+    /**
      * Return the name of the assigned security profile.
      *
      * @return the assigned profile name (possibly null)
@@ -132,6 +172,7 @@
     {
         return "[target: " + getPath() + ", " 
           + (getConfiguration() != null ) + ", " 
+          + (getParameters() != null ) + ", " 
           + (getCategoriesDirective() != null ) + ", " 
           + (getSecurityProfileName() != null )
           + " ]";

Modified: avalon/trunk/runtime/composition/impl/src/java/org/apache/avalon/composition/data/builder/XMLTargetsCreator.java
==============================================================================
--- avalon/trunk/runtime/composition/impl/src/java/org/apache/avalon/composition/data/builder/XMLTargetsCreator.java	(original)
+++ avalon/trunk/runtime/composition/impl/src/java/org/apache/avalon/composition/data/builder/XMLTargetsCreator.java	Sat Jul 31 10:21:49 2004
@@ -23,6 +23,8 @@
 import org.apache.avalon.composition.data.Targets;
 
 import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.parameters.Parameters;
 
 /**
  * Handles internalization of an XML based description of a {@link Targets}
@@ -34,7 +36,7 @@
 public class XMLTargetsCreator extends XMLComponentProfileCreator 
 {
    /**
-    * Create a set of target directives from the confiugration.
+    * Create a set of target directives from the configuration.
     * @param config the targets configuration
     */
     public Targets createTargets( Configuration config )
@@ -46,6 +48,26 @@
         {
             targets[i] = createTargetDirective( children[i] );
         }
+
+        //
+        // check that no non-target elements are declared
+        //
+
+        Configuration[] nodes = config.getChildren();
+        for( int i=0; i<nodes.length; i++ )
+        {
+            final Configuration node = nodes[i];
+            final String name = node.getName();
+            if( ! name.equals( "target" ) )
+            {
+                final String error = 
+                  "Unrecognized configuration element '" 
+                  + name + "' is declared within a targets directive. "
+                  + "A 'targets' directive may only contain 'target' elements.";
+                throw new ConfigurationException( error );
+            }
+        }
+        
         return new Targets( targets );
     }
 
@@ -91,9 +113,24 @@
         final Configuration conf = config.getChild( "configuration", false );
 
         //
+        // get the overriding parameters
+        //
+
+        final Configuration paramsConfig = config.getChild( "parameters", false );
+        final Parameters params = getTargetParameters( paramsConfig );
+
+        //
         // and create the target directive
         //
 
-        return new TargetDirective( name, conf, categories, profile );
+        return new TargetDirective( name, conf, params, categories, profile );
     }
+
+    private Parameters getTargetParameters( Configuration config ) throws ConfigurationException
+    {
+        if( null == config ) 
+          return null;
+        return Parameters.fromConfiguration( config );
+    }
+
 }

Modified: avalon/trunk/runtime/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultComponentModel.java
==============================================================================
--- avalon/trunk/runtime/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultComponentModel.java	(original)
+++ avalon/trunk/runtime/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultComponentModel.java	Sat Jul 31 10:21:49 2004
@@ -151,15 +151,32 @@
 
         if( isParameterizable() )
         {
+            Parameters staticDefaults = m_context.getType().getParameters();
             final Parameters parameters = 
               m_context.getComponentProfile().getParameters();
             if( parameters != null )
             {
-                m_parameters = parameters;
+                if( null == staticDefaults )
+                {
+                    m_parameters = parameters;
+                }
+                else
+                {
+                    m_parameters = new Parameters();
+                    m_parameters.merge( staticDefaults );
+                    m_parameters.merge( parameters );
+                }
             }
             else
             {
-                m_parameters = Parameters.EMPTY_PARAMETERS;
+                if( null == staticDefaults )
+                {
+                    m_parameters = Parameters.EMPTY_PARAMETERS;
+                }
+                else
+                {
+                    m_parameters = staticDefaults;
+                }
             }
         }
 
@@ -585,14 +602,14 @@
     * 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
+    * @param policy if TRUE the supplied parameters are merged with existing 
+    *    parameters otherwise the supplied parameters replace any existing
+    *    parameters
     * @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 )
+    public void setParameters( Parameters parameters, boolean merge )
       throws IllegalStateException
     {
         if( !isParameterizable() )
@@ -610,7 +627,7 @@
             throw new NullPointerException( "parameters" );
         }
 
-        if( policy )
+        if( merge )
         {
             Properties props = Parameters.toProperties( m_parameters );
             Properties suppliment = Parameters.toProperties( parameters );
@@ -638,14 +655,18 @@
 
    /**
     * Return the parameters to be applied to the component.
-    * If the the component type does not implementation the 
-    * Parameterizable interface, the implementation returns null. 
     *
     * @return the assigned parameters
     */
     public Parameters getParameters()
     {
-        return m_parameters;
+        Parameters params = new Parameters();
+        if( null != m_parameters )
+        {
+            params.merge( m_parameters );
+        }
+        params.makeReadOnly();
+        return params;
     }
 
    /**
@@ -682,7 +703,7 @@
     * configuration may suppliment or replace the existing configuration.
     *
     * @param config the supplied configuration
-    * @param policy if TRUE the supplied configuration replaces the current
+    * @param policy if FALSE the supplied configuration replaces the current
     *   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)

Modified: avalon/trunk/runtime/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModel.java
==============================================================================
--- avalon/trunk/runtime/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModel.java	(original)
+++ avalon/trunk/runtime/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModel.java	Sat Jul 31 10:21:49 2004
@@ -69,6 +69,7 @@
 import org.apache.avalon.framework.logger.Logger;
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
+import org.apache.avalon.framework.parameters.Parameters;
 
 import org.apache.avalon.meta.info.DependencyDescriptor;
 import org.apache.avalon.meta.info.ServiceDescriptor;
@@ -811,10 +812,16 @@
                 if( model instanceof ComponentModel )
                 {
                     ComponentModel deployment = (ComponentModel) model;
-                    if( target.getConfiguration() != null )
+                    Configuration config = target.getConfiguration();
+                    if( config != null )
                     {
-                        deployment.setConfiguration( 
-                          target.getConfiguration() );
+                        deployment.setConfiguration( config );
+                    }
+
+                    Parameters params = target.getParameters();
+                    if( params != null )
+                    {
+                        deployment.setParameters( params  );
                     }
                 }
             }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.