mcconnell    2003/03/08 07:31:31

  Modified:    merlin/src/java/org/apache/avalon/merlin/kernel/impl
                        DefaultKernel.java
  Log:
  Back-out multi-block support in favor of a strict block hierarchy.
  
  Revision  Changes    Path
  1.18      +51 -36    
avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/kernel/impl/DefaultKernel.java
  
  Index: DefaultKernel.java
  ===================================================================
  RCS file: 
/home/cvs/avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/kernel/impl/DefaultKernel.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- DefaultKernel.java        8 Mar 2003 06:51:03 -0000       1.17
  +++ DefaultKernel.java        8 Mar 2003 15:31:31 -0000       1.18
  @@ -222,11 +222,6 @@
       private DefaultLocator m_system;
   
       /**
  -     * The list of blocks established by the kernel.
  -     */
  -    private List m_blocks = new ArrayList();
  -
  -    /**
        * The root block.
        */
       private Block m_block;
  @@ -261,6 +256,11 @@
       */
       private boolean m_initialized = false;
   
  +   /**
  +    * Flag holding the contextualized state of the kernel.
  +    */
  +    private boolean m_contextualized = false;
  +
   
       //==============================================================
       // Contextualizable
  @@ -275,11 +275,6 @@
       *     <td><b>key</b></td><td><b>type</b></td><td><b>description</b></td>
       *   </tr>
       *   <tr>
  -    *     <td><code>urn:merlin:home</code></td>
  -    *     <td>[EMAIL PROTECTED] java.io.File}</td>
  -    *     <td>The working home directory.</td> 
  -    *   </tr>
  -    *   <tr>
       *     <td><code>urn:merlin:system</code></td>
       *     <td>[EMAIL PROTECTED] java.io.File}</td>
       *     <td>The Merlin system home directory.</td> 
  @@ -295,6 +290,11 @@
       *     <td>The internal system classloader.</td> 
       *   </tr>
       *   <tr>
  +    *     <td><code>urn:merlin:debug</code></td>
  +    *     <td>[EMAIL PROTECTED] java.lang.String}</td>
  +    *     <td>The system logging priority (a value of INFO, WARN, ERROR, or 
DEBUG.</td> 
  +    *   </tr>
  +    *   <tr>
       *     <td><code>urn:merlin:block.url</code></td>
       *     <td>[EMAIL PROTECTED] java.net.URL}</td>
       *     <td>The url to the block.xml file.</td> 
  @@ -305,9 +305,9 @@
       *     <td>The url to a configuration overide file. This entry is optional.</td> 
       *   </tr>
       *   <tr>
  -    *     <td><code>urn:merlin:debug</code></td>
  -    *     <td>[EMAIL PROTECTED] java.lang.String}</td>
  -    *     <td>The system logging priority (a value of INFO, WARN, ERROR, or 
DEBUG.</td> 
  +    *     <td><code>urn:merlin:home</code></td>
  +    *     <td>[EMAIL PROTECTED] java.io.File}</td>
  +    *     <td>The working home directory.</td> 
       *   </tr>
       * </table>
       * @param context the runtime context
  @@ -315,6 +315,13 @@
       */
       public void contextualize( Locator context ) throws ContextException
       {
  +        if( m_contextualized ) 
  +        {
  +            final String error =
  +              "Illegal attempt to recontextualize the kernel.";
  +            throw new IllegalStateException( error );
  +        }
  +
           m_home = (File) context.get( "urn:merlin:home" );
           m_root = (File) context.get( "urn:merlin:system" );
           m_common = (ClassLoader) context.get( "urn:merlin:classloader.common" );
  @@ -337,6 +344,8 @@
                   m_override = (URL) context.get( "urn:merlin:block.config" );
               }
           }
  +
  +        m_contextualized = true;
       }
   
       //==============================================================
  @@ -368,12 +377,10 @@
       {
           if( m_initialized )
           {
  -            final String error = 
  -              "Kernel has already been initialized.";
  -            throw new IllegalStateException( error );
  +            throw new IllegalStateException( "initialization" );
           }
   
  -        if( m_home == null )
  +        if( !m_contextualized )
           {
                throw new IllegalStateException("context");
           }
  @@ -486,13 +493,27 @@
           // install a block if a block URL was included in the context argument
           //
   
  -        if( m_url != null )
  +        try
           {
  -            install( m_url, m_override );
  +            m_block = install( m_url, m_override );
  +            if( getLogger().isInfoEnabled() )
  +            {
  +                final String info = "Block hierarchy established.";
  +                getLogger().info( info );
  +            }
  +        }
  +        catch( Throwable e )
  +        {
  +            final String error = "Root block instalation failure.";
  +            String log = ExceptionHelper.packException( error, e );
  +            if( getLogger().isErrorEnabled() )
  +            {
  +                getLogger().error( log );
  +            }
  +            throw new KernelException( error, e );
           }
       }
   
  -
       //==============================================================
       // Kernel
       //==============================================================
  @@ -598,7 +619,6 @@
               throw new KernelException( error, e );
           }
   
  -        m_blocks.add( block );
           return block;
       }
   
  @@ -620,14 +640,13 @@
               }
           }
   
  -        Block[] blocks = (Block[]) m_blocks.toArray( new Block[0] );
  -        for( int i=0; i<blocks.length; i++ )
  +        if( m_block != null )
           {
  -            Block block = blocks[i];
               try
               {
  -                block.decommission();
  -                block.terminate();
  +                m_block.decommission();
  +                m_block.terminate();
  +                m_block = null;
               }
               catch( Throwable e )
               {
  @@ -638,7 +657,6 @@
                       getLogger().warn( error, e );
                   }        
               }
  -            m_blocks.remove( block );
           }
   
           if( getLogger().isInfoEnabled() )
  @@ -669,9 +687,9 @@
           {
               throw new IllegalStateException( "configuration" );
           }
  -        if( m_home == null )
  +        if( !m_contextualized )
           {
  -            throw new IllegalStateException( "context" );
  +            throw new IllegalStateException( "contextualization" );
           }
           if( CREATOR == null )
           {
  @@ -796,16 +814,13 @@
       {
           StringBuffer buffer = new StringBuffer( "DefaultKernel: " + 
System.identityHashCode( this ) );
   
  -        Block[] blocks = (Block[]) m_blocks.toArray( new Block[0] );
  -        buffer.append( "\nBlock count: " + blocks.length );
  -        for( int j=0; j<blocks.length; j++ )
  +        if( m_block != null )
           {
  -            Block block = blocks[j];
  -            buffer.append( "\nBlock: " + block );
  +            buffer.append( "\nBlock: " + m_block );
   
               // list the block URLs
   
  -            URL[] urls = block.getURLs();
  +            URL[] urls = m_block.getURLs();
               for( int i=0; i<urls.length; i++ )
               {
                   buffer.append( "\n  " + urls[i].toString() );
  
  
  

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

Reply via email to