This patch does all the same as [Patch] #11
but also it changes private to public in
ContextManager on several member variables
(m_childContext, m_contextManagerContext, etc)
and one function (assumeOwership).

As all of the initialize* methods are protected
this assumes that theoretically this class might
be switched from final to non-final in the future
and subclassed.

Well, I sort of felt embarassed the initialize*
methods are protected and the variables that
their overriden analogs would need to operate
upon (if the class was not final) are private.

I beleive that this change is otherwise useless,
except that it improves the style and readablity.

I beleive that this discrepance is really somthing
a Java developer may stumble upon reading the code and
burn his mind-cycles on solving an unexisting puzzle.

So I ask you to kindly accept these changes :)

Oh, BTW, I have also relocated m_localSourceResolver
to a more suitable location in the file.

- Anton

diff -ru src.orig/java/org/apache/avalon/fortress/impl/DefaultContainerManager.java 
src/java/org/apache/avalon/fortress/impl/DefaultContainerManager.java
--- src.orig/java/org/apache/avalon/fortress/impl/DefaultContainerManager.java  
2003-05-28 10:20:10.000000000 +0400
+++ src/java/org/apache/avalon/fortress/impl/DefaultContainerManager.java       
2003-05-28 12:33:30.000000000 +0400
@@ -205,7 +205,7 @@
             ContainerUtil.enableLogging( instance, m_logger );
             ContainerUtil.contextualize( instance, implContext );
 
-            final ServiceManager serviceManager = createServiceManager( implContext );
+            final ServiceManager serviceManager = createServiceManager( 
managerContext );
 
             ContainerUtil.service( instance, serviceManager );
 
diff -ru src.orig/java/org/apache/avalon/fortress/util/ContextManager.java 
src/java/org/apache/avalon/fortress/util/ContextManager.java
--- src.orig/java/org/apache/avalon/fortress/util/ContextManager.java   2003-05-28 
10:20:26.000000000 +0400
+++ src/java/org/apache/avalon/fortress/util/ContextManager.java        2003-05-28 
13:29:43.000000000 +0400
@@ -103,20 +103,16 @@
  * get an instance of the Context, it is made read-only and returned.  No
  * further operations will be possible on it.</p>
  *
- * <p>You can get two different contexts from the ContextManager: the child
- * context and the impl manager context. The former contains all
- * managers, such as the pool manager etc. necessary for a child impl to
- * create additional child containers. The impl manager context contains
- * all of the child context, but also initialization parameters for the
- * impl, such as a Configuration object, a ComponentLocator, etc., that
- * the impl wants, but does not want to pass on to its children.</p>
+ * <p>You can get two different contexts from the ContextManager: 
+ * the container context (m_childContext) 
+ * and the container manager context (m_contaimerManagerContext).
  *
- * <p>You would typically use the impl manager context to initialize
- * the impl manager, and let it pass the child context on to the
- * impl.</p>
+ * <p>The container manager context is used to provide the container manager
+ * with all the data needed to initialize the container.</p>
+ * <p>The container context is passed directly to the container.</p>
  *
- * <p>The ContextManager will sometimes create new components, such as a
- * component manager, a pool manager, etc. It will manage these components
+ * <p>The ContextManager will sometimes create new components, such as
+ * a service manager, a pool manager, etc. It will manage these components
  * and dispose of them properly when it itself is disposed .</p>
  *
  * @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
@@ -139,21 +135,21 @@
     /**
      * The root context.
      */
-    private final Context m_rootContext;
+    protected final Context m_rootContext;
 
     /**
      * The context of the new impl. This context has the rootContext
      * as its parent. Put everything here that you want the new impl
      * to have in its own context.
      */
-    private final DefaultContext m_childContext;
+    protected final DefaultContext m_childContext;
 
     /**
      * Container manager's context. This context has the child context
      * as parent. Put things here that you want the impl manager
      * to see, but do not wish to expose to the impl.
      */
-    private final DefaultContext m_containerManagerContext;
+    protected final DefaultContext m_containerManagerContext;
 
     /**
      * New context passed in, maybe from a FortressConfig.
@@ -161,9 +157,15 @@
      * other pointers. The ContextManager inspects it for
      * elements it can use to create component managers etc.
      */
-    private Logger m_logger;
-    private final Logger m_primordialLogger;
-    private ServiceManager m_manager;
+    protected Logger m_logger;
+    protected final Logger m_primordialLogger;
+
+    /**
+     *  Source resolver used to read-in the configurations.
+     *  and provided as a default source resolver if the
+     *  user has not supplied a ServiceManager.
+     */
+    protected SourceResolver m_defaultSourceResolver;
 
     /**
      * The components that are "owned" by this context and should
@@ -219,7 +221,7 @@
      *
      * @throws IllegalArgumentException if the object is null.
      */
-    private void assumeOwnership( final Object object )
+    protected void assumeOwnership( final Object object )
     {
         if ( object == null )
         {
@@ -237,6 +239,7 @@
      */
     public void initialize() throws Exception
     {
+        initializeDefaultSourceResolver();
         initializeServiceManager();
         initializeLoggerManager();
         initializeMetaInfoManager();
@@ -248,6 +251,8 @@
 
         m_childContext.makeReadOnly();
         m_containerManagerContext.makeReadOnly();
+
+        m_defaultSourceResolver = null;
     }
 
     /**
@@ -295,6 +300,16 @@
             getLogger().debug( "Could not copy Context parameters.  This may be Ok 
depending on "
                 + "other configured context values." );
         }
+       
+        // hide from the container implementation what it does not need
+        m_childContext.put( CONFIGURATION, null );
+        m_childContext.put( CONFIGURATION_URI, null );
+        m_childContext.put( ROLE_MANAGER_CONFIGURATION, null );
+        m_childContext.put( ROLE_MANAGER_CONFIGURATION_URI, null );
+        m_childContext.put( LOGGER_MANAGER_CONFIGURATION, null );
+        m_childContext.put( LOGGER_MANAGER_CONFIGURATION_URI, null );
+        m_childContext.put( INSTRUMENT_MANAGER_CONFIGURATION, null );
+        m_childContext.put( INSTRUMENT_MANAGER_CONFIGURATION_URI, null );
     }
 
     /**
@@ -392,7 +407,7 @@
     {
         try
         {
-            m_rootContext.get( Queue.ROLE );
+            copyEntry( Queue.ROLE );
             return;
         }
         catch ( ContextException ce )
@@ -400,7 +415,7 @@
         }
 
         // No CommandQueue specified, create a default one
-        m_childContext.put( Queue.ROLE, createCommandSink() );
+        m_containerManagerContext.put( Queue.ROLE, createCommandSink() );
     }
 
     /**
@@ -418,7 +433,7 @@
         assumeOwnership( tm );
 
         // Get the context Logger Manager
-        final LoggerManager loggerManager = (LoggerManager) m_childContext.get( 
LoggerManager.ROLE );
+        final LoggerManager loggerManager = (LoggerManager) 
m_containerManagerContext.get( LoggerManager.ROLE );
 
         // Get the logger for the thread manager
         final Logger tmLogger = loggerManager.getLoggerForCategory( 
"system.threadmgr" );
@@ -487,16 +502,16 @@
     {
         try
         {
-            m_rootContext.get( PoolManager.ROLE );
+            copyEntry( PoolManager.ROLE );
             return;
         }
         catch ( ContextException ce )
         {
         }
 
-        final PoolManager pm = new DefaultPoolManager( (Sink) m_childContext.get( 
Queue.ROLE ) );
+        final PoolManager pm = new DefaultPoolManager( (Sink) 
m_containerManagerContext.get( Queue.ROLE ) );
         assumeOwnership( pm );
-        m_childContext.put( PoolManager.ROLE, pm );
+        m_containerManagerContext.put( PoolManager.ROLE, pm );
     }
 
     /**
@@ -535,7 +550,7 @@
         }
 
         // Get the context Logger Manager
-        final LoggerManager loggerManager = (LoggerManager) m_childContext.get( 
LoggerManager.ROLE );
+        final LoggerManager loggerManager = (LoggerManager) 
m_containerManagerContext.get( LoggerManager.ROLE );
 
         // Lookup the context class loader
         final ClassLoader classLoader = (ClassLoader) m_rootContext.get( 
ClassLoader.class.getName() );
@@ -560,7 +575,17 @@
 
     protected void initializeMetaInfoManager() throws Exception
     {
-        final boolean mmSupplied = entryPresent( m_rootContext, MetaInfoManager.ROLE 
);
+        boolean mmSupplied = false;
+        try
+        {
+            copyEntry( MetaInfoManager.ROLE );
+            mmSupplied = true;
+        }
+        catch( ContextException ce )
+        {
+            // okay, we will create one
+        }
+
         RoleManager roleManager = obtainRoleManager();
         final boolean rmSupplied = roleManager != null;
 
@@ -575,7 +600,7 @@
         }
         else
         {
-            final LoggerManager loggerManager = (LoggerManager)m_childContext.get( 
LoggerManager.ROLE );
+            final LoggerManager loggerManager = 
(LoggerManager)m_containerManagerContext.get( LoggerManager.ROLE );
             final ClassLoader classLoader = (ClassLoader)m_rootContext.get( 
ClassLoader.class.getName() );
 
             if ( ! rmSupplied )
@@ -592,21 +617,16 @@
             metaManager.enableLogging( 
loggerManager.getLoggerForCategory("system.meta") );
             metaManager.initialize();
             assumeOwnership( metaManager );
-            m_childContext.put( MetaInfoManager.ROLE, metaManager );
+            m_containerManagerContext.put( MetaInfoManager.ROLE, metaManager );
         }
     }
 
     /**
-     * Get a reference to the initial ComponentLocator used by the
-     * ContainerManager to hold the Components used for parsing the config
-     * files and setting up the environment.
-     *
-     * @throws Exception when there is an error.
+     *  Initialize the default SrouceResolver.
      */
-    protected void initializeServiceManager() throws Exception
+    protected void initializeDefaultSourceResolver() throws Exception
     {
-        final ServiceManager parent = (ServiceManager) get( m_rootContext, 
SERVICE_MANAGER, null );
-        final DefaultServiceManager manager = new DefaultServiceManager( parent );
+        final DefaultServiceManager manager = new DefaultServiceManager();
         final DefaultServiceSelector selector = new DefaultServiceSelector();
         final URLSourceFactory file = new URLSourceFactory();
         file.enableLogging( getLogger() );
@@ -623,15 +643,32 @@
         ContainerUtil.service( resolver, manager );
         ContainerUtil.parameterize( resolver, new Parameters() );
 
-        manager.put( SourceResolver.ROLE, resolver );
-
-        manager.makeReadOnly();
-
-        assumeOwnership( manager );
-
-        m_manager = manager;
-
-        m_childContext.put( ContextManagerConstants.SERVICE_MANAGER, m_manager );
+        m_defaultSourceResolver = resolver;
+    }
+    /**
+     * Get a reference to the initial ComponentLocator used by the
+     * ContainerManager to hold the Components used for parsing the config
+     * files and setting up the environment.
+     *
+     * @throws Exception when there is an error.
+     */
+    protected void initializeServiceManager() throws Exception
+    {
+        try
+        {
+             copyEntry( SERVICE_MANAGER );
+        }
+        catch( ContextException ce )
+        {
+            final DefaultServiceManager manager = new DefaultServiceManager();
+        
+            // provide a default source resolver good in many situations
+            manager.put( SourceResolver.ROLE, m_defaultSourceResolver );
+        
+            manager.makeReadOnly();
+        
+            m_containerManagerContext.put( ContextManagerConstants.SERVICE_MANAGER, 
manager );
+        }
     }
 
     /**
@@ -668,8 +705,7 @@
         Source src = null;
         try
         {
-            resolver = (SourceResolver) m_manager.lookup( SourceResolver.ROLE );
-            src = resolver.resolveURI( configUri );
+            src = m_defaultSourceResolver.resolveURI( configUri );
             if ( configBuilder == null )
             {
                 configBuilder = new DefaultConfigurationBuilder();
@@ -685,12 +721,7 @@
         }
         finally
         {
-            if ( null != resolver )
-            {
-                resolver.release( src );
-            }
-
-            m_manager.release( resolver );
+            m_defaultSourceResolver.release( src );
         }
     }
 
@@ -747,7 +778,7 @@
         {
             // Try copying an already existing logger manager from the override 
context.
 
-            m_childContext.put( LoggerManager.ROLE, m_rootContext.get( 
LoggerManager.ROLE ) );
+            copyEntry( LoggerManager.ROLE );
         }
         catch ( ContextException ce )
         {
@@ -788,7 +819,7 @@
 
             assumeOwnership( logManager );
 
-            m_childContext.put( LoggerManager.ROLE, logManager );
+            m_containerManagerContext.put( LoggerManager.ROLE, logManager );
         }
 
         // Since we now have a LoggerManager, we can update the this.logger field
@@ -798,7 +829,7 @@
         {
             getLogger().debug( "Switching to default Logger provided by 
LoggerManager." );
 
-            final LoggerManager loggerManager = (LoggerManager) m_childContext.get( 
LoggerManager.ROLE );
+            final LoggerManager loggerManager = (LoggerManager) 
m_containerManagerContext.get( LoggerManager.ROLE );
             m_logger = loggerManager.getDefaultLogger();
         }
     }
@@ -819,7 +850,7 @@
         {
             // Try copying an already existing instrument manager from the override 
context.
 
-            m_rootContext.get( InstrumentManager.ROLE );
+            copyEntry( InstrumentManager.ROLE );
         }
         catch ( ContextException ce )
         {
@@ -833,7 +864,7 @@
             }
 
             // Get the context Logger Manager
-            final LoggerManager loggerManager = (LoggerManager) m_childContext.get( 
LoggerManager.ROLE );
+            final LoggerManager loggerManager = (LoggerManager) 
m_containerManagerContext.get( LoggerManager.ROLE );
 
             // Get the logger for the instrument manager
             final Logger imLogger = loggerManager.getLoggerForCategory(
@@ -847,7 +878,7 @@
 
             assumeOwnership( instrumentManager );
 
-            m_childContext.put( InstrumentManager.ROLE, instrumentManager );
+            m_containerManagerContext.put( InstrumentManager.ROLE, instrumentManager 
);
         }
     }
 
Only in src/java/org/apache/avalon/fortress/util: patch11-bis-2.diff


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to