avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/util ContextManager.java
Date Mon, 04 Mar 2002 22:37:01 GMT
bloritsch    02/03/04 14:37:01

  Modified:    src/scratchpad/org/apache/avalon/excalibur/system
                        ContainerManager.java DefaultContainerManager.java
               src/scratchpad/org/apache/avalon/excalibur/system/util
                        ContextManager.java
  Log:
  next step in the DefaultContainerManager
  
  Revision  Changes    Path
  1.31      +11 -10    jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/ContainerManager.java
  
  Index: ContainerManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/ContainerManager.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- ContainerManager.java	4 Mar 2002 21:11:50 -0000	1.30
  +++ ContainerManager.java	4 Mar 2002 22:37:01 -0000	1.31
  @@ -99,19 +99,20 @@
    * </table>
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision: 1.30 $ $Date: 2002/03/04 21:11:50 $
  + * @version CVS $Revision: 1.31 $ $Date: 2002/03/04 22:37:01 $
    */
   public interface ContainerManager extends Disposable, Initializable
   {
  -    String CONTEXT_DIRECTORY = Container.CONTEXT_DIRECTORY;
  -    String WORK_DIRECTORY    = Container.WORK_DIRECTORY;
  -    String CONTAINER_CLASS   = "container.class";
  -    String LOGKIT_CONFIG     = "container.loggerConfig";
  -    String ROLE_CONFIG       = "container.roles";
  -    String THREADS_CPU       = "container.threadsPerCPU";
  -    String THREAD_TIMEOUT    = "container.threadTimeout";
  -    String CONTAINER_CONFIG  = "container.configFile";
  -    String LOG_CATEGORY      = "container.logCategory";
  +    String CONTEXT_DIRECTORY        = Container.CONTEXT_DIRECTORY;
  +    String WORK_DIRECTORY           = Container.WORK_DIRECTORY;
  +    String CONTAINER_CLASS          = "container.class";
  +    String LOGKIT_CONFIG            = "container.loggerConfig";
  +    String ROLE_CONFIG              = "container.roles";
  +    String THREADS_CPU              = "container.threadsPerCPU";
  +    String THREAD_TIMEOUT           = "container.threadTimeout";
  +    String CONTAINER_CONFIG         = "container.configFile";
  +    String LOG_CATEGORY             = "container.logCategory";
  +    String PARENT_COMPONENT_MANAGER = "container.componentManager";
   
       /**
        * Get a reference to your Container.  Typically, you would cast this to
  
  
  
  1.2       +118 -7    jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/DefaultContainerManager.java
  
  Index: DefaultContainerManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/DefaultContainerManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultContainerManager.java	4 Mar 2002 21:14:21 -0000	1.1
  +++ DefaultContainerManager.java	4 Mar 2002 22:37:01 -0000	1.2
  @@ -7,10 +7,15 @@
    */
   package org.apache.avalon.excalibur.system;
   
  +import org.apache.avalon.framework.component.*;
   import org.apache.avalon.framework.context.Context;
  +import org.apache.avalon.framework.configuration.*;
   import org.apache.avalon.framework.logger.*;
   import org.apache.avalon.excalibur.logger.*;
  +import org.apache.avalon.excalibur.source.*;
   import org.apache.avalon.excalibur.system.util.*;
  +import org.apache.avalon.excalibur.util.ComponentStateValidator;
  +import org.apache.avalon.excalibur.util.SystemUtil;
   
   import java.io.File;
   
  @@ -28,10 +33,24 @@
    * </p>
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision: 1.1 $ $Date: 2002/03/04 21:14:21 $
  + * @version CVS $Revision: 1.2 $ $Date: 2002/03/04 22:37:01 $
    */
   public class DefaultContainerManager implements ContainerManager
   {
  +    private static final Configuration EMPTY_CONFIG;
  +
  +    static
  +    {
  +        DefaultConfiguration config = new DefaultConfiguration("", "", "", "");
  +        config.makeReadOnly();
  +        EMPTY_CONFIG = config;
  +    }
  +
  +    private final DefaultConfigurationBuilder    m_configBuilder =
  +                                                     new DefaultConfigurationBuilder();
  +    private final DefaultConfigurationSerializer m_configSerializer =
  +                                                     new DefaultConfigurationSerializer();
  +
       private final ContextManager m_contextManager;
       private       Logger         m_logger;
       private       Object         m_containerInstance;
  @@ -58,13 +77,22 @@
   
               try
               {
  -                LoggerManager manager = (LoggerManager) m_contextManager
  -                        .getContextInstance().get( Container.LOGGER_MANAGER );
  +                LoggerManager manager = (LoggerManager) m_contextManager.get( Container.LOGGER_MANAGER
);
  +
  +                testLogger = manager.getDefaultLogger();
               }
               catch (Exception e)
               {
  +                if ( null == testLogger )
  +                {
  +                    testLogger = new ConsoleLogger();
  +                }
               }
  +
  +            m_logger = testLogger;
           }
  +
  +        setupContext();
       }
   
       /**
  @@ -102,8 +130,91 @@
        * Get a reference to the ContextManager.  The ContextManager is used to
        * set up the initial properties for the system.
        */
  -   public ContextManager getContextManager()
  -   {
  -       return m_contextManager;
  -   }
  +    public ContextManager getContextManager()
  +    {
  +        return m_contextManager;
  +    }
  +
  +    protected void setupContext()
  +    {
  +    }
  +
  +    /**
  +     * Get a reference to the initial ComponentManager used by the ContainerManager
  +     * to hold the Components used for parsing the config files and setting up the
  +     * environment.
  +     */
  +    protected ComponentManager getComponentManager()
  +    {
  +        ComponentManager parentManager = (ComponentManager)
  +            m_contextManager.get( ContainerManager.PARENT_COMPONENT_MANAGER );
  +
  +        if ( null == parentManager )
  +        {
  +            DefaultComponentManager manager = new DefaultComponentManager();
  +
  +            try
  +            {
  +                DefaultComponentSelector selector = new DefaultComponentSelector();
  +                ResourceSourceFactory resource = new ResourceSourceFactory();
  +                resource.enableLogging( getLogger() );
  +                selector.put("resource", resource);
  +
  +                manager.put( resource.ROLE + "Selector", selector );
  +
  +                SourceResolverImpl resolver = new SourceResolverImpl();
  +                resolver.enableLogging( getLogger() );
  +                resolver.contextualize( m_contextManager.getContextInstance() );
  +                resolver.compose( manager );
  +                manager.put( resolver.ROLE, resolver );
  +            }
  +            catch ( Exception e )
  +            {
  +                getLogger().warn("Could not set up the initial components", e);
  +            }
  +
  +            manager.makeReadOnly();
  +            m_contextManager.setComponentManager( manager );
  +            parentManager = manager;
  +        }
  +
  +        return parentManager;
  +    }
  +
  +    protected Configuration getConfiguration( String key )
  +    {
  +        Object value = m_contextManager.get( key );
  +
  +        if ( value instanceof Configuration )
  +        {
  +            return (Configuration) value;
  +        }
  +
  +        Configuration config = null;
  +        SourceResolver resolver = null;
  +        try
  +        {
  +            resolver = (SourceResolver) getComponentManager().lookup(SourceResolver.ROLE);
  +            Source src = resolver.resolve( key );
  +
  +            config = m_configBuilder.build( src.getInputStream() );
  +
  +            resolver.release( src );
  +        }
  +        catch (Exception e)
  +        {
  +            config = EMPTY_CONFIG;
  +
  +            if ( getLogger().isWarnEnabled() )
  +            {
  +                getLogger().warn("Could not read configuration file: " + key, e);
  +            }
  +        }
  +        finally
  +        {
  +            getComponentManager().release(resolver);
  +        }
  +
  +        return config;
  +    }
   }
  
  
  
  1.5       +35 -1     jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/util/ContextManager.java
  
  Index: ContextManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/util/ContextManager.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ContextManager.java	4 Mar 2002 21:11:50 -0000	1.4
  +++ ContextManager.java	4 Mar 2002 22:37:01 -0000	1.5
  @@ -9,7 +9,9 @@
   
   import org.apache.avalon.excalibur.system.*;
   import org.apache.avalon.framework.context.*;
  +import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.parameters.*;
  +import org.apache.avalon.framework.configuration.*;
   import org.apache.avalon.excalibur.logger.LoggerManager;
   import org.apache.avalon.excalibur.event.Queue;
   import org.apache.avalon.excalibur.mpool.PoolManager;
  @@ -26,7 +28,7 @@
    * will be possible on it.
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision: 1.4 $ $Date: 2002/03/04 21:11:50 $
  + * @version CVS $Revision: 1.5 $ $Date: 2002/03/04 22:37:01 $
    * @since 4.1
    */
   public class ContextManager
  @@ -60,6 +62,18 @@
           m_currContext.makeReadOnly();
       }
   
  +    public Object get( Object key )
  +    {
  +        try
  +        {
  +            return m_currContext.get( key );
  +        }
  +        catch (Exception e)
  +        {
  +            return null;
  +        }
  +    }
  +
       public Context getContextInstance()
           throws ContextException
       {
  @@ -101,16 +115,31 @@
           m_currContext.put( ContainerManager.LOGKIT_CONFIG, location );
       }
   
  +    public void setLogKitLoggerManagerConfiguration( Configuration config )
  +    {
  +        m_currContext.put( ContainerManager.ROLE_CONFIG, config );
  +    }
  +
       public void setRoleManagerConfiguration( String location )
       {
           m_currContext.put( ContainerManager.ROLE_CONFIG, location );
       }
   
  +    public void setRoleManagerConfiguration( Configuration config )
  +    {
  +        m_currContext.put( ContainerManager.ROLE_CONFIG, config );
  +    }
  +
       public void setContainerConfiguration( String location )
       {
           m_currContext.put( ContainerManager.CONTAINER_CONFIG, location );
       }
   
  +    public void setContainerConfiguration( Configuration config )
  +    {
  +        m_currContext.put( ContainerManager.CONTAINER_CONFIG, config );
  +    }
  +
       public void setLoggerCategory( String category )
       {
           m_currContext.put( ContainerManager.LOG_CATEGORY, category );
  @@ -144,6 +173,11 @@
       public void setRoleManager( RoleManager roleManager )
       {
           m_currContext.put( Container.ROLE_MANAGER, roleManager );
  +    }
  +
  +    public void setComponentManager( ComponentManager componentManager )
  +    {
  +        m_currContext.put( ContainerManager.PARENT_COMPONENT_MANAGER, componentManager
);
       }
   
       private static final Parameters defaultParameters()
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message