mcconnell 2002/12/27 08:38:54 Modified: merlin/src/java/org/apache/avalon/merlin/block Block.java DefaultBlock.java Log: Refactored implementation to extend from Appliance. Implementation now parrallels Appliance in that is managing the establishment of a compoennt - but in the Block case, the component is a containement heirachy. Revision Changes Path 1.5 +7 -12 avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/block/Block.java Index: Block.java =================================================================== RCS file: /home/cvs/avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/block/Block.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- Block.java 17 Dec 2002 04:45:21 -0000 1.4 +++ Block.java 27 Dec 2002 16:38:54 -0000 1.5 @@ -51,23 +51,18 @@ package org.apache.avalon.merlin.block; import org.apache.avalon.assembly.appliance.Appliance; +import org.apache.avalon.merlin.container.Container; /** - * A block is a deployment model supporting composite components. + * A block is a deployment model supporting composite components. A block is + * both an appliance and a proxy to a container. As an appliance it manages + * the deployment of a root container. As a container it handles delatation + * of containment lifecycle operations to the managed container instance. * * @author <a href="mailto:avalon-dev@jakarta.apache.org">Avalon Development Team</a> * @version $Revision$ $Date$ */ -public interface Block +public interface Block extends Appliance, Container { static final String AVALON_BLOCK_KEY = "Avalon-Block"; - - - /** - * Get appliance managing the root container. - * @return the root container appliance - */ - Appliance getAppliance(); - } - 1.9 +105 -42 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.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- DefaultBlock.java 17 Dec 2002 04:45:21 -0000 1.8 +++ DefaultBlock.java 27 Dec 2002 16:38:54 -0000 1.9 @@ -12,10 +12,17 @@ import java.util.Map; import java.util.Hashtable; -import org.apache.avalon.framework.logger.Logger; -import org.apache.avalon.framework.logger.AbstractLogEnabled; +import org.apache.avalon.assembly.appliance.Appliance; import org.apache.avalon.assembly.appliance.DefaultAppliance; +import org.apache.avalon.assembly.appliance.ApplianceContext; +import org.apache.avalon.assembly.appliance.ApplianceException; import org.apache.avalon.assembly.engine.EngineClassLoader; +import org.apache.avalon.assembly.lifestyle.LifestyleException; +import org.apache.avalon.assembly.lifestyle.LifestyleService; +import org.apache.avalon.assembly.lifecycle.AssemblyService; +import org.apache.avalon.assembly.lifecycle.AssemblyException; +import org.apache.avalon.framework.logger.Logger; +import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.activity.Initializable; import org.apache.avalon.framework.context.Context; import org.apache.avalon.framework.context.Contextualizable; @@ -23,101 +30,157 @@ 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.assembly.engine.model.ClasspathDescriptor; -import org.apache.avalon.assembly.appliance.Appliance; -import org.apache.avalon.assembly.lifestyle.LifestyleException; import org.apache.avalon.merlin.container.DefaultContainer; import org.apache.avalon.merlin.container.ContainerDescriptor; +import org.apache.avalon.merlin.container.Container; import org.apache.avalon.meta.info.Type; +import org.apache.avalon.meta.info.builder.XMLTypeCreator; import org.apache.avalon.meta.info.StageDescriptor; import org.apache.avalon.meta.info.DependencyDescriptor; +import org.apache.avalon.meta.model.builder.XMLProfileCreator; import org.apache.avalon.meta.model.Profile; -public class DefaultBlock extends AbstractLogEnabled implements Block +/** + * The default implementation of a Block. The implementation provides + * support for convinence operations related to its role as a container + * by delegating to the container it is managing. As an appliance it is + * responsible for the establishment of a containment heirachy that + * represents the implemetation model for the block. + */ +public class DefaultBlock extends DefaultAppliance implements Block { //============================================================== // static //============================================================== - public static final Attributes.Name BLOCK_NAME = new Attributes.Name( "Block-Name" ); + public static final Attributes.Name BLOCK_PACKAGE = new Attributes.Name( "Block-Package" ); - public static String getName( Manifest manifest ) + public static String getPackageName( Manifest manifest ) { Attributes attributes = manifest.getAttributes( Block.AVALON_BLOCK_KEY ); if( attributes == null ) { return null; } - if( attributes.containsKey( BLOCK_NAME ) ) + if( attributes.containsKey( BLOCK_PACKAGE ) ) { - return (String) attributes.get( BLOCK_NAME ); + return (String) attributes.get( BLOCK_PACKAGE ); } return null; } + public static boolean isBlock( Manifest manifest ) + { + if( manifest == null ) + { + return false; + } + return ( manifest.getAttributes( Block.AVALON_BLOCK_KEY ) != null ); + } + + //============================================================== // state //============================================================== - private String m_name; + private Container m_container; - private Manifest m_manifest; + private boolean m_assembled = false; - private URL m_url; + //============================================================== + // constructor + //============================================================== - /** - * The applaince holding the root container. - */ - private Appliance m_appliance; + public DefaultBlock( + EngineClassLoader engine, LifestyleService lifestyle, AssemblyService assembly, + ApplianceContext context, Context system, Logger logger ) + throws ApplianceException + { + super( engine, lifestyle, assembly, context, system, logger ); + } //============================================================== - // constructor + // Block //============================================================== - public DefaultBlock( Appliance appliance, URL url, Manifest manifest ) - throws BlockException + /** + * Assemble the appliance. The implementation extends the default + * appliance behavior by instantiating the container it is managing, + * and applying assembly to the container instance. This results in + * container creating appliance instances for the component is is + * managing together with assembly of its sub-containers. + * + * @exception AssemblyException if an error occurs during appliance assembly + */ + public void assemble() throws AssemblyException { - if( appliance == null ) + if( m_assembled ) { - throw new NullPointerException( "appliance" ); + return; } - if( url == null ) + + if( getLogger().isDebugEnabled() ) { - throw new NullPointerException( "url" ); + getLogger().debug("block assembly" ); } - if( manifest == null ) + + super.assemble(); + + try { - throw new NullPointerException( "manifest" ); + m_assembled = true; + m_container = (Container) super.access(); + m_container.assemble(); } + catch( Throwable e ) + { + m_assembled = false; + final String error = "Unable to establish containment implemetation."; + throw new AssemblyException( error, e ); + } + } - m_url = url; - m_manifest = manifest; - m_appliance = appliance; + /** + * Terminate the block. If a container has been established, the implemetation + * will relase the container and continue with appliance termination. + */ + public void terminate() + { + if( m_container != null ) + { + release( m_container ); + m_container = null; + } + super.terminate(); } - //============================================================== - // Block - //============================================================== + //------------------------------------------------------------------------------- + // Container + //------------------------------------------------------------------------------- /** - * Return the name of the block. - * @return the name + * Convinience operation to startup the components in the container. + * @exception Exception if a container startup error occurs */ - public String getName() + public void startup() throws Exception { - if( m_name == null ) + if( !m_assembled ) { - m_name = getName( m_manifest ); + throw new IllegalStateException( "assembly" ); } - return m_name; + m_container.startup(); } /** - * Get appliance managing the root container. - * @return the root container appliance + * Convinience operation to shutdown the components in the container. + * @exception Exception if a container shutdown error occurs */ - public Appliance getAppliance() + public void shutdown() throws Exception { - return m_appliance; + if( !m_assembled ) + { + throw new IllegalStateException( "assembly" ); + } + m_container.shutdown(); } }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>