mcconnell 2003/02/04 20:07:36
Modified: merlin/src/java/org/apache/avalon/merlin/kernel/impl
DefaultKernel.java KernelLoader.java
Log:
Update to the DefaultKernal be Configurable instead of apasing a file reference.
This simplifies embedded scenarios such as creation in a web-app where a containing
servlet may not be expanded.
Revision Changes Path
1.5 +47 -49
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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DefaultKernel.java 27 Jan 2003 07:11:57 -0000 1.4
+++ DefaultKernel.java 5 Feb 2003 04:07:36 -0000 1.5
@@ -139,7 +139,7 @@
* @see Block
*/
-public class DefaultKernel extends AbstractLogEnabled implements Kernel,
Contextualizable, Initializable, Startable, Disposable
+public class DefaultKernel extends AbstractLogEnabled implements Kernel,
Contextualizable, Configurable, Initializable, Startable, Disposable
{
//==============================================================
// static
@@ -165,16 +165,11 @@
//==============================================================
/**
- * The kernel profile file.
+ * The kernel configuration profile.
*/
- private File m_profile;
+ private Configuration m_profile;
/**
- * The kernel configuration.
- */
- private Configuration m_kernelConfig;
-
- /**
* The block configuration.
*/
private Configuration m_configuration;
@@ -254,7 +249,20 @@
m_home = (File) context.get( "urn:merlin:home" );
m_common = (ClassLoader) context.get( "urn:merlin:classloader.common" );
m_bootstrap = (ClassLoader) context.get( "urn:merlin:classloader.system" );
- m_profile = (File) context.get( "urn:merlin:profile" );
+ //m_profile = (File) context.get( "urn:merlin:profile" );
+ }
+
+ //==============================================================
+ // Configurable
+ //==============================================================
+
+ /**
+ * Application of the kernel configuration profile.
+ * @param config the configuration profile
+ */
+ public void configure( Configuration config )
+ {
+ m_profile = config;
}
//==============================================================
@@ -280,19 +288,8 @@
// load the kernel configuration
//
- try
- {
- m_kernelConfig = getConfiguration( m_profile );
- m_configuration = m_kernelConfig.getChild( "blocks" );
- }
- catch( Throwable e )
- {
- final String error =
- "Unable to load kernel configuration from file: "
- + m_profile;
- throw new CascadingException( error, e );
- }
-
+ m_configuration = m_profile.getChild( "blocks" );
+
//
// Setup the logging system
//
@@ -302,7 +299,7 @@
if( LOGGING == null )
{
LOGGING = bootstrapLoggingManager( Container.PATH_SEPERATOR );
- Configuration categoriesConfig = m_kernelConfig.getChild(
"categories" );
+ Configuration categoriesConfig = m_profile.getChild( "categories" );
LoggingDirective categories =
CREATOR.createLoggingDirective( Container.PATH_SEPERATOR,
categoriesConfig );
LOGGING.addCategories( Container.PATH_SEPERATOR, categories );
@@ -322,13 +319,13 @@
// setup the thread pool
//
- POOL = getPoolManager( m_kernelConfig.getChild( "pool" ) );
+ POOL = getPoolManager( m_profile.getChild( "pool" ) );
//
// setup the domain and service registry
//
- String domain = m_kernelConfig.getChild( "system" ).getAttribute( "host",
"localhost" );
+ String domain = m_profile.getChild( "system" ).getAttribute( "host",
"localhost" );
m_registry = new DefaultRegistry( domain );
//
@@ -346,7 +343,7 @@
try
{
- m_engine = bootstrapEngine( LOGGING, POOL, m_kernelConfig.getChild(
"engine" ) );
+ m_engine = bootstrapEngine( LOGGING, POOL, m_profile.getChild( "engine"
) );
}
catch( Throwable e )
{
@@ -547,9 +544,30 @@
// internals
//==============================================================
+ private Configuration getConfiguration( final File file ) throws
ConfigurationException
+ {
+ try
+ {
+ DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
+ InputStream is = new FileInputStream( file );
+ if( is == null )
+ {
+ throw new ConfigurationException(
+ "Could not load the configuration resource \"" + file + "\"" );
+ }
+ return builder.build( is );
+ }
+ catch( Throwable e )
+ {
+ final String error = "Unable to create configuration from file: " +
file;
+ throw new ConfigurationException( error, e );
+ }
+ }
+
+
private LoggingManager bootstrapLoggingManager( String root ) throws Exception
{
- if( m_kernelConfig == null )
+ if( m_profile == null )
{
throw new IllegalStateException( "configuration" );
}
@@ -568,7 +586,7 @@
LoggingDescriptor descriptor =
CREATOR.createLoggingDescriptor(
- m_kernelConfig.getChild( "logging" ), root );
+ m_profile.getChild( "logging" ), root );
DefaultLocator context = new DefaultLocator();
context.put( "urn:assembly:home", m_home );
@@ -663,26 +681,6 @@
m_system = context;
}
return m_system;
- }
-
- private Configuration getConfiguration( final File file ) throws
ConfigurationException
- {
- try
- {
- DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
- InputStream is = new FileInputStream( file );
- if( is == null )
- {
- throw new ConfigurationException(
- "Could not load the configuration resource \"" + file + "\"" );
- }
- return builder.build( is );
- }
- catch( Throwable e )
- {
- final String error = "Unable to create configuration from file: " +
file;
- throw new ConfigurationException( error, e );
- }
}
private PoolManager getPoolManager( Configuration config ) throws Exception
1.3 +34 -1
avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/kernel/impl/KernelLoader.java
Index: KernelLoader.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/kernel/impl/KernelLoader.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- KernelLoader.java 27 Jan 2003 03:27:46 -0000 1.2
+++ KernelLoader.java 5 Feb 2003 04:07:36 -0000 1.3
@@ -99,12 +99,25 @@
context.put( "urn:merlin:home", base );
context.put( "urn:merlin:classloader.common", common );
context.put( "urn:merlin:classloader.system", system );
- context.put( "urn:merlin:profile", profile );
context.makeReadOnly();
+ Configuration config = null;
+ try
+ {
+ config = getConfiguration( profile );
+ }
+ catch( ConfigurationException e )
+ {
+ final String error =
+ "Unable to load kernel configuration from file: "
+ + profile;
+ throw new RuntimeException( error.toString() );
+ }
+
try
{
m_kernel.contextualize( context );
+ m_kernel.configure( config );
m_kernel.initialize();
m_kernel.start();
}
@@ -122,6 +135,26 @@
String message = ExceptionHelper.packException( error, e );
System.err.println( message );
m_kernel.dispose();
+ }
+ }
+
+ private Configuration getConfiguration( final File file ) throws
ConfigurationException
+ {
+ try
+ {
+ DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
+ InputStream is = new FileInputStream( file );
+ if( is == null )
+ {
+ throw new ConfigurationException(
+ "Could not load the configuration resource \"" + file + "\"" );
+ }
+ return builder.build( is );
+ }
+ catch( Throwable e )
+ {
+ final String error = "Unable to create configuration from file: " +
file;
+ throw new ConfigurationException( error, e );
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]