Update of /cvsroot/plexus/plexus-container-new/src/java/org/apache/plexus
In directory eng.werken.com:/tmp/cvs-serv18165
Modified Files:
DefaultPlexusContainer.java
Log Message:
o The container now has no avalon specific notions (we intentionally borrow the Context,
Configuration, and Logger). There is a lifecycle handler per container and this is
currently taken from the internal configuration. I will soon make it possible to
override this and any base entities by providing a definition in your own plexus.conf.
So a lifecycle handler is created and some basic entities are populated. Namely the
ServiceRepository, Logger and Context. Lifecycle handlers and create new entities
from these basic entities if they wish. This mechanism is used in the AvalonLifecycleHandler
to create an AvalonServiceManager from the plexus ServiceRepository.
Later on today I hope to make the segments and phases configurable and hook in
blissed (state machines) to create lifecycle enforces based on the contents
of a lifecycle handlers segments and phases.
Index: DefaultPlexusContainer.java
===================================================================
RCS file: /cvsroot/plexus/plexus-container-new/src/java/org/apache/plexus/DefaultPlexusContainer.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- DefaultPlexusContainer.java 24 Apr 2003 03:04:08 -0000 1.7
+++ DefaultPlexusContainer.java 25 Apr 2003 17:42:05 -0000 1.8
@@ -65,8 +65,6 @@
import org.apache.plexus.configuration.DefaultConfigurationBuilder;
import org.apache.plexus.context.DefaultContext;
import org.apache.plexus.lifecycle.LifecycleHandler;
-import org.apache.plexus.lifecycle.avalon.AvalonLifecycleHandler;
-import org.apache.plexus.lifecycle.avalon.AvalonServiceManager;
import org.apache.plexus.logging.AbstractLogEnabled;
import org.apache.plexus.logging.ConsoleLogger;
import org.apache.plexus.logging.LoggerManager;
@@ -157,6 +155,12 @@
*/
private ResourceManager resourceManager;
+ /** Default Configuration Builder. */
+ private DefaultConfigurationBuilder builder;
+
+ /** Default Configuration. */
+ private PlexusDefaults plexusDefaults;
+
// ----------------------------------------------------------------------
// Constructors
// ----------------------------------------------------------------------
@@ -166,6 +170,7 @@
*/
public DefaultPlexusContainer()
{
+ builder = new DefaultConfigurationBuilder();
}
// ----------------------------------------------------------------------
@@ -313,13 +318,10 @@
public void initialize()
throws Exception
{
+ initializeClassLoader();
+ initializeDefaultConfiguration();
initializeConfiguration();
initializeLogging();
-
- // Now if we're going to use the resource manager to instantiate pluggable
- // core components
-
-
initializeResourceManager();
initializeServiceRepository();
initializeContext();
@@ -344,11 +346,30 @@
*
* @throws Exception
*/
- protected void initializeConfiguration()
+ protected void initializeDefaultConfiguration()
throws Exception
{
- DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
+ InputStream is = getClassLoader().getResourceAsStream( "org/apache/plexus/plexus.conf" );
+ setPlexusDefaults( new PlexusDefaults( builder.build( new InputSource( new InputStreamReader( is ) ) ) ) );
+ }
+
+ public PlexusDefaults getPlexusDefaults()
+ {
+ return plexusDefaults;
+ }
+ public void setPlexusDefaults( PlexusDefaults plexusDefaults )
+ {
+ this.plexusDefaults = plexusDefaults;
+ }
+
+ /** Initialize the configuration.
+ *
+ * @throws Exception
+ */
+ protected void initializeConfiguration()
+ throws Exception
+ {
InterpolationFilterReader interpolationFilterReader =
new InterpolationFilterReader( getConfigurationReader(), getConfigurationVariables() );
@@ -378,11 +399,7 @@
}
}
- /** Initialize the resource manager.
- *
- * @throws Exception
- */
- protected void initializeResourceManager()
+ protected void initializeClassLoader()
throws Exception
{
if ( getClassWorld() != null )
@@ -393,16 +410,24 @@
}
catch ( NoSuchRealmException e )
{
- getLogger().error( "Cannot retrieve classloader from Classworlds configuration." );
}
}
else
{
classLoader = Thread.currentThread().getContextClassLoader();
}
+ }
+
+ /** Initialize the resource manager.
+ *
+ * @throws Exception
+ */
+ protected void initializeResourceManager()
+ throws Exception
+ {
// Resource Manager
- setResourceManager( new ResourceManager( classLoader ) );
+ setResourceManager( new ResourceManager( getClassLoader() ) );
setupLogger( getResourceManager(), "resource-manager" );
getResourceManager().configure( configuration.getChild( "resources" ) );
setClassLoader( getResourceManager().getClassLoader() );
@@ -436,12 +461,24 @@
*
*/
protected void initializeLifecycleHandler()
+ throws Exception
{
- setLifecycleHandler( new AvalonLifecycleHandler() );
+ Class c = getClassLoader().loadClass( getPlexusDefaults().getDefaultLifecycleHandler() );
+ LifecycleHandler lh = (LifecycleHandler) c.newInstance();
+ lh.initialize();
+ lh.assembleSegments();
+
+ // Add some standard entities to the lifecycle handler. The lifecycle
+ // handler may wish to use some of these entities to create new types
+ // of entities for its lifecycle phases. For example the AvalonLifecycleHandler
+ // uses the ServiceRepository and adapts it to create an Avalon ServiceManager.
+ lh.addEntity( LifecycleHandler.LOGGER, getLoggerManager().getRootLogger() );
+ lh.addEntity( LifecycleHandler.CONTEXT, getContext() );
+ lh.addEntity( LifecycleHandler.SERVICE_REPOSITORY, getServiceRepository() );
+
setupLogger( getLifecycleHandler(), "lifecycle-handler" );
- getLifecycleHandler().addEntity( AvalonLifecycleHandler.LOGGER, getLoggerManager().getRootLogger() );
- getLifecycleHandler().addEntity( AvalonLifecycleHandler.CONTEXT, getContext() );
- getLifecycleHandler().addEntity( AvalonLifecycleHandler.SERVICE_MANAGER, new AvalonServiceManager( getServiceRepository() ) );
+
+ setLifecycleHandler( lh );
}
/** Initialize system properties.
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.