mcconnell    2002/12/16 20:45:21

  Modified:    merlin/src/java/org/apache/avalon/merlin/block
                        DefaultBlock.java BlockLoader.java Block.java
  Log:
  Refactored block to hold a root containement appliance (simplifying the block design 
significantly).
  
  Revision  Changes    Path
  1.8       +13 -279   
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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DefaultBlock.java 15 Dec 2002 14:13:02 -0000      1.7
  +++ DefaultBlock.java 17 Dec 2002 04:45:21 -0000      1.8
  @@ -33,7 +33,7 @@
   import org.apache.avalon.meta.info.DependencyDescriptor;
   import org.apache.avalon.meta.model.Profile;
   
  -public class DefaultBlock implements Block
  +public class DefaultBlock extends AbstractLogEnabled implements Block
   {
       //==============================================================
       // static
  @@ -59,172 +59,46 @@
       // state
       //==============================================================
   
  -    private Logger m_logger;
  -
       private String m_name;
   
  -    private EngineClassLoader m_engine;
  -
       private Manifest m_manifest;
   
       private URL m_url;
   
  -    private File m_home;
  -
  -   /**
  -    * The packaged configuration.
  -    */
  -    private Configuration m_config;
  -
      /**
       * The applaince holding the root container.
       */
       private Appliance m_appliance;
   
  -   /**
  -    * The set of subsidiary blocks.
  -    */
  -    private Appliance[] m_blocks;
  -
  - 
       //==============================================================
       // constructor
       //==============================================================
   
  -    public DefaultBlock( 
  -      EngineClassLoader engine, BlockContext context, Context system, Logger logger 
)
  +    public DefaultBlock( Appliance appliance, URL url, Manifest manifest )
         throws BlockException
       {
  -        if( engine == null )
  -        {
  -            throw new NullPointerException( "engine" );
  -        }
  -        if( context == null )
  -        {
  -            throw new NullPointerException( "context" );
  -        }
  -        if( system == null )
  +        if( appliance == null )
           {
  -            throw new NullPointerException( "system" );
  +            throw new NullPointerException( "appliance" );
           }
  -        if( logger == null )
  -        {
  -            throw new NullPointerException( "logger" );
  -        }
  -
  -        m_logger = logger;
  -
  -        m_url = context.getURL();
  -        if( m_url == null )
  +        if( url == null )
           {
               throw new NullPointerException( "url" );
           }
  -
  -        m_manifest = context.getManifest();
  -        if( m_manifest == null )
  +        if( manifest == null )
           {
               throw new NullPointerException( "manifest" );
           }
   
  -        try
  -        {
  -            m_home = (File) system.get( "urn:avalon:home" );
  -        }
  -        catch( ContextException e )
  -        {
  -            final String error = 
  -              "System context does not declare the 'urn:avalon:home' entry.";
  -            throw new BlockException( error, e );
  -        }
  -
  -        String name = getName();
  -        getLogger().debug( "block initialization: " + name );
  -
  -        ContainerDescriptor descriptor = (ContainerDescriptor) context.getProfile();
  -        getLogger().debug( "root container component count: " + 
descriptor.getComponents().length );
  -        
  -        //m_config = getBlockConfiguration( getJarFile( m_url ) );
  -
  -        //
  -        // create the root container for this block
  -        //
  -
  -        //m_appliance = createContainmentAppliance( m_config );
  -        //m_appliance.access();
  -
  -        //
  -        // create any nested blocks contained within this block
  -        //
  -
  -        /*
  -        try
  -        {
  -            ClasspathDescriptor path = 
  -              CREATOR.createClasspathDescriptor( m_config.getChild( "blocks" ) );
  -            URL[] urls = ClasspathDescriptor.expand( m_home, path );
  -            m_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 );
  -        }
  -        */
  -    }
  -
  -   /**
  -    * Return the loging channel for the appliance.
  -    * @return the logging channel
  -    */
  -    protected Logger getLogger()
  -    {
  -        return m_logger;
  -    }
  -
  -    //==============================================================
  -    // Block
  -    //==============================================================
  -
  -    public void assemble() throws Exception
  -    {
  -        //getLogger().debug( "assemble" );
  -        //ClasspathDescriptor path = 
  -        //  CREATOR.createClasspathDescriptor( m_config.getChild( "blocks" ) );
  -        //URL[] urls = ClasspathDescriptor.expand( m_home, path );
  -        //Appliance[] blocks = install( m_engine, m_home, urls );
  +        m_url = url;
  +        m_manifest = manifest;
  +        m_appliance = appliance;
       }
   
       //==============================================================
       // Block
       //==============================================================
   
  -   /*
  -    public Appliance createContainmentAppliance( Configuration config ) throws 
Exception
  -    {
  -        String name = getName();
  -        Configuration containment = m_config.getChild( "container" );
  -        String classname = containment.getAttribute( "class", 
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 );
  -        }
  -    }
  -    */
  -
      /**
       * Return the name of the block.
       * @return the name
  @@ -238,152 +112,12 @@
           return m_name;
       }
   
  -    //==============================================================
  -    // Appliance
  -    //==============================================================
  -
  -   /**
  -    * Get the appliance path.
  -    */
  -    public String getPath()
  -    {
  -        return m_appliance.getPath();
  -    }
  -
  -    /**
  -     * Return the profile backing the appliance.
  -     * @return the profile that this appliance is managing
  -     */
  -    public Profile getProfile()
  -    {
  -        return m_appliance.getProfile();
  -    }
  -
  -    /**
  -     * Return the activation policy for the component.  If TRUE, activation
  -     * will occur at startup.  If false, activation will be deferred to
  -     * the first lookup invocation if any (i.e. lazy activation).
  -     *
  -     * @return the activation policy
  -     */
  -    public boolean getActivationPolicy()
  -    {
  -        return m_appliance.getActivationPolicy();
  -    }
  -
  -    /**
  -     * Test is this profile is enabled.  A profile is enabled unless explicitly 
disabled by an
  -     * assembly directive, or implicity disabled as a result of an assembly failure.
  -     *
  -     * @return TRUE if the profile is enabled.
  -     * @see #setEnabled( boolean )
  -     */
  -    public boolean isEnabled()
  -    {
  -        return m_appliance.isEnabled();
  -    }
  -
  -    /**
  -     * Set the enabled status of the profile to the supplied value.
  -     * @param value the enabled status - TRUE or FALSE
  -     */
  -    public void setEnabled( boolean value )
  -    {
  -        m_appliance.setEnabled( value );
  -    }
  -
  -    /**
  -     * Return the assigned service providers.
  -     * @return the set of service provider appliances.
  -     */
  -    public Appliance[] getServiceProviders()
  -    {
  -        return m_appliance.getServiceProviders();
  -    }
  -
  -    /**
  -     * Return the dependency associations for component type with specified role.
  -     *
  -     * @param role the dependency role name
  -     * @return the dependency metadata for component with specified role.
  -     */
  -    public Appliance getServiceProvider( final String role )
  -    {
  -        return m_appliance.getServiceProvider( role );
  -    }
  -
  -    /**
  -     * Add the appliance that will acts as provider for a named dependency.
  -     * @param role the role against which the supplied appliance is to be associated
  -     * @param appliance the appliance that will fulfill the provider dependency
  -     */
  -    public void addServiceProvider( final String role, final Appliance appliance )
  -    {
  -        m_appliance.addServiceProvider( role, appliance );
  -    }
  -
  -    /**
  -     * Return the assigned extension providers.
  -     *
  -     * @return the set of extension provider appliances.
  -     */
  -    public Appliance[] getExtensionProviders()
  -    {
  -        return m_appliance.getExtensionProviders();
  -    }
  -
  -    /**
  -     * Returns the appliace assigned to handle the components lifecycle stage.
  -     * @param stage the lifecycle stage specification
  -     * @return a reference to the stage extension
  -     */
  -    public Appliance getExtensionProvider( final StageDescriptor stage )
  -    {
  -        return m_appliance.getExtensionProvider( stage );
  -    }
  -
  -    /**
  -     * Add a lifecycle stage extension.
  -     * @param stage the identifier of the stage to assign the manager to
  -     * @param appliance the appliance that will handle the stage
  -     */
  -    public void addExtensionProvider( final StageDescriptor stage, final Appliance 
appliance )
  -    {
  -        m_appliance.addExtensionProvider( stage, appliance );
  -    }
  -
  -   /**
  -    * Activate of the appliance.
  -    * @return the implementation object
  -    */
  -    public Object access() throws LifestyleException
  -    {
  -        return m_appliance.access();
  -    }
  -
  -   /**
  -    * Activate a service provided by the appliance.
  -    * @param dependency the service dependecy decsriptor
  -    */
  -    public Object access( final DependencyDescriptor dependency ) throws 
LifestyleException
  -    {
  -        return m_appliance.access( dependency );
  -    }
  -
  -   /**
  -    * Activate an extension handler provided by the appliance.
  -    * @param appliance the appliance to deploy
  -    */
  -    public Object access( final StageDescriptor stage ) throws LifestyleException
  -    {
  -        return m_appliance.access( stage );
  -    }
  -
      /**
  -    * Release a reference to a service provided by this appliance.
  +    * Get appliance managing the root container.
  +    * @return the root container appliance
       */
  -    public void release( final Object object )
  +    public Appliance getAppliance()
       {
  -        m_appliance.release( object );
  +        return m_appliance;
       }
   }
  
  
  
  1.5       +16 -23    
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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BlockLoader.java  16 Dec 2002 01:09:47 -0000      1.4
  +++ BlockLoader.java  17 Dec 2002 04:45:21 -0000      1.5
  @@ -153,11 +153,11 @@
           {
               if( n > 1 )
               {
  -                getLogger().debug( "installing " + urls.length + " blocks." );
  +                getLogger().debug( "loading " + urls.length + " blocks." );
               }
               else
               {
  -                getLogger().debug( "installing one subsidiary block." );
  +                getLogger().debug( "loading one subsidiary block." );
               }
           }
   
  @@ -190,11 +190,11 @@
           {
               if( n > 1 )
               {
  -                getLogger().debug( "installed " + urls.length + " blocks." );
  +                getLogger().debug( "loaded " + urls.length + " blocks." );
               }
               else
               {
  -                getLogger().debug( "installed one subsidiary block." );
  +                getLogger().debug( "loaded one subsidiary block." );
               }
           }
   
  @@ -207,7 +207,7 @@
       {
           if( getLogger().isDebugEnabled() )
           {
  -            getLogger().debug( "block: " + url );
  +            getLogger().debug( "loading block: " + url );
           }
           
           JarFile jar = getJarFile( url );
  @@ -244,25 +244,18 @@
           // create and root container
           //
   
  -        /*
           Configuration containerConfig = config.getChild( "container" );
  -        String classname = containerConfig.getAttribute( "class", 
DefaultContainer.class.getName() );
  -        Type type = engine.getRepository().getTypeManager().getType( classname );
  -        ContainerDescriptor descriptor = CREATOR.createContainerDescriptor( type, 
containerConfig, name );
  -        Configuration[] components = containerConfig.getChildren( "component" );
  -        for( int i=0; i<components.length; i++ )
  -        {
  -            Profile profile = createProfile( name, engine, components[i] );
  -            descriptor.addComponent( profile );
  -        }
  -        */
  -
  -        Appliance container = createContainer( engine, name, home, config, logger, 
true );
  -        BlockContext context = new BlockContext( url, manifest );
  -        context.setProfile( (ContainerDescriptor) container.getProfile() );
  -
  +        Appliance appliance = createContainer( engine, name, home, containerConfig, 
logger );
           Logger child = getLogger().getChildLogger( name );
  -        return new DefaultBlock( engine, context, system, child );
  +        DefaultBlock block = new DefaultBlock( appliance, url, manifest );
  +        block.enableLogging( child );
  +
  +        if( getLogger().isDebugEnabled() )
  +        {
  +            getLogger().debug( "loaded block: " + name );
  +        }
  +
  +        return block;
       }
   
       protected boolean isBlock( Manifest manifest )
  
  
  
  1.4       +10 -2     
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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Block.java        15 Dec 2002 14:13:02 -0000      1.3
  +++ Block.java        17 Dec 2002 04:45:21 -0000      1.4
  @@ -58,8 +58,16 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Avalon Development 
Team</a>
    * @version $Revision$ $Date$
    */
  -public interface Block extends Appliance
  +public interface Block
   {
       static final String AVALON_BLOCK_KEY = "Avalon-Block";
  +
  +
  +   /**
  +    * Get appliance managing the root container.
  +    * @return the root container appliance
  +    */
  +    Appliance getAppliance();
  +
   }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to