mcconnell 2002/12/11 16:34:07 Modified: merlin/src/java/org/apache/avalon/merlin/block DefaultBlock.java Log: Addition of code to handle the creation of a root container within a block. Revision Changes Path 1.6 +69 -1 avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/block/DefaultBlock.java Index: DefaultBlock.java =================================================================== RCS file: /home/cvs/avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/block/DefaultBlock.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- DefaultBlock.java 11 Dec 2002 04:59:46 -0000 1.5 +++ DefaultBlock.java 12 Dec 2002 00:34:07 -0000 1.6 @@ -9,6 +9,8 @@ import java.util.jar.Attributes; import java.util.jar.Manifest; import java.util.jar.JarFile; +import java.util.Map; +import java.util.Hashtable; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.assembly.appliance.DefaultAppliance; @@ -21,6 +23,10 @@ import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.assembly.engine.model.ClasspathDescriptor; +import org.apache.avalon.assembly.appliance.Appliance; +import org.apache.avalon.merlin.container.DefaultContainer; +import org.apache.avalon.meta.info.Type; +import org.apache.avalon.meta.model.Profile; public class DefaultBlock extends BlockLoader implements Block, Contextualizable, Initializable { @@ -48,6 +54,8 @@ // state //============================================================== + private String m_name; + private EngineClassLoader m_engine; private Manifest m_manifest; @@ -61,6 +69,11 @@ */ private Configuration m_config; + /** + * The applaince holding the root container. + */ + private Appliance m_appliance; + //============================================================== // Contextualizable //============================================================== @@ -87,6 +100,57 @@ { getLogger().debug( "initialization" ); m_config = getBlockConfiguration( getJarFile( m_url ) ); + + String name = getName(); + m_appliance = createContainmentAppliance( m_config ); + m_appliance.access(); + + try + { + ClasspathDescriptor path = + CREATOR.createClasspathDescriptor( m_config.getChild( "blocks" ) ); + URL[] urls = ClasspathDescriptor.expand( m_home, path ); + Block[] blocks = install( m_engine, m_home, urls ); + } + catch( Throwable e ) + { + final String error = + "Subsidiary block deployment failure in parent block: " + name; + throw new BlockException( error, e ); + } + } + + public Appliance createContainmentAppliance( Configuration config ) throws Exception + { + String name = getName(); + Configuration containment = m_config.getChild( "container" ); + String classname = containment.getAttribute( "type", DefaultContainer.class.getName() ); + Type type = m_engine.getRepository().getTypeManager().getType( classname ); + Profile profile = m_engine.getRepository().getProfileManager().getProfile( type ); + + try + { + Map map = new Hashtable(); + map.put( "urn:assembly:engine.classloader", m_engine ); + Appliance appliance = m_engine.createAppliance( profile, map, false ); + m_engine.assemble( appliance ); + return appliance; + } + catch( Throwable e ) + { + final String error = + "Root container establishment error in block: " + name; + throw new BlockException( error, e ); + } + } + + //============================================================== + // Block + //============================================================== + + public void assemble() throws Exception + { + getLogger().debug( "assemble" ); ClasspathDescriptor path = CREATOR.createClasspathDescriptor( m_config.getChild( "blocks" ) ); URL[] urls = ClasspathDescriptor.expand( m_home, path ); @@ -99,6 +163,10 @@ public String getName() { - return getName( m_manifest ); + if( m_name == null ) + { + m_name = getName( m_manifest ); + } + return m_name; } }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>