CVS: plexus-container/src/java/org/apache/plexus DefaultPlexusContainer.java,1.25,1.26

[email protected] Thu, 12 Jun 2003 20:52:26 -0500
Newsgroups gmane.comp.java.plexus.devel
Message-ID <[email protected]>
Update of /cvsroot/plexus/plexus-container/src/java/org/apache/plexus
In directory eng.werken.com:/tmp/cvs-serv21782/src/java/org/apache/plexus

Modified Files:
	DefaultPlexusContainer.java 
Log Message:
Formatting changes (re-arrangement of the methods) and I made anything
that didn't need to be public in scope as private.  We can always loosen
up as we go.  I just find it easier to start with tighter restrictions
and keep the public API as small as possible.



Index: DefaultPlexusContainer.java
===================================================================
RCS file: /cvsroot/plexus/plexus-container/src/java/org/apache/plexus/DefaultPlexusContainer.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- DefaultPlexusContainer.java	13 Jun 2003 01:13:53 -0000	1.25
+++ DefaultPlexusContainer.java	13 Jun 2003 01:52:24 -0000	1.26
@@ -162,139 +162,139 @@
     }
 
     // ----------------------------------------------------------------------
-    // Public SPI
+    // Lifecylce Management
     // ----------------------------------------------------------------------
 
-    // --[ Configuration ]--
-
-    /** @see PlexusContainer#setConfigurationResource(Reader) */
-    public void setConfigurationResource( Reader configuration )
-        throws ConfigurationResourceException
+    /**
+     * - Initialize ClassLoader
+     * - Initialize the default configuration
+     * - Initialize the configuration
+     * - Initialize logger manager
+     * - Initialize service repository
+     * - Initialize resource manager
+     * - Initialize the context. Values put into the context at this point won't
+     *   be interpolated into the configuration.  This may need to change later.
+     * - Initialize lifecycle handler
+     *
+     * @throws Exception
+     */
+    public void initialize()
+        throws Exception
     {
-        this.configurationReader = configuration;
+        initializeClassLoader();
+        initializeDefaultConfiguration();
+        initializeConfiguration();
+        initializeLoggerManager();
+        initializeComponentRepository();
+        initializeResourceManager();
+        initializeContext();
+        initializeLifecycleHandler();
+        initializeSystemProperties();
     }
 
-    public Configuration getDefaultConfiguration()
+    public void start()
+        throws Exception
     {
-        return defaultConfiguration;
+        loadOnStart();
     }
 
-    public void setDefaultConfiguration( Configuration defaultConfiguration )
+    public void dispose()
     {
-        this.defaultConfiguration = defaultConfiguration;
+        componentRepository.dispose();
     }
 
-    // --[ ResourceManager ]--
-
-    /**
-     *
-     * @param classLoader
-     */
-    public void setClassLoader( ClassLoader classLoader )
+    // ----------------------------------------------------------------------
+    // Pre-initialization - can only be called prior to initialization
+    // ----------------------------------------------------------------------
+    
+    public void addContextValue( Object key, Object value )
     {
-        this.classLoader = classLoader;
+        getContext().put( key, value );
     }
 
-    /**
-     *
-     * @return
-     */
-    public ClassLoader getClassLoader()
+    public void setClassLoader( ClassLoader classLoader )
     {
-        if ( classLoader == null )
-        {
-            throw new IllegalStateException( "This container must be assigned a ClassLoader." );
-        }
-
-        return classLoader;
+        this.classLoader = classLoader;
     }
 
-    /**
-     *
-     * @param classWorld
-     */
     public void setClassWorld( ClassWorld classWorld )
     {
         this.classWorld = classWorld;
     }
 
-    public ClassWorld getClassWorld()
+    /** @see PlexusContainer#setConfigurationResource(Reader) */
+    public void setConfigurationResource( Reader configuration )
+        throws ConfigurationResourceException
     {
-        return classWorld;
+        this.configurationReader = configuration;
     }
 
-    // --[ Context ]--
+    // ----------------------------------------------------------------------
+    // Post-initialization - can only be called post initialization
+    // ----------------------------------------------------------------------
 
-    public void addContextValue( Object key, Object value )
+    public LifecycleHandler getLifecycleHandler()
     {
-        getContext().put( key, value );
+        return lifecycleHandler;
     }
 
-    // --[ ServiceRepository ]--
-
-    public ComponentRepository getComponentRepository()
+    public ClassLoader getClassLoader()
     {
-        return componentRepository;
-    }
+        if ( classLoader == null )
+        {
+            throw new IllegalStateException( "This container must be assigned a ClassLoader." );
+        }
 
-    // --[ LifecycleHandler ]--
+        return classLoader;
+    }
 
-    /**
-     *
-     * @return
-     */
-    public LifecycleHandler getLifecycleHandler()
+    public ComponentRepository getComponentRepository()
     {
-        return lifecycleHandler;
+        return componentRepository;
     }
 
     // ----------------------------------------------------------------------
-    //  Lifecycle
+    // Implementation 
     // ----------------------------------------------------------------------
 
     /**
-     * - Initialize ClassLoader
-     * - Initialize the default configuration
-     * - Initialize the configuration
-     * - Initialize logger manager
-     * - Initialize service repository
-     * - Initialize resource manager
-     * - Initialize the context. Values put into the context at this point won't
-     *   be interpolated into the configuration.  This may need to change later.
-     * - Initialize lifecycle handler
-     *
-     * @throws Exception
+     *  Load specifies roles during server startup.
      */
-    public void initialize()
+    protected void loadOnStart()
         throws Exception
     {
-        initializeClassLoader();
-        initializeDefaultConfiguration();
-        initializeConfiguration();
-        initializeLoggerManager();
-        initializeComponentRepository();
-        initializeResourceManager();
-        initializeContext();
-        initializeLifecycleHandler();
-        initializeSystemProperties();
-    }
+        Configuration[] loadOnStartServices = configuration.getChild( "load-on-start" ).getChildren( "service" );
 
-    public void start()
-        throws Exception
-    {
-        loadOnStart();
-    }
+        for ( int i = 0; i < loadOnStartServices.length; i++ )
+        {
+            String role = loadOnStartServices[i].getAttribute( "role" );
+            String id = loadOnStartServices[i].getAttribute( "id", "" );
 
-    public void dispose()
-    {
-        componentRepository.dispose();
-    }
+            getLogger().info( "Loading on start [role,id]: " + "[" + role + "," + id + "]" );
 
+            try
+            {
+                if ( id.length() == 0 )
+                {
+                    getComponentRepository().lookup( role );
+                }
+                else
+                {
+                    getComponentRepository().lookup( role, id );
+                }
+            }
+            catch ( ServiceException e )
+            {
+                getLogger().error( "Cannot load-on-start " + role, e );
+            }
+        }
+    }
+    
     // ----------------------------------------------------------------------
-    // Internal initialization methods
+    // Initialization Implementation 
     // ----------------------------------------------------------------------
 
-    protected void initializeClassLoader()
+    private void initializeClassLoader()
         throws Exception
     {
         if ( getClassWorld() != null )
@@ -313,19 +313,20 @@
         }
     }
 
-    /** Initialize the context.
-     *
+    /** 
+     * Initialize the context.
      */
-    protected void initializeContext()
+    private void initializeContext()
     {
         addContextValue( PlexusConstants.COMMON_CLASSLOADER, getClassLoader() );
     }
 
-    /** Initialize the configuration.
+    /** 
+     * Initialize the configuration.
      *
-     *  @throws Exception
+     * @throws Exception
      */
-    protected void initializeDefaultConfiguration()
+    private void initializeDefaultConfiguration()
         throws Exception
     {
         InputStream is = getClassLoader().getResourceAsStream( "org/apache/plexus/plexus.conf" );
@@ -340,11 +341,12 @@
         setDefaultConfiguration( builder.parse( new InputStreamReader( is ) ) );
     }
 
-    /** Initialize the configuration.
+    /** 
+     * Initialize the configuration.
      *
-     *  @throws Exception
+     * @throws Exception
      */
-    protected void initializeConfiguration()
+    private void initializeConfiguration()
         throws Exception
     {
         InterpolationFilterReader interpolationFilterReader =
@@ -361,7 +363,7 @@
      * specified. The specified directory is scanned recursively so configurations
      * can be within nested directories to help with component organization.
      */
-    protected void processConfigurationsDirectory()
+    private void processConfigurationsDirectory()
         throws Exception
     {
         String s = getConfiguration().getChild( "configurations-directory" ).getValue( null );
@@ -394,12 +396,12 @@
         }
     }
 
-
-    /** Initialize Logging.
+    /** 
+     * Initialize Logging.
      *
-     *  @throws Exception
+     * @throws Exception
      */
-    protected void initializeLoggerManager()
+    private void initializeLoggerManager()
         throws Exception
     {
         LoggerManager loggerManager =
@@ -411,11 +413,12 @@
         setLoggerManager( loggerManager );
     }
 
-    /** Intialize the service repository.
+    /** 
+     * Intialize the service repository.
      *
-     *  @throws Exception
+     * @throws Exception
      */
-    protected void initializeComponentRepository()
+    private void initializeComponentRepository()
         throws Exception
     {
         ComponentRepository componentRepository =
@@ -428,12 +431,12 @@
         setComponentRepository( componentRepository );
     }
 
-
-    /** Initialize the resource manager.
+    /** 
+     * Initialize the resource manager.
      *
-     *  @throws Exception
+     * @throws Exception
      */
-    protected void initializeResourceManager()
+    private void initializeResourceManager()
         throws Exception
     {
         DefaultResourceManager rm =
@@ -451,10 +454,10 @@
         Thread.currentThread().setContextClassLoader( getClassLoader() );
     }
 
-    /** Initialize the lifecycle handler.
-     *
+    /** 
+     * Initialize the lifecycle handler.
      */
-    protected void initializeLifecycleHandler()
+    private void initializeLifecycleHandler()
         throws Exception
     {
         LifecycleHandler lh = LifecycleHandlerFactory.create( getDefaultConfiguration(),
@@ -467,14 +470,15 @@
         setLifecycleHandler( lh );
     }
 
-    /** Initialize system properties.
+    /** 
+     * Initialize system properties.
      *
-     *  If the application needs to setup any system properties than they will
-     *  be initialized here.
+     * If the application needs to setup any system properties than they will
+     * be initialized here.
      *
-     *  @throws Exception
+     * @throws Exception
      */
-    protected void initializeSystemProperties()
+    private void initializeSystemProperties()
         throws Exception
     {
         Configuration[] systemProperties =
@@ -491,17 +495,15 @@
     }
 
     // ----------------------------------------------------------------------
-    //  Internal accessors
+    // Internal Accessors 
     // ----------------------------------------------------------------------
 
-    // --[ LoggerManager ]--
-
     /**
-     *  Set the logger manager.
+     * Set the logger manager.
      *
      * @param loggerManager
      */
-    void setLoggerManager( LoggerManager loggerManager )
+    private void setLoggerManager( LoggerManager loggerManager )
     {
         this.loggerManager = loggerManager;
     }
@@ -511,70 +513,63 @@
      *
      * @return The logger manager.
      */
-    LoggerManager getLoggerManager()
+    private LoggerManager getLoggerManager()
     {
         return loggerManager;
     }
 
-    // --[ Configuration ]--
-
     /**
      *
      * @return
      */
-    Configuration getConfiguration()
+    private Configuration getConfiguration()
     {
         return configuration;
     }
 
-    void setConfiguration( Configuration configuration )
+    private void setConfiguration( Configuration configuration )
     {
         this.configuration = configuration;
     }
 
-    Reader getConfigurationReader()
+    private Reader getConfigurationReader()
     {
         return configurationReader;
     }
-
-    // --[ ResourceManager ]--
-
+  
     /**
      *
      * @param resourceManager
      */
-    void setResourceManager( DefaultResourceManager resourceManager )
+    private void setResourceManager( DefaultResourceManager resourceManager )
     {
         this.resourceManager = resourceManager;
     }
 
     /**
-     *  Retri eve the <code>ResourceManager</code>.
+     *  Retrieve the <code>ResourceManager</code>.
      *
      *  @return The resource manager.
      */
-    DefaultResourceManager getResourceManager()
+    private DefaultResourceManager getResourceManager()
     {
         return resourceManager;
     }
 
-    // --[ Context ]--
-
     /**
      *
      * @param context
      */
-    void setContext( DefaultContext context )
+    private void setContext( DefaultContext context )
     {
         this.context = context;
     }
 
-
     /**
      *
      * @return
      */
-    DefaultContext getContext()
+    private DefaultContext getContext()
     {
         if ( context == null )
         {
@@ -583,14 +578,12 @@
 
         return context;
     }
-
-    // --[ ServiceRepository ]--
-
+ 
     /**
      *
      * @param componentRepository
      */
-    void setComponentRepository( ComponentRepository componentRepository )
+    private void setComponentRepository( ComponentRepository componentRepository )
     {
         this.componentRepository = componentRepository;
     }
@@ -601,46 +594,36 @@
      *
      * @param lifecycleHandler
      */
-    void setLifecycleHandler( LifecycleHandler lifecycleHandler )
+    private void setLifecycleHandler( LifecycleHandler lifecycleHandler )
     {
         this.lifecycleHandler = lifecycleHandler;
     }
-
-    // ----------------------------------------------------------------------
-    //  Implementation
-    // ----------------------------------------------------------------------
-
+    
     /**
-     *  Load specifies roles during server startup.
+     * 
+     * @return
      */
-    protected void loadOnStart()
-        throws Exception
+    private Configuration getDefaultConfiguration()
     {
-        Configuration[] loadOnStartServices = configuration.getChild( "load-on-start" ).getChildren( "service" );
-
-        for ( int i = 0; i < loadOnStartServices.length; i++ )
-        {
-            String role = loadOnStartServices[i].getAttribute( "role" );
-            String id = loadOnStartServices[i].getAttribute( "id", "" );
-
-            getLogger().info( "Loading on start [role,id]: " + "[" + role + "," + id + "]" );
+        return defaultConfiguration;
+    }
 
-            try
-            {
-                if ( id.length() == 0 )
-                {
-                    getComponentRepository().lookup( role );
-                }
-                else
-                {
-                    getComponentRepository().lookup( role, id );
-                }
-            }
-            catch ( ServiceException e )
-            {
-                getLogger().error( "Cannot load-on-start " + role, e );
-            }
-        }
+    /**
+     * 
+     * @param defaultConfiguration
+     */
+    private void setDefaultConfiguration( Configuration defaultConfiguration )
+    {
+        this.defaultConfiguration = defaultConfiguration;
+    }
+  
+    /**
+     * 
+     * @return
+     */
+    private ClassWorld getClassWorld()
+    {
+        return classWorld;
     }
 }