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/src/test/org/apache/avalon/playground StandardComponent.java StandardComponent.xconfig StandardComponent.xprofile
Date Sun, 19 Jan 2003 18:18:51 GMT
mcconnell    2003/01/19 10:18:50

  Modified:    merlin   blocks.xml kernel.xml
               merlin/src/java/org/apache/avalon/merlin/block
                        BlockLoader.java
               merlin/src/java/org/apache/avalon/merlin/block/impl
                        DefaultBlock.java DefaultBlockLoader.java
               merlin/src/java/org/apache/avalon/merlin/kernel/impl
                        DefaultKernel.java
               merlin/src/test/config demo.xml
               merlin/src/test/org/apache/avalon/playground
                        StandardComponent.java StandardComponent.xconfig
                        StandardComponent.xprofile
  Log:
  Rebuilt configuration handling for non-embedded fragment handling.
  
  Revision  Changes    Path
  1.9       +5 -6      avalon-sandbox/merlin/blocks.xml
  
  Index: blocks.xml
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/blocks.xml,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- blocks.xml	19 Jan 2003 15:49:03 -0000	1.8
  +++ blocks.xml	19 Jan 2003 18:18:50 -0000	1.9
  @@ -8,7 +8,6 @@
   
   <blocks>
   
  -<!--
      <block name="james" src="src/test/config/james.xml" enabled="true" >
        <configuration target="dns">
           <servers>
  @@ -20,14 +19,14 @@
         </configuration>
      </block>
   
  +<!--
      <block name="playground" path="../assembly/build/lib/avalon-assembly-demo-1.0.jar"
enabled="true" />
  --->
   
      <block name="demo" src="src/test/config/demo.xml" enabled="true">
  -     <configuration target="test">
  -       <configuration target="standard">
  -         <message>Client supplied message.</message>
  -       </configuration>
  +     <configuration target="standard">
  +       <message>Configuration from target in blocks.xml.</message>
        </configuration>
      </block>
  +-->
  +
   </blocks>
  
  
  
  1.15      +2 -2      avalon-sandbox/merlin/kernel.xml
  
  Index: kernel.xml
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/kernel.xml,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- kernel.xml	19 Jan 2003 15:49:03 -0000	1.14
  +++ kernel.xml	19 Jan 2003 18:18:50 -0000	1.15
  @@ -2,7 +2,7 @@
   <kernel>
   
      <!-- 
  -   The kerenel can contain the following declarations:
  +   The kernel can contain the following declarations:
      1. a system descriptor
      2. a logging descriptor
      3. a logging catagories descriptor that establishes logging priority
  @@ -12,7 +12,7 @@
   
      <system host="localhost"/>
   
  -   <logging target="default" priority="WARN">
  +   <logging target="default" priority="INFO">
         <category name="/sys/logger" priority="WARN"/>
         <target name="kernel">
           <file location="kernel.log" />
  
  
  
  1.10      +2 -2      avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/block/BlockLoader.java
  
  Index: BlockLoader.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/block/BlockLoader.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- BlockLoader.java	18 Jan 2003 16:23:54 -0000	1.9
  +++ BlockLoader.java	19 Jan 2003 18:18:50 -0000	1.10
  @@ -75,6 +75,6 @@
       * @param system the system context
       * @return the set of blocks
       */
  -    public Block[] createBlocks( Configuration conf ) throws BlockException;
  +    public Block[] createBlocks() throws BlockException;
   
   }
  
  
  
  1.3       +17 -6     avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/block/impl/DefaultBlock.java
  
  Index: DefaultBlock.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/block/impl/DefaultBlock.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultBlock.java	19 Jan 2003 15:49:03 -0000	1.2
  +++ DefaultBlock.java	19 Jan 2003 18:18:50 -0000	1.3
  @@ -36,8 +36,10 @@
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.Configurable;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  +import org.apache.avalon.framework.configuration.DefaultConfiguration;
   import org.apache.avalon.merlin.block.Block;
   import org.apache.avalon.merlin.block.BlockException;
  +import org.apache.avalon.merlin.block.Library;
   import org.apache.avalon.merlin.container.impl.DefaultContainer;
   import org.apache.avalon.merlin.container.ContainerDescriptor;
   import org.apache.avalon.merlin.container.Container;
  @@ -163,7 +165,7 @@
      /**
       * The block configuration.
       */
  -    private Configuration m_config;
  +    private Library m_library;
   
      /**
       * The service registry assigned to the block.
  @@ -235,7 +237,7 @@
           m_applianceContext = (ApplianceContext) context.get( "urn:assembly:appliance.context"
);
           m_descriptor = (ContainerDescriptor) context.get( "urn:merlin:container.descriptor"
);
           m_registry = (Registry) context.get( "urn:merlin:container.registry" );
  -        m_config = (Configuration) context.get( "urn:merlin:container.configuration" );
  +        m_library = (Library) context.get( "urn:merlin:container.library" );
           m_blocks = (List) context.get( "urn:merlin:container.containers" );
       }
   
  @@ -271,8 +273,9 @@
                   getLogger().debug( message );
               }
   
  -            Configuration config = 
  -               DefaultKernel.getNamedConfiguration( m_config, profile.getName() );
  +            Configuration config = m_library.getConfiguration( getPath() + "/" + profile.getName()
);
  +            //Configuration config = 
  +            //   getNamedConfiguration( m_config, profile.getName() );
   
               DefaultApplianceContext context = 
                  new DefaultApplianceContext( profile );
  @@ -374,10 +377,18 @@
           if( getLogger().isDebugEnabled() )
           {
               Appliance[] startup = graph.getStartupGraph( );
  -            StringBuffer buffer = new StringBuffer( "startup sequence: " );
  +            StringBuffer buffer = new StringBuffer( 
  +              "statup sequence for for " + this + " (" + startup.length + ") " );
               for( int p=0; p<startup.length; p++ )
               {
  -               buffer.append( ", " + startup[p] );
  +                if( p == 0 )
  +                {
  +                    buffer.append( startup[p] );
  +                }
  +                else
  +                {
  +                    buffer.append( ", " + startup[p] );
  +                }
               }
               getLogger().debug( buffer.toString() );
           }
  
  
  
  1.3       +87 -68    avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/block/impl/DefaultBlockLoader.java
  
  Index: DefaultBlockLoader.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/block/impl/DefaultBlockLoader.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultBlockLoader.java	19 Jan 2003 15:49:03 -0000	1.2
  +++ DefaultBlockLoader.java	19 Jan 2003 18:18:50 -0000	1.3
  @@ -104,6 +104,7 @@
   import org.apache.avalon.framework.service.DefaultServiceSelector;
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.avalon.merlin.block.Block;
  +import org.apache.avalon.merlin.block.Library;
   import org.apache.avalon.merlin.block.BlockException;
   import org.apache.avalon.merlin.block.BlockLoader;
   import org.apache.avalon.merlin.container.builder.XMLContainerCreator;
  @@ -147,7 +148,7 @@
    * @see DefaultBlock
    */
   
  -public class DefaultBlockLoader extends AbstractLogEnabled implements Contextualizable,
Initializable, Disposable, BlockLoader
  +public class DefaultBlockLoader extends AbstractLogEnabled implements Contextualizable,
Initializable, Configurable, Disposable, BlockLoader, Library
   {
       //==============================================================
       // static
  @@ -165,26 +166,6 @@
   
       private static final XMLProfileCreator BUILDER = new XMLProfileCreator();
   
  -   /**
  -    * Return a configuration element relative to a target name.  The implementation 
  -    * will locate a configuration child in the supplied configuration with an element name
  -    * of "configuration" with a attribute named "target" with a value corresponding to

  -    * the supplied name.
  -    *
  -    * @param config the configuration holding a set of child "configuration" elements
  -    * @param name the name to match against child "target" attribute names
  -    * @return the matching configuration or new empty configuration if no match found
  -    */
  -    public static Configuration getNamedConfiguration( Configuration config, String name
)
  -    {
  -        int i = config.getChildren("configuration").length;
  -        if( i < 1 )
  -        {
  -            return new DefaultConfiguration( "configuration", BlockLoader.class.getName()
);
  -        }
  -        return ConfigurationUtil.matchFirstOccurance( config, "configuration", "target",
name );
  -    }
  -
       //==============================================================
       // state
       //==============================================================
  @@ -211,6 +192,16 @@
   
       private SourceResolverImpl m_resolver;
   
  +   /**
  +    * The blocks cofiguration.
  +    */
  +    private Configuration m_config;
  +
  +   /**
  +    * Configuration framgments keyed by appliance path.
  +    */
  +    private final Map m_library = new Hashtable();
  +
       //==============================================================
       // Contextualizable
       //==============================================================
  @@ -228,6 +219,29 @@
       }
   
       //==============================================================
  +    // Configurable
  +    //==============================================================
  +
  +    public void configure( Configuration config ) throws ConfigurationException
  +    {
  +        m_config = config;
  +        Configuration[] blocks = config.getChildren("block");
  +        for( int i=0; i<blocks.length; i++ )
  +        {
  +            Configuration block = blocks[i];
  +            String name = block.getAttribute( "name" );
  +            Configuration[] entries = block.getChildren( "configuration" );
  +            for( int j=0; j<entries.length; j++ )
  +            {
  +                Configuration entry = entries[j];
  +                String key = "/" + name + "/" + entry.getAttribute( "target" );
  +                m_library.put( key, entry );
  +                getLogger().debug( "registering configuration for key: " + key );
  +            } 
  +        }
  +    }
  +
  +    //==============================================================
       // Initializable
       //==============================================================
   
  @@ -287,6 +301,49 @@
       }
   
       //==============================================================
  +    // Library
  +    //==============================================================
  +
  +    /**
  +     * The context key for the path to the configuration. If no
  +     * configuration is available relative to the supplied path, an 
  +     * implementation shall return a new empty configuration.
  +     *
  +     * @param path the path identifiying he configuration
  +     */
  +    public Configuration getConfiguration( String path )
  +    {
  +        return getConfiguration( path, true );
  +    }
  +
  +    /**
  +     * The context key for the path to the configuration. If no
  +     * configuration is available relative to the supplied path, an 
  +     * implementation shall return either null or a new empty
  +     * configuration depending on the supplied creation policy.
  +     *
  +     * @param path the path identifiying he configuration
  +     * @param create the creation policy
  +     */
  +    public Configuration getConfiguration( String path, boolean create )
  +    {
  +        Configuration config = (Configuration) m_library.get( path );
  +        if( config != null )
  +        {
  +            return config;
  +        }
  +
  +        if( create )
  +        {
  +            return new DefaultConfiguration( "configuration", "BlockLoader.class" );
  +        }
  +        else
  +        {
  +            return null;
  +        }
  +    }
  +
  +    //==============================================================
       // BlockLoader
       //==============================================================
   
  @@ -300,10 +357,10 @@
       * @param system the system context
       * @return the set of blocks
       */
  -    public Block[] createBlocks( Configuration conf )
  +    public Block[] createBlocks()
         throws BlockException
       {
  -        Configuration[] configs = conf.getChildren("block");
  +        Configuration[] configs = m_config.getChildren("block");
           getLogger().info("block count = " + configs.length );
   
           ArrayList blocks = new ArrayList();
  @@ -384,41 +441,6 @@
                throw new BlockException( error, e );
           }
   
  -        Logger logger = getLogger().getChildLogger( name );
  -
  -        try
  -        {
  -            String string = config.getAttribute( "url", null );
  -            if( string != null )
  -            {
  -                if( string.indexOf(":") > -1 )
  -                {
  -                    // its a URL
  -                    if( string.toLowerCase().startsWith("file:") )
  -                    {
  -                        // its a file
  -                        String filename = string.substring(7);
  -                        File file = new File( m_home, filename ).getCanonicalFile();
  -                        getLogger().info( "FILE: " + file );
  -                    }
  -                    else
  -                    {
  -                        URL myURL = new URL( string );
  -                        getLogger().info( "URL: " + myURL );
  -                        Object object = myURL.getContent();
  -                        getLogger().info( "OBJECT: " + object );
  -                    }
  -                }
  -            }
  -            if( string != null )
  -            {
  -            }
  -        }
  -        catch( Throwable e )
  -        {
  -            getLogger().error( "URL ERROR: " + e.toString() );
  -        }
  -
           if( config.getAttribute( "path", null ) != null )
           {
   
  @@ -429,7 +451,9 @@
               String path = config.getAttribute("path", null );
               if( getLogger().isDebugEnabled() )
               {
  -                getLogger().debug( "assigning path to " + this + " path [" + path + "]
as [" + name + "]");
  +                getLogger().debug( 
  +                  "assigning path to " + this 
  +                  + " path [" + path + "] as [" + name + "]");
               }
   
               //
  @@ -508,7 +532,6 @@
   
           try
           {
  -            //engine = createChildEngine( m_engine, m_home, engineConfig, url, logger );
               engine = createChildEngine( m_engine, m_home, engineConfig, url, getLogger()
);
           }
           catch( Throwable ee )
  @@ -538,7 +561,6 @@
               throw new BlockException( error, ee );
           }
   
  -        //List list = createChildBlocks( engine, registry, partition, implementation, config,
logger );
           List list = createChildBlocks( engine, registry, partition, implementation, config,
getLogger() );
           return createBlock( engine, list, descriptor, name, registry, Container.PATH_SEPERATOR,
config ); 
       }
  @@ -583,7 +605,8 @@
               Configuration[] children = config.getChildren( "appliance" );
               for( int i=0; i<children.length; i++ )
               {
  -                Profile profile = createProfile( name, engine, children[i] );
  +                Configuration child = children[i];
  +                Profile profile = createProfile( name, engine, child );
                   engine.getRepository().getProfileManager().addProfile( profile );
                   descriptor.addComponent( profile );
               }
  @@ -636,7 +659,6 @@
                     + ConfigurationUtil.list( child );
                   throw new BlockException( error );
               }
  -            Logger log = logger.getChildLogger( name );
   
               //
               // create the block classloader
  @@ -646,7 +668,6 @@
               try
               {
                   loader = createChildEngine( 
  -                  //engine, m_home, child.getChild("engine"), log );
                     engine, m_home, child.getChild("engine"), getLogger() );
               }
               catch( ConfigurationException ce )
  @@ -675,7 +696,7 @@
               }
   
               Block block = createContainmentBlock( 
  -              loader, reg, partition, name, child, custom, log );
  +              loader, reg, partition, name, child, custom, getLogger() );
               list.add( block );
           }
   
  @@ -740,8 +761,6 @@
               getLogger().debug( "creating block: " + partition + name );
           }
   
  -        Configuration target = getNamedConfiguration( custom, name );
  -
           //
           // create the appliance context for the container - the map
           // contains the context entries that will be provided to the 
  @@ -761,7 +780,7 @@
           context.setApplianceClassname( DefaultBlock.class.getName() );
           context.put("urn:merlin:container.descriptor", descriptor ); 
           context.put("urn:merlin:container.registry", registry );
  -        context.put("urn:merlin:container.configuration", target );
  +        context.put("urn:merlin:container.library", this );
           context.put("urn:merlin:container.containers", containers );
           context.makeReadOnly();
   
  
  
  
  1.2       +3 -21     avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/kernel/impl/DefaultKernel.java
  
  Index: DefaultKernel.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/kernel/impl/DefaultKernel.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultKernel.java	19 Jan 2003 15:53:56 -0000	1.1
  +++ DefaultKernel.java	19 Jan 2003 18:18:50 -0000	1.2
  @@ -151,25 +151,6 @@
   
       protected static final XMLContainerCreator CREATOR = new XMLContainerCreator();
   
  -   /**
  -    * Return a configuration element relative to a target name.  The implementation 
  -    * will locate a configuration child in the supplied configuration with an element name
  -    * of "configuration" with a attribute named "target" with a value corresponding to

  -    * the supplied name.
  -    * @param config the configuration holding a set of child "configuration" elements
  -    * @param name the name to match against child "target" attribute names
  -    * @return the matching configuration or new empty configuration if no match found
  -    */
  -    public static Configuration getNamedConfiguration( Configuration config, String name
)
  -    {
  -        int i = config.getChildren("configuration").length;
  -        if( i < 1 )
  -        {
  -            return new DefaultConfiguration( "configuration", DefaultKernel.class.getName()
);
  -        }
  -        return ConfigurationUtil.matchFirstOccurance( config, "configuration", "target",
name );
  -    }
  -
       //==============================================================
       // state
       //==============================================================
  @@ -388,9 +369,10 @@
               context.put( "urn:assembly:system-context", getSystemContext() );
               context.makeReadOnly();
               loader.contextualize( context );
  +            loader.configure( m_configuration );
               loader.initialize();
   
  -            blocks = loader.createBlocks( m_configuration );
  +            blocks = loader.createBlocks();
   
               for( int i=0; i<blocks.length; i++ )
               {
  
  
  
  1.2       +4 -1      avalon-sandbox/merlin/src/test/config/demo.xml
  
  Index: demo.xml
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/src/test/config/demo.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- demo.xml	18 Jan 2003 02:11:43 -0000	1.1
  +++ demo.xml	19 Jan 2003 18:18:50 -0000	1.2
  @@ -23,7 +23,10 @@
        <engine/>
   
        <appliance name="standard" class="org.apache.avalon.playground.StandardComponent"
activation="startup">
  -         <context class="org.apache.avalon.playground.StandardContextImp"/>
  +       <context class="org.apache.avalon.playground.StandardContextImp"/>
  +       <configuration>
  +         <message>Message declared in block descriptor.</message>
  +       </configuration>
        </appliance>
   
        <container name="test"/>
  
  
  
  1.7       +2 -53     avalon-sandbox/merlin/src/test/org/apache/avalon/playground/StandardComponent.java
  
  Index: StandardComponent.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/src/test/org/apache/avalon/playground/StandardComponent.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- StandardComponent.java	15 Jan 2003 09:14:52 -0000	1.6
  +++ StandardComponent.java	19 Jan 2003 18:18:50 -0000	1.7
  @@ -124,7 +124,6 @@
        */
       public void initialize() throws Exception
       {
  -        //doThreadTest();
           m_message = 
             "\n  home: " + m_home
             + "\n  work: " + m_work
  @@ -170,57 +169,7 @@
        */
       public void printMessage()
       {
  -        getLogger().info( m_config.getChild("message").getValue("") );
  -        getLogger().info( "listing context\n" + m_message + "\n");
  +        getLogger().info( "config message: " + m_config.getChild("message").getValue("")
);
  +        getLogger().info( "context\n" + m_message + "\n");
       }
  -    
  -
  -    /**
  -     * Do a test related to the thread library.
  -     */
  -/*
  -    public void doTreadTest() throws Exception
  -    {
  -        try
  -        {
  -            getLogger().error( "START" );
  -            DefaultThreadPool pool = new DefaultThreadPool( "test", 12 );
  -        }
  -        catch( Throwable e )
  -        {
  -            ClassLoader loader = Thread.currentThread().getContextClassLoader();
  -            try
  -            {
  -                loader.loadClass( DefaultThreadPool.class.getName() );
  -            }
  -            catch( Throwable ex )
  -            {
  -                getLogger().error( "CONTEXT: " + ex.toString() );
  -            }
  -
  -            if( loader instanceof URLClassLoader )
  -            {
  -                listURLs( (URLClassLoader) loader );
  -            }
  -            getLogger().error( "THROWABLE: " + e );
  -            getLogger().error( "LOADER:" + loader );
  -            throw new Exception( "zutt", e );
  -        }
  -    }
  -    private void listURLs( URLClassLoader loader )
  -    {
  -        if( loader != null )
  -        {
  -            URL[] urls = loader.getURLs();
  -            for( int i=0; i<urls.length; i++ )
  -            {
  -                getLogger().debug( "URL: " + urls[i] );
  -            }
  -            if( loader.getParent() instanceof URLClassLoader )
  -            {
  -                listURLs( (URLClassLoader) loader.getParent() );
  -            }
  -        }
  -    }
  -*/
   }
  
  
  
  1.4       +1 -1      avalon-sandbox/merlin/src/test/org/apache/avalon/playground/StandardComponent.xconfig
  
  Index: StandardComponent.xconfig
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/src/test/org/apache/avalon/playground/StandardComponent.xconfig,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StandardComponent.xconfig	23 Dec 2002 17:10:41 -0000	1.3
  +++ StandardComponent.xconfig	19 Jan 2003 18:18:50 -0000	1.4
  @@ -15,6 +15,6 @@
   -->
   
   <configuration>
  -   <message>Standard preconfigured message.</message>
  +   <message>Standard preconfigured message from .xconfig.</message>
   </configuration>
   
  
  
  
  1.4       +3 -0      avalon-sandbox/merlin/src/test/org/apache/avalon/playground/StandardComponent.xprofile
  
  Index: StandardComponent.xprofile
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/src/test/org/apache/avalon/playground/StandardComponent.xprofile,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StandardComponent.xprofile	27 Dec 2002 16:48:21 -0000	1.3
  +++ StandardComponent.xprofile	19 Jan 2003 18:18:50 -0000	1.4
  @@ -21,6 +21,9 @@
    
      <profile name="standard">
        <context class="org.apache.avalon.playground.StandardContextImp"/>
  +     <configuration>
  +       <message>Packaged configuration message from .xprofile.</message>
  +     </configuration>
      </profile>
   
   </profiles>
  
  
  

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


Mime
View raw message