mcconnell 2003/03/08 07:32:36
Modified: merlin/src/java/org/apache/avalon/merlin/block/impl
DefaultBlockLoader.java
Log:
Addition of support for the embedding of blocks with a block implementation.
Revision Changes Path
1.16 +100 -13
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.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- DefaultBlockLoader.java 6 Mar 2003 12:05:24 -0000 1.15
+++ DefaultBlockLoader.java 8 Mar 2003 15:32:36 -0000 1.16
@@ -277,16 +277,34 @@
//==============================================================
/**
- * Load the blocks declared in the supplied configuration.
+ * 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 block the block defintion URL
+ * @param path the block defintion URL
* @param overrides the URL to a configuration containing configuration overrides
* @return the block
*/
public Block install( URL path, URL overrides )
throws BlockException
{
- Configuration block = getBlockConfiguration( path );
+ return installSource( m_engine, Container.PATH_SEPERATOR, path, overrides );
+ }
+
+ /**
+ * 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
+ */
+ private Block installSource( EngineClassLoader loader, String root, URL path,
URL overrides )
+ throws BlockException
+ {
+
+ Configuration block = getSourceConfiguration( path );
Configuration config = getTargetsConfiguration( overrides );
String name = getBlockName( block );
@@ -302,7 +320,7 @@
Configuration target = targets[j];
try
{
- String key = "/" + name + "/" + target.getAttribute( "name" );
+ String key = root + name + "/" + target.getAttribute( "name" );
m_library.put( key, target.getChild( "configuration" ) );
getLogger().debug( "registering configuration for key: " + key );
}
@@ -322,7 +340,7 @@
EngineClassLoader engine = null;
try
{
- engine = createEngine( m_engine, m_home, engineConfig, name, base, base
);
+ engine = createEngine( loader, m_home, engineConfig, name, base, base );
}
catch( Throwable e )
{
@@ -335,10 +353,10 @@
// create an appliance context
//
- String partition = name + Container.PATH_SEPERATOR;
+ String partition = root + name + Container.PATH_SEPERATOR;
ContainerDescriptor descriptor = createContainerDescriptor( name, engine,
implementation );
List list = createChildBlocks( engine, partition, implementation, config,
base, getLogger() );
- return createBlock( engine, list, descriptor, name,
Container.PATH_SEPERATOR, config );
+ return createBlock( engine, list, descriptor, name, root, config );
}
//==============================================================
@@ -411,7 +429,7 @@
}
}
- private Configuration getBlockConfiguration( URL url ) throws BlockException
+ private Configuration getSourceConfiguration( URL url ) throws BlockException
{
String uri = url.toString();
if( url.getProtocol().equals( "jar" ) )
@@ -419,7 +437,7 @@
try
{
JarFile jar = getJarFile( url );
- return getBlockConfiguration( jar );
+ return getSourceConfiguration( jar );
}
catch( Throwable e )
{
@@ -430,8 +448,8 @@
}
else
{
- // its a simulated block
- //String source = appendName( uri, "block-inf/block.xml" );
+ // its either a simulated block or include
+
try
{
return createConfiguration( uri );
@@ -515,6 +533,75 @@
throws BlockException
{
List list = new ArrayList();
+
+ //
+ // build the set of included blocks
+ //
+
+ Configuration[] includes = config.getChildren( "include" );
+
+ for( int j=0; j<includes.length; j++ )
+ {
+ Configuration include = includes[j];
+ String path = null;
+ URL source = null;
+ try
+ {
+ path = include.getAttribute( "path" );
+ source = new URL( base, path );
+ }
+ catch( ConfigurationException ce )
+ {
+ final String error =
+ "Missing path attribute on include directive.\n"
+ + ConfigurationUtil.list( include );
+ throw new BlockException( error, ce );
+ }
+ catch( MalformedURLException e )
+ {
+ final String error =
+ "Error during URL manipulation of path: " + path
+ + " from base: " + base;
+ throw new BlockException( error, e );
+ }
+
+ //
+ // check if there is a qualifying configuration URL
+ //
+
+ Configuration target = include.getChild("configuration");
+ String ref = target.getAttribute( "src", null );
+ URL conf = null;
+ if( ref != null )
+ {
+ try
+ {
+ conf = new URL( base, ref );
+ }
+ catch( MalformedURLException mue )
+ {
+ final String error =
+ "Cannot parse supplied configuration src attribute: " + ref
+ + ConfigurationUtil.list( target );
+ throw new BlockException( error );
+ }
+ }
+
+ if( getLogger().isDebugEnabled() )
+ {
+ final String info =
+ "Installing embedded block: " + source;
+ getLogger().debug( info );
+ }
+
+ Block block = installSource( engine, partition, source, conf );
+ list.add( block );
+ }
+
+ //
+ // build the set of embedded blocks
+ //
+
Configuration[] children = config.getChildren( "container" );
for( int i=0; i<children.length; i++ )
@@ -654,7 +741,7 @@
}
}
- private Configuration getBlockConfiguration( JarFile jar ) throws Exception
+ private Configuration getSourceConfiguration( JarFile jar ) throws Exception
{
if( jar == null )
{
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]