You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2003/07/17 02:05:20 UTC

cvs commit: avalon-sandbox/merlin/meta/src/test/org/apache/avalon/meta/data DataTestCase.java

mcconnell    2003/07/16 17:05:20

  Modified:    merlin/meta/src/java/org/apache/avalon/meta/data/builder
                        XMLDeploymentProfileCreator.java
               merlin/meta/src/java/org/apache/avalon/meta/data/writer
                        XMLDeploymentProfileWriter.java
               merlin/meta/src/test block.xml
               merlin/meta/src/test/org/apache/avalon/meta/data
                        DataTestCase.java
  Log:
  Add dependency directive reading and writing together with associated selection directive.
  
  Revision  Changes    Path
  1.6       +57 -3     avalon-sandbox/merlin/meta/src/java/org/apache/avalon/meta/data/builder/XMLDeploymentProfileCreator.java
  
  Index: XMLDeploymentProfileCreator.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/meta/src/java/org/apache/avalon/meta/data/builder/XMLDeploymentProfileCreator.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XMLDeploymentProfileCreator.java	14 Jul 2003 22:07:28 -0000	1.5
  +++ XMLDeploymentProfileCreator.java	17 Jul 2003 00:05:20 -0000	1.6
  @@ -56,6 +56,8 @@
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
   import org.apache.avalon.meta.data.DeploymentProfile;
  +import org.apache.avalon.meta.data.DependencyDirective;
  +import org.apache.avalon.meta.data.SelectionDirective;
   import org.apache.avalon.meta.data.*;
   
   /**
  @@ -97,7 +99,8 @@
       * @param config the configuration
       * @return the deployment profile
       */
  -    public DeploymentProfile createDeploymentProfile( String classname, Configuration config, String name )
  +    public DeploymentProfile createDeploymentProfile( 
  +      String classname, Configuration config, String name )
         throws Exception
       {
           final boolean activation = getActivationPolicy( config, true );
  @@ -106,14 +109,65 @@
             getCategoriesDirective( config.getChild( "categories", false ), name );
           final ContextDirective context = 
             getContextDirective( config.getChild( "context", false ) );
  +        final DependencyDirective[] dependencies = 
  +          getDependencyDirectives( config.getChild( "dependencies" ) );
           final Parameters params = 
             getParameters( config.getChild( "parameters", false ) );
           final Configuration configuration = 
             config.getChild( "configuration", false );
   
           return new DeploymentProfile( 
  -          name, activation, classname, categories, context, params, 
  +          name, activation, classname, categories, context, dependencies, params, 
             configuration, Mode.EXPLICIT );
  +    }
  +
  +    protected DependencyDirective[] getDependencyDirectives( Configuration config )
  +      throws ConfigurationException
  +    {
  +        if( config != null )
  +        {
  +            ArrayList list = new ArrayList();
  +            Configuration[] deps = config.getChildren( "dependency" );
  +            for( int i=0; i<deps.length; i++ )
  +            {
  +                list.add( getDependencyDirective( deps[i] ) );
  +            }
  +            return (DependencyDirective[]) list.toArray( new DependencyDirective[0] );
  +        }
  +        return new DependencyDirective[0];
  +    }
  +
  +    protected DependencyDirective getDependencyDirective( Configuration config )
  +      throws ConfigurationException
  +    {
  +        final String key = config.getAttribute( "key" );
  +        final String source = config.getAttribute( "source", null );
  +        if( source != null )
  +        {
  +            return new DependencyDirective( key, source );
  +        }
  +        else
  +        {
  +            Configuration[] children = config.getChildren( "select" );
  +            ArrayList list = new ArrayList();
  +            for( int i=0; i<children.length; i++ )
  +            {
  +                list.add( getSelectionDirective( children[i] ) );
  +            }
  +            SelectionDirective[] features = 
  +              (SelectionDirective[]) list.toArray( new SelectionDirective[0] );
  +            return new DependencyDirective( key, features );
  +        }
  +    }
  +
  +    protected SelectionDirective getSelectionDirective( Configuration config )
  +      throws ConfigurationException
  +    {
  +        final String feature = config.getAttribute( "feature" );
  +        final String value = config.getAttribute( "value" );
  +        final String match = config.getAttribute( "match", "required" );
  +        final boolean optional = config.getAttributeAsBoolean( "optional", false );
  +        return new SelectionDirective( feature, value, match, optional );
       }
   
       protected CategoriesDirective getCategoriesDirective( Configuration config, String name )
  
  
  
  1.5       +79 -1     avalon-sandbox/merlin/meta/src/java/org/apache/avalon/meta/data/writer/XMLDeploymentProfileWriter.java
  
  Index: XMLDeploymentProfileWriter.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/meta/src/java/org/apache/avalon/meta/data/writer/XMLDeploymentProfileWriter.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- XMLDeploymentProfileWriter.java	10 Jul 2003 19:42:07 -0000	1.4
  +++ XMLDeploymentProfileWriter.java	17 Jul 2003 00:05:20 -0000	1.5
  @@ -61,6 +61,8 @@
   import org.apache.avalon.meta.data.ContainmentProfile;
   import org.apache.avalon.meta.data.DeploymentProfile;
   import org.apache.avalon.meta.data.ContextDirective;
  +import org.apache.avalon.meta.data.DependencyDirective;
  +import org.apache.avalon.meta.data.SelectionDirective;
   import org.apache.avalon.meta.data.CategoriesDirective;
   import org.apache.avalon.meta.data.CategoryDirective;
   import org.apache.avalon.meta.data.ImportDirective;
  @@ -127,10 +129,86 @@
        
           writeCategories( writer, profile.getCategories(), pad );
           writeContext( writer, profile.getContext(), pad );
  +        writeDependencies( writer, profile.getDependencyDirectives(), pad );
           writeConfiguration( writer, profile.getConfiguration(), pad );
           writeParameters( writer, profile.getParameters(), pad );
       }
   
  +    /**
  +     * Write out xml representation of the dependency directives.
  +     *
  +     * @param writer the writer
  +     * @param dependencies the dependency directives
  +     * @throws IOException if unable to write xml
  +     */
  +    private void writeDependencies( 
  +      final Writer writer, final DependencyDirective[] dependencies, String pad )
  +      throws IOException
  +    {
  +        if( dependencies.length == 0 ) return;
  +        writer.write( "\n" + pad + "<dependencies>" );
  +        final String padding = pad + INDENT;
  +        for( int i=0; i<dependencies.length; i++ )
  +        {
  +            writeDependency( writer, dependencies[i], padding );
  +        }
  +        writer.write( "\n" + pad + "</dependencies>" );
  +    }
  +
  +    /**
  +     * Write out xml representation of a dependency directive.
  +     *
  +     * @param writer the writer
  +     * @param dependency the dependency directive
  +     * @throws IOException if unable to write xml
  +     */
  +    private void writeDependency( 
  +      final Writer writer, final DependencyDirective dependency, String pad )
  +      throws IOException
  +    {
  +        writer.write( "\n" + pad + "<dependency key=\"" + dependency.getKey() + "\"" );
  +        if( dependency.getSource() != null )
  +        {
  +            writer.write( " source=\"" + dependency.getSource() + "\"/>" );
  +        }
  +        else
  +        {
  +            writer.write( ">" );
  +            SelectionDirective[] features = dependency.getSelectionDirectives();
  +            final String padding = pad + INDENT;
  +            for( int i=0; i<features.length; i++ )
  +            {
  +                writeSelectionDirective( writer, features[i], padding );
  +            }
  +            writer.write( "\n" + pad + "</dependency>" );
  +        }
  +    }
  +
  +    /**
  +     * Write out xml representation of a dependency selection directive.
  +     *
  +     * @param writer the writer
  +     * @param feature the dependency selection directive
  +     * @throws IOException if unable to write xml
  +     */
  +    private void writeSelectionDirective( 
  +      final Writer writer, final SelectionDirective feature, String pad )
  +      throws IOException
  +    {
  +        writer.write( "\n" + pad 
  +          + "<select feature=\"" + feature.getFeature() 
  +          + "\" value=\"" + feature.getValue() 
  +          + "\" match=\"" + feature.getCriteria() 
  +          + "\"" );
  +        if( feature.isOptional() )
  +        {
  +            writer.write( " optional=\"true\"/>" );
  +        }
  +        else
  +        {
  +            writer.write( "/>" );
  +        }
  +    }
   
       /**
        * Write out xml representation of the logging categories
  
  
  
  1.5       +7 -0      avalon-sandbox/merlin/meta/src/test/block.xml
  
  Index: block.xml
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/meta/src/test/block.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- block.xml	10 Jul 2003 19:42:07 -0000	1.4
  +++ block.xml	17 Jul 2003 00:05:20 -0000	1.5
  @@ -61,6 +61,13 @@
            <parameter name="fred" value="blue"/>
            <parameter name="alice" value="pink"/>
          </parameters>
  +       <dependencies>
  +         <dependency key="first-key" source="../comp"/>
  +         <dependency key="second-key">
  +           <select feature="color" value="red" match="equals"/>
  +           <select feature="publisher" value="ASF" match="exists" optional="true"/>
  +         </dependency>
  +       </dependencies>
        </component>
      </container>
   </container>
  
  
  
  1.3       +2 -2      avalon-sandbox/merlin/meta/src/test/org/apache/avalon/meta/data/DataTestCase.java
  
  Index: DataTestCase.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/meta/src/test/org/apache/avalon/meta/data/DataTestCase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DataTestCase.java	6 Jul 2003 10:08:18 -0000	1.2
  +++ DataTestCase.java	17 Jul 2003 00:05:20 -0000	1.3
  @@ -51,7 +51,7 @@
           // as the input block.xml)
           //
   
  -        m_xml = new File( getTestDir(), "test.xml" );
  +        m_xml = new File( getTestDir(), "test-classes/test.xml" );
           writeToXML( m_profile, m_xml );
   
           //
  @@ -72,7 +72,7 @@
   
       private void print( ContainmentProfile profile ) throws Exception
       {
  -        File temp = new File( getTestDir(), "test.xml" );
  +        File temp = new File( getTestDir(), "test-classes/test.xml" );
           DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
           Configuration config = builder.buildFromFile( temp );
           System.out.println( ConfigurationUtil.list( config ) );
  
  
  

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