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 Wed, 20 Feb 2002 15:24:22 GMT
bloritsch    02/02/20 07:24:22

  Modified:    src/scratchpad/org/apache/avalon/excalibur/system
                        ContainerManager.java
               src/scratchpad/org/apache/avalon/excalibur/system/test
                        ContainerProfile.java
               src/scratchpad/org/apache/avalon/excalibur/system/util
                        ContextManager.java
  Log:
  fix ClassCastException opportunity and implement ContextManager
  
  Revision  Changes    Path
  1.29      +4 -4      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.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- ContainerManager.java	19 Feb 2002 20:48:03 -0000	1.28
  +++ ContainerManager.java	20 Feb 2002 15:24:22 -0000	1.29
  @@ -110,7 +110,7 @@
    * </table>
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision: 1.28 $ $Date: 2002/02/19 20:48:03 $
  + * @version CVS $Revision: 1.29 $ $Date: 2002/02/20 15:24:22 $
    */
   public class ContainerManager implements Disposable
   {
  @@ -153,7 +153,7 @@
       private       Configuration           m_roleConfig;
       private       Context                 m_rootContext;
       private       Context                 m_containerContext;
  -    private       Container               m_containerInstance;
  +    private       Object                  m_containerInstance;
       private       ComponentStateValidator m_validator;
       private       RoleManager             m_roleManager;
   
  @@ -284,10 +284,10 @@
       {
           if ( null == m_containerInstance )
           {
  -            Container instance = null;
  +            Object instance = null;
               try
               {
  -                instance = (Container) m_contextClassLoader
  +                instance = m_contextClassLoader
                           .loadClass( m_initialParameters.getParameter( CONTAINER_CLASS )
)
                           .newInstance();
               }
  
  
  
  1.3       +1 -2      jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/test/ContainerProfile.java
  
  Index: ContainerProfile.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/test/ContainerProfile.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ContainerProfile.java	19 Feb 2002 14:03:22 -0000	1.2
  +++ ContainerProfile.java	20 Feb 2002 15:24:22 -0000	1.3
  @@ -30,7 +30,7 @@
    * Used as a basis for the PoolComparisonProfile Tests
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version $Id: ContainerProfile.java,v 1.2 2002/02/19 14:03:22 bloritsch Exp $
  + * @version $Id: ContainerProfile.java,v 1.3 2002/02/20 15:24:22 bloritsch Exp $
    */
   public final class ContainerProfile
       extends TestCase
  @@ -99,7 +99,6 @@
               params.setParameter( ContainerManager.CONTAINER_CONFIG, "resource://org/apache/avalon/excalibur/system/test/ContainerProfile.xconf"
);
               params.setParameter( ContainerManager.LOG_CATEGORY, "test" );
               params.setParameter( ContainerManager.LOGKIT_CONFIG, "resource://org/apache/avalon/excalibur/system/test/ContainerProfile.xlog"
);
  -            params.setParameter( ContainerManager.LOG_CATEGORY, "test" );
               params.setParameter( ContainerManager.THREADS_CPU, "2" );
               params.makeReadOnly();
               ContainerManager cm = new ContainerManager( params, new NullLogger() );
  
  
  
  1.2       +166 -47   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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ContextManager.java	19 Feb 2002 20:48:04 -0000	1.1
  +++ ContextManager.java	20 Feb 2002 15:24:22 -0000	1.2
  @@ -7,57 +7,176 @@
    */
   package org.apache.avalon.excalibur.system.util;
   
  +import org.apache.avalon.excalibur.system.*;
  +import org.apache.avalon.framework.context.*;
  +import org.apache.avalon.framework.parameters.*;
  +import org.apache.avalon.excalibur.logger.LoggerManager;
  +import org.apache.avalon.excalibur.event.Queue;
  +import org.apache.avalon.excalibur.mpool.PoolManager;
  +
  +import java.io.File;
  +
  +
   /**
  - * RoleManager Interface, use this to specify the Components and how they
  - * correspond to easy shorthand names.  The RoleManager assumes a flat
  - * relationship of shorthand names to classes, and classes to roles.
  + * The ContextManager is used to manage the values in a Container's Context.
  + * Use this helper class to create the initial context to pass into the
  + * ContainerManager.  Its purpose is to add the default values, and give
  + * convenient methods to override those defaults.  Once you get an instance
  + * of the Context, it is made read-only and returned.  No further operations
  + * will be possible on it.
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision: 1.1 $ $Date: 2002/02/19 20:48:04 $
  + * @version CVS $Revision: 1.2 $ $Date: 2002/02/20 15:24:22 $
    * @since 4.1
    */
  -public interface ContextManager
  +public class ContextManager
   {
  -    /**
  -     * Find the Class for the given shorthand name.  If there is no
  -     * correspondence between the class and the shorthand name, the method
  -     * returns <code>null</code>.  If this RoleManager does not have the match,
  -     * and there is a parent RoleManager, the parent will be asked to resolve
  -     * the request.
  -     */
  -    Class getClassForName( final String shorthandName );
  -
  -    /**
  -     * This method is merely a hint for serialization.  If this RoleManager does
  -     * not have the match, and there is a parent RoleManager, the parent will be
  -     * asked to resolve the request.
  -     */
  -    String getNameForClass( final Class component );
  -
  -    /**
  -     * Get the Role name for a specific class.  If the class does not belong to
  -     * a Component, or the Role is not easily determinable, this method will return
  -     * <code>null</code>.  If this RoleManager does not have the match, and
  -     * there is a parent RoleManager, the parent will be asked to resolve the
  -     * request.
  -     */
  -    String getRoleForClass( final Class component );
  -
  -    /**
  -     * Get an array of classes registered with the role manager that implement a
  -     * role.  If this RoleManager does not have the match, and there is a parent
  -     * RoleManager, the parent will be asked to resolve the request.
  -     */
  -    Class[] getClassesForRole( final String role );
  -
  -    /**
  -     * Retrieves the handler class name for the specified class.  This
  -     * is called for every Component Implementation.  If this RoleManager does
  -     * not have the match, and there is a parent RoleManager, the parent will be
  -     * asked to resolve the handler's class name.
  -     *
  -     * @param class  The class of the Component in question.
  -     * @return the Class instance of the ComponentHandler.
  -     */
  -    Class getHandlerClassForClass( final Class className );
  +    private final Context        m_rootContext;
  +    private       DefaultContext m_currContext;
  +
  +    public ContextManager()
  +    {
  +        this( defaultParameters() );
  +    }
  +
  +    public ContextManager( Parameters params )
  +    {
  +        this( params, Thread.currentThread().getContextClassLoader() );
  +    }
  +
  +    public ContextManager( Parameters params, ClassLoader contextClassLoader )
  +    {
  +        this( defaultContext( params, contextClassLoader ) );
  +    }
  +
  +    public ContextManager( Context context )
  +    {
  +        m_rootContext = context;
  +        m_currContext = new DefaultContext( m_rootContext );
  +    }
  +
  +    public Context getContextInstance()
  +        throws ContextException
  +    {
  +        m_currContext.get( ContainerManager.CONTAINER_CLASS );
  +
  +        try
  +        {
  +            m_currContext.get( ContainerManager.LOGKIT_CONFIG );
  +        }
  +        catch (Exception e)
  +        {
  +            m_currContext.get( Container.LOGGER_MANAGER );
  +        }
  +
  +        m_currContext.makeReadOnly();
  +        return m_currContext;
  +    }
  +
  +    public void setContainerClass( String className )
  +    {
  +        m_currContext.put( ContainerManager.CONTAINER_CLASS, className );
  +    }
  +
  +    public void setContextDirectory( File file )
  +    {
  +        m_currContext.put( Container.CONTEXT_DIRECTORY, file );
  +    }
  +
  +    public void setWorkDirectory( File file )
  +    {
  +        m_currContext.put( Container.WORK_DIRECTORY, file );
  +    }
  +
  +    public void setContextClassLoader( ClassLoader loader )
  +    {
  +        m_currContext.put( Container.CONTEXT_CLASSLOADER, loader );
  +    }
  +
  +    public void setLogKitLoggerManagerConfiguration( String location )
  +    {
  +        m_currContext.put( ContainerManager.LOGKIT_CONFIG, location );
  +    }
  +
  +    public void setRoleManagerConfiguration( String location )
  +    {
  +        m_currContext.put( ContainerManager.ROLE_CONFIG, location );
  +    }
  +
  +    public void setContainerConfiguration( String location )
  +    {
  +        m_currContext.put( ContainerManager.CONTAINER_CONFIG, location );
  +    }
  +
  +    public void setLoggerCategory( String category )
  +    {
  +        m_currContext.put( ContainerManager.LOG_CATEGORY, category );
  +    }
  +
  +    public void setNumberOfThreadsPerCPU( int numberOfThreads )
  +    {
  +        m_currContext.put( ContainerManager.THREADS_CPU, new Integer( numberOfThreads )
);
  +    }
  +
  +    public void setThreadTimeout( long timeout )
  +    {
  +        m_currContext.put( ContainerManager.THREAD_TIMEOUT, new Long( timeout ) );
  +    }
  +
  +    public void setLoggerManager( LoggerManager logManager )
  +    {
  +        m_currContext.put( Container.LOGGER_MANAGER, logManager );
  +    }
  +
  +    public void setCommandQueue( Queue commandQueue )
  +    {
  +        m_currContext.put( Container.COMMAND_QUEUE, commandQueue );
  +    }
  +
  +    public void setPoolManager( PoolManager poolManager )
  +    {
  +        m_currContext.put( Container.POOL_MANAGER, poolManager );
  +    }
  +
  +    public void setRoleManager( RoleManager roleManager )
  +    {
  +        m_currContext.put( Container.ROLE_MANAGER, roleManager );
  +    }
  +
  +    private static final Parameters defaultParameters()
  +    {
  +        Parameters params = new Parameters();
  +        params.setParameter( ContainerManager.CONTEXT_DIRECTORY, "./" );
  +        params.setParameter( ContainerManager.WORK_DIRECTORY, "/tmp/" );
  +        params.setParameter( ContainerManager.LOG_CATEGORY, "test" );
  +        params.setParameter( ContainerManager.THREADS_CPU, "2" );
  +        params.setParameter( ContainerManager.THREAD_TIMEOUT, "1000" );
  +        params.makeReadOnly();
  +
  +        return params;
  +    }
  +
  +    private static final Context defaultContext( Parameters params,
  +                                          ClassLoader contextClassLoader )
  +    {
  +        DefaultContext context = new DefaultContext();
  +
  +        String[] keys = params.getNames();
  +        for (int i = 0; i < keys.length; i++)
  +        {
  +            context.put( keys[i], params.getParameter( keys[i], null ) );
  +        }
  +
  +        context.put( ContainerManager.CONTEXT_DIRECTORY,
  +                     new File( params.getParameter( ContainerManager.CONTEXT_DIRECTORY,
"./" ) ) );
  +        context.put( ContainerManager.WORK_DIRECTORY,
  +                     new File( params.getParameter( ContainerManager.CONTEXT_DIRECTORY,
"/tmp" ) ));
  +        context.put( ContainerManager.LOG_CATEGORY,
  +                params.getParameter(ContainerManager.LOG_CATEGORY, null)
  +        );
  +        context.put( Container.CONTEXT_CLASSLOADER, contextClassLoader );
  +        context.makeReadOnly();
  +
  +        return context;
  +    }
   }
  
  
  

--
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