mcconnell    2003/07/30 07:44:33

  Modified:    merlin/composition/src/java/org/apache/avalon/composition/data/builder
                        XMLContainmentProfileCreator.java
               merlin/composition/src/java/org/apache/avalon/composition/data/writer
                        XMLContainmentProfileWriter.java
               merlin/composition/src/test/conf data-test.xml
  Log:
  Add inital support for block composition.
  
  Revision  Changes    Path
  1.5       +89 -6     
avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/data/builder/XMLContainmentProfileCreator.java
  
  Index: XMLContainmentProfileCreator.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/data/builder/XMLContainmentProfileCreator.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- XMLContainmentProfileCreator.java 27 Jul 2003 15:02:51 -0000      1.4
  +++ XMLContainmentProfileCreator.java 30 Jul 2003 14:44:33 -0000      1.5
  @@ -67,6 +67,8 @@
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.avalon.meta.info.DependencyDescriptor;
   import org.apache.avalon.meta.info.ServiceDescriptor;
  +import org.apache.avalon.composition.data.BlockCompositionDirective;
  +import org.apache.avalon.composition.data.BlockIncludeDirective;
   import org.apache.avalon.composition.data.ContainmentProfile;
   import org.apache.avalon.composition.data.DeploymentProfile;
   import org.apache.avalon.composition.data.FilesetDirective;
  @@ -119,10 +121,15 @@
           ServiceDirective[] exports = 
             getServicesDirectives( config.getChild( "services", false ) );
   
  +        //
  +        // check for any legacy "implementation" tags and if it exists
  +        // then run with it, otherwise continue with the container defintion
  +        //
  +
           Configuration implementation = config;
           if( config.getChild( "implementation", false ) != null )
           {
  -            implementation = config.getChild( "implementation", false );
  +            implementation = config.getChild( "implementation" );
           }
   
           final ClassLoaderDirective classloader = 
  @@ -220,14 +227,21 @@
           for( int i = 0; i < resources.length; i++ )
           {
               Configuration resource = resources[i];
  -            String id = resource.getAttribute( "id" );
  -            String version = resource.getAttribute( "version", null );
  -            res.add( new ResourceDirective( id, version ) );
  +            res.add( getResourceDirective( resource ) );
           }
   
           return (ResourceDirective[]) res.toArray( new ResourceDirective[0] );
       }
   
  +    private ResourceDirective getResourceDirective( Configuration config )
  +       throws ConfigurationException
  +    {
  +        String id = config.getAttribute( "id" );
  +        String version = config.getAttribute( "version", null );
  +        return new ResourceDirective( id, version );
  +    }
  +
  +
       private FilesetDirective[] getFilesetDirectives( Configuration config )
          throws ConfigurationException
       {
  @@ -314,6 +328,13 @@
           }
       }
   
  +   /**
  +    * Return the set of profiles embedded in the supplied 
  +    * configuration.
  +    *
  +    * @param config a container or implementation configutation
  +    * @return the set of profile 
  +    */ 
       protected Profile[] getProfiles( Configuration config )
         throws Exception
       {
  @@ -334,7 +355,7 @@
                   }
                   else if( child.getName().equals( "include" ) )
                   {
  -                    System.out.println( "INCLUDES NOT IMPLEMENTED YET" );
  +                    list.add( createFromInclude( child ) );
                   }
               }
           }
  @@ -390,6 +411,68 @@
                 "Invalid service declaration in block specification:\n"
                  + ConfigurationUtil.list( config );
               throw new MetaDataException( error, ce );
  +        }
  +    }
  +
  +   /**
  +    * Create a containment defintion for an include statement. Two variant
  +    * of include are supported - include by resource reference, and include
  +    * of a source container defintion.
  +    *
  +    * @param the include description
  +    * @return the containment directive
  +    */
  +    private Profile createFromInclude( Configuration config )
  +      throws MetaDataException, ConfigurationException
  +    {
  +        final String name = getBlockIncludeName( config );
  +        if( config.getAttribute( "id", null ) != null )
  +        {
  +            ResourceDirective resource = getResourceDirective( config );
  +            return new BlockCompositionDirective( name, resource );
  +        }
  +        else
  +        {
  +            final String path = getBlockIncludePath( config );
  +            return new BlockIncludeDirective( name, path );
  +        }
  +    }
  +
  +    private String getBlockIncludeName( Configuration config ) throws 
MetaDataException
  +    {
  +        try
  +        {
  +            return config.getAttribute( "name" );
  +        }
  +        catch( ConfigurationException e )
  +        {
  +            final String error =
  +              "Missing 'name' attribute in the block include statement:\n"
  +               + ConfigurationUtil.list( config );
  +            throw new MetaDataException( error, e );
  +        }
  +    }
  +
  +    private String getBlockIncludePath( Configuration config ) throws 
MetaDataException
  +    {
  +        try
  +        {
  +            Configuration source = config.getChild( "source", false );
  +            if( null == source )
  +            {
  +                final String error =
  +                  "Missing 'source' element in the block include statement:\n"
  +                 + ConfigurationUtil.list( config );
  +                throw new MetaDataException( error );
  +            }
  +            return source.getValue();
  +        }
  +        catch( ConfigurationException e )
  +        {
  +            final String error =
  +              "Missing source value in the block include statement:\n"
  +               + ConfigurationUtil.list( config );
  +            throw new MetaDataException( error, e );
           }
       }
   }
  
  
  
  1.3       +29 -1     
avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/data/writer/XMLContainmentProfileWriter.java
  
  Index: XMLContainmentProfileWriter.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/merlin/composition/src/java/org/apache/avalon/composition/data/writer/XMLContainmentProfileWriter.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XMLContainmentProfileWriter.java  27 Jul 2003 15:02:51 -0000      1.2
  +++ XMLContainmentProfileWriter.java  30 Jul 2003 14:44:33 -0000      1.3
  @@ -54,6 +54,8 @@
   import java.io.OutputStreamWriter;
   import java.io.Writer;
   
  +import org.apache.avalon.composition.data.BlockIncludeDirective;
  +import org.apache.avalon.composition.data.BlockCompositionDirective;
   import org.apache.avalon.composition.data.Profile;
   import org.apache.avalon.composition.data.ContainmentProfile;
   import org.apache.avalon.composition.data.DeploymentProfile;
  @@ -383,10 +385,36 @@
                   writer.write( "\n" );
                   writeDeploymentProfile( writer, component, pad );
               }
  +            else if( profile instanceof BlockIncludeDirective )
  +            {
  +                BlockIncludeDirective directive = (BlockIncludeDirective) profile;
  +                writer.write( "\n" );
  +                writeBlockIncludeDirective( writer, directive, pad );
  +            }
  +            else if( profile instanceof BlockCompositionDirective )
  +            {
  +                BlockCompositionDirective directive = (BlockCompositionDirective) 
profile;
  +                writer.write( "\n" );
  +                writeBlockCompositionDirective( writer, directive, pad );
  +            }
               else
               {
                   System.out.println( "UNRECOGNIZED PROFILE: " + profile );
               }
           }
  +    }
  +
  +    private void writeBlockIncludeDirective( 
  +      final Writer writer, final BlockIncludeDirective directive, String pad )
  +      throws Exception
  +    {
  +        throw new UnsupportedOperationException();
  +    }
  +
  +    private void writeBlockCompositionDirective( 
  +      final Writer writer, final BlockCompositionDirective directive, String pad )
  +      throws Exception
  +    {
  +        throw new UnsupportedOperationException();
       }
   }
  
  
  
  1.6       +6 -0      avalon-sandbox/merlin/composition/src/test/conf/data-test.xml
  
  Index: data-test.xml
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/composition/src/test/conf/data-test.xml,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- data-test.xml     27 Jul 2003 15:04:54 -0000      1.5
  +++ data-test.xml     30 Jul 2003 14:44:33 -0000      1.6
  @@ -73,4 +73,10 @@
          </parameters>
        </component>
      </container>
  +   <!--
  +   <include name="include-1">
  +     <source>./somename.xml</source>
  +   </include>
  +   <include name="include-2" id="" version="SNAPSHOT"/>
  +   -->
   </container>
  
  
  

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

Reply via email to