Return-Path: Delivered-To: apmail-avalon-cvs-archive@avalon.apache.org Received: (qmail 96188 invoked by uid 500); 15 Jun 2003 18:25:55 -0000 Mailing-List: contact cvs-help@avalon.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Avalon CVS List" Reply-To: "Avalon Developers List" Delivered-To: mailing list cvs@avalon.apache.org Received: (qmail 96177 invoked by uid 500); 15 Jun 2003 18:25:55 -0000 Received: (qmail 96174 invoked from network); 15 Jun 2003 18:25:55 -0000 Received: from icarus.apache.org (208.185.179.13) by daedalus.apache.org with SMTP; 15 Jun 2003 18:25:55 -0000 Received: (qmail 32002 invoked by uid 1438); 15 Jun 2003 18:25:54 -0000 Date: 15 Jun 2003 18:25:54 -0000 Message-ID: <20030615182554.32001.qmail@icarus.apache.org> From: mcconnell@apache.org To: avalon-sandbox-cvs@apache.org Subject: cvs commit: avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/kernel/impl DefaultKernel.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N mcconnell 2003/06/15 11:25:54 Modified: merlin/merlin-core/src/java/org/apache/avalon/merlin/block/impl StandardBlockLoader.java Target.java Targets.java XMLContainerCreator.java merlin/merlin-core/src/java/org/apache/avalon/merlin/kernel/impl DefaultKernel.java Log: Upgrading of the management of the Target meta-data to provide support for overriding logging directives. Revision Changes Path 1.13 +5 -3 avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/block/impl/StandardBlockLoader.java Index: StandardBlockLoader.java =================================================================== RCS file: /home/cvs/avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/block/impl/StandardBlockLoader.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- StandardBlockLoader.java 14 Jun 2003 11:13:09 -0000 1.12 +++ StandardBlockLoader.java 15 Jun 2003 18:25:54 -0000 1.13 @@ -253,7 +253,9 @@ //============================================================== /** - * Load a block declared in the supplied block and configuration URL. + * Load a root block under the name "/" using the supplied block + * configuration and optional configuration target override URL. + * * The path URL may refer to a XML file containing a block directive * or a jar file containing a block.xml file. * @@ -262,7 +264,7 @@ * @return the block */ public Block install( final URL path, final URL overrides ) - throws BlockException + throws Exception { // // establish a URL referencing the base directory 1.3 +49 -7 avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/block/impl/Target.java Index: Target.java =================================================================== RCS file: /home/cvs/avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/block/impl/Target.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- Target.java 12 Jun 2003 18:56:19 -0000 1.2 +++ Target.java 15 Jun 2003 18:25:54 -0000 1.3 @@ -56,6 +56,7 @@ package org.apache.avalon.merlin.block.impl; import org.apache.avalon.framework.configuration.Configuration; +import org.apache.avalon.meta.model.LoggingDirective; /** *

A target is a tagged configuration fragment. The tag is a path @@ -81,11 +82,27 @@ */ private final Configuration m_config; + /** + * The configuration. + */ + private final LoggingDirective m_logging; + //======================================================================== // constructors //======================================================================== /** + * Create a new null Target instance. + * + * @param path target path + * @param configuration the configuration + */ + public Target( final String path ) + { + this( path, null ); + } + + /** * Create a new Target instance. * * @param path target path @@ -93,15 +110,27 @@ */ public Target( final String path, final Configuration configuration ) { + this( path, configuration, null ); + } + + /** + * Create a new Target instance. + * + * @param path target path + * @param configuration the configuration + */ + public Target( final String path, final Configuration configuration, LoggingDirective logging ) + { if( !path.startsWith("/") ) { - final String error = - "Supplied target path '" + path - + "' does not commence with the path delimiter '/'."; - throw new IllegalArgumentException( error ); + m_path = "/" + path; + } + else + { + m_path = path; } - m_path = path; m_config = configuration; + m_logging = logging; } //======================================================================== @@ -130,12 +159,25 @@ } /** + * Return the logging categories directive. + * + * @return the logging categories (possibly null) + */ + public LoggingDirective getLoggingDirective() + { + return m_logging; + } + + /** * Return a string representation of the target. * @return a string representing the target instance */ public String toString() { - return "[target: " + getPath() + ", " + (getConfiguration() != null ) + " ]"; + return "[target: " + getPath() + ", " + + (getConfiguration() != null ) + ", " + + (getLoggingDirective() != null ) + + " ]"; } } 1.3 +12 -15 avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/block/impl/Targets.java Index: Targets.java =================================================================== RCS file: /home/cvs/avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/block/impl/Targets.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- Targets.java 12 Jun 2003 18:56:19 -0000 1.2 +++ Targets.java 15 Jun 2003 18:25:54 -0000 1.3 @@ -128,14 +128,6 @@ public Target getTarget( String path ) { final String key = getKey( path ); - if( m_parent != null ) - { - Target t = m_parent.getTarget( key ); - if( t.getConfiguration() != null ) - { - return t; - } - } for( int i=0; i 0 ) { - if( target.getConfiguration() != null ) - { - Target t = new Target( getKey( name ), target.getConfiguration() ); - list.add( t ); - } + list.add( + new Target( + getKey( name ), + target.getConfiguration(), + target.getLoggingDirective() ) ); } } } 1.4 +263 -54 avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/block/impl/XMLContainerCreator.java Index: XMLContainerCreator.java =================================================================== RCS file: /home/cvs/avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/block/impl/XMLContainerCreator.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- XMLContainerCreator.java 14 Jun 2003 11:13:54 -0000 1.3 +++ XMLContainerCreator.java 15 Jun 2003 18:25:54 -0000 1.4 @@ -287,64 +287,243 @@ */ private ContainmentProfile expandContainmentInclude( URL base, EngineClassLoader parent, Configuration config, Targets targets ) - throws Exception + throws ContainerException { + // + // get the source of the block description and convert in into a + // configuration instance + // + + URL source = getIncludeBlockSource( base, config ); + Configuration block = null; try { - URL source = null; - Configuration block = null; - final String blockPath = config.getAttribute( "path", null ); - if( blockPath != null ) - { - source = new URL( base, base.getPath() + blockPath ); - block = getSourceConfiguration( source ); - } - else if( config.getAttribute( "id", null ) != null ) - { - String id = config.getAttribute( "id" ); - String version = config.getAttribute( "version", "1.0" ); - source = m_repository.getArtifact( id, version, "jar" ); - block = getSourceConfiguration( source ); - } - else - { - final String error = - "Include directive does not declare a 'path' or 'id' attribute.\n" - + ConfigurationUtil.list( config ); - throw new IllegalArgumentException( error ); - } + block = getSourceConfiguration( source ); + } + catch( Throwable e ) + { + final String error = + "Unable to read the block directive relative to the source:" + + source; + throw new ContainerException( error, e ); + } + // + // get the name to assign to the block from the include using + // the block name as the default value + // + + final String name = config.getAttribute( + "name", block.getChild("info").getChild("name").getValue("block") ); + + // + // handle the loading of the override targets + // + + Targets newTargets = null; + try + { // - // get the name to assign to the block from the include using - // the block name as the default value + // if there is a nested targets element and it refers to + // an external targets file then pull ito in and + // expand out set of know target overrides // - final String name = config.getAttribute( - "name", block.getChild("info").getChild("name").getValue("block") ); - Targets candidates = targets.getTargets( name ); - - final String configPath = config.getAttribute( "config", null ); - Targets newTargets = null; + final String configPath = getTargetPath( config ); if( configPath != null ) { - URL conf = new URL( base, base.getPath() + configPath ); + URL url = new URL( base, base.getPath() + configPath ); newTargets = createTargets( - candidates, createConfiguration( conf.toString() ) ); + candidates, createConfiguration( url.toString() ) ); } else { - newTargets = candidates; + // + // check for embedded target declarations, otherwise + // the new target reverts to the current set of + // targets + // + + if( config.getChild( "targets", false ) != null ) + { + newTargets = createTargets( + candidates, config.getChild( "targets" ) ); + } + else + { + newTargets = candidates; + } } + } + catch( Throwable e ) + { + final String error = + "Unable to resolve configuration targets from include directive:" + + ConfigurationUtil.list( config ); + throw new ContainerException( error, e ); + } + try + { return createBlockProfile( name, base, source, parent, block, newTargets ); } - catch( Throwable ce ) + catch( Throwable e ) { - final String error = - "Could not create block descriptor for include directive.\n" - + ConfigurationUtil.list( config ); - throw new ContainerException( error, ce ); + final String error = + "Unable to establish containment profile relative to the include directive:" + + ConfigurationUtil.list( config ); + throw new ContainerException( error, e ); + } + } + + /** + * Get the path attribute value from the supplied include directive. + * @param include the include directive + * @return the path value (possibly null) + */ + private String getTargetPath( Configuration include ) throws ConfigurationException + { + if( include.getAttribute( "config", null ) != null ) + { + return include.getAttribute( "config" ); + } + else if( include.getChild( "targets", false ) != null ) + { + if( include.getChild( "targets" ).getAttribute( "path", null ) != null ) + { + return include.getChild( "targets" ).getAttribute( "path" ); + } + else + { + return null; + } + } + else + { + return null; + } + } + + /** + * The the URL of an included block defintion relative to the supplied + * base url and include directive. + * @param base the base url + * @param config the include directive + * @return the URL of the block source + * @exception ContainerException if the source URL is not resolvable + */ + private URL getIncludeBlockSource( URL base, Configuration config ) throws ContainerException + { + String path = getIncludePath( config ); + if( path != null ) + { + try + { + return new URL( base, base.getPath() + path ); + } + catch( Throwable e ) + { + final String error = + "Unable to resolve block descriptor from path: " + path + + " relative to the base url: " + base; + throw new ContainerException( error, e ); + } + } + else + { + if( config.getAttribute( "id", null ) != null ) + { + return getSourceFromResource( config ); + } + else if( config.getChild( "resource", false ) != null ) + { + return getSourceFromResource( config.getChild( "resource" ) ); + } + else + { + final String error = + "Supplied include directive does not contain a nested source or resource element." + + ConfigurationUtil.list( config ); + throw new ContainerException( error ); + } + } + } + + /** + * The the URL of an included block defintion from the repository. + * @param config the configuration fragment contaiing the artifact identifier + * @return the URL of the block source + * @exception ContainerException if the source URL is not resolvable + */ + private URL getSourceFromResource( Configuration config ) + throws ContainerException + { + String id = getArtifactID( config ); + String version = config.getAttribute( "version", "1.0" ); + try + { + return m_repository.getArtifact( id, version, "jar" ); + } + catch( Throwable e ) + { + final String error = + "Unable to resolve the block directive relative to the supplied repository id:" + + id + " and version: " + version; + throw new ContainerException( error, e ); + } + } + + /** + * Return the artifact identitier from a configuration fragment. + * @param config the configuration fragment containing the artifact identifier + * @return the artifact identifier + * @exception ContainerException if the fragment does not contain the id attribute + */ + private String getArtifactID( Configuration config ) throws ContainerException + { + try + { + return config.getAttribute( "id" ); + } + catch( Throwable e ) + { + final String error = + "Missing artifict identifier (id) in include directive." + + ConfigurationUtil.list( config ); + throw new ContainerException( error ); + } + } + + /** + * Return the path from an include directive. + * @param config the include directive + * @return the include path + * @exception ContainerException if the path is not resolvable + */ + private String getIncludePath( Configuration config ) throws ContainerException + { + if( config.getAttribute( "path", null ) != null ) + { + return config.getAttribute( "path", null ); + } + else if( config.getChild( "source", false ) != null ) + { + try + { + return config.getChild( "source" ).getAttribute("path"); + } + catch( ConfigurationException e ) + { + final String error = + "Missing path value in source directive." + + ConfigurationUtil.list( config ); + throw new ContainerException( error ); + } + } + else + { + return null; } } @@ -552,7 +731,8 @@ String classname = config.getAttribute( "class" ); Type type = engine.getRepository().getTypeRepository().getType( classname ); Profile profile = - BUILDER.createProfile( type, config, target.getConfiguration() ); + BUILDER.createProfile( + type, config, target.getConfiguration(), target.getLoggingDirective() ); boolean policy = getActivationPolicy( config ); profile.setActivationPolicy( policy ); return profile; @@ -573,7 +753,7 @@ * elements * @return the targets instance */ - public Targets createTargets( Configuration config ) + public Targets createTargets( Configuration config ) throws Exception { return createTargets( null, config.getChildren( "target" ) ); } @@ -585,7 +765,7 @@ * elements * @return the targets instance */ - public Targets createTargets( Targets targets, Configuration config ) + public Targets createTargets( Targets targets, Configuration config ) throws Exception { return createTargets( targets, config.getChildren( "target" ) ); } @@ -596,24 +776,53 @@ * @param targets a configuration array of <target> instances; * @return the targets instance */ - public Targets createTargets( Targets targets, Configuration[] conf ) + public Targets createTargets( Targets targets, Configuration[] conf ) throws Exception { ArrayList list = new ArrayList(); for( int i=0; i