avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/util ContextBuilder.java
Date Sun, 10 Nov 2002 23:22:28 GMT
donaldp     2002/11/10 15:22:28

  Modified:    fortress/src/java/org/apache/excalibur/fortress/util
                        ContextBuilder.java
  Log:
  Delegate to FortressConfig so we don't have to maintain code in multiple places
  
  Revision  Changes    Path
  1.31      +35 -82    jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/util/ContextBuilder.java
  
  Index: ContextBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/util/ContextBuilder.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- ContextBuilder.java	10 Nov 2002 12:00:17 -0000	1.30
  +++ ContextBuilder.java	10 Nov 2002 23:22:27 -0000	1.31
  @@ -53,8 +53,6 @@
   import org.apache.avalon.excalibur.logger.LoggerManager;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.context.Context;
  -import org.apache.avalon.framework.context.ContextException;
  -import org.apache.avalon.framework.context.DefaultContext;
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.excalibur.event.Queue;
   import org.apache.excalibur.fortress.role.RoleManager;
  @@ -67,7 +65,7 @@
   public class ContextBuilder
       implements ContextManagerConstants
   {
  -    private final DefaultContext context;
  +    private final FortressConfig m_config;
   
       /**
        * Creates a context builder and initializes it with default values.
  @@ -85,7 +83,7 @@
        */
       public ContextBuilder()
       {
  -        this( createDefaultContext() );
  +        m_config = new FortressConfig();
       }
   
       /**
  @@ -93,9 +91,9 @@
        *
        * @param parent parent context with default values.
        */
  -    public ContextBuilder( Context parent )
  +    public ContextBuilder( final Context parent )
       {
  -        context = new OverridableContext( parent );
  +        m_config = new FortressConfig( parent );
       }
   
       /**
  @@ -103,7 +101,7 @@
        */
       public static final Context createDefaultContext()
       {
  -        return createDefaultContext( Thread.currentThread().getContextClassLoader() );
  +        return FortressConfig.createDefaultConfig();
       }
   
       /**
  @@ -111,32 +109,7 @@
        */
       public static final Context createDefaultContext( ClassLoader classLoader )
       {
  -        DefaultContext defaultContext = new DefaultContext();
  -
  -        try
  -        {
  -            defaultContext.put( CONTAINER_CLASS, classLoader.loadClass(
  -                "org.apache.excalibur.fortress.container.DefaultContainer" ) );
  -        }
  -        catch( Exception e )
  -        {
  -            // ignore
  -        }
  -
  -        defaultContext.put( THREADS_CPU, new Integer( 2 ) );
  -        defaultContext.put( THREAD_TIMEOUT, new Long( 1000 ) );
  -        defaultContext.put( CONTEXT_DIRECTORY, new File( "../" ) );
  -        defaultContext.put( WORK_DIRECTORY, new File( "/tmp" ) );
  -        defaultContext.put( LOG_CATEGORY, "fortress" );
  -        defaultContext.put( ClassLoader.class.getName(), classLoader );
  -        defaultContext.put( CONFIGURATION_URI, "conf/system.xconf" );
  -        defaultContext.put( LOGGER_MANAGER_CONFIGURATION_URI, "conf/logkit.xconf" );
  -        defaultContext.put( ROLE_MANAGER_CONFIGURATION_URI, "resource://ext/system.roles"
);
  -        defaultContext.put( ASSEMBLY_CONFIGURATION_URI, "resource://ext/assembly.xml" );
  -
  -        defaultContext.makeReadOnly();
  -
  -        return defaultContext;
  +        return FortressConfig.createDefaultConfig( classLoader );
       }
   
       /**
  @@ -144,189 +117,169 @@
        */
       public Context getContext()
       {
  -        context.makeReadOnly();
  -        return context;
  +        return m_config.getContext();
       }
   
       public ContextBuilder setCommandQueue( Queue commandQueue )
       {
  -        context.put( Queue.ROLE, commandQueue );
  +        m_config.setCommandQueue( commandQueue );
           return this;
       }
   
       public ContextBuilder setServiceManagerParent( ServiceManager serviceManager )
       {
  -        context.put( SERVICE_MANAGER_PARENT, serviceManager );
  +        m_config.setServiceManagerParent( serviceManager );
           return this;
       }
   
  -    public ContextBuilder setServiceManager( ServiceManager componentManager )
  +    public ContextBuilder setServiceManager( ServiceManager serviceManager )
       {
  -        context.put( SERVICE_MANAGER, componentManager );
  +        m_config.setServiceManager( serviceManager );
           return this;
       }
   
       public ContextBuilder setContainerClass( String containerClass )
           throws ClassNotFoundException
       {
  -        ClassLoader classLoader = null;
  -        try
  -        {
  -            classLoader = (ClassLoader)context.get( ClassLoader.class.getName() );
  -        }
  -        catch( ContextException ce )
  -        {
  -            classLoader = Thread.currentThread().getContextClassLoader();
  -        }
  -
  -        context.put( CONTAINER_CLASS, classLoader.loadClass( containerClass ) );
  +        m_config.setContainerClass( containerClass );
           return this;
       }
   
       public ContextBuilder setContainerClass( Class containerClass )
       {
  -        context.put( CONTAINER_CLASS, containerClass );
  +        m_config.setContainerClass( containerClass );
           return this;
       }
   
       public ContextBuilder setContainerConfiguration( Configuration config )
       {
  -        context.put( CONFIGURATION, config );
  -        context.put( CONFIGURATION_URI, null );
  +        m_config.setContainerConfiguration( config );
           return this;
       }
   
       public ContextBuilder setContainerConfiguration( String location )
       {
  -        context.put( CONFIGURATION_URI, location );
  +        m_config.setContainerConfiguration( location );
           return this;
       }
   
       public ContextBuilder setAssemblyConfiguration( Configuration config )
       {
  -        context.put( ASSEMBLY_CONFIGURATION, config );
  -        context.put( ASSEMBLY_CONFIGURATION_URI, null );
  +        m_config.setAssemblyConfiguration( config );
           return this;
       }
   
       public ContextBuilder setAssemblyConfiguration( String location )
       {
  -        context.put( ASSEMBLY_CONFIGURATION_URI, location );
  +        m_config.setAssemblyConfiguration( location );
           return this;
       }
   
       public ContextBuilder setContextClassLoader( ClassLoader loader )
       {
  -        context.put( ClassLoader.class.getName(), loader );
  +        m_config.setContextClassLoader( loader );
           return this;
       }
   
       public ContextBuilder setContextDirectory( File file )
       {
  -        context.put( CONTEXT_DIRECTORY, file );
  +        m_config.setContextDirectory( file );
           return this;
       }
   
       public ContextBuilder setContextDirectory( String directory )
       {
  -        context.put( CONTEXT_DIRECTORY, new File( directory ) );
  +        m_config.setContextDirectory( directory );
           return this;
       }
   
       public ContextBuilder setLoggerCategory( String category )
       {
  -        context.put( LOG_CATEGORY, category );
  +        m_config.setLoggerCategory( category );
           return this;
       }
   
       public ContextBuilder setLoggerManager( LoggerManager logManager )
       {
  -        context.put( LoggerManager.ROLE, logManager );
  -        context.put( LOGGER_MANAGER_CONFIGURATION, null );
  -        context.put( LOGGER_MANAGER_CONFIGURATION_URI, null );
  +        m_config.setLoggerManager( logManager );
           return this;
       }
   
       public ContextBuilder setLoggerManagerConfiguration( Configuration config )
       {
  -        context.put( LOGGER_MANAGER_CONFIGURATION, config );
  -        context.put( LOGGER_MANAGER_CONFIGURATION_URI, null );
  +        m_config.setLoggerManagerConfiguration( config );
           return this;
       }
   
       public ContextBuilder setLoggerManagerConfiguration( String location )
       {
  -        context.put( LOGGER_MANAGER_CONFIGURATION_URI, location );
  +        m_config.setLoggerManagerConfiguration( location );
           return this;
       }
   
       public ContextBuilder setInstrumentManager( InstrumentManager profiler )
       {
  -        context.put( InstrumentManager.ROLE, profiler );
  -        context.put( INSTRUMENT_MANAGER_CONFIGURATION, null );
  -        context.put( INSTRUMENT_MANAGER_CONFIGURATION_URI, null );
  +        m_config.setInstrumentManager( profiler );
           return this;
       }
   
       public ContextBuilder setInstrumentManagerConfiguration( Configuration config )
       {
  -        context.put( INSTRUMENT_MANAGER_CONFIGURATION, config );
  -        context.put( INSTRUMENT_MANAGER_CONFIGURATION_URI, null );
  +        m_config.setInstrumentManagerConfiguration( config );
           return this;
       }
   
       public ContextBuilder setInstrumentManagerConfiguration( String location )
       {
  -        context.put( INSTRUMENT_MANAGER_CONFIGURATION_URI, location );
  +        m_config.setInstrumentManagerConfiguration( location );
           return this;
       }
   
       public ContextBuilder setNumberOfThreadsPerCPU( int numberOfThreads )
       {
  -        context.put( THREADS_CPU, new Integer( numberOfThreads ) );
  +        m_config.setNumberOfThreadsPerCPU( numberOfThreads );
           return this;
       }
   
       public ContextBuilder setPoolManager( PoolManager poolManager )
       {
  -        context.put( PoolManager.ROLE, poolManager );
  +        m_config.setPoolManager( poolManager );
           return this;
       }
   
       public ContextBuilder setRoleManager( RoleManager roleManager )
       {
  -        context.put( RoleManager.ROLE, roleManager );
  +        m_config.setRoleManager( roleManager );
           return this;
       }
   
       public ContextBuilder setRoleManagerConfiguration( Configuration config )
       {
  -        context.put( ROLE_MANAGER_CONFIGURATION, config );
  -        context.put( ROLE_MANAGER_CONFIGURATION_URI, null );
  +        m_config.setRoleManagerConfiguration( config );
           return this;
       }
   
       public ContextBuilder setRoleManagerConfiguration( String location )
       {
  -        context.put( ROLE_MANAGER_CONFIGURATION_URI, location );
  +        m_config.setRoleManagerConfiguration( location );
           return this;
       }
   
       public ContextBuilder setThreadTimeout( long timeout )
       {
  -        context.put( THREAD_TIMEOUT, new Long( timeout ) );
  +        m_config.setThreadTimeout( timeout );
           return this;
       }
   
       public ContextBuilder setWorkDirectory( File file )
       {
  -        context.put( WORK_DIRECTORY, file );
  +        m_config.setWorkDirectory( file );
           return this;
       }
   
       public ContextBuilder setWorkDirectory( String directory )
       {
  -        setWorkDirectory( new File( directory ) );
  +        m_config.setWorkDirectory( directory );
           return this;
       }
   }
  
  
  

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