CVS: plexus-container-new/src/java/org/apache/plexus DefaultPlexusContainer.java,1.10,1.11

[email protected] Sun, 27 Apr 2003 15:20:05 -0500
Newsgroups gmane.comp.java.plexus.devel
Message-ID <[email protected]>
Update of /cvsroot/plexus/plexus-container-new/src/java/org/apache/plexus
In directory eng.werken.com:/tmp/cvs-serv9114/src/java/org/apache/plexus

Modified Files:
	DefaultPlexusContainer.java 
Log Message:
o Added an abstract factory that will be the basis for allowing pluggable
  base entities in Plexus. Currently the logger manager and lifecycle handler
  are pluggable.


Index: DefaultPlexusContainer.java
===================================================================
RCS file: /cvsroot/plexus/plexus-container-new/src/java/org/apache/plexus/DefaultPlexusContainer.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- DefaultPlexusContainer.java	27 Apr 2003 16:27:39 -0000	1.10
+++ DefaultPlexusContainer.java	27 Apr 2003 20:20:03 -0000	1.11
@@ -69,6 +69,7 @@
 import org.apache.plexus.logging.AbstractLogEnabled;
 import org.apache.plexus.logging.ConsoleLogger;
 import org.apache.plexus.logging.LoggerManager;
+import org.apache.plexus.logging.LoggerManagerFactory;
 import org.apache.plexus.logging.log4j.Log4JLoggerManager;
 import org.apache.plexus.service.repository.DefaultServiceRepository;
 import org.apache.plexus.service.repository.ServiceRepository;
@@ -114,16 +115,13 @@
     /** Configuration for this container. */
     private Configuration configuration;
 
-    /**
-     *  The configuration reader which is ultimately used to read the
-     *  configuration file.
-     */
+    /** The configuration resource. */
     private Reader configurationReader;
 
     /**
-     *  Lifecycle handler for this container. One lifecycle handler per
-     *  is permitted. This may change in the short term to allow running
-     *  components with varying lifecycles in the same container.
+     * Lifecycle handler for this container. One lifecycle handler per
+     * container is permitted. This may change in the short term to allow running
+     * components with varying lifecycles in the same container.
      */
     private LifecycleHandler lifecycleHandler;
 
@@ -147,6 +145,7 @@
     /** Default Configuration Builder. */
     private DefaultConfigurationBuilder builder;
 
+    /** Default configuration. */
     private Configuration defaultConfiguration;
 
     // ----------------------------------------------------------------------
@@ -174,6 +173,16 @@
         setConfigurationReader( configuration );
     }
 
+    public Configuration getDefaultConfiguration()
+    {
+        return defaultConfiguration;
+    }
+
+    public void setDefaultConfiguration( Configuration defaultConfiguration )
+    {
+        this.defaultConfiguration = defaultConfiguration;
+    }
+
     // --[ ResourceManager ]--
 
     /**
@@ -242,6 +251,18 @@
     //  Lifecycle
     // ----------------------------------------------------------------------
 
+    /**
+     * - Initialize ClassLoader
+     * - Initialize the context as there may be values that need to be interpolated
+     * - Initialize the default configuration
+     * - Initialize the configuration
+     * - Initialize logger manager
+     * - Initialize service repository
+     * - Initialize resource manager
+     * - Initialize lifecycle handler
+     *
+     * @throws Exception
+     */
     public void initialize()
         throws Exception
     {
@@ -250,8 +271,8 @@
         initializeDefaultConfiguration();
         initializeConfiguration();
         initializeLogging();
-        initializeResourceManager();
         initializeServiceRepository();
+        initializeResourceManager();
         initializeLifecycleHandler();
     }
 
@@ -269,13 +290,30 @@
     // Internal initialization methods
     // ----------------------------------------------------------------------
 
+    protected void initializeClassLoader()
+        throws Exception
+    {
+        if ( getClassWorld() != null )
+        {
+            try
+            {
+                classLoader = getClassWorld().getRealm( "core" ).getClassLoader();
+            }
+            catch ( NoSuchRealmException e )
+            {
+            }
+        }
+        else
+        {
+            classLoader = Thread.currentThread().getContextClassLoader();
+        }
+    }
+
     /** Initialize the context.
      *
      */
     protected void initializeContext()
     {
-        // The resource manager is plexus specific and really shouldn't go into the context.
-        //addContextValue( PlexusConstants.RESOURCE_MANAGER_KEY, getResourceManager() );
         addContextValue( PlexusConstants.COMMON_CLASSLOADER, getClassLoader() );
     }
 
@@ -290,16 +328,6 @@
         setDefaultConfiguration( builder.build( new InputSource( new InputStreamReader( is ) ) ) );
     }
 
-    public Configuration getDefaultConfiguration()
-    {
-        return defaultConfiguration;
-    }
-
-    public void setDefaultConfiguration( Configuration defaultConfiguration )
-    {
-        this.defaultConfiguration = defaultConfiguration;
-    }
-
     /** Initialize the configuration.
      *
      *  @throws Exception
@@ -321,41 +349,37 @@
     protected void initializeLogging()
         throws Exception
     {
-        if ( getConfiguration().getChild( "logging" ) != null )
+        if ( getConfiguration().getChild( "logging", false ) != null )
         {
-            setLoggerManager( new Log4JLoggerManager() );
-            getLoggerManager().configure( getConfiguration() );
-            getLoggerManager().initialize();
-            getLoggerManager().start();
-
-            // Container logging
-            enableLogging( getLoggerManager().getRootLogger() );
+            setLoggerManager(
+                LoggerManagerFactory.create( getConfiguration().getChild( "logging" ),
+                                             getClassLoader() ) );
         }
         else
         {
-            enableLogging( new ConsoleLogger() );
-        }
+            setLoggerManager(
+                LoggerManagerFactory.create( getDefaultConfiguration().getChild( "logging" ),
+                                             getClassLoader() ) );
+       }
+
+        enableLogging( getLoggerManager().getRootLogger() );
     }
 
-    protected void initializeClassLoader()
+    /** Intialize the service repository.
+     *
+     *  @throws Exception
+     */
+    protected void initializeServiceRepository()
         throws Exception
     {
-        if ( getClassWorld() != null )
-        {
-            try
-            {
-                classLoader = getClassWorld().getRealm( "core" ).getClassLoader();
-            }
-            catch ( NoSuchRealmException e )
-            {
-            }
-        }
-        else
-        {
-            classLoader = Thread.currentThread().getContextClassLoader();
-        }
+        setServiceRepository( new DefaultServiceRepository() );
+        setupLogger( getServiceRepository(), "service-repository" );
+        getServiceRepository().setPlexusContainer( this );
+        getServiceRepository().configure( getConfiguration() );
+        getServiceRepository().initialize();
     }
 
+
     /** Initialize the resource manager.
      *
      *  @throws Exception
@@ -370,20 +394,6 @@
         getResourceManager().configure( configuration.getChild( "resources" ) );
         setClassLoader( getResourceManager().getClassLoader() );
         Thread.currentThread().setContextClassLoader( getClassLoader() );
-    }
-
-    /** Intialize the service repository.
-     *
-     *  @throws Exception
-     */
-    protected void initializeServiceRepository()
-        throws Exception
-    {
-        setServiceRepository( new DefaultServiceRepository() );
-        setupLogger( getServiceRepository(), "service-repository" );
-        getServiceRepository().setPlexusContainer( this );
-        getServiceRepository().configure( getConfiguration() );
-        getServiceRepository().initialize();
     }
 
     /** Initialize the lifecycle handler.