leif 2002/08/06 20:22:11
Modified: fortress/src/java/org/apache/excalibur/fortress
DefaultContainerManager.java
Log:
The ContextManager was not being initialized correctly, this was leading to
cases
where it was being intialized twice. At the least it was being intialized
late.
Revision Changes Path
1.19 +45 -10
jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/DefaultContainerManager.java
Index: DefaultContainerManager.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/DefaultContainerManager.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- DefaultContainerManager.java 6 Aug 2002 20:42:24 -0000 1.18
+++ DefaultContainerManager.java 7 Aug 2002 03:22:11 -0000 1.19
@@ -105,19 +105,50 @@
public DefaultContainerManager( ContextManager contextManager, Logger
logger )
{
this.contextManager = contextManager;
- this.logger = logger == null ? createLoggerFromContext(
this.contextManager.getContainerManagerContext() ) : logger;
+ this.logger = logger == null ?
+ createLoggerFromContext(
this.contextManager.getContainerManagerContext() ) : logger;
}
public DefaultContainerManager( Context initParameters )
{
- this( new ContextManager(initParameters, new NullLogger()), null );
+ this( initParameters, null );
}
public DefaultContainerManager( Context initParameters, Logger logger )
{
- this( new ContextManager(initParameters, logger), logger );
+ this( getInitializedContextManager( initParameters, logger ), logger
);
}
+ /**
+ * Creates and initializes a contextManager given an initialization
context.
+ * This is necessary so that these operations can complete before the
+ * super constructor has been executed.
+ */
+ private static ContextManager getInitializedContextManager( Context
initParameters,
+ Logger
logger )
+ {
+ // The context manager will use an internal coonsole logger if
logger is null.
+ ContextManager contextManager = new ContextManager(initParameters,
logger);
+ try
+ {
+ contextManager.initialize();
+ return contextManager;
+ }
+ catch ( Exception e )
+ {
+ if ( logger == null )
+ {
+ logger = new ConsoleLogger( ConsoleLogger.LEVEL_INFO );
+ }
+ logger.fatalError( "Unable to initialize the contextManager.", e
);
+
+ // What should happen now. There needs to be a failure mode
here.
+ // As is, this will result in an NPE, but it can't really be
allowed
+ // to continue without having been initialized.
+ return null;
+ }
+ }
+
protected Logger createLoggerFromContext( Context initParameters )
{
try
@@ -127,7 +158,8 @@
catch( ContextException ce )
{
Logger consoleLogger = new ConsoleLogger();
- consoleLogger.error( "Could not obtain logger manager from init
parameters (this should not happen). Using console instead." );
+ consoleLogger.error( "Could not obtain logger manager from init
parameters "
+ + "(this should not happen). Using console instead." );
return consoleLogger;
}
}
@@ -137,7 +169,6 @@
*/
public void initialize() throws Exception
{
- this.contextManager.initialize();
initializeContainer();
}
@@ -149,13 +180,15 @@
try
{
- instance = (
(Class)this.contextManager.getContainerManagerContext().get( CONTAINER_CLASS )
).newInstance();
+ instance = (
(Class)this.contextManager.getContainerManagerContext().
+ get( CONTAINER_CLASS ) ).newInstance();
}
catch( Exception e )
{
instance = null;
- throw new InitializationException( "Cannot set up container.
Unable to create container class", e );
+ throw new InitializationException(
+ "Cannot set up container. Unable to create container
class", e );
}
validator = new ComponentStateValidator( instance );
@@ -220,7 +253,8 @@
{
instance = null;
- throw new InitializationException( "Cannot set up container.
Startup lifecycle failure", e );
+ throw new InitializationException(
+ "Cannot set up container. Startup lifecycle failure", e
);
}
containerInstance = instance;
@@ -260,7 +294,8 @@
{
if( getLogger().isWarnEnabled() )
{
- getLogger().warn( "Caught an exception when stopping
the Container, continuing with shutdown", e );
+ getLogger().warn( "Caught an exception when stopping
the Container, "
+ + "continuing with shutdown", e );
}
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>