bloritsch 02/01/30 07:44:06
Modified: src/scratchpad/org/apache/avalon/excalibur/system
AbstractContainer.java ConfigurableRoleManager.java
ExcaliburRoleManager.java RoleManager.java
src/scratchpad/org/apache/avalon/excalibur/system/handler
ComponentHandler.java
Added: src/scratchpad/org/apache/avalon/excalibur/system
AbstractRoleManager.java
Log:
Final AbstractContainer done
Revision Changes Path
1.4 +188 -13
jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/AbstractContainer.java
Index: AbstractContainer.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/AbstractContainer.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AbstractContainer.java 29 Jan 2002 19:11:17 -0000 1.3
+++ AbstractContainer.java 30 Jan 2002 15:44:06 -0000 1.4
@@ -28,25 +28,20 @@
import java.util.List;
import java.util.Map;
+import java.lang.reflect.Constructor;
+
/**
* The Container is an interface used to mark the Containers in your system.
It
* exposes a protected getComponentManager() method so that the Container's
* Manager can expose that to the instantiating class.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
- * @version CVS $Revision: 1.3 $ $Date: 2002/01/29 19:11:17 $
+ * @version CVS $Revision: 1.4 $ $Date: 2002/01/30 15:44:06 $
*/
public abstract class AbstractContainer
extends AbstractLogEnabled
implements Contextualizable, Composable, Configurable, Initializable,
Disposable
{
- private final static Class[] HANDLER_CONSTRUCTOR = new Class[] {
- Class.class,
- Configuration.class,
- ComponentManager.class,
- Context.class
- };
-
private final ComponentStateValidator m_validator = new
ComponentStateValidator( this );
private Context m_context;
@@ -123,6 +118,156 @@
{
m_validator.checkConfigured();
m_configuration = configElement;
+ Map managerMap = new HashMap();
+ m_childManager = new ContainerComponentManager( managerMap,
m_manager );
+
+ Configuration[] components = configElement.getChildren();
+
+ for ( int i = 0; i < components.length; i++ )
+ {
+ final String name = components[ i ].getName();
+ String role;
+ Class klass;
+ Class handlerKlass;
+ Configuration config = null;
+
+ if ( name.equals( "component" ) )
+ {
+ config = components[ i ];
+ role = config.getAttribute( "role" );
+
+ try
+ {
+ klass = m_classLoader.loadClass( config.getAttribute(
"class" ) );
+ handlerKlass = m_classLoader.loadClass(
config.getAttribute( "handler" ) );
+ }
+ catch ( Exception e )
+ {
+ if ( getLogger().isDebugEnabled() )
+ {
+ getLogger().debug( "Component class '" +
config.getAttribute( "class" ) +
+ "' is not valid.", e );
+ }
+ continue;
+ }
+
+ assignHandler( getHandler( handlerKlass, klass, config ),
config, managerMap );
+ }
+ else
+ {
+ handleConfiguration( components[ i ], managerMap );
+ }
+ }
+ }
+
+ /**
+ * 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 void handleConfiguration( final Configuration configItem,
+ final Map managerMap )
+ throws ConfigurationException
+ {
+ DefaultConfiguration temp = new DefaultConfiguration( "component",
"AbstractContainer-rewrite" );
+ Class klass = m_roleManager.getClassForName( configItem.getName() );
+ Class handlerKlass = m_roleManager.getHandlerClassForClass( klass );
+ String role = m_roleManager.getRoleForClass( klass );
+
+ temp.setAttribute( "role", role );
+ temp.setAttribute( "class", klass.getName() );
+ temp.setAttribute( "handler", handlerKlass.getName() );
+
+ final String id = configItem.getAttribute( "id", null );
+ if ( null != id )
+ {
+ temp.setAttribute( "id", id );
+ }
+
+ Configuration[] children = configItem.getChildren();
+ for ( int i = 0; i < children.length; i++ )
+ {
+ temp.addChild( children[ i ] );
+ }
+
+ temp.makeReadOnly();
+
+ assignHandler( getHandler( klass, handlerKlass, temp ), temp,
managerMap );
+ }
+
+ /**
+ * Adds the ComponentHandler and Configuration to the system.
+ */
+ protected void assignHandler( ComponentHandler handler, Configuration
config, Map managerMap )
+ throws ConfigurationException
+ {
+ m_components.add( handler );
+ m_configs.put( handler, config );
+ String role = config.getAttribute( "role" );
+
+ Object contents = managerMap.get( role );
+ if ( null == contents )
+ {
+ managerMap.put( role, handler );
+ }
+ else
+ {
+ if ( contents instanceof ComponentHandler )
+ {
+ Map selectorMap = new HashMap( 3 );
+ selectorMap.put( ( (Configuration) m_configs.get(contents) )
+ .getAttribute( "id", "1" ), contents );
+ selectorMap.put( config.getAttribute( "id", "2" ), contents
);
+
+ assignSelector( role, new ContainerComponentSelector(
selectorMap ), managerMap );
+ }
+ else if ( contents instanceof ContainerComponentSelector )
+ {
+ ( (ContainerComponentSelector) contents )
+ .addComponentHandler( config.getAttribute( "id", null ),
+ handler);
+ }
+ }
+ }
+
+ /**
+ * Adds the ComponentHandler and Configuration to the system.
+ */
+ protected void assignSelector( String role, ComponentSelector selector,
Map managerMap )
+ throws ConfigurationException
+ {
+ managerMap.put( role, selector );
+ }
+
+ /**
+ * Get a ComponentHandler with the standard
<code>HANDLER_CONSTRUCTOR</code>
+ * for the component class passed in.
+ */
+ protected ComponentHandler getHandler( Class handlerKlass,
+ Class klass,
+ Configuration configuration )
+ {
+ Constructor constructor;
+ ComponentHandler handler = null;
+
+ try
+ {
+ constructor = handlerKlass.getConstructor(
ComponentHandler.HANDLER_CONSTRUCTOR );
+ handler = (ComponentHandler) constructor.newInstance(new
Object[] {
+ klass, configuration, m_childManager, m_context
+ });
+ }
+ catch ( Exception e )
+ {
+ if ( getLogger().isDebugEnabled() )
+ {
+ getLogger().debug( "Could not create the '" +
handlerKlass.getName() +
+ "' handler for the '" + klass.getName() +
+ "' component.", e );
+ }
+ }
+
+ return handler;
}
/**
@@ -225,18 +370,26 @@
* a very simple abstraction, and makes it easy for the Container to
manage
* the references.
*/
- private final static class ContainerComponentManager
+ protected final static class ContainerComponentManager
implements ComponentManager
{
private final Map m_components;
private final Map m_used;
private final ComponentManager m_parent;
+ /**
+ * This constructor is for a ContainerComponentManager with no parent
+ * ComponentManager
+ */
protected ContainerComponentManager( Map componentMap )
{
this( componentMap, null );
}
+ /**
+ * This constructor is for a ContainerComponentManager with a parent
+ * ComponentManager
+ */
protected ContainerComponentManager( Map componentMap,
ComponentManager parent )
{
m_parent = null;
@@ -247,7 +400,19 @@
public Component lookup( String role )
throws ComponentException
{
- ComponentHandler handler = (ComponentHandler) m_components.get(
role );
+ Object temp = m_components.get( role );
+
+ if ( temp instanceof ComponentSelector )
+ {
+ return (ComponentSelector) temp;
+ }
+
+ if ( ! ( temp instanceof ComponentHandler ) )
+ {
+ throw new ComponentException( "Invalid entry in component
manager: " + temp );
+ }
+
+ ComponentHandler handler = (ComponentHandler) temp;
if ( null == handler )
{
@@ -321,15 +486,15 @@
* a very simple abstraction, and makes it easy for the Container to
manage
* the references.
*/
- private final static class ContainerComponentSelector
+ protected final static class ContainerComponentSelector
implements ComponentSelector
{
private final Map m_components;
private final Map m_used;
- protected ContainerComponentSelector( Map componentMap )
+ protected ContainerComponentSelector( Map selectorMap )
{
- m_components = componentMap;
+ m_components = selectorMap;
m_used = new HashMap( m_components.size() );
}
@@ -382,6 +547,16 @@
}
handler.put( component );
+ }
+
+ protected void addComponentHandler( Object hint, ComponentHandler
handler )
+ {
+ if ( null == hint )
+ {
+ hint = new Integer( m_components.size() ).toString();
+ }
+
+ m_components.put( hint, handler );
}
}
1.3 +21 -198
jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/ConfigurableRoleManager.java
Index: ConfigurableRoleManager.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/ConfigurableRoleManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ConfigurableRoleManager.java 28 Jan 2002 22:04:50 -0000 1.2
+++ ConfigurableRoleManager.java 30 Jan 2002 15:44:06 -0000 1.3
@@ -21,39 +21,22 @@
* in the org.apache.avalon.component package.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
- * @author <a href="mailto:[EMAIL PROTECTED]">Ricardo Rocha</a>
- * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
- * @version CVS $Revision: 1.2 $ $Date: 2002/01/28 22:04:50 $
+ * @version CVS $Revision: 1.3 $ $Date: 2002/01/30 15:44:06 $
* @since 4.1
*/
public class ConfigurableRoleManager
- implements RoleManager, Configurable
+ extends AbstractRoleManager
+ implements Configurable
{
- private static final String EMPTY_STRING = "";
-
- /** Map for shorthand to role mapping */
- private Map m_shorthands;
-
- /** Map for role to default classname mapping */
- private Map m_classNames;
-
- /** Map for role to default classname mapping */
- private Map m_handlerNames;
-
- /** Map for role->hint to classname mapping */
- private Map m_hintClassNames;
-
- /** Parent <code>RoleManager</code> for nested resolution */
- private final RoleManager m_parent;
-
/**
* Default constructor--this RoleManager has no parent.
*/
public ConfigurableRoleManager()
{
- m_parent = null;
+ super( null );
}
+
/**
* Alternate constructor--this RoleManager has the specified
* parent.
@@ -62,157 +45,20 @@
*/
public ConfigurableRoleManager(RoleManager parent)
{
- m_parent = parent;
- }
-
- /**
- * Retrieves the real role name from a shorthand name. Usually
- * the shorthand name refers to a configuration element name. If
- * this RoleManager does not have the match, and there is a parent
- * RoleManager, the parent will be asked to resolve the role.
- *
- * @param shorthandName The shortname that is an alias for the role.
- * @return the official role name.
- */
- public final String getRoleForName( final String shorthandName )
- {
- final String role = (String)m_shorthands.get( shorthandName );
-
- if( null == role && null != m_parent )
- {
- return m_parent.getRoleForName( shorthandName );
- }
-
- return role;
- }
-
- /**
- * Retrieves the real role name from a shorthand name. Usually
- * the shorthand name refers to a configuration element name. If
- * this RoleManager does not have the match, and there is a parent
- * RoleManager, the parent will be asked to resolve the role.
- *
- * @param shorthandName The shortname that is an alias for the role.
- * @return the official role name.
- */
- public final String getNameForRole( final String role )
- {
- final String shorthandName = (String)m_shorthands.get( role );
-
- if( null == shorthandName && null != m_parent )
- {
- return m_parent.getNameForRole( role );
- }
-
- return role;
+ super( parent, Thread.currentThread().getContextClassLoader() );
}
/**
- * Retrieves the default class name for the specified role. This
- * is only called when the configuration does not specify the
- * class explicitly. If this RoleManager does not have the match,
- * and there is a parent RoleManager, the parent will be asked
- * to resolve the class name.
- *
- * @param role The role that has a default implementation.
- * @return the Fully Qualified Class Name (FQCN) for the role.
- */
- public final String getDefaultClassNameForRole( final String role )
- {
- final String className = (String)m_classNames.get( role );
-
- if( null == className && null != m_parent )
- {
- return m_parent.getDefaultClassNameForRole( role );
- }
-
- return className;
- }
-
- /**
- * Retrieves the handler class name for the specified class name. This
- * is called for every ComponentImplementation. 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 role The role that has a default implementation.
- * @return the Fully Qualified Class Name (FQCN) for the role.
- */
- public final String getHandlerClassNameForClassname( final String
className )
- {
- final String handlerName = (String)m_handlerNames.get( className );
-
- if( null == handlerName && null != m_parent )
- {
- return m_parent.getHandlerClassNameForClassname( className );
- }
-
- return handlerName;
- }
-
- /**
- * Retrieves a default class name for a role/hint combination.
- * This is only called when a role is mapped to a
- * DefaultComponentSelector, and the configuration elements use
- * shorthand names for the type of component. If this RoleManager
- * does not have the match, and there is a parent RoleManager, the
- * parent will be asked to resolve the class name.
+ * Alternate constructor--this RoleManager has the specified
+ * parent and a classloader.
*
- * @param role The role that this shorthand refers to.
- * @param shorthand The shorthand name for the type of Component
- * @return the FQCN for the role/hint combination.
+ * @param parent The parent <code>RoleManager</code>.
*/
- public final String getDefaultClassNameForHint( final String hintType,
- final String role )
+ public ConfigurableRoleManager(RoleManager parent, ClassLoader loader)
{
- final Map hintMap = (Map)m_hintClassNames.get( role );
-
- if( null == hintMap )
- {
- if( null != m_parent )
- {
- return m_parent.getDefaultClassNameForHint( hintType, role );
- }
- else
- {
- return EMPTY_STRING;
- }
- }
-
- return (String)hintMap.get( hintType );
+ super( parent, loader );
}
- /**
- * Retrieves a default class name for a role/hint combination.
- * This is only called when a role is mapped to a
- * DefaultComponentSelector, and the configuration elements use
- * shorthand names for the type of component. If this RoleManager
- * does not have the match, and there is a parent RoleManager, the
- * parent will be asked to resolve the class name.
- *
- * @param role The role that this shorthand refers to.
- * @param shorthand The shorthand name for the type of Component
- * @return the FQCN for the role/hint combination.
- */
- public final String getAliasForHintType( final String className,
- final String role )
- {
- final Map hintMap = (Map)m_hintClassNames.get( role );
-
- if( null == hintMap )
- {
- if( null != m_parent )
- {
- return m_parent.getAliasForHintType( className, role );
- }
- else
- {
- return EMPTY_STRING;
- }
- }
-
- return (String)hintMap.get( className );
- }
/**
* Reads a configuration object and creates the role, shorthand,
@@ -233,47 +79,24 @@
for( int i = 0; i < roles.length; i++ )
{
- final String name = roles[ i ].getAttribute( "name" );
- final String shorthand = roles[ i ].getAttribute( "shorthand" );
- final String defaultClassName =
- roles[ i ].getAttribute( "default-class", null );
- final String handlerClassName =
- roles[ i ].getAttribute( "handler",
-
"org.apache.avalon.excalibur.system.handler.PerThreadComponentHandler" );
-
- shorts.put( shorthand, name );
- shorts.put( name, shorthand );
+ final String role = roles[ i ].getAttribute( "name" );
+ Configuration[] components = roles[i].getChildren( "component" );
- if( null != defaultClassName )
+ for ( int j = 0; i < components.length; j++)
{
- classes.put( name, defaultClassName );
- handlers.put( defaultClassName, handlerClassName );
- }
-
- final Configuration[] hints = roles[ i ].getChildren( "hint" );
- if( hints.length > 0 )
- {
- HashMap hintMap = new HashMap();
-
- for( int j = 0; j < hints.length; j++ )
- {
- final String shortHand = hints[ j
].getAttribute("shorthand").trim();
- final String className = hints[ j
].getAttribute("class").trim();
- final String handlerName = hints[ j ].getAttribute(
"handler",
-
"org.apache.avalon.excalibur.system.handler.PerThreadComponentHandler" );
-
- hintMap.put( shortHand, className );
- hintMap.put( className, shortHand );
- handlers.put( className, handlerName );
- }
+ final String shorthand = components[ j ].getAttribute(
"shorthand" );
+ final String className =
+ components[ j ].getAttribute( "class", null );
+ final String handlerClassName =
+ components[ j ].getAttribute( "handler",
+
"org.apache.avalon.excalibur.system.handler.PerThreadComponentHandler" );
- hintclasses.put( name, Collections.unmodifiableMap( hintMap
) );
+ setup( shorts, classes, handlers, shorthand, role,
className, handlerClassName );
}
}
m_shorthands = Collections.unmodifiableMap( shorts );
m_classNames = Collections.unmodifiableMap( classes );
m_handlerNames = Collections.unmodifiableMap( handlers );
- m_hintClassNames = Collections.unmodifiableMap( hintclasses );
}
}
1.3 +76 -265
jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/ExcaliburRoleManager.java
Index: ExcaliburRoleManager.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/ExcaliburRoleManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ExcaliburRoleManager.java 28 Jan 2002 22:04:50 -0000 1.2
+++ ExcaliburRoleManager.java 30 Jan 2002 15:44:06 -0000 1.3
@@ -7,8 +7,12 @@
*/
package org.apache.avalon.excalibur.system;
+import org.apache.avalon.framework.component.Component;
+
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
/**
@@ -16,35 +20,18 @@
* information is hard-coded.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
- * @version CVS $Revision: 1.2 $ $Date: 2002/01/28 22:04:50 $
+ * @version CVS $Revision: 1.3 $ $Date: 2002/01/30 15:44:06 $
* @since 4.1
*/
public class ExcaliburRoleManager
- implements RoleManager
+ extends AbstractRoleManager
{
- private static final String EMPTY_STRING = "";
-
- /** Map for shorthand to role mapping */
- private Map m_shorthands;
-
- /** Map for role to default classname mapping */
- private Map m_classNames;
-
- /** Map for role to handler classname mapping */
- private Map m_handlerNames;
-
- /** Map for role->hint to classname mapping */
- private Map m_hintClassNames;
-
- /** Parent <code>RoleManager</code> for nested resolution */
- private final RoleManager m_parent;
-
/**
* Default constructor--this RoleManager has no parent.
*/
public ExcaliburRoleManager()
{
- this( null );
+ super( null );
}
/**
@@ -55,267 +42,91 @@
*/
public ExcaliburRoleManager(RoleManager parent)
{
- m_parent = parent;
+ super( parent, Thread.currentThread().getContextClassLoader() );
+ }
+
+ /**
+ * Alternate constructor--this RoleManager has the specified
+ * parent and a classloader.
+ *
+ * @param parent The parent <code>RoleManager</code>.
+ */
+ public ExcaliburRoleManager(RoleManager parent, ClassLoader loader)
+ {
+ super( parent, loader );
+
HashMap shorts = new HashMap( 10 );
HashMap classes = new HashMap( 10 );
- HashMap hints = new HashMap( 5 );
HashMap handlers = new HashMap( 10 );
+ /* Set up Cache relations */
+ setup( shorts, classes, handlers, "cache",
+ "org.apache.avalon.excalibur.cache.Cache",
+ "org.apache.avalon.excalibur.cache.DefaultCache",
+
"org.apache.avalon.excalibur.system.handler.ThreadSafeComponentHandler" );
+ setup( shorts, classes, handlers, "lru-cache",
+ "org.apache.avalon.excalibur.cache.Cache",
+ "org.apache.avalon.excalibur.cache.LRUCache",
+
"org.apache.avalon.excalibur.system.handler.ThreadSafeComponentHandler" );
+
/* Set up DataSource relations */
- shorts.put( "datasource",
"org.apache.avalon.excalibur.datasource.DataSourceComponent" );
- shorts.put(
"org.apache.avalon.excalibur.datasource.DataSourceComponent", "datasource" );
- classes.put(
"org.apache.avalon.excalibur.datasource.DataSourceComponent",
- "org.apache.avalon.excalibur.datasource.JdbcDataSource"
);
- classes.put( "org.apache.avalon.excalibur.datasource.JdbcDataSource",
-
"org.apache.avalon.excalibur.datasource.DataSourceComponent" );
-
- shorts.put( "datasources",
"org.apache.avalon.excalibur.datasource.DataSourceComponentSelector" );
- shorts.put(
"org.apache.avalon.excalibur.datasource.DataSourceComponentSelector",
"datasources" );
- classes.put(
"org.apache.avalon.excalibur.datasource.DataSourceComponentSelector",
-
"org.apache.avalon.excalibur.datasource.ExcaliburComponentSelector" );
- classes.put(
"org.apache.avalon.excalibur.datasource.ExcaliburComponentSelector",
-
"org.apache.avalon.excalibur.datasource.DataSourceComponentSelector" );
- HashMap dsMap = new HashMap( 3 );
- dsMap.put( "jdbc",
"org.apache.avalon.excalibur.datasource.JdbcDataSource" );
- dsMap.put( "org.apache.avalon.excalibur.datasource.JdbcDataSource",
"jdbc" );
- dsMap.put( "informix",
"org.apache.avalon.excalibur.datasource.InformixDataSource" );
- dsMap.put(
"org.apache.avalon.excalibur.datasource.InformixDataSource", "informix" );
- dsMap.put( "j2ee",
"org.apache.avalon.excalibur.datasource.J2eeDataSource" );
- dsMap.put( "org.apache.avalon.excalibur.datasource.J2eeDataSource",
"j2ee" );
- hints.put(
"org.apache.avalon.excalibur.datasource.DataSourceComponentSelector",
- Collections.unmodifiableMap( dsMap ) );
-
- handlers.put(
"org.apache.avalon.excalibur.datasource.JdbcDataSource",
-
"org.apache.avalon.excalibur.system.handler.ThreadSafeComponentHandler" );
- handlers.put(
"org.apache.avalon.excalibur.datasource.InformixDataSource",
-
"org.apache.avalon.excalibur.system.handler.ThreadSafeComponentHandler" );
- handlers.put(
"org.apache.avalon.excalibur.datasource.J2eeDataSource",
-
"org.apache.avalon.excalibur.system.handler.ThreadSafeComponentHandler" );
+ setup( shorts, classes, handlers, "jdbc-datasource",
+ "org.apache.avalon.excalibur.datasource.DataSourceComponent",
+ "org.apache.avalon.excalibur.datasource.JdbcDataSource",
+
"org.apache.avalon.excalibur.system.handler.ThreadSafeComponentHandler" );
+ setup( shorts, classes, handlers, "j2ee-datasource",
+ "org.apache.avalon.excalibur.datasource.DataSourceComponent",
+ "org.apache.avalon.excalibur.datasource.J2eeDataSource",
+
"org.apache.avalon.excalibur.system.handler.ThreadSafeComponentHandler" );
+ setup( shorts, classes, handlers, "informix-datasource",
+ "org.apache.avalon.excalibur.datasource.DataSourceComponent",
+ "org.apache.avalon.excalibur.datasource.InformixDataSource",
+
"org.apache.avalon.excalibur.system.handler.ThreadSafeComponentHandler" );
+
+ /* Set up i18n relations */
+ setup( shorts, classes, handlers, "i18n",
+ "org.apache.avalon.excalibur.i18n.BundleSelector",
+ "org.apache.avalon.excalibur.i18n.BundleSelector",
+
"org.apache.avalon.excalibur.system.handler.ThreadSafeComponentHandler" );
/* Set up Monitor relations */
- shorts.put( "monitor", "org.apache.avalon.excalibur.monitor.Monitor"
);
- shorts.put( "org.apache.avalon.excalibur.monitor.Monitor", "monitor"
);
- classes.put( "org.apache.avalon.excalibur.monitor.Monitor",
- "org.apache.avalon.excalibur.monitor.ActiveMonitor" );
- classes.put( "org.apache.avalon.excalibur.monitor.ActiveMonitor",
- "org.apache.avalon.excalibur.monitor.Monitor" );
-
- handlers.put( "org.apache.avalon.excalibur.monitor.ActiveMonitor",
-
"org.apache.avalon.excalibur.system.handler.ThreadSafeComponentHandler" );
- handlers.put( "org.apache.avalon.excalibur.monitor.PassiveMonitor",
-
"org.apache.avalon.excalibur.system.handler.ThreadSafeComponentHandler" );
+ setup( shorts, classes, handlers, "monitor",
+ "org.apache.avalon.excalibur.monitor.Monitor",
+ "org.apache.avalon.excalibur.monitor.ActiveMonitor",
+
"org.apache.avalon.excalibur.system.handler.ThreadSafeComponentHandler" );
+ setup( shorts, classes, handlers, "passive-monitor",
+ "org.apache.avalon.excalibur.monitor.Monitor",
+ "org.apache.avalon.excalibur.monitor.PassiveMonitor",
+
"org.apache.avalon.excalibur.system.handler.ThreadSafeComponentHandler" );
/* Set up XPath relations */
- shorts.put( "xpath",
"org.apache.avalon.excalibur.xml.xpath.XPathProcessor" );
- shorts.put( "org.apache.avalon.excalibur.xml.xpath.XPathProcessor",
"xpath" );
- classes.put( "org.apache.avalon.excalibur.xml.xpath.XPathProcessor",
-
"org.apache.avalon.excalibur.xml.xpath.XPathProcessorImpl" );
- classes.put(
"org.apache.avalon.excalibur.xml.xpath.XPathProcessorImpl",
- "org.apache.avalon.excalibur.xml.xpath.XPathProcessor"
);
-
- handlers.put(
"org.apache.avalon.excalibur.xml.xpath.XPathProcessorImpl",
-
"org.apache.avalon.excalibur.system.handler.ThreadSafeComponentHandler" );
- handlers.put(
"org.apache.avalon.excalibur.xml.xpath.JaxenProcessorImpl",
-
"org.apache.avalon.excalibur.system.handler.ThreadSafeComponentHandler" );
-
- /* Set up i18n relations */
- shorts.put( "i18n", "org.apache.avalon.excalibur.i18n.Bundle" );
- shorts.put( "org.apache.avalon.excalibur.i18n.Bundle", "i18n" );
- classes.put( "org.apache.avalon.excalibur.i18n.Bundle",
- "org.apache.avalon.excalibur.i18n.BundleSelector" );
- classes.put( "org.apache.avalon.excalibur.i18n.BundleSelector",
- "org.apache.avalon.excalibur.i18n.Bundle" );
- HashMap bundleMap = new HashMap( 3 );
- bundleMap.put( "xml", "org.apache.avalon.excalibur.i18n.XmlBundle" );
- bundleMap.put( "org.apache.avalon.excalibur.i18n.XmlBundle", "xml" );
- bundleMap.put( "flat",
"org.apache.avalon.excalibur.i18n.FlatXmlBundle" );
- bundleMap.put( "org.apache.avalon.excalibur.i18n.FlatXmlBundle",
"flat" );
- hints.put(
"org.apache.avalon.excalibur.datasource.DataSourceComponentSelector",
- Collections.unmodifiableMap( bundleMap ) );
-
- handlers.put( "org.apache.avalon.excalibur.i18n.BundleSelector",
-
"org.apache.avalon.excalibur.system.handler.ThreadSafeComponentHandler" );
- handlers.put( "org.apache.avalon.excalibur.i18n.XmlBundle",
-
"org.apache.avalon.excalibur.system.handler.PerThreadComponentHandler" );
- handlers.put( "org.apache.avalon.excalibur.i18n.FlatXmlBundle",
-
"org.apache.avalon.excalibur.system.handler.PerThreadComponentHandler" );
+ setup( shorts, classes, handlers, "xalan-xpath",
+ "org.apache.avalon.excalibur.xml.xpath.XPathProcessor",
+ "org.apache.avalon.excalibur.xml.xpath.XPathProcessorImpl",
+
"org.apache.avalon.excalibur.system.handler.ThreadSafeComponentHandler" );
+ setup( shorts, classes, handlers, "jaxpath",
+ "org.apache.avalon.excalibur.xml.xpath.XPathProcessor",
+ "org.apache.avalon.excalibur.xml.xpath.JaxenProcessorImpl",
+
"org.apache.avalon.excalibur.system.handler.ThreadSafeComponentHandler" );
/* Set up SourceResolver relations */
- shorts.put( "resolver",
"org.apache.avalon.excalibur.source.SourceResolver" );
- shorts.put( "org.apache.avalon.excalibur.source.SourceResolver",
"resolver" );
- classes.put( "org.apache.avalon.excalibur.source.SourceResolver",
- "org.apache.avalon.excalibur.source.SourceResolverImpl"
);
- classes.put( "org.apache.avalon.excalibur.source.SourceResolverImpl",
- "org.apache.avalon.excalibur.source.SourceResolver" );
-
- handlers.put(
"org.apache.avalon.excalibur.source.SourceResolverImpl",
-
"org.apache.avalon.excalibur.system.handler.ThreadSafeComponentHandler" );
+ setup( shorts, classes, handlers, "jaxpath",
+ "org.apache.avalon.excalibur.source.SourceResolver",
+ "org.apache.avalon.excalibur.source.SourceResolverImpl",
+
"org.apache.avalon.excalibur.system.handler.ThreadSafeComponentHandler" );
/* Set up XML parser relations */
- shorts.put( "parsre", "org.apache.avalon.excalibur.xml.Parser" );
- shorts.put( "org.apache.avalon.excalibur.xml.Parser", "parser" );
- classes.put( "org.apache.avalon.excalibur.xml.Parser",
- "org.apache.avalon.excalibur.xml.JaxpParser" );
- classes.put( "org.apache.avalon.excalibur.xml.JaxpParser",
- "org.apache.avalon.excalibur.xml.Parser" );
-
- handlers.put( "org.apache.avalon.excalibur.xml.JaxpParser",
-
"org.apache.avalon.excalibur.system.handler.PoolableComponentHandler" );
- handlers.put( "org.apache.avalon.excalibur.xml.XercesParser",
-
"org.apache.avalon.excalibur.system.handler.FactoryComponentHandler" );
+ setup( shorts, classes, handlers, "parser",
+ "org.apache.avalon.excalibur.xml.Parser",
+ "org.apache.avalon.excalibur.xml.JaxpParser",
+
"org.apache.avalon.excalibur.system.handler.PoolableComponentHandler" );
+ setup( shorts, classes, handlers, "xerces-parser",
+ "org.apache.avalon.excalibur.xml.Parser",
+ "org.apache.avalon.excalibur.xml.XercesParser",
+
"org.apache.avalon.excalibur.system.handler.FactoryComponentHandler" );
m_shorthands = Collections.unmodifiableMap( shorts );
m_classNames = Collections.unmodifiableMap( classes );
- m_hintClassNames = Collections.unmodifiableMap( hints );
m_handlerNames = Collections.unmodifiableMap( handlers );
- }
-
- /**
- * Retrieves the real role name from a shorthand name. Usually
- * the shorthand name refers to a configuration element name. If
- * this RoleManager does not have the match, and there is a parent
- * RoleManager, the parent will be asked to resolve the role.
- *
- * @param shorthandName The shortname that is an alias for the role.
- * @return the official role name.
- */
- public final String getRoleForName( final String shorthandName )
- {
- final String role = (String)m_shorthands.get( shorthandName );
-
- if( null == role && null != m_parent )
- {
- return m_parent.getRoleForName( shorthandName );
- }
-
- return role;
- }
-
- /**
- * Retrieves the real role name from a shorthand name. Usually
- * the shorthand name refers to a configuration element name. If
- * this RoleManager does not have the match, and there is a parent
- * RoleManager, the parent will be asked to resolve the role.
- *
- * @param shorthandName The shortname that is an alias for the role.
- * @return the official role name.
- */
- public final String getNameForRole( final String role )
- {
- final String shorthandName = (String)m_shorthands.get( role );
-
- if( null == shorthandName && null != m_parent )
- {
- return m_parent.getNameForRole( role );
- }
-
- return role;
- }
-
- /**
- * Retrieves the handler class name for the specified class name. This
- * is called for every ComponentImplementation. 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 role The role that has a default implementation.
- * @return the Fully Qualified Class Name (FQCN) for the role.
- */
- public final String getHandlerClassNameForClassname( final String
className )
- {
- final String handlerName = (String)m_handlerNames.get( className );
-
- if( null == handlerName && null != m_parent )
- {
- return m_parent.getHandlerClassNameForClassname( className );
- }
-
- return handlerName;
- }
-
- /**
- * Retrieves the default class name for the specified role. This
- * is only called when the configuration does not specify the
- * class explicitly. If this RoleManager does not have the match,
- * and there is a parent RoleManager, the parent will be asked
- * to resolve the class name.
- *
- * @param role The role that has a default implementation.
- * @return the Fully Qualified Class Name (FQCN) for the role.
- */
- public final String getDefaultClassNameForRole( final String role )
- {
- final String className = (String)m_classNames.get( role );
-
- if( null == className && null != m_parent )
- {
- return m_parent.getDefaultClassNameForRole( role );
- }
-
- return className;
- }
-
- /**
- * Retrieves a default class name for a role/hint combination.
- * This is only called when a role is mapped to a
- * DefaultComponentSelector, and the configuration elements use
- * shorthand names for the type of component. If this RoleManager
- * does not have the match, and there is a parent RoleManager, the
- * parent will be asked to resolve the class name.
- *
- * @param role The role that this shorthand refers to.
- * @param shorthand The shorthand name for the type of Component
- * @return the FQCN for the role/hint combination.
- */
- public final String getDefaultClassNameForHint( final String hintType,
- final String role )
- {
- final Map hintMap = (Map)m_hintClassNames.get( role );
-
- if( null == hintMap )
- {
- if( null != m_parent )
- {
- return m_parent.getDefaultClassNameForHint( hintType, role );
- }
- else
- {
- return EMPTY_STRING;
- }
- }
-
- return (String)hintMap.get( hintType );
- }
-
- /**
- * Retrieves a default class name for a role/hint combination.
- * This is only called when a role is mapped to a
- * DefaultComponentSelector, and the configuration elements use
- * shorthand names for the type of component. If this RoleManager
- * does not have the match, and there is a parent RoleManager, the
- * parent will be asked to resolve the class name.
- *
- * @param role The role that this shorthand refers to.
- * @param shorthand The shorthand name for the type of Component
- * @return the FQCN for the role/hint combination.
- */
- public final String getAliasForHintType( final String className,
- final String role )
- {
- final Map hintMap = (Map)m_hintClassNames.get( role );
-
- if( null == hintMap )
- {
- if( null != m_parent )
- {
- return m_parent.getAliasForHintType( className, role );
- }
- else
- {
- return EMPTY_STRING;
- }
- }
-
- return (String)hintMap.get( className );
}
}
1.3 +32 -35
jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/RoleManager.java
Index: RoleManager.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/RoleManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RoleManager.java 28 Jan 2002 22:04:50 -0000 1.2
+++ RoleManager.java 30 Jan 2002 15:44:06 -0000 1.3
@@ -8,59 +8,56 @@
package org.apache.avalon.excalibur.system;
/**
- * RoleManager Interface, use this to specify the Roles and how they
- * correspond easy shorthand names. The new RoleManager interface specifies
- * how to interpret shorthand names in a configuration file. It also helps
- * by providing serialization hints so that self-healing configuration is
- * possible.
+ * 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.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
- * @version CVS $Revision: 1.2 $ $Date: 2002/01/28 22:04:50 $
+ * @version CVS $Revision: 1.3 $ $Date: 2002/01/30 15:44:06 $
* @since 4.1
*/
public interface RoleManager
{
/**
- * Find Role name based on shorthand name. Please note that if
- * this returns <code>null</code> or an empty string, then the
- * shorthand name is assumed to be a "reserved word". In other
- * words, you should not try to instantiate a class from an empty
- * role.
+ * 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.
*/
- String getRoleForName( String shorthandName );
+ Class getClassForName( final String shorthandName );
/**
- * Find shorthand name based on Role name. Please note that if
- * this returns <code>null</code> or an empty string, then the
- * config file will use the expanded format.
- */
- String getNameForRole( String roleName );
-
- /**
- * Get the default classname for a given role.
+ * 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 getDefaultClassNameForRole( String role );
+ String getNameForClass( final Class component );
/**
- * Retrieves the handler class name for the specified class name. This
- * is called for every ComponentImplementation. 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 role The role that has a default implementation.
- * @return the Fully Qualified Class Name (FQCN) for the role.
+ * 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 getHandlerClassNameForClassname( final String className );
+ String getRoleForClass( final Class component );
/**
- * Get the default classname for a given hint type. This is only
- * used by ComponentSelectors.
+ * 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.
*/
- String getDefaultClassNameForHint( String hintType, String role );
+ Class[] getClassesForRole( final String role );
/**
- * Get the type name for classname for a given role. This is only
- * used by ComponentSelectors.
+ * 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.
*/
- String getAliasForHintType( String className, String role );
+ Class getHandlerClassForClass( final Class className );
}
1.1
jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/AbstractRoleManager.java
Index: AbstractRoleManager.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.avalon.excalibur.system;
import org.apache.avalon.framework.component.Component;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* The Excalibur Role Manager is used for Excalibur Role Mappings. All of the
* information is hard-coded.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/01/30 15:44:06 $
* @since 4.1
*/
public abstract class AbstractRoleManager
implements RoleManager
{
protected static final String EMPTY_STRING = "";
protected final ClassLoader m_loader;
/** Map for shorthand to class mapping */
protected Map m_shorthands;
/** Map for role to classname mapping */
protected Map m_classNames;
/** Map for role to handler classname mapping */
protected Map m_handlerNames;
/** Parent <code>RoleManager</code> for nested resolution */
protected final RoleManager m_parent;
/**
* Default constructor--this RoleManager has no parent.
*/
public AbstractRoleManager()
{
this( null );
}
/**
* Alternate constructor--this RoleManager has the specified
* parent.
*
* @param parent The parent <code>RoleManager</code>.
*/
public AbstractRoleManager(RoleManager parent)
{
this( parent, Thread.currentThread().getContextClassLoader() );
}
/**
* Alternate constructor--this RoleManager has the specified
* parent.
*
* @param parent The parent <code>RoleManager</code>.
*/
public AbstractRoleManager(RoleManager parent, ClassLoader loader)
{
ClassLoader thisLoader = loader;
if ( null == thisLoader )
{
thisLoader = Thread.currentThread().getContextClassLoader();
}
m_loader = thisLoader;
m_parent = parent;
}
protected void setup( Map shorts, Map classes, Map handlers,
String shortName, String role, String className,
String handlerClassName )
{
final Class klass;
Class handlerKlass;
try
{
klass = m_loader.loadClass( className );
if ( ! Component.class.isAssignableFrom( klass ) )
{
// Do not store reference if it is not a Component
return;
}
}
catch ( Exception e )
{
// Do not store reference if class does not exist.
return;
}
try
{
handlerKlass = m_loader.loadClass( handlerClassName );
}
catch ( Exception e )
{
handlerKlass =
org.apache.avalon.excalibur.system.handler.PerThreadComponentHandler.class;
}
shorts.put( shortName, klass );
shorts.put( klass, shortName );
classes.put( klass,
role );
List classList = (List) classes.get( role );
if ( null == classList )
{
classList = new ArrayList(5);
}
classList.add( klass );
classes.put( role, classList );
handlers.put( klass, handlerKlass );
}
/**
* 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.
*/
public final Class getClassForName( final String shorthandName )
{
final Class component = (Class)m_shorthands.get( shorthandName );
if( null == component && null != m_parent )
{
return m_parent.getClassForName( shorthandName );
}
return component;
}
/**
* Retrieves the real role name from a shorthand name. Usually
* the shorthand name refers to a configuration element name. If
* this RoleManager does not have the match, and there is a parent
* RoleManager, the parent will be asked to resolve the role.
*
* @param shorthandName The shortname that is an alias for the role.
* @return the official role name.
*/
public final String getNameForClass( final Class klass )
{
final String shorthandName = (String)m_shorthands.get( klass );
if( null == shorthandName && null != m_parent )
{
return m_parent.getNameForClass( klass );
}
return shorthandName;
}
/**
* Retrieves the handler class name for the specified class name. This
* is called for every ComponentImplementation. 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 role The role that has a default implementation.
* @return the Fully Qualified Class Name (FQCN) for the role.
*/
public final Class getHandlerClassForClass( final Class className )
{
final Class handler = (Class)m_handlerNames.get( className );
if( null == handler && null != m_parent )
{
return m_parent.getHandlerClassForClass( className );
}
return handler;
}
/**
* Retrieves the default class name for the specified role. This
* is only called when the configuration does not specify the
* class explicitly. If this RoleManager does not have the match,
* and there is a parent RoleManager, the parent will be asked
* to resolve the class name.
*
* @param role The role that has a default implementation.
* @return the Fully Qualified Class Name (FQCN) for the role.
*/
public final Class[] getClassesForRole( final String role )
{
final List classes = (List)m_classNames.get( role );
if( null == classes && null != m_parent )
{
return m_parent.getClassesForRole( role );
}
return (Class []) classes.toArray( new Class[] {} );
}
/**
* Retrieves a default class name for a role/hint combination.
* This is only called when a role is mapped to a
* DefaultComponentSelector, and the configuration elements use
* shorthand names for the type of component. If this RoleManager
* does not have the match, and there is a parent RoleManager, the
* parent will be asked to resolve the class name.
*
* @param role The role that this shorthand refers to.
* @param shorthand The shorthand name for the type of Component
* @return the FQCN for the role/hint combination.
*/
public final String getRoleForClass( final Class klass )
{
final String role = (String)m_classNames.get( klass );
if( null == role )
{
if( null != m_parent )
{
return m_parent.getRoleForClass( klass );
}
else
{
return EMPTY_STRING;
}
}
return role;
}
}
1.4 +11 -1
jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/handler/ComponentHandler.java
Index: ComponentHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/system/handler/ComponentHandler.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ComponentHandler.java 29 Jan 2002 16:18:53 -0000 1.3
+++ ComponentHandler.java 30 Jan 2002 15:44:06 -0000 1.4
@@ -10,18 +10,28 @@
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.component.Component;
+import org.apache.avalon.framework.component.ComponentManager;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.context.Context;
/**
* The ComponentHandler interface marks the ComponentHandler implementations.
* The desire for a ComponentHandler is to manage the instances of a
Component.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
- * @version CVS $Revision: 1.3 $ $Date: 2002/01/29 16:18:53 $
+ * @version CVS $Revision: 1.4 $ $Date: 2002/01/30 15:44:06 $
* @since 4.0
*/
public interface ComponentHandler
extends Initializable, Disposable
{
+ Class[] HANDLER_CONSTRUCTOR = new Class[] {
+ Class.class,
+ Configuration.class,
+ ComponentManager.class,
+ Context.class
+ };
+
/**
* Sometimes Components call other components during their initialization
* process. This is a quick test that the ComponentManager will perform
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>