You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by do...@apache.org on 2002/11/11 07:28:52 UTC
cvs commit: jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/container ComponentHandlerMetaData.java AbstractContainer.java ComponentHandlerEntry.java DefaultContainer.java
donaldp 2002/11/10 22:28:52
Modified: fortress/src/java/org/apache/excalibur/fortress/container
AbstractContainer.java ComponentHandlerEntry.java
DefaultContainer.java
Added: fortress/src/java/org/apache/excalibur/fortress/container
ComponentHandlerMetaData.java
Log:
Migrate to using real metadata structures to hold handler metadata.
Revision Changes Path
1.18 +11 -66 jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/container/AbstractContainer.java
Index: AbstractContainer.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/container/AbstractContainer.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- AbstractContainer.java 11 Nov 2002 00:10:01 -0000 1.17
+++ AbstractContainer.java 11 Nov 2002 06:28:51 -0000 1.18
@@ -57,7 +57,6 @@
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.container.ContainerUtil;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.ContextException;
@@ -80,8 +79,8 @@
import org.apache.excalibur.fortress.lookup.FortressServiceManager;
import org.apache.excalibur.fortress.lookup.FortressServiceSelector;
import org.apache.excalibur.fortress.role.ExcaliburRoleManager;
-import org.apache.excalibur.fortress.role.RoleManager;
import org.apache.excalibur.fortress.role.RoleEntry;
+import org.apache.excalibur.fortress.role.RoleManager;
import org.apache.excalibur.instrument.InstrumentManager;
import org.apache.excalibur.instrument.Instrumentable;
import org.apache.excalibur.mpool.ObjectFactory;
@@ -95,6 +94,7 @@
* @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>
+ * @author <a href="mailto:peter at apache.org">Peter Donald</a>
* @version CVS $Revision$ $Date$
*/
public abstract class AbstractContainer
@@ -109,7 +109,6 @@
protected ClassLoader m_classLoader;
protected RoleManager m_roleManager;
protected InstrumentManager m_instrumentManager;
- protected Configuration m_configuration;
protected Map m_mapper = new StaticBucketMap();
protected List m_components = new ArrayList( 10 );
protected LifecycleExtensionManager m_extManager;
@@ -222,29 +221,11 @@
}
/**
- * 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.
- * Override this so that your container can translate the container's
- * config to the default standard config.
- */
- protected abstract Configuration rewriteConfiguration( final Configuration configItem )
- throws ConfigurationException;
-
- /**
* Add a Component.
*/
- protected void addComponent( final Configuration component, Object hint )
+ protected void addComponent( final ComponentHandlerMetaData metaData )
{
- if( null == hint )
- {
- final String message = "Hint must not be null";
- throw new IllegalArgumentException( message );
- }
-
- final String classname = component.getAttribute( "class", null );
- boolean isLazy = isLazyComponentHandler( component );
-
+ final String classname = metaData.getClassname();
final RoleEntry roleEntry = m_roleManager.getRoleForClassname( classname );
if( null == roleEntry )
{
@@ -253,7 +234,7 @@
}
final ComponentHandler handler =
- getComponentHandler( roleEntry, component, isLazy );
+ getComponentHandler( roleEntry, metaData );
final String role = roleEntry.getRole();
@@ -266,7 +247,7 @@
hintMap = new StaticBucketMap();
}
- hintMap.put( hint, handler );
+ hintMap.put( metaData.getName(), handler );
if( hintMap.containsKey( "default" ) )
{
@@ -287,55 +268,19 @@
}
}
- /**
- * Helper method to determine whether a given component handler
- * configuration requests a lazy or startup based initialization policy.
- *
- * @param component <code>Configuration</code>
- *
- * @return true if the given handler configuration specifies a lazy init
- * policy, false otherwise
- *
- * @throws java.lang.IllegalArgumentException if the handler specifies an unknown init
- * policy
- */
- private boolean isLazyComponentHandler( Configuration component )
- {
- String policy = component.getAttribute( "activation", null );
-
- final boolean policyUnspecified = policy == null;
- final boolean isLazy = "request".equalsIgnoreCase( policy );
- final boolean isNonLazy = "startup".equalsIgnoreCase( policy );
-
- if( policyUnspecified || isNonLazy )
- {
- return false;
- }
- else if( isLazy )
- {
- return true;
- }
-
- // policy was not null, but didn't match anything above
- final String classname = component.getAttribute( "class", null );
-
- final String message =
- "Unknown activation policy for class " + classname + ": " + policy;
- throw new IllegalArgumentException( message );
- }
/**
* Get a ComponentHandler with the standard
* <code>HANDLER_CONSTRUCTOR</code> for the component class passed in.
*/
private ComponentHandler getComponentHandler( final RoleEntry roleEntry,
- final Configuration configuration,
- final boolean isLazy )
+ final ComponentHandlerMetaData metaData )
{
ComponentHandler handler = null;
final String classname = roleEntry.getComponentClass().getName();
try
{
+ final Configuration configuration = metaData.getConfiguration();
final ObjectFactory factory =
createObjectFactory( classname, configuration );
@@ -384,7 +329,7 @@
}
final ComponentHandlerEntry entry =
- new ComponentHandlerEntry( handler, isLazy );
+ new ComponentHandlerEntry( handler, metaData );
m_components.add( entry );
return handler;
@@ -516,7 +461,7 @@
{
final ComponentHandlerEntry entry = (ComponentHandlerEntry)i.next();
final ComponentHandler handler = entry.getHandler();
- if( !entry.isLazy() )
+ if( !entry.getMetaData().isLazyActivation() )
{
if( null != m_commandQueue )
{
1.3 +14 -9 jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/container/ComponentHandlerEntry.java
Index: ComponentHandlerEntry.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/container/ComponentHandlerEntry.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ComponentHandlerEntry.java 9 Nov 2002 09:14:37 -0000 1.2
+++ ComponentHandlerEntry.java 11 Nov 2002 06:28:52 -0000 1.3
@@ -19,24 +19,29 @@
class ComponentHandlerEntry
{
private final ComponentHandler m_handler;
- private final boolean m_isLazy;
+ private final ComponentHandlerMetaData m_metaData;
/**
* Create an entry for a particular handler.
*
* @param handler the handler
- * @param lazy true if handler should be lazily prepared
+ * @param metaData the metadata for handler
*/
public ComponentHandlerEntry( final ComponentHandler handler,
- final boolean lazy )
+ final ComponentHandlerMetaData metaData )
{
if( null == handler )
{
throw new NullPointerException( "handler" );
}
+ if( null == metaData )
+ {
+ throw new NullPointerException( "metaData" );
+ }
+
m_handler = handler;
- m_isLazy = lazy;
+ m_metaData= metaData;
}
/**
@@ -50,12 +55,12 @@
}
/**
- * Return true if handler should be lazily prepared.
+ * Return the meta data for handler.
*
- * @return true if handler should be lazily prepared.
+ * @return the meta data for handler.
*/
- public boolean isLazy()
+ public ComponentHandlerMetaData getMetaData()
{
- return m_isLazy;
+ return m_metaData;
}
}
1.14 +63 -46 jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/container/DefaultContainer.java
Index: DefaultContainer.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/container/DefaultContainer.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- DefaultContainer.java 11 Nov 2002 01:53:30 -0000 1.13
+++ DefaultContainer.java 11 Nov 2002 06:28:52 -0000 1.14
@@ -52,7 +52,6 @@
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.service.ServiceManager;
import org.apache.excalibur.fortress.role.RoleEntry;
@@ -63,6 +62,7 @@
* @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>
+ * @author <a href="mailto:peter at apache.org">Peter Donald</a>
* @version CVS $Revision$ $Date$
*/
public class DefaultContainer
@@ -93,76 +93,93 @@
* </component>
* </pre>
*
- * @param configElement The configuration element to translate into the
+ * @param config The configuration element to translate into the
* list of components this container managers.
*
* @throws ConfigurationException if the configuration is not valid
*/
- public void configure( Configuration configElement )
+ public void configure( final Configuration config )
throws ConfigurationException
{
- m_configuration = configElement;
-
- Configuration elements[] = configElement.getChildren();
-
+ final Configuration[] elements = config.getChildren();
for( int i = 0; i < elements.length; i++ )
{
- Configuration component = null;
- Object hint = elements[ i ].getAttribute( "id", null );
-
+ final Configuration element = elements[ i ];
+ final String hint = element.getAttribute( "id", null );
if( null != hint )
{
- if( "component".equals( elements[ i ].getName() ) )
- {
- component = elements[ i ];
- }
- else
- {
- component = rewriteConfiguration( elements[ i ] );
- }
+ final String classname = getClassname( element );
+ final boolean isLazy = isLazyComponentHandler( element );
+ final ComponentHandlerMetaData metaData =
+ new ComponentHandlerMetaData( hint, classname, element, isLazy );
- addComponent( component, hint );
+ addComponent( metaData );
}
}
}
/**
- * 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 ServiceSelector.
+ * Retrieve the classname for component configuration.
*
- * @param config The configuration snippet to translate into the
- * standard format.
- *
- * @return <code>Configuration</code> representing the native format.
- *
- * @throws ConfigurationException if the configuration is invalid
+ * @param config the component configuration
+ * @return the class name
*/
- protected Configuration rewriteConfiguration( final Configuration config )
+ private String getClassname( final Configuration config )
throws ConfigurationException
{
- final RoleEntry roleEntry = m_roleManager.getRoleForShortName( config.getName() );
- if( null == roleEntry )
+ if( "component".equals( config.getName() ) )
{
- final String message = "No class found matching configuration name " +
- "[name: " + config.getName() + ", location: " + config.getLocation() + "]";
- throw new ConfigurationException( message );
+ return config.getAttribute( "class" );
}
+ else
+ {
+ final RoleEntry roleEntry = m_roleManager.getRoleForShortName( config.getName() );
+ if( null == roleEntry )
+ {
+ final String message = "No class found matching configuration name " +
+ "[name: " + config.getName() + ", location: " + config.getLocation() + "]";
+ throw new ConfigurationException( message );
+ }
+ return roleEntry.getComponentClass().getName();
+ }
+ }
- final String location = "AbstractContainer-rewrite [name: " +
- config.getName() + ", location: " + config.getLocation() + "]";
- final DefaultConfiguration newConfig =
- new DefaultConfiguration( "component", location );
-
- newConfig.addAll( config );
+ /**
+ * Helper method to determine whether a given component handler
+ * configuration requests a lazy or startup based initialization policy.
+ *
+ * @param component <code>Configuration</code>
+ *
+ * @return true if the given handler configuration specifies a lazy init
+ * policy, false otherwise
+ *
+ * @throws java.lang.IllegalArgumentException if the handler specifies an unknown init
+ * policy
+ */
+ private boolean isLazyComponentHandler( Configuration component )
+ {
+ String policy = component.getAttribute( "activation", "startup" );
- //We set these before copying all other attributes so the class / handler can be overriden if needed if
- //the shorthand name is used
- newConfig.setAttribute( "class", roleEntry.getComponentClass().getName() );
+ final boolean isLazy = "request".equalsIgnoreCase( policy );
+ final boolean isNonLazy = "startup".equalsIgnoreCase( policy );
- newConfig.makeReadOnly();
+ if( isNonLazy )
+ {
+ return false;
+ }
+ else if( isLazy )
+ {
+ return true;
+ }
+ else
+ {
+ // policy was not null, but didn't match anything above
+ final String classname = component.getAttribute( "class", null );
- return newConfig;
+ final String message =
+ "Unknown activation policy for class " + classname + ": " + policy;
+ throw new IllegalArgumentException( message );
+ }
}
/**
1.1 jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/container/ComponentHandlerMetaData.java
Index: ComponentHandlerMetaData.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.avalon.framework.configuration.Configuration;
/**
* A class to containe metadata about a component handler.
*
* @author <a href="mailto:peter at apache.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/11/11 06:28:52 $
*/
public class ComponentHandlerMetaData
{
private final String m_name;
private final String m_classname;
private final Configuration m_configuration;
private final boolean m_lazyActivation;
public ComponentHandlerMetaData( final String name,
final String classname,
final Configuration configuration,
final boolean lazyActivation )
{
if( null == name )
{
throw new NullPointerException( "name" );
}
if( null == classname )
{
throw new NullPointerException( "classname" );
}
if( null == configuration )
{
throw new NullPointerException( "configuration" );
}
m_name = name;
m_classname = classname;
m_configuration = configuration;
m_lazyActivation = lazyActivation;
}
public String getName()
{
return m_name;
}
public String getClassname()
{
return m_classname;
}
public Configuration getConfiguration()
{
return m_configuration;
}
public boolean isLazyActivation()
{
return m_lazyActivation;
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>