avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/kernel/impl DefaultKernel.java DefaultKernelLoader.java
Date Sun, 20 Apr 2003 12:21:04 GMT
mcconnell    2003/04/20 05:21:04

  Modified:    merlin/merlin-core/src/java/org/apache/avalon/merlin/kernel/impl
                        DefaultKernel.java DefaultKernelLoader.java
  Log:
  Eliminated engine creation for kernel and placed functionality under the block creation
classes resulting in a clearner and more consistent model.
  
  Revision  Changes    Path
  1.10      +38 -163   avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/kernel/impl/DefaultKernel.java
  
  Index: DefaultKernel.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/kernel/impl/DefaultKernel.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- DefaultKernel.java	16 Apr 2003 14:44:15 -0000	1.9
  +++ DefaultKernel.java	20 Apr 2003 12:21:04 -0000	1.10
  @@ -76,7 +76,7 @@
   import org.apache.avalon.framework.logger.Logger;
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.avalon.merlin.block.Block;
  -import org.apache.avalon.merlin.block.impl.DefaultBlockLoader;
  +import org.apache.avalon.merlin.block.impl.StandardBlockLoader;
   import org.apache.avalon.merlin.container.Container;
   import org.apache.avalon.merlin.container.builder.XMLContainerCreator;
   import org.apache.avalon.merlin.kernel.Kernel;
  @@ -135,7 +135,7 @@
       /**
        * The block loader.
        */
  -    private DefaultBlockLoader m_installer;
  +    private StandardBlockLoader m_installer;
   
      /**
       * The kernel configuration profile.
  @@ -173,6 +173,11 @@
       private ClassLoader m_loader;
   
       /**
  +     * The common classloader.
  +     */
  +    private ClassLoader m_common;
  +
  +    /**
        * The assembly engine.
        */
       private EngineClassLoader m_engine;
  @@ -202,6 +207,11 @@
       */
       private String m_debug;
   
  +    /**
  +    * The debug flag.
  +    */
  +    private boolean m_flag = false;
  +
      /**
       * The default logging level.
       */
  @@ -285,10 +295,12 @@
   
           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" );
           m_loader = (ClassLoader) context.get( "urn:merlin:classloader.system" );
           if( context.hasEntry( "urn:merlin:debug" ) )
           {
               m_debug = (String) context.get( "urn:merlin:debug" );
  +            m_flag = m_debug.equalsIgnoreCase( "debug" );
           }
   
           //
  @@ -355,8 +367,6 @@
                m_config = new DefaultConfiguration("kernel", "DefaultKernel");
           }
   
  -        setShutdownHook( this );
  -
           //
           // Setup the logging system
           //
  @@ -413,47 +423,31 @@
           }
   
           //
  -        // setup the bootstrap assembly engine
  -        //
  -
  -        try
  -        {
  -            Configuration engine = m_config.getChild( "engine" );
  -            m_engine = bootstrapEngine( m_logging, m_pool, engine, m_loader );
  -            Thread.currentThread().setContextClassLoader( m_engine );
  -        }
  -        catch( Throwable e )
  -        {
  -            final String error =
  -              "Engine establishment error.";
  -            String log = ExceptionHelper.packException( error, e );
  -            if( getLogger().isErrorEnabled() )
  -            {
  -                getLogger().error( log );
  -            }
  -            throw new KernelException( error, e );
  -        }
  -
  -        //
           // we are now ready to assemble the block
           //
   
  -        m_installer = new DefaultBlockLoader();
  +        m_installer = new StandardBlockLoader();
           try
           {
               m_installer.enableLogging( getLogger() );
  +
               DefaultLocator context = new DefaultLocator();
  -            context.put( "urn:assembly:engine", m_engine );
  -            context.put( "urn:assembly:system-context", getSystemContext() );
               context.put( "urn:assembly:system", m_root );
  +            context.put( "urn:merlin:home", m_home );
  +            context.put( "urn:merlin:logging-manager", m_logging );
  +            context.put( "urn:merlin:pool-manager", m_pool );
  +            context.put( "urn:merlin:classloader.system", m_loader );
  +            context.put( "urn:merlin:classloader.common", m_common );
  +            context.put( "urn:merlin:domain", m_domain );
               context.makeReadOnly();
  +
               m_installer.contextualize( context );
               m_installer.initialize();
           }
           catch( Throwable e )
           {
               final String error = "Block installer establishment failure.";
  -            String log = ExceptionHelper.packException( error, e );
  +            String log = ExceptionHelper.packException( error, e, m_flag );
               if( getLogger().isErrorEnabled() )
               {
                   getLogger().error( log );
  @@ -479,13 +473,15 @@
           catch( Throwable e )
           {
               final String error = "Root block installation failure.";
  -            String log = ExceptionHelper.packException( error, e );
  +            String log = ExceptionHelper.packException( error, e, m_flag );
               if( getLogger().isErrorEnabled() )
               {
                   getLogger().error( log );
               }
               throw new KernelException( error, e );
           }
  +
  +        setShutdownHook( this );
       }
   
       //==============================================================
  @@ -542,13 +538,7 @@
           }
           catch( Throwable e )
           {
  -            final String error =
  -              "Block install failure: " + m_url;
  -            String log = ExceptionHelper.packException( error, e );
  -            if( getLogger().isErrorEnabled() )
  -            {
  -                getLogger().error( log );
  -            }
  +            final String error = "Block install failure.\nURL:" + m_url;
               throw new KernelException( error, e );
           }
   
  @@ -564,12 +554,8 @@
           catch( Throwable e )
           {
               final String error =
  -              "Unable to deploy block: " + block.getName() + " due to an assembly failure.";
  -            String log = ExceptionHelper.packException( error, e );
  -            if( getLogger().isErrorEnabled() )
  -            {
  -                getLogger().error( log );
  -            }
  +              "Unable to deploy block.\nBlock: " 
  +              + block.getName() + " due to an assembly failure.";
               throw new KernelException( error, e );
           }
   
  @@ -580,12 +566,9 @@
           catch( Throwable e )
           {
               final String error =
  -              "Unable to deploy block: " + block.getName() + " due to an deployment failure.";
  -            String log = ExceptionHelper.packException( error, e );
  -            if( getLogger().isErrorEnabled() )
  -            {
  -                getLogger().error( log );
  -            }
  +              "Unable to deploy block.\nBlock: " 
  +              + block.getName() 
  +              + " due to an deployment failure.";
               throw new KernelException( error, e );
           }
   
  @@ -689,124 +672,16 @@
       }
   
      /**
  -    * Creation of the root engine.
  -    *
  -    * @param logging the logging manager
  -    * @param pool the pool manager
  -    * @param config the engine configuration from which extension paths and
  -    *    classpath declarations are resolved
  -    * @param loader the system classloader
  -    * @return the engine
  -    */
  -    private EngineClassLoader bootstrapEngine(
  -      LoggingManager logging, PoolManager pool, Configuration config, ClassLoader loader
)
  -      throws Exception
  -    {
  -        if( m_home == null )
  -        {
  -            throw new IllegalStateException( "context" );
  -        }
  -        if( getLogger() == null )
  -        {
  -            throw new IllegalStateException( "logging" );
  -        }
  -        if( CREATOR == null )
  -        {
  -            throw new NullPointerException( "creator" );
  -        }
  -
  -        if( getLogger().isDebugEnabled() )
  -        {
  -            getLogger().debug( "bootstrap engine" );
  -        }
  -
  -        Configuration lib = config.getChild( "library", false );
  -
  -        Classpath classpath = null;
  -        Configuration classpathConfig = config.getChild( "classpath", false );
  -        if( classpathConfig != null )
  -        {
  -            ClasspathDescriptor descriptor =
  -              CREATOR.createClasspathDescriptor( classpathConfig );
  -            try
  -            {
  -                classpath = new DefaultClasspath( m_root, m_url, descriptor );
  -            }
  -            catch( IllegalArgumentException iae )
  -            {
  -                final String error =
  -                 "Cannot construct classpath due to unresolvable base directory.";
  -                throw new CascadingException( error, iae );
  -            }
  -        }
  -
  -        try
  -        {
  -            EngineClassLoader engine =
  -              new EngineClassLoader(
  -                new URL[]{ DefaultBlockLoader.getBasePath( m_url ) }, loader );
  -
  -            engine.enableLogging( getLogger() );
  -            Locator system = getSystemContext();
  -            DefaultLocator context = new DefaultLocator( system );
  -            context.put( "urn:assembly:engine.bootstrap", "true" );
  -            context.put( "urn:assembly:home", m_home );
  -            context.put( "urn:assembly:system", m_root );
  -            if( lib != null )
  -            {
  -                LibraryDescriptor extensions =
  -                  CREATOR.createLibraryDescriptor( config.getChild( "library" ) );
  -                context.put( "urn:assembly:engine.extensions", extensions );
  -            }
  -            if( classpath != null )
  -            {
  -                context.put( "urn:assembly:engine.classpath", classpath );
  -            }
  -            context.put( "urn:assembly:logging.manager", logging );
  -            context.put( "urn:assembly:threads.manager", pool );
  -            context.makeReadOnly();
  -            engine.contextualize( context );
  -            engine.initialize();
  -
  -            //
  -            // make sure that the merlin internal components are registered
  -            // (problem occurs when running under a junit test where the
  -            // classloader does not expose the loaded jar files)
  -            //
  -
  -            try
  -            {
  -                engine.register(
  -                  "org.apache.avalon.assembly.lifecycle.context.DefaultContextualizer"
);
  -                engine.register(
  -                  "org.apache.avalon.assembly.lifecycle.context.AvalonContextualizer" );
  -                engine.register(
  -                  "org.apache.avalon.merlin.container.impl.DefaultContainer" );
  -                engine.register(
  -                  "org.apache.avalon.merlin.block.impl.DefaultBlock" );
  -            }
  -            catch( Throwable e )
  -            {
  -                // already registered
  -            }
  -
  -            return engine;
  -        }
  -        catch( Throwable e )
  -        {
  -            final String error = "Engine bootstrap failure.";
  -             throw new CascadingException( error, e );
  -        }
  -    }
  -
  -   /**
       * Return a string representation of the kernel.
       * @return the string representation
       */
       public String toString()
       {
           StringBuffer buffer =
  -          new StringBuffer( "DefaultKernel: " + System.identityHashCode( this ) + " block:
" );
  +          new StringBuffer( 
  +            "DefaultKernel: " 
  +            + System.identityHashCode( this ) 
  +            + " block: " );
   
           if( m_block != null )
           {
  
  
  
  1.3       +4 -16     avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/kernel/impl/DefaultKernelLoader.java
  
  Index: DefaultKernelLoader.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/merlin-core/src/java/org/apache/avalon/merlin/kernel/impl/DefaultKernelLoader.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultKernelLoader.java	16 Apr 2003 14:44:15 -0000	1.2
  +++ DefaultKernelLoader.java	20 Apr 2003 12:21:04 -0000	1.3
  @@ -93,34 +93,22 @@
               kernel.contextualize( context );
               kernel.configure( getKernelConfiguration( profile ) );
               kernel.initialize();
  +            return kernel;
           }
           catch( KernelException e )
           {
  -            // its already been logged
  -            cause = e;
  +            return null;
           }
           catch( BlockException e )
           {
  -            // its already been logged
  -            cause = e;
  +            return null;
           }
           catch( Throwable e )
           {
               final String error = "Unexpected kernel deployment failure.";
               String message = ExceptionHelper.packException( error, e );
               System.err.println( message );
  -            cause = new Exception( error );
  -        }
  -        finally
  -        {
  -            if( cause != null )
  -            {
  -                throw new KernelException( "Kernel error.", cause );
  -            }
  -            else
  -            {
  -                return kernel;
  -            }
  +            throw new KernelException( message, cause );
           }
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org


Mime
View raw message