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/10 17:16:43 UTC
cvs commit: jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/role RoleEntry.java ConfigurableRoleManager.java ExcaliburRoleManager.java AbstractRoleManager.java RoleManager.java
donaldp 2002/11/10 08:16:43
Modified: fortress/src/java/org/apache/excalibur/fortress/container
DefaultContainer.java AbstractContainer.java
fortress/src/java/org/apache/excalibur/fortress/role
ConfigurableRoleManager.java
ExcaliburRoleManager.java AbstractRoleManager.java
RoleManager.java
Added: fortress/src/java/org/apache/excalibur/fortress/role
RoleEntry.java
Log:
Simplified Role management. Prepare to start integrating proper separation of metadata for roles.
Revision Changes Path
1.11 +7 -9 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.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- DefaultContainer.java 8 Nov 2002 05:05:56 -0000 1.10
+++ DefaultContainer.java 10 Nov 2002 16:16:43 -0000 1.11
@@ -54,6 +54,7 @@
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;
/**
* This is the default container, and it marks the default markup for
@@ -145,11 +146,8 @@
"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 )
+ final RoleEntry roleEntry = m_roleManager.getRoleForShortName( configItem.getName() );
+ if( null == roleEntry )
{
throw new ConfigurationException( "No class found matching configuration name "
+ "[name: " + configItem.getName()
@@ -158,9 +156,9 @@
//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.setAttribute( "role", roleEntry.getRole() );
+ temp.setAttribute( "class", roleEntry.getComponentClass().getName() );
+ temp.setAttribute( "handler", roleEntry.getHandlerClass().getName() );
temp.setValue( configItem.getValue( null ) );
1.16 +11 -12 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.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- AbstractContainer.java 10 Nov 2002 12:01:53 -0000 1.15
+++ AbstractContainer.java 10 Nov 2002 16:16:43 -0000 1.16
@@ -205,7 +205,7 @@
}
/**
- * Create a default RoleManager that can be used to setup system.
+ * Create a default RoleManager that can be used to addRole system.
*
* @return the default role manager
* @throws Exception if unable to create role manager
@@ -237,7 +237,8 @@
{
if( null == hint )
{
- throw new IllegalArgumentException( "Hint must not be null" );
+ final String message = "Hint must not be null";
+ throw new IllegalArgumentException( message );
}
String role = component.getAttribute( "role", null );
@@ -307,10 +308,10 @@
}
// policy was not null, but didn't match anything above
- final String klass = component.getAttribute( "class", null );
+ final String classname = component.getAttribute( "class", null );
final String message =
- "Unknown activation policy for class " + klass + ": " + policy;
+ "Unknown activation policy for class " + classname + ": " + policy;
throw new IllegalArgumentException( message );
}
@@ -520,15 +521,14 @@
{
if( getLogger().isDebugEnabled() )
{
- getLogger().debug(
- "ComponentHandler (" + handler +
+ final String message = "ComponentHandler (" + handler +
") has specified request time initialization policy, " +
- "initialization deferred till first use"
- );
+ "initialization deferred till first use";
+ getLogger().debug( message );
}
}
}
- catch( Exception e )
+ catch( final Exception e )
{
if( getLogger().isWarnEnabled() )
{
@@ -575,5 +575,4 @@
{
return m_serviceManager;
}
-}
-
+}
\ No newline at end of file
1.3 +3 -14 jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/role/ConfigurableRoleManager.java
Index: ConfigurableRoleManager.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/role/ConfigurableRoleManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ConfigurableRoleManager.java 10 Nov 2002 12:00:17 -0000 1.2
+++ ConfigurableRoleManager.java 10 Nov 2002 16:16:43 -0000 1.3
@@ -49,9 +49,6 @@
*/
package org.apache.excalibur.fortress.role;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
@@ -104,15 +101,11 @@
* and class name mapping.
*
* @param configuration The configuration object.
- * @throws org.apache.avalon.framework.configuration.ConfigurationException if the configuration is malformed
+ * @throws ConfigurationException if the configuration is malformed
*/
public final void configure( final Configuration configuration )
throws ConfigurationException
{
- final Map shorts = new HashMap();
- final Map classes = new HashMap();
- final Map handlers = new HashMap();
-
final Configuration[] roles = configuration.getChildren( "role" );
for( int i = 0; i < roles.length; i++ )
@@ -129,12 +122,8 @@
components[ j ].getAttribute( "handler",
"org.apache.excalibur.fortress.handler.PerThreadComponentHandler" );
- setup( shorts, classes, handlers, shorthand, role, className, handlerClassName );
+ addRole( shorthand, role, className, handlerClassName );
}
}
-
- m_shorthands = Collections.unmodifiableMap( shorts );
- m_classNames = Collections.unmodifiableMap( classes );
- m_handlerNames = Collections.unmodifiableMap( handlers );
}
}
1.3 +53 -63 jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/role/ExcaliburRoleManager.java
Index: ExcaliburRoleManager.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/role/ExcaliburRoleManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ExcaliburRoleManager.java 10 Nov 2002 12:00:17 -0000 1.2
+++ ExcaliburRoleManager.java 10 Nov 2002 16:16:43 -0000 1.3
@@ -49,8 +49,6 @@
*/
package org.apache.excalibur.fortress.role;
-import java.util.Collections;
-import java.util.HashMap;
import org.apache.avalon.framework.activity.Initializable;
/**
@@ -101,79 +99,71 @@
*/
public void initialize()
{
- HashMap shorts = new HashMap( 10 );
- HashMap classes = new HashMap( 10 );
- HashMap handlers = new HashMap( 10 );
-
/* Set up Cache relations */
- setup( shorts, classes, handlers, "cache",
- "org.apache.excalibur.cache.Cache",
- "org.apache.excalibur.cache.impl.DefaultCache",
- "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
- setup( shorts, classes, handlers, "lru-cache",
- "org.apache.excalibur.cache.Cache",
- "org.apache.excalibur.cache.impl.LRUCache",
- "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
+ addRole( "cache",
+ "org.apache.excalibur.cache.Cache",
+ "org.apache.excalibur.cache.impl.DefaultCache",
+ "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
+ addRole( "lru-cache",
+ "org.apache.excalibur.cache.Cache",
+ "org.apache.excalibur.cache.impl.LRUCache",
+ "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
/* Set up DataSource relations */
- setup( shorts, classes, handlers, "jdbc-datasource",
- "org.apache.avalon.excalibur.datasource.DataSourceComponent",
- "org.apache.avalon.excalibur.datasource.JdbcDataSource",
- "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
- setup( shorts, classes, handlers, "j2ee-datasource",
- "org.apache.avalon.excalibur.datasource.DataSourceComponent",
- "org.apache.avalon.excalibur.datasource.J2eeDataSource",
- "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
- setup( shorts, classes, handlers, "informix-datasource",
- "org.apache.avalon.excalibur.datasource.DataSourceComponent",
- "org.apache.avalon.excalibur.datasource.InformixDataSource",
- "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
+ addRole( "jdbc-datasource",
+ "org.apache.avalon.excalibur.datasource.DataSourceComponent",
+ "org.apache.avalon.excalibur.datasource.JdbcDataSource",
+ "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
+ addRole( "j2ee-datasource",
+ "org.apache.avalon.excalibur.datasource.DataSourceComponent",
+ "org.apache.avalon.excalibur.datasource.J2eeDataSource",
+ "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
+ addRole( "informix-datasource",
+ "org.apache.avalon.excalibur.datasource.DataSourceComponent",
+ "org.apache.avalon.excalibur.datasource.InformixDataSource",
+ "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
/* Set up i18n relations */
- setup( shorts, classes, handlers, "i18n",
- "org.apache.excalibur.xmlbundle.BundleSelector",
- "org.apache.excalibur.xmlbundle.BundleSelector",
- "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
+ addRole( "i18n",
+ "org.apache.excalibur.xmlbundle.BundleSelector",
+ "org.apache.excalibur.xmlbundle.BundleSelector",
+ "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
/* Set up Monitor relations */
- setup( shorts, classes, handlers, "monitor",
- "org.apache.avalon.excalibur.monitor.Monitor",
- "org.apache.avalon.excalibur.monitor.ActiveMonitor",
- "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
- setup( shorts, classes, handlers, "passive-monitor",
- "org.apache.avalon.excalibur.monitor.Monitor",
- "org.apache.avalon.excalibur.monitor.PassiveMonitor",
- "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
+ addRole( "monitor",
+ "org.apache.avalon.excalibur.monitor.Monitor",
+ "org.apache.avalon.excalibur.monitor.ActiveMonitor",
+ "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
+ addRole( "passive-monitor",
+ "org.apache.avalon.excalibur.monitor.Monitor",
+ "org.apache.avalon.excalibur.monitor.PassiveMonitor",
+ "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
/* Set up XPath relations */
- setup( shorts, classes, handlers, "xalan-xpath",
- "org.apache.avalon.excalibur.xml.xpath.XPathProcessor",
- "org.apache.avalon.excalibur.xml.xpath.XPathProcessorImpl",
- "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
- setup( shorts, classes, handlers, "jaxpath",
- "org.apache.avalon.excalibur.xml.xpath.XPathProcessor",
- "org.apache.avalon.excalibur.xml.xpath.JaxenProcessorImpl",
- "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
+ addRole( "xalan-xpath",
+ "org.apache.avalon.excalibur.xml.xpath.XPathProcessor",
+ "org.apache.avalon.excalibur.xml.xpath.XPathProcessorImpl",
+ "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
+ addRole( "jaxpath",
+ "org.apache.avalon.excalibur.xml.xpath.XPathProcessor",
+ "org.apache.avalon.excalibur.xml.xpath.JaxenProcessorImpl",
+ "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
/* Set up SourceResolver relations */
- setup( shorts, classes, handlers, "resolver",
- "org.apache.excalibur.source.SourceResolver",
- "org.apache.excalibur.source.impl.SourceResolverImpl",
- "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
+ addRole( "resolver",
+ "org.apache.excalibur.source.SourceResolver",
+ "org.apache.excalibur.source.impl.SourceResolverImpl",
+ "org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler" );
/* Set up XML parser relations */
- setup( shorts, classes, handlers, "parser",
- "org.apache.avalon.excalibur.xml.Parser",
- "org.apache.avalon.excalibur.xml.JaxpParser",
- "org.apache.excalibur.fortress.handler.PerThreadComponentHandler" );
- setup( shorts, classes, handlers, "xerces-parser",
- "org.apache.avalon.excalibur.xml.Parser",
- "org.apache.avalon.excalibur.xml.XercesParser",
- "org.apache.excalibur.fortress.handler.FactoryComponentHandler" );
-
- m_shorthands = Collections.unmodifiableMap( shorts );
- m_classNames = Collections.unmodifiableMap( classes );
- m_handlerNames = Collections.unmodifiableMap( handlers );
+ addRole( "parser",
+ "org.apache.avalon.excalibur.xml.Parser",
+ "org.apache.avalon.excalibur.xml.JaxpParser",
+ "org.apache.excalibur.fortress.handler.PerThreadComponentHandler" );
+ addRole( "xerces-parser",
+ "org.apache.avalon.excalibur.xml.Parser",
+ "org.apache.avalon.excalibur.xml.XercesParser",
+ "org.apache.excalibur.fortress.handler.FactoryComponentHandler" );
}
}
1.3 +48 -237 jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/role/AbstractRoleManager.java
Index: AbstractRoleManager.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/role/AbstractRoleManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractRoleManager.java 10 Nov 2002 12:00:17 -0000 1.2
+++ AbstractRoleManager.java 10 Nov 2002 16:16:43 -0000 1.3
@@ -49,10 +49,10 @@
*/
package org.apache.excalibur.fortress.role;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.Hashtable;
import java.util.Map;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.excalibur.fortress.handler.PerThreadComponentHandler;
/**
* The Excalibur Role Manager is used for Excalibur Role Mappings. All of
@@ -66,21 +66,17 @@
extends AbstractLogEnabled
implements RoleManager
{
- protected static final String EMPTY_STRING = "";
+ private final ClassLoader m_loader;
- 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;
+ /**
+ * Map for shorthand to RoleEntry
+ */
+ private Map m_shorthands = new Hashtable();
- /** Parent <code>RoleManager</code> for nested resolution */
- protected final RoleManager m_parent;
+ /**
+ * Parent <code>RoleManager</code> for nested resolution
+ */
+ private final RoleManager m_parent;
/**
* Default constructor--this RoleManager has no parent.
@@ -96,7 +92,7 @@
*
* @param parent The parent <code>RoleManager</code>.
*/
- public AbstractRoleManager( RoleManager parent )
+ public AbstractRoleManager( final RoleManager parent )
{
this( parent, Thread.currentThread().getContextClassLoader() );
}
@@ -107,10 +103,10 @@
*
* @param parent The parent <code>RoleManager</code>.
*/
- public AbstractRoleManager( RoleManager parent, ClassLoader loader )
+ public AbstractRoleManager( final RoleManager parent,
+ final ClassLoader loader )
{
ClassLoader thisLoader = loader;
-
if( null == thisLoader )
{
thisLoader = Thread.currentThread().getContextClassLoader();
@@ -120,261 +116,76 @@
m_parent = parent;
}
- protected void setup( Map shorts, Map classes, Map handlers,
- String shortName, String role, String className,
- String handlerClassName )
+ protected void addRole( final String shortName,
+ final String role,
+ final String className,
+ final String handlerClassName )
{
- final Class klass;
+ final Class clazz;
Class handlerKlass;
if( getLogger().isDebugEnabled() )
{
- getLogger().debug( "setup role: name='" + shortName + "', role='" + role + "', "
+ getLogger().debug( "addRole role: name='" + shortName + "', role='" + role + "', "
+ "class='" + className + "', handler='" + handlerClassName + "'" );
}
try
{
- klass = m_loader.loadClass( className );
- }
- catch( Exception e )
- {
- // Do not store reference if class does not exist.
- return;
+ clazz = m_loader.loadClass( className );
}
- catch( NoClassDefFoundError e )
+ catch( final Exception e )
{
+ final String message =
+ "Unable to load class " + className + ". Skipping.";
+ getLogger().warn( message );
// Do not store reference if class does not exist.
return;
}
- try
- {
- handlerKlass = m_loader.loadClass( handlerClassName );
- }
- catch( Exception e )
- {
- handlerKlass = org.apache.excalibur.fortress.handler.PerThreadComponentHandler.class;
- }
-
- shorts.put( shortName, klass );
- shorts.put( klass, shortName );
- classes.put( klass,
- role );
-
- List classList = (List)classes.get( role );
-
- if( null == classList )
+ if( null != handlerClassName )
{
- 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 )
- {
- if( shorthandName == null ) return null;
-
- Class component = (Class)m_shorthands.get( shorthandName );
-
- if( null == component && null != m_parent )
- {
- component = m_parent.getClassForName( shorthandName );
- }
-
- if( getLogger().isDebugEnabled() )
- {
- if( component == null )
+ try
{
- getLogger().debug( "looking up class with shorthand '" + shorthandName
- + "' but a class was not found." );
+ handlerKlass = m_loader.loadClass( handlerClassName );
}
- else
+ catch( final Exception e )
{
- getLogger().debug( "looking up class with shorthand '" + shorthandName
- + "' returning '" + component.getName() + "'" );
+ final String message = "Unable to load handler " +
+ handlerClassName + " for class " + className + ". Skipping.";
+ getLogger().warn( message );
+ return;
}
}
-
- 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 klass The class whose role is being requested.
- * @return the official role name.
- */
- public final String getNameForClass( final Class klass )
- {
- String shorthandName = (String)m_shorthands.get( klass );
-
- if( null == shorthandName && null != m_parent )
- {
- shorthandName = m_parent.getNameForClass( klass );
- }
-
- if( getLogger().isDebugEnabled() )
+ else
{
- if( shorthandName == null )
- {
- getLogger().debug( "looking up shorthand with class '" + klass.getName()
- + "' but a shorthand was not found." );
- }
- else
- {
- getLogger().debug( "looking up shorthand with class '" + klass.getName()
- + "' returning '" + shorthandName + "'" );
- }
+ handlerKlass = guessHandlerFor( clazz );
}
- return shorthandName;
+ final RoleEntry entry = new RoleEntry( role, clazz, handlerKlass );
+ m_shorthands.put( shortName, entry );
}
- /**
- * 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 klass The role that has a default implementation.
- * @return the Fully Qualified Class Name (FQCN) for the role.
- */
- public final Class getHandlerClassForClass( final Class klass )
+ protected Class guessHandlerFor( final Class clazz )
{
- Class handler = (Class)m_handlerNames.get( klass );
-
- if( null == handler && null != m_parent )
- {
- handler = m_parent.getHandlerClassForClass( klass );
- }
-
- if( getLogger().isDebugEnabled() )
- {
- if( handler == null )
- {
- getLogger().debug( "looking up handler class with class '" + klass.getName()
- + "' but a handler was not found." );
- }
- else
- {
- getLogger().debug( "looking up handler class with class '" + klass.getName()
- + "' returning '" + handler.getName() + "'" );
- }
- }
-
- return handler;
+ return PerThreadComponentHandler.class;
}
- /**
- * 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 )
+ public RoleEntry getRoleForShortName( final String shortname )
{
- List classes = (List)m_classNames.get( role );
-
- Class[] classAry;
- if( null == classes && null != m_parent )
+ final RoleEntry roleEntry = (RoleEntry)m_shorthands.get( shortname );
+ if( null != roleEntry )
{
- classAry = m_parent.getClassesForRole( role );
+ return roleEntry;
}
- else
+ else if( null != m_parent )
{
- // Convert the list into an array
- if( classes == null )
- {
- classAry = new Class[ 0 ];
- }
- else
- {
- classAry = new Class[ classes.size() ];
- classes.toArray( classAry );
- }
+ return m_parent.getRoleForShortName( shortname );
}
-
- if( getLogger().isDebugEnabled() )
- {
- if( classes == null )
- {
- getLogger().debug( "looking up classes with role '" + role
- + "' but no classes were found." );
- }
- else
- {
- StringBuffer sb = new StringBuffer();
- for( int i = 0; i < classAry.length; i++ )
- {
- if( i > 0 )
- {
- sb.append( ", " );
- }
- sb.append( "'" );
- sb.append( classAry[ i ].getName() );
- sb.append( "'" );
- }
- getLogger().debug( "looking up classes with role '" + role
- + "' returning [" + sb + "]" );
- }
- }
-
- return classAry;
- }
-
- /**
- * 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 klass The class to get rolename for
- * @return the FQCN for the role/hint combination.
- */
- public final String getRoleForClass( final Class klass )
- {
- String role = (String)m_classNames.get( klass );
-
- if( null == role )
- {
- if( null != m_parent )
- {
- role = m_parent.getRoleForClass( klass );
- }
- else
- {
- role = EMPTY_STRING;
- }
- }
-
- if( getLogger().isDebugEnabled() )
+ else
{
- getLogger().debug( "looking up role with class '" + klass.getName()
- + "' returning '" + role + "'" );
+ return null;
}
-
- return role;
}
}
1.3 +3 -44 jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/role/RoleManager.java
Index: RoleManager.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/role/RoleManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RoleManager.java 10 Nov 2002 03:39:12 -0000 1.2
+++ RoleManager.java 10 Nov 2002 16:16:43 -0000 1.3
@@ -55,6 +55,7 @@
* relationship of shorthand names to classes, and classes to roles.
*
* @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
+ * @author <a href="mailto:peter at apache.org">Peter Donald</a>
* @version CVS $Revision$ $Date$
* @since 4.1
*/
@@ -62,47 +63,5 @@
{
String ROLE = RoleManager.class.getName();
- /**
- * 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( 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( 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( 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( 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 clazz The class of the Component in question.
- * @return the Class instance of the ComponentHandler.
- */
- Class getHandlerClassForClass( Class clazz );
+ RoleEntry getRoleForShortName( String shortname );
}
1.1 jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/role/RoleEntry.java
Index: RoleEntry.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.role;
/**
*
* @author <a href="mailto:peter at apache.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/11/10 16:16:43 $
*/
public class RoleEntry
{
private final String m_role;
private final Class m_componentClass;
private final Class m_handlerClass;
public RoleEntry( final String role,
final Class componentClass,
final Class handlerClass )
{
if( null == role )
{
throw new NullPointerException( "role" );
}
if( null == componentClass )
{
throw new NullPointerException( "componentClass" );
}
if( null == handlerClass )
{
throw new NullPointerException( "handlerClass" );
}
m_role = role;
m_componentClass = componentClass;
m_handlerClass = handlerClass;
}
public String getRole()
{
return m_role;
}
public Class getComponentClass()
{
return m_componentClass;
}
public Class getHandlerClass()
{
return m_handlerClass;
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>