avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/block/impl DefaultBlock.java DefaultBlock.xinfo DefaultBlockLoader.java
Date Tue, 15 Apr 2003 03:00:18 GMT
mcconnell    2003/04/14 20:00:18

  Modified:    merlin/merlin-core/src/java/org/apache/avalon/merlin/block/impl
                        DefaultBlock.java DefaultBlock.xinfo
                        DefaultBlockLoader.java
  Log:
  Updated bloc and loader implementation to removed redundencies between block and appliance
repository.  Block now resolves embedded appliance instances relative to the underlying appliance
repository instead of maintaining it own references.
  
  Revision  Changes    Path
  1.9       +65 -97    avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/block/impl/DefaultBlock.java
  
  Index: DefaultBlock.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/block/impl/DefaultBlock.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DefaultBlock.java	13 Apr 2003 03:20:32 -0000	1.8
  +++ DefaultBlock.java	15 Apr 2003 03:00:18 -0000	1.9
  @@ -30,6 +30,7 @@
   import org.apache.avalon.merlin.container.StateListener;
   import org.apache.avalon.meta.info.DependencyDescriptor;
   import org.apache.avalon.meta.info.ServiceDescriptor;
  +import org.apache.avalon.meta.info.InfoDescriptor;
   import org.apache.avalon.meta.model.Profile;
   
   /**
  @@ -124,12 +125,6 @@
       private ApplianceRepository m_repository;
   
      /**
  -    * List of the appliance instances that the block is 
  -    * managing.
  -    */
  -    private List m_appliances = new ArrayList();
  -
  -   /**
       * List of the subsidiary blocks.
       */
       private List m_blocks = new ArrayList();
  @@ -167,7 +162,7 @@
       private boolean m_terminated = false;
   
      /**
  -    * The set of dependecies declared by the block.
  +    * The set of dependencies declared by the block.
       */ 
       private DependencyDescriptor[] m_dependencies;
   
  @@ -211,7 +206,7 @@
           //
           // if dependecies are declared then use the supplied dependencies
           // together with any dependecies declared by the underlying 
  -        // containerment solution, otherwise we default to the underlying
  +        // containement solution, otherwise we default to the underlying
           // container type
           //
   
  @@ -302,22 +297,7 @@
               context.setStartupPolicy( false );
               context.makeReadOnly();
   
  -            Appliance appliance = m_engine.createAppliance( context, true );
  -            m_appliances.add( appliance );
  -        }
  -
  -        // ## 
  -        // ## TODO clean up the duplication of references to appliances.  This 
  -        // ## should be driven by the content in the appliance repository and 
  -        // ## and local references should be dropped.
  -        // ##
  -
  -        //System.out.println( "## APPLIANCE LIST: " + this );
  -        ApplianceRepository rep = m_engine.getApplianceRepository();
  -        Appliance[] appliances = rep.getAppliances();
  -        for( int a=0; a<appliances.length; a++ )
  -        {
  -            //System.out.println( "## APPLIANCE: " + appliances[a] ); 
  +            m_engine.createAppliance( context, true );
           }
       }
   
  @@ -325,36 +305,6 @@
       // Block
       //-------------------------------------------------------------------------------
   
  -   /**
  -    * Return the set of locally managed appliance instances.
  -    * @return the set of appliance instances local to this block.
  -    */
  -    private Appliance[] getAppliances()
  -    {
  -        // ## 
  -        // ## TODO clean up the duplication of references to appliances.  This 
  -        // ## should be driven by the content in the appliance repository and 
  -        // ## and local references should be dropped.
  -        // ##
  -
  -        return (Appliance[]) m_appliances.toArray( new Appliance[0] );
  -    }
  -
  -   /**
  -    * Return the set of blocks locally managed by this block.
  -    * @return the set of immediate sibling blocks.
  -    */
  -    private Block[] getBlocks()
  -    {
  -        // ## 
  -        // ## TODO clean up the duplication of references to appliances.  This 
  -        // ## should be driven by the content in the appliance repository and 
  -        // ## and local references should be dropped.
  -        // ##
  -
  -        return (Block[]) m_blocks.toArray( new Block[0] );
  -    }
  -
       //-------------------------------------------------------------------------------
       // Appliance
       //-------------------------------------------------------------------------------
  @@ -402,18 +352,20 @@
           }
   
           //
  -        // add the dependecy graph to the context that will be used to establish
  -        // the container so that the container can handle orderly startup and 
  -        // shutdown of compoents
  +        // add the dependency graph to the context that will be used to establish
  +        // the container so that the container can handle orderly startup and
  +        // shutdown of components, then assemble the appliances contained within
  +        // the block
           //
  - 
  +
           Map context = m_applianceContext.getDeploymentContext();
           context.put( "urn:merlin:container.dependency-graph", graph );
  -        context.put( "urn:merlin:container.listener", this );
  -        context.put( "urn:merlin:container.descriptor", m_descriptor );
  +        context.put( "urn:merlin:container.listener", this ); 
  +        super.assemble( graph );
   
           //
  -        // assemble the components handled by the block
  +        // now that we have assembled ourself we can continue with the 
  +        // assembly of the contents of this block
           //
   
           try
  @@ -431,12 +383,6 @@
           // assemble the subsidiary blocks
           //
   
  -        // ## 
  -        // ## TODO clean up the duplication of references to appliances.  This 
  -        // ## should be driven by the content in the appliance repository and 
  -        // ## and local references should be dropped.
  -        // ##
  -
           Iterator iterator = m_blocks.iterator();
           while( iterator.hasNext() )
           {
  @@ -465,7 +411,7 @@
               }
           }
   
  -        super.assemble( graph );
  +        //super.assemble( graph );
   
           if( getLogger().isDebugEnabled() )
           {
  @@ -493,19 +439,57 @@
       */
       private void assembleComponents( DependencyGraph graph ) throws ApplianceException
       {
  +        //
  +        // add all of the children to the graph so that they are available
  +        // in the dependency resolution process
  +        //
  +
  +        Appliance[] appliances = getAppliances();
  +        for( int i=0; i<appliances.length; i++ )
  +        {
  +            Appliance appliance = appliances[i];
  +            if( appliance != this )
  +            {
  +                graph.add( appliance );
  +            }
  +        }
  +
  +        //
  +        // for all of the appliances invoke assembly
  +        //
  +
  +        for( int i=0; i<appliances.length; i++ )
  +        {
  +            Appliance appliance = appliances[i];
  +            if(( appliance != this ) )
  +            {
  +                appliance.assemble( graph );
  +            }
  +        }
  +    }
  +
  +   /**
  +    * Return the set of locally managed appliance instances.
  +    * @return the set of appliance instances local to this block.
  +    */
  +    private Appliance[] getAppliances()
  +    {
  +        return m_engine.getApplianceRepository().getAppliances();
  +    }
  +
  +   /**
  +    * Return the set of blocks locally managed by this block.
  +    * @return the set of immediate sibling blocks.
  +    */
  +    private Block[] getBlocks()
  +    {
           // ## 
           // ## TODO clean up the duplication of references to appliances.  This 
           // ## should be driven by the content in the appliance repository and 
           // ## and local references should be dropped.
           // ##
   
  -        Iterator iterator = m_appliances.iterator();
  -        while( iterator.hasNext() )
  -        {
  -            Appliance appliance = (Appliance) iterator.next();
  -            graph.add( appliance );
  -            appliance.assemble( graph );
  -        }
  +        return (Block[]) m_blocks.toArray( new Block[0] );
       }
   
      /**
  @@ -679,7 +663,6 @@
   
           synchronized( m_action )
           {
  -
               m_action = new Integer( StateEvent.STOPPED );
               while( ( m_state < StateEvent.STOPPED ) && ( m_error == null ) )
               {
  @@ -776,12 +759,6 @@
   
       private void handleDecommissioning()
       {
  -        // ## 
  -        // ## TODO clean up the duplication of references to appliances.  This 
  -        // ## should be driven by the content in the appliance repository and 
  -        // ## and local references should be dropped.
  -        // ##
  -
           //
           // decommission the subsidiary blocks
           //
  @@ -844,12 +821,6 @@
               }
           }
   
  -        // ## 
  -        // ## TODO clean up the duplication of references to appliances.  This 
  -        // ## should be driven by the content in the appliance repository and 
  -        // ## and local references should be dropped.
  -        // ##
  -
           Iterator iterator = m_blocks.iterator();
           while( iterator.hasNext() )
           {
  @@ -876,7 +847,6 @@
       {
           if( m_terminated )
           {
  -            // already terminated
               return;
           }
   
  @@ -896,14 +866,6 @@
               appliance.terminate();
           }
   
  -        // ## 
  -        // ## TODO clean up the duplication of references to appliances.  This 
  -        // ## should be driven by the content in the appliance repository and 
  -        // ## and local references should be dropped.
  -        // ##
  -
  -        m_appliances = null;
  -
           Iterator iterator = m_blocks.iterator();
           while( iterator.hasNext() )
           {
  @@ -967,4 +929,10 @@
               // return
           }
       }
  +
  +    public String toString()
  +    {
  +        return "[block:/" + getURL().getPath() + "]";
  +    }
  +
   }
  
  
  
  1.6       +22 -31    avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/block/impl/DefaultBlock.xinfo
  
  Index: DefaultBlock.xinfo
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/block/impl/DefaultBlock.xinfo,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DefaultBlock.xinfo	13 Apr 2003 03:20:32 -0000	1.5
  +++ DefaultBlock.xinfo	15 Apr 2003 03:00:18 -0000	1.6
  @@ -20,56 +20,47 @@
     </info>
   
     <context>
  +
       <attributes>
  -      <attribute 
  -          key="urn:assembly:lifecycle.context.strategy"
  +      <attribute key="urn:assembly:lifecycle.context.strategy"
             value="org.apache.avalon.assembly.locator.Contextualizable"/>
       </attributes>
  -    <entry 
  -       key="urn:assembly:engine" 
  +
  +    <entry key="urn:assembly:engine" 
          type="org.apache.avalon.assembly.engine.EngineClassLoader"/>
  -    <entry 
  -       key="urn:assembly:lifestyle.service" 
  +
  +    <entry key="urn:assembly:lifestyle.service" 
          type="org.apache.avalon.assembly.lifestyle.LifestyleService"/>
  -    <entry 
  -       key="urn:assembly:appliance.context" 
  +
  +    <entry key="urn:assembly:appliance.context" 
          type="org.apache.avalon.assembly.appliance.ApplianceContext"/>
  -    <entry 
  -       key="urn:assembly:appliance.system" 
  +
  +    <entry key="urn:assembly:appliance.system" 
          type="org.apache.avalon.assembly.locator.Locator"/>
  -    <entry 
  -       key="urn:assembly:appliance.repository" 
  +
  +    <entry key="urn:assembly:appliance.repository" 
          type="org.apache.avalon.assembly.appliance.ApplianceRepository"/>
  -    <entry 
  -       key="urn:assembly:threads.manager" 
  +
  +    <entry key="urn:assembly:threads.manager" 
          type="org.apache.excalibur.mpool.PoolManager"/>
   
  -    <!--
  -    The containement profile holding the initial set of contained
  -    profiles.
  -    -->
  -    <entry 
  -       key="urn:merlin:container.descriptor" 
  +    <entry key="urn:merlin:container.descriptor" 
          type="org.apache.avalon.merlin.container.ContainmentProfile"/>
   
  -    <!--
  -    A list of subsidiary blocks.
  -    -->
  -    <entry 
  -       key="urn:merlin:container.blocks" 
  +    <entry key="urn:merlin:container.blocks" 
          type="java.util.List"/>
   
  -    <entry 
  -       key="urn:merlin:container.library" 
  +    <entry key="urn:merlin:container.library" 
          type="org.apache.avalon.merlin.block.Library"/>
  -    <entry 
  -       key="urn:merlin:container.dependencies" 
  +
  +    <entry key="urn:merlin:container.dependencies" 
          type="org.apache.avalon.meta.info.DependencyDescriptor[]"
          optional="true"/>
  -    <entry 
  -       key="urn:merlin:container.services" 
  +
  +    <entry key="urn:merlin:container.services" 
          type="org.apache.avalon.meta.info.ServiceDescriptor[]"
          optional="true"/>
  +
     </context>
   
     <services>
  
  
  
  1.11      +267 -201  avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/block/impl/DefaultBlockLoader.java
  
  Index: DefaultBlockLoader.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/block/impl/DefaultBlockLoader.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- DefaultBlockLoader.java	13 Apr 2003 12:13:50 -0000	1.10
  +++ DefaultBlockLoader.java	15 Apr 2003 03:00:18 -0000	1.11
  @@ -67,6 +67,7 @@
   import java.util.jar.Manifest;
   import java.util.zip.ZipEntry;
   import java.net.JarURLConnection;
  +import java.util.Properties;
   
   import org.apache.avalon.assembly.logging.LoggingManager;
   import org.apache.avalon.assembly.logging.LoggingDescriptor;
  @@ -88,6 +89,7 @@
   import org.apache.avalon.assembly.locator.Locator;
   import org.apache.avalon.assembly.locator.LocatorException;
   import org.apache.avalon.assembly.locator.DefaultLocator;
  +import org.apache.avalon.framework.Version;
   import org.apache.avalon.framework.CascadingException;
   import org.apache.avalon.framework.logger.Logger;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
  @@ -119,6 +121,7 @@
   import org.apache.avalon.meta.model.LoggingDirective;
   import org.apache.avalon.meta.model.Profile;
   import org.apache.avalon.meta.info.Type;
  +import org.apache.avalon.meta.info.InfoDescriptor;
   import org.apache.avalon.meta.info.DependencyDescriptor;
   import org.apache.avalon.meta.info.ServiceDescriptor;
   import org.apache.avalon.meta.info.builder.XMLTypeCreator;
  @@ -556,7 +559,7 @@
           }
   
           //
  -        // build the set of embedded blocks
  +        // build the set of embedded containers
           //
   
           final Configuration[] children = config.getChildren( "container" );
  @@ -564,7 +567,7 @@
           for( int i=0; i<children.length; i++ )
           {
               final Configuration child = children[i];
  -            final String name = getBlockName( child );
  +            final String name = getContainerName( child );
               EngineClassLoader loader;
               try
               {
  @@ -587,140 +590,33 @@
       }
   
      /**
  -    * Load a block declared in the supplied block and configuration URL.
  -    * The path URL may refer to a XML file containing a block directive
  -    * or a jar file containing a block.xml file. 
  -    *
  -    * @param path the block defintion URL
  -    * @param overrides the URL to a configuration containing configuration overrides
  -    * @return the block
  +    * Get the name of the block from the blockk configuration.
  +    * @param config the block configuration
  +    * @return the block name
       */
  -    private Block installSource( EngineClassLoader loader, String root, URL path, URL overrides
)
  -      throws BlockException
  +    private String getContainerName( Configuration config ) throws BlockException
       {
  -
  -        Configuration block = getSourceConfiguration( path );
  -        Configuration config = getTargetsConfiguration( overrides );
  -        String name = getBlockName( block );
  -
  -        Configuration[] targets = config.getChildren( "target" );
  -
  -        if( getLogger().isDebugEnabled() )
  -        {
  -            getLogger().debug("target override count: " + targets.length );
  -        }
  -
  -        for( int j=0; j<targets.length; j++ )
  -        {
  -            Configuration target = targets[j];
  -            try
  -            {
  -                String key = root + name + "/" + target.getAttribute( "name" );
  -                m_library.put( key, target.getChild( "configuration" ) );
  -                getLogger().debug( "registering configuration for key: " + key );
  -            }
  -            catch( Throwable e )
  -            {
  -                final String error =
  -                  "A configuration target override does not declare a target." 
  -                  + "\nURL: " + overrides
  -                  + ConfigurationUtil.list( target );
  -                throw new BlockException( error, e );
  -            }
  -        }
  -
  -        URL base = getBasePath( path );
  -        Configuration implementation = block.getChild( "implementation", false );
  -        if( implementation == null )
  -        {
  -            implementation = block.getChild( "container" );
  -        }
  -        Configuration engineConfig = implementation.getChild( "engine" );
  -        EngineClassLoader engine = null;
           try
           {
  -            engine = createEngine( loader, m_home, engineConfig, name, base, base );
  +            return config.getAttribute( "name" );
           }
           catch( Throwable e )
           {
               final String error = 
  -              "Could not construct engine for block: " + name;
  +              "Supplied block configuration does not conain the required name attribute:\n"
  +              + ConfigurationUtil.list( config );
               throw new BlockException( error, e );
           }
  -
  -        //
  -        // create the containment profile
  -        //
  -
  -        ContainmentProfile descriptor = 
  -          createContainmentProfile( name, engine, implementation );
  -
  -        //
  -        // create the block dependencies
  -        //
  -
  -        Configuration depsConfig = block.getChild( "dependencies", false );
  -        DependencyDescriptor[] dependencies = null; 
  -        if( depsConfig != null )
  -        {
  -            try
  -            {
  -                dependencies = TYPE_CREATOR.buildDependencies( depsConfig );
  -            }
  -            catch( ConfigurationException ce )
  -            {
  -                final String error = 
  -                  "Invalid dependencies declaration in block specification:\n"
  -                  + ConfigurationUtil.list( depsConfig );
  -                throw new BlockException( error, ce );
  -            }
  -        }
  -        
  -        //
  -        // create the block services
  -        //
  -
  -        Configuration servicesConfig = block.getChild( "dependencies" , false );
  -        ServiceDescriptor[] services = null;
  -        if( servicesConfig != null )
  -        {
  -            try
  -            {
  -                services = TYPE_CREATOR.buildServices( servicesConfig );
  -            }
  -            catch( ConfigurationException ce )
  -            {
  -                final String error = 
  -                  "Invalid services declaration in block specification:\n"
  -                  + ConfigurationUtil.list( depsConfig );
  -                throw new BlockException( error, ce );
  -            }
  -        }
  -
  -        //
  -        // create any subsidiary blocks
  -        //
  -
  -        String partition = root + name + Container.PATH_SEPERATOR;
  -        List children = 
  -          createChildBlocks( engine, partition, implementation, config, base );
  -
  -        //
  -        // create the block 
  -        //
  -
  -        return createBlock( 
  -          dependencies, services, engine, children, descriptor, name, root, config );
       }
   
      /**
       * Create a single containment block.
       *
       * @param engine the containers classloader
  -    * @param partition the partition to assigne to the container
  +    * @param partition the partition to assign to the container
       * @param name the appliance name
       * @param config the configuration of the container
  -    * @param custom configuratio target overrides
  +    * @param custom configuration target overrides
       * @param base the base url
       * @return the containment block
       * @exception BlockException if an error occurs during creation of the block
  @@ -738,7 +634,8 @@
               final ContainmentProfile descriptor = 
                 createContainmentProfile( name, engine, config );
               return createBlock( 
  -              null, null, engine, blocks, descriptor, name, partition, custom ); 
  +              new InfoDescriptor( name, DefaultBlock.class.getName(), null, null ), 
  +              null, null, engine, blocks, descriptor, name, partition, custom ) ; 
           }
           catch( Throwable e )
           {
  @@ -751,6 +648,7 @@
      /**
       * Create a block.
       *
  +    * @param info block info descriptor
       * @param dependencies virtual block dependencies
       * @param services virtual block services
       * @param engine the containers classloader
  @@ -763,6 +661,7 @@
       * @exception BlockException if an error occurs during creation of the block
       */
       private Block createBlock( 
  +      final InfoDescriptor info,
         final DependencyDescriptor[] dependencies, final ServiceDescriptor[] services, 
         final EngineClassLoader engine, final List blocks, final ContainmentProfile descriptor,

         final String name, final String partition, final Configuration custom )
  @@ -824,100 +723,287 @@
       {
   
           Configuration block = getSourceConfiguration( path );
  +        Configuration implementation = getImplementationFragment( block );
           Configuration config = getTargetsConfiguration( overrides );
   
  -        Configuration[] targets = config.getChildren( "target" );
  -        if( getLogger().isDebugEnabled() )
  -        {
  -            getLogger().debug("target override count: " + targets.length );
  -        }
  +        InfoDescriptor info = createBlockInfoDescriptor( "", block );
   
  -        for( int j=0; j<targets.length; j++ )
  -        {
  -            Configuration target = targets[j];
  -            try
  -            {
  -                String key = Container.PATH_SEPERATOR + target.getAttribute( "name" );
  -                m_library.put( key, target.getChild( "configuration" ) );
  -                getLogger().debug( "registering configuration for key: " + key );
  -            }
  -            catch( Throwable e )
  -            {
  -                final String error =
  -                  "A configuration target override does not declare a target." 
  -                  + "\nURL: " + overrides
  -                  + ConfigurationUtil.list( target );
  -                throw new BlockException( error, e );
  -            }
  -        }
  +        captureConfigurationTargets( Container.PATH_SEPERATOR, config );
   
           URL base = getBasePath( path );
   
           //
  +        // create the block logical dependencies (as distinct from the 
  +        // physical dependencies of the type managed by the block)
  +        //
  +
  +        Configuration deps = block.getChild( "dependencies" );
  +        DependencyDescriptor[] dependencies = getBlockLogicalDependencies( deps ); 
  +        
  +        //
  +        // create the logical block services
  +        //
  +
  +        Configuration svcs = block.getChild( "services" );
  +        ServiceDescriptor[] services = getBlockLogicalServices( svcs );
  +
  +        //
           // create the containment profile and extract the list of
           // container profiles
           //
   
           ContainmentProfile descriptor = 
  -          createContainmentProfile( "", m_engine, block );
  +          createContainmentProfile( "", m_engine, implementation );
   
           //
  -        // create the block dependencies
  +        // create any subsidiary blocks
  +        //
  +
  +        List blocks = createChildBlocks( 
  +          m_engine, Container.PATH_SEPERATOR, implementation, config, base );
  +
           //
  +        // create the block
  +        //
  +
  +        return createBlock( 
  +          info, dependencies, services, m_engine, blocks, descriptor, "", 
  +          Container.PATH_SEPERATOR, config );
  +    }
  +
  +   /**
  +    * Load a block declared in the supplied block and configuration URL.
  +    * The path URL may refer to a XML file containing a block directive
  +    * or a jar file containing a block.xml file. 
  +    *
  +    * @param loader the classloader
  +    * @param root the relative root path
  +    * @param path the block defintion URL
  +    * @param overrides the URL to a configuration containing configuration overrides
  +    * @return the block
  +    */
  +    private Block installSource( EngineClassLoader loader, String root, URL path, URL overrides
)
  +      throws BlockException
  +    {
  +
  +        Configuration block = getSourceConfiguration( path );
  +        Configuration config = getTargetsConfiguration( overrides );
  +
  +        InfoDescriptor info = createBlockInfoDescriptor( block.getChild( "info" ) );
  +        String name = info.getName();
   
  -        Configuration depsConfig = block.getChild( "dependencies", false );
  -        DependencyDescriptor[] dependencies = null; 
  -        if( depsConfig != null )
  +        String basePath = root + name;
  +        captureConfigurationTargets( basePath, config );
  +
  +        URL base = getBasePath( path );
  +        Configuration implementation = getImplementationFragment( block );
  +
  +        Configuration engineConfig = implementation.getChild( "engine" );
  +        EngineClassLoader engine = null;
  +        try
           {
  -            try
  -            {
  -                dependencies = TYPE_CREATOR.buildDependencies( depsConfig );
  -            }
  -            catch( ConfigurationException ce )
  -            {
  -                final String error = 
  -                  "Invalid dependencies declaration in block specification:\n"
  -                  + ConfigurationUtil.list( depsConfig );
  -                throw new BlockException( error, ce );
  -            }
  +            engine = createEngine( loader, m_home, engineConfig, name, base, base );
           }
  +        catch( Throwable e )
  +        {
  +            final String error = 
  +              "Could not construct engine for block: " + name;
  +            throw new BlockException( error, e );
  +        }
  +
  +        //
  +        // create the computational containment profile
  +        //
  +
  +        ContainmentProfile descriptor = 
  +          createContainmentProfile( name, engine, implementation );
  +
  +        //
  +        // create the block logical dependencies (as distinct from the 
  +        // physical dependencies of the type managed by the block)
  +        //
  +
  +        Configuration deps = block.getChild( "dependencies" );
  +        DependencyDescriptor[] dependencies = getBlockLogicalDependencies( deps ); 
           
           //
  -        // create the block services
  +        // create the logical block services
           //
   
  -        Configuration servicesConfig = block.getChild( "dependencies" , false );
  -        ServiceDescriptor[] services = null;
  -        if( servicesConfig != null )
  -        {
  -            try
  -            {
  -                services = TYPE_CREATOR.buildServices( servicesConfig );
  -            }
  -            catch( ConfigurationException ce )
  -            {
  -                final String error = 
  -                  "Invalid services declaration in block specification:\n"
  -                  + ConfigurationUtil.list( depsConfig );
  -                throw new BlockException( error, ce );
  -            }
  -        }
  +        Configuration svcs = block.getChild( "services" );
  +        ServiceDescriptor[] services = getBlockLogicalServices( svcs );
   
           //
  -        // create any subsidiary blocks
  +        // create the subsidiary blocks contained within this block
           //
   
  -        List blocks = 
  -          createChildBlocks( m_engine, Container.PATH_SEPERATOR, block, config, base );
  +        String partition = basePath + Container.PATH_SEPERATOR;
  +        List blocks = createChildBlocks( engine, partition, implementation, config, base
);
   
           //
  -        // create the block
  +        // create the block 
           //
   
           return createBlock( 
  -          dependencies, services, m_engine, blocks, descriptor, "", Container.PATH_SEPERATOR,
config );
  +          info, dependencies, services, engine, blocks, descriptor, name, root, config
);
  +    }
  +
  +   /**
  +    * Return the configuration fragment holding the implementation defintion.
  +    * This method checks for a child component named 'implementation' and if it exists
  +    * then the child is returned, otherwise, do the old method of checking for a 
  +    * root container and return that.  If neaither of the above work, throw a exception.
  +    * 
  +    * @param config the block confiugration
  +    * @return the implementation configuration fragment
  +    * @exception BlockException of the implementation fragment cannot be resolved
  +    */
  +    private Configuration getImplementationFragment( Configuration config ) throws BlockException
  +    {
  +        Configuration imp = config.getChild( "implementation", false );
  +        if( imp != null )
  +        {
  +            return imp;
  +        }
  +        imp = config.getChild( "container", false );
  +        if( imp != null )
  +        {
  +            final String error = 
  +              "Block contains a depricated reference to 'container'. \n"
  +              + "Please replace the root 'container' declaration with 'imlementation'.";
  +            getLogger().warn( error );
  +            return imp;
  +        }
  +        final String error =
  +          "Supplied block does not contain an 'implementation' element.\n"
  +          + ConfigurationUtil.list( config );
  +        throw new BlockException( error );
  +    }
  +
  +   /**
  +    * Create a block info descriptor holding the block name, version and 
  +    * optional properties.
  +    *
  +    * @param info the &lt;info&gt; configuration fragment
  +    * @return the block info descriptor
  +    */
  +    private InfoDescriptor createBlockInfoDescriptor( Configuration info )
  +      throws BlockException
  +    {
  +        final String name = info.getChild( "name" ).getValue( null );
  +        if( name == null )
  +        {
  +            final String error =
  +              "Block " + this + " does not contain a name.";
  +            getLogger().warn( error );
  +            return createBlockInfoDescriptor( "unknown", info );
  +        }
  +        return createBlockInfoDescriptor( name, info );
  +    }
  +
  +   /**
  +    * Create a block info descriptor holding the block name, version and 
  +    * optional properties.
  +    *
  +    * @param name the name to assign to the block
  +    * @param info the &lt;info&gt; configuration fragment
  +    * @return the block info descriptor
  +    */
  +    private InfoDescriptor createBlockInfoDescriptor( String name, Configuration info )
  +      throws BlockException
  +    {
  +        try
  +        {
  +            final String classname = DefaultBlock.class.getName();
  +            final Version version = 
  +              Version.getVersion( info.getChild( "version" ).getValue( "1.0" ) );
  +            final Properties attributes =
  +              TYPE_CREATOR.buildAttributes( info.getChild( "attributes" ) );
  +            return new InfoDescriptor( name, classname, version, attributes );
  +        }
  +        catch( ConfigurationException ce )
  +        {
  +            final String error = 
  +              "Unexpected error building block info desciptor: " 
  +              + name + "\n"
  +              + ConfigurationUtil.list( info );
  +            throw new BlockException( error, ce );
  +        }
  +    }
  +
  +   /**
  +    * Resolve the logical dependencies declared by this block.
  +    * @param config the dependecies configuration fragment
  +    * @return the set of declared depedency descriptors
  +    */
  +    private DependencyDescriptor[] getBlockLogicalDependencies( Configuration config )
  +      throws BlockException
  +    {
  +        try
  +        {
  +            return TYPE_CREATOR.buildDependencies( config );
  +        }
  +        catch( ConfigurationException ce )
  +        {
  +            final String error = 
  +              "Invalid dependencies declaration in block specification:\n"
  +               + ConfigurationUtil.list( config );
  +            throw new BlockException( error, ce );
  +        }
  +    }
  +
  +   /**
  +    * Resolve the logical services declared by this block.
  +    * @param config the dependecies configuration fragment
  +    * @return the set of declared depedency descriptors
  +    */
  +    private ServiceDescriptor[] getBlockLogicalServices( Configuration config )
  +      throws BlockException
  +    {
  +        try
  +        {
  +            return TYPE_CREATOR.buildServices( config );
  +        }
  +        catch( ConfigurationException ce )
  +        {
  +            final String error = 
  +              "Invalid services declaration in block specification:\n"
  +               + ConfigurationUtil.list( config );
  +            throw new BlockException( error, ce );
  +        }
  +    }
  +
  +    private void captureConfigurationTargets( String path, Configuration config )
  +      throws BlockException
  +    {
  +        Configuration[] targets = config.getChildren( "target" );
  +
  +        if( getLogger().isDebugEnabled() )
  +        {
  +            getLogger().debug("target override count: " + targets.length );
  +        }
  +
  +        for( int j=0; j<targets.length; j++ )
  +        {
  +            Configuration target = targets[j];
  +            try
  +            {
  +                String key = path + "/" + target.getAttribute( "name" );
  +                m_library.put( key, target.getChild( "configuration" ) );
  +                getLogger().debug( "registering configuration for key: " + key );
  +            }
  +            catch( Throwable e )
  +            {
  +                final String error =
  +                  "A configuration target does not declare a name in: " 
  +                  + path
  +                  + ConfigurationUtil.list( target );
  +                throw new BlockException( error, e );
  +            }
  +        }
       }
   
  +
       private JarFile getJarFile( URL url ) throws MalformedURLException
       {
           URL xurl;
  @@ -1154,26 +1240,6 @@
               final String error = "Bad classpath descriptor: \n"
                 + ConfigurationUtil.list( config );
               throw new EngineException( error, e );
  -        }
  -    }
  -
  -   /**
  -    * Get the name of the block from the blockk configuration.
  -    * @param config the block configuration
  -    * @return the block name
  -    */
  -    private String getBlockName( Configuration config ) throws BlockException
  -    {
  -        try
  -        {
  -            return config.getAttribute( "name" );
  -        }
  -        catch( Throwable e )
  -        {
  -            final String error = 
  -              "Supplied block configuration does not conain the required name attribute:\n"
  -              + ConfigurationUtil.list( config );
  -            throw new BlockException( error, e );
           }
       }
   
  
  
  

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


Mime
View raw message