You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by bl...@apache.org on 2002/07/30 17:12:30 UTC
cvs commit: jakarta-avalon-excalibur/fortress/src/test/org/apache/excalibur/fortress/test ContainerProfile.java TestContainer.java
bloritsch 2002/07/30 08:12:30
Modified: fortress/src/java/org/apache/excalibur/fortress
AbstractContainer.java
fortress/src/java/org/apache/excalibur/fortress/util
ContextBuilder.java
fortress/src/test/org/apache/excalibur/fortress/test
ContainerProfile.java
Added: fortress/src/java/org/apache/excalibur/fortress/container
DefaultContainer.java
Removed: fortress/src/test/org/apache/excalibur/fortress/test
TestContainer.java
Log:
add new DefaultContainer
Revision Changes Path
1.49 +10 -101 jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/AbstractContainer.java
Index: AbstractContainer.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/AbstractContainer.java,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- AbstractContainer.java 22 Jul 2002 17:46:58 -0000 1.48
+++ AbstractContainer.java 30 Jul 2002 15:12:30 -0000 1.49
@@ -20,7 +20,6 @@
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.ComponentSelector;
-import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
@@ -56,7 +55,7 @@
*/
public abstract class AbstractContainer
extends AbstractLogEnabled
- implements Contextualizable, Serviceable, Configurable, Initializable, Disposable, Container
+ implements Contextualizable, Serviceable, Initializable, Disposable, Container
{
protected Context m_context;
protected ServiceManager m_serviceManager;
@@ -137,104 +136,14 @@
}
/**
- * Process the configuration and set up the components and their mappings.
- * At this point, all components are prepared and all mappings are made.
- * However, nothing is initialized.
- *
- * <p>The native Configuration format follows a specific convention. If you
- * use a RoleManager to map roles and implementations to more helpful names,
- * we will internally rewrite the configuration to match this format. Please
- * note: If a configuration element does *not* have a unique id, it will not
- * be treated as a Component. That ID is used as the hint when there is more
- * than one implementation of a role.</p>
- *
- * <pre>
- * <component role="org.apache.avalon.excalibur.datasource.DataSourceComponent"
- * id="default-connection"
- * class="org.apache.avalon.excalibur.datasource.JdbcDataSourceComponent"
- * handler="org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler">
- *
- * <!-- Component specific configuration -->
- *
- * </component>
- * </pre>
- */
- public void configure( Configuration configElement )
- throws ConfigurationException
- {
- m_configuration = configElement;
-
- Configuration elements[] = configElement.getChildren();
-
- for( int i = 0; i < elements.length; i++ )
- {
- Configuration component = null;
- Object hint = elements[ i ].getAttribute( "id", null );
-
- if( null != hint )
- {
- if( "component".equals( elements[ i ].getName() ) )
- {
- component = elements[ i ];
- }
- else
- {
- component = rewriteConfiguration( elements[ i ] );
- }
-
- addComponent( component, hint );
- }
- }
- }
-
- /**
* Handles when a configuration name is used that is not "component", so it
* makes it easier to handle ComponentSelector hierarchies. It is meant to
- * either return a ComponentHandler or a ComponentSelector
+ * either return a ComponentHandler or a ComponentSelector. Override this
+ * so that your container can translate the container's config to the default
+ * standard config.
*/
- protected Configuration rewriteConfiguration( final Configuration configItem )
- throws ConfigurationException
- {
- DefaultConfiguration temp =
- new DefaultConfiguration( "component",
- "AbstractContainer-rewrite [name: " + configItem.getName()
- + ", location: " + configItem.getLocation() + "]" );
-
- Class klass = m_roleManager.getClassForName( configItem.getName() );
- Class handlerKlass = m_roleManager.getHandlerClassForClass( klass );
- String role = m_roleManager.getRoleForClass( klass );
-
- if( null == klass )
- {
- throw new ConfigurationException( "No class found matching configuration name "
- + "[name: " + configItem.getName()
- + ", location: " + configItem.getLocation() + "]" );
- }
-
- //We set these before copying all other attributes so the class / handler can be overriden if needed if
- //the shorthand name is used
- temp.setAttribute( "role", role );
- temp.setAttribute( "class", klass.getName() );
- temp.setAttribute( "handler", handlerKlass.getName() );
-
- temp.setValue( configItem.getValue( null ) );
-
- String[] attributes = configItem.getAttributeNames();
- for( int i = 0; i < attributes.length; i++ )
- {
- temp.setAttribute( attributes[i], configItem.getAttribute( attributes[i] ) );
- }
-
- Configuration[] children = configItem.getChildren();
- for( int i = 0; i < children.length; i++ )
- {
- temp.addChild( children[ i ] );
- }
-
- temp.makeReadOnly();
-
- return temp;
- }
+ protected abstract Configuration rewriteConfiguration( final Configuration configItem )
+ throws ConfigurationException;
/**
* Add a Component.
@@ -276,8 +185,8 @@
hintMap.put( "default", handler );
}
- // FIXME(MC) is this always needed ? should only need to be done if
- // hintMap is not yet in m_mapper ? or is it here due to threading issues ?
+ // FIXME(MC) is this always needed ? should only need to be done if
+ // hintMap is not yet in m_mapper ? or is it here due to threading issues ?
m_mapper.put( role, hintMap );
}
}
@@ -553,7 +462,7 @@
*
* @return the child component manager
*/
- protected final ComponentManager getComponentManager()
+ protected ComponentManager getComponentManager()
{
// if a component manager is really needed
return new ServiceComponentManager( m_serviceManager );
1.1 jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/container/DefaultContainer.java
Index: DefaultContainer.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.excalibur.fortress.container;
import org.apache.excalibur.fortress.AbstractContainer;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.component.ComponentManager;
/**
* The Container is an interface used to mark the Containers in your system. It
* exposes a protected getServiceManager() method so that the
* Container's Manager can expose that to the instantiating class.
*
* @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
* @author <a href="mailto:proyal@apache.org">Peter Royal</a>
* @author <a href="mailto:crafterm@apache.org">Marcus Crafter</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/07/30 15:12:30 $
*/
public class DefaultContainer
extends AbstractContainer
implements Configurable
{
/**
* Process the configuration and set up the components and their mappings.
* At this point, all components are prepared and all mappings are made.
* However, nothing is initialized.
*
* <p>The native Configuration format follows a specific convention. If you
* use a RoleManager to map roles and implementations to more helpful names,
* we will internally rewrite the configuration to match this format. Please
* note: If a configuration element does *not* have a unique id, it will not
* be treated as a Component. That ID is used as the hint when there is more
* than one implementation of a role.</p>
*
* <pre>
* <component role="org.apache.avalon.excalibur.datasource.DataSourceComponent"
* id="default-connection"
* class="org.apache.avalon.excalibur.datasource.JdbcDataSourceComponent"
* handler="org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler">
*
* <!-- Component specific configuration -->
*
* </component>
* </pre>
*/
public void configure( Configuration configElement )
throws ConfigurationException
{
m_configuration = configElement;
Configuration elements[] = configElement.getChildren();
for( int i = 0; i < elements.length; i++ )
{
Configuration component = null;
Object hint = elements[ i ].getAttribute( "id", null );
if( null != hint )
{
if( "component".equals( elements[ i ].getName() ) )
{
component = elements[ i ];
}
else
{
component = rewriteConfiguration( elements[ i ] );
}
addComponent( component, hint );
}
}
}
/**
* Handles when a configuration name is used that is not "component", so it
* makes it easier to handle ComponentSelector hierarchies. It is meant to
* either return a ComponentHandler or a ComponentSelector
*/
protected Configuration rewriteConfiguration( final Configuration configItem )
throws ConfigurationException
{
DefaultConfiguration temp =
new DefaultConfiguration( "component",
"AbstractContainer-rewrite [name: " + configItem.getName()
+ ", location: " + configItem.getLocation() + "]" );
Class klass = m_roleManager.getClassForName( configItem.getName() );
Class handlerKlass = m_roleManager.getHandlerClassForClass( klass );
String role = m_roleManager.getRoleForClass( klass );
if( null == klass )
{
throw new ConfigurationException( "No class found matching configuration name "
+ "[name: " + configItem.getName()
+ ", location: " + configItem.getLocation() + "]" );
}
//We set these before copying all other attributes so the class / handler can be overriden if needed if
//the shorthand name is used
temp.setAttribute( "role", role );
temp.setAttribute( "class", klass.getName() );
temp.setAttribute( "handler", handlerKlass.getName() );
temp.setValue( configItem.getValue( null ) );
String[] attributes = configItem.getAttributeNames();
for( int i = 0; i < attributes.length; i++ )
{
temp.setAttribute( attributes[i], configItem.getAttribute( attributes[i] ) );
}
Configuration[] children = configItem.getChildren();
for( int i = 0; i < children.length; i++ )
{
temp.addChild( children[ i ] );
}
temp.makeReadOnly();
return temp;
}
public ComponentManager getComponentManager()
{
return super.getComponentManager();
}
}
1.17 +6 -3 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.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- ContextBuilder.java 30 Jul 2002 14:15:42 -0000 1.16
+++ ContextBuilder.java 30 Jul 2002 15:12:30 -0000 1.17
@@ -24,11 +24,12 @@
* The default values are:
*
* <ul>
+ * <li>CONTAINER_CLASS = "org.apache.excalibur.fortress.container.DefaultContainer" </li>
* <li>THREADS_CPU = 2</li>
* <li>THREAD_TIMEOUT = 1000</li>
- * <li>CONTEXT_DIRECTORY = "./"</li>
+ * <li>CONTEXT_DIRECTORY = "../"</li>
* <li>WORK_DIRECTORY = "/tmp"</li>
- * <li>LOG_CATEGORY = "test"</li>
+ * <li>LOG_CATEGORY = "fortress"</li>
* <li>CONTEXT_CLASSLOADER = the thread context class loader</li>
* </ul>
*/
@@ -62,9 +63,11 @@
{
DefaultContext defaultContext = new DefaultContext();
+ defaultContext.put( CONTAINER_CLASS,
+ "org.apache.excalibur.fortress.container.DefaultContainer" );
defaultContext.put( THREADS_CPU, new Integer( 2 ) );
defaultContext.put( THREAD_TIMEOUT, new Long( 1000 ) );
- defaultContext.put( CONTEXT_DIRECTORY, new File( "./" ) );
+ defaultContext.put( CONTEXT_DIRECTORY, new File( "../" ) );
defaultContext.put( WORK_DIRECTORY, new File( "/tmp" ) );
defaultContext.put( LOG_CATEGORY, "fortress" );
defaultContext.put( CONTEXT_CLASSLOADER, contextClassLoader );
1.19 +7 -6 jakarta-avalon-excalibur/fortress/src/test/org/apache/excalibur/fortress/test/ContainerProfile.java
Index: ContainerProfile.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/test/org/apache/excalibur/fortress/test/ContainerProfile.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- ContainerProfile.java 5 Jun 2002 16:45:54 -0000 1.18
+++ ContainerProfile.java 30 Jul 2002 15:12:30 -0000 1.19
@@ -24,10 +24,12 @@
import org.apache.avalon.framework.context.DefaultContext;
import org.apache.avalon.framework.logger.LogKitLogger;
import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.logger.NullLogger;
import org.apache.excalibur.fortress.ContainerManager;
import org.apache.excalibur.fortress.DefaultContainerManager;
import org.apache.excalibur.fortress.util.ContextBuilder;
import org.apache.excalibur.fortress.util.ContextManager;
+import org.apache.excalibur.fortress.container.DefaultContainer;
/**
* Used as a basis for the PoolComparisonProfile Tests
@@ -96,19 +98,18 @@
long cmStart = System.currentTimeMillis();
ContextBuilder contextBuilder = new ContextBuilder();
- contextBuilder.setContainerClass( "org.apache.excalibur.fortress.test.TestContainer" );
contextBuilder.setContextDirectory( "./" );
- contextBuilder.setWorkDirectory( "./" );
+ contextBuilder.setWorkDirectory( "./tmp" );
contextBuilder.setContainerConfiguration( "resource://org/apache/excalibur/fortress/test/ContainerProfile.xconf" );
contextBuilder.setLoggerManagerConfiguration( "resource://org/apache/excalibur/fortress/test/ContainerProfile.xlog" );
contextBuilder.setRoleManagerConfiguration( "resource://org/apache/excalibur/fortress/test/ContainerProfile.roles" );
- ContextManager contextManager = new ContextManager( contextBuilder.getContext(), null );
+ ContextManager contextManager = new ContextManager( contextBuilder.getContext(), new NullLogger() );
contextManager.initialize();
ContainerManager cm = new DefaultContainerManager( contextManager );
cm.initialize();
- TestContainer container = (TestContainer)cm.getContainer();
+ DefaultContainer container = (DefaultContainer)cm.getContainer();
assertNotNull( container );
long cmStop = System.currentTimeMillis();
long cmDuration = cmStop - cmStart;
@@ -129,7 +130,7 @@
resetMemory();
- lookupTest( "Test Case: ECM_ContainerManager_UseageTime", container.getCM(), manager );
+ lookupTest( "Test Case: ECM_ContainerManager_UseageTime", container.getComponentManager(), manager );
resetMemory();
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>