mcconnell    2003/01/06 22:26:37

  Modified:    merlin/src/java/org/apache/avalon/merlin/kernel
                        DefaultKernel.java
               merlin/src/test/config block.xml
  Added:       merlin   external.xml
  Log:
  Added support for optional loading of an external block implementation 
configuration file.
  
  Revision  Changes    Path
  1.1                  avalon-sandbox/merlin/external.xml
  
  Index: external.xml
  ===================================================================
  
  <!--
  Demonstration of an external block implementation configuration file.
  To use an external file, the packaged block.xml "implementation" 
  element must contain a file name of the external source under an 
  attibute named "src".
  -->
  
     <implementation>
  
       <container name="test">
         <appliance name="standard" 
class="org.apache.avalon.playground.StandardComponent" activation="startup">
           <context class="org.apache.avalon.playground.StandardContextImp"/>
         </appliance>
       </container>
  
     </implementation>
  
  
  
  1.20      +44 -3     
avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/kernel/DefaultKernel.java
  
  Index: DefaultKernel.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/kernel/DefaultKernel.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- DefaultKernel.java        6 Jan 2003 01:05:53 -0000       1.19
  +++ DefaultKernel.java        7 Jan 2003 06:26:37 -0000       1.20
  @@ -646,7 +646,8 @@
           //
   
           String partition = name + Container.PATH_SEPERATOR;
  -        Configuration containment = base.getChild( "implementation" );
  +        Configuration containment = 
  +          getImplementationConfiguration( base.getChild( "implementation" ) 
);
           ContainerDescriptor descriptor = createContainerDescriptor( name, 
engine, containment );
           Registry registry = m_registry.createChild( name );
           List list = createChildContainers( engine, registry, partition, 
containment, config, logger );
  @@ -656,7 +657,6 @@
           //
   
           return createBlock( engine, list, descriptor, name, registry, 
Container.PATH_SEPERATOR, config ); 
  -
       }
   
      /**
  @@ -1065,6 +1065,47 @@
           {
               final String error = "Unable to create configuration from jar 
file: " + jar.getName();
               throw new BlockException( error, e );
  +        }
  +    }
  +
  +   /**
  +    * Check the implementation configuration for a src attribute and if not 
null 
  +    * load an external implememntation configuration.
  +    *
  +    * @param implementation the block implementation configuration 
  +    * @return the resolved implementation configuration
  +    */
  +    private Configuration getImplementationConfiguration( Configuration 
implementation )
  +      throws ConfigurationException
  +    {
  +        String path = implementation.getAttribute( "src", null );
  +        if( path == null )
  +        {
  +            getLogger().info( "loading block implementation" );
  +            return implementation;
  +        }
  +        else
  +        {
  +            File file = new File( m_home, path );
  +            try
  +            {
  +                DefaultConfigurationBuilder builder = new 
DefaultConfigurationBuilder();
  +                getLogger().info( "loading external block implementation 
from: " + file );
  +                InputStream input = new FileInputStream( file );
  +                if( input == null )
  +                {
  +                    final String error = 
  +                      "Null stream returned from path: " + file;
  +                    throw new IllegalArgumentException( error );
  +                }
  +                return builder.build( input );
  +            }
  +            catch( Throwable e )
  +            {
  +                final String error = 
  +                  "Unable to load extenal block implementation configuration 
from src: " + file;
  +                throw new ConfigurationException( error, e );
  +            }
           }
       }
   }
  
  
  
  1.10      +4 -1      avalon-sandbox/merlin/src/test/config/block.xml
  
  Index: block.xml
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/src/test/config/block.xml,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- block.xml 27 Dec 2002 16:46:43 -0000      1.9
  +++ block.xml 7 Jan 2003 06:26:37 -0000       1.10
  @@ -17,13 +17,16 @@
      and container entities. The block implementation statement is equivalent
      to a root container who's name is implied by the name of the block.
      -->
  -   <implementation>
  +   <implementation src="external.xml">
   
  +     <!-- use external file or embedded defintion -->
  +     <!--
        <container name="test">
          <appliance name="standard" 
class="org.apache.avalon.playground.StandardComponent" activation="startup">
            <context class="org.apache.avalon.playground.StandardContextImp"/>
          </appliance>
        </container>
  +     -->
   
      </implementation>
   
  
  
  

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

Reply via email to