You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2004/11/01 11:28:54 UTC
svn commit: rev 56223 - in cocoon/trunk/src: core/java/org/apache/cocoon/core/container core/test/org/apache/cocoon/core/container java/org/apache/cocoon/components/container java/org/apache/cocoon/components/modules/input java/org/apache/cocoon/components/treeprocessor/sitemap
Author: cziegeler
Date: Mon Nov 1 02:28:54 2004
New Revision: 56223
Modified:
cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractServiceManager.java
cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CocoonServiceManager.java
cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CocoonServiceSelector.java
cocoon/trunk/src/core/java/org/apache/cocoon/core/container/RoleManager.java
cocoon/trunk/src/core/test/org/apache/cocoon/core/container/RoleManagerTestCase.java
cocoon/trunk/src/java/org/apache/cocoon/components/container/CocoonServiceManager.java
cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/DigestMetaModule.java
cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/ComponentsSelector.java
Log:
Clean up
Modified: cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractServiceManager.java
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractServiceManager.java (original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractServiceManager.java Mon Nov 1 02:28:54 2004
@@ -119,7 +119,7 @@
}
protected void addComponent(String className,
- Object role,
+ String role,
Configuration configuration)
throws ConfigurationException {
// check for old excalibur class names - we only test against the selector
@@ -162,7 +162,7 @@
}
}
- protected abstract void addComponent(Object role, Class clazz, Configuration config)
+ protected abstract void addComponent(String role, Class clazz, Configuration config)
throws ServiceException;
Modified: cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CocoonServiceManager.java
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CocoonServiceManager.java (original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CocoonServiceManager.java Mon Nov 1 02:28:54 2004
@@ -402,18 +402,18 @@
* @param component the class of this component.
* @param configuration the configuration for this component.
*/
- public void addComponent( final Object role,
+ public void addComponent( final String role,
final Class component,
final Configuration configuration )
throws ServiceException {
if( this.initialized ) {
- throw new ServiceException( role.toString(),
+ throw new ServiceException( role,
"Cannot add components to an initialized CocoonServiceManager." );
}
try {
if( this.getLogger().isDebugEnabled() ) {
- this.getLogger().debug( "Attempting to get handler for role [" + role.toString() + "]" );
+ this.getLogger().debug( "Attempting to get handler for role [" + role + "]" );
}
final AbstractComponentHandler handler = this.getComponentHandler( component,
@@ -424,12 +424,12 @@
this.getLogger().debug( "Handler type = " + handler.getClass().getName() );
}
- this.componentHandlers.put( role.toString(), handler );
+ this.componentHandlers.put( role, handler );
this.newComponentHandlers.add( handler );
} catch ( final ServiceException se ) {
throw se;
} catch( final Exception e ) {
- throw new ServiceException( role.toString(), "Could not set up component handler.", e );
+ throw new ServiceException( role, "Could not set up component handler.", e );
}
}
Modified: cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CocoonServiceSelector.java
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CocoonServiceSelector.java (original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CocoonServiceSelector.java Mon Nov 1 02:28:54 2004
@@ -236,7 +236,7 @@
Configuration instance = instances[i];
- Object hint = instance.getAttribute("name").trim();
+ String key = instance.getAttribute("name").trim();
String classAttr = instance.getAttribute(getClassAttributeName(), null);
String className;
@@ -244,7 +244,7 @@
if (compInstanceName == null) {
// component-instance implicitly defined by the presence of the 'class' attribute
if (classAttr == null) {
- className = this.roleManager.getDefaultClassNameForHint(roleName, instance.getName());
+ className = this.roleManager.getDefaultClassNameForKey(roleName, instance.getName());
} else {
className = classAttr.trim();
}
@@ -254,19 +254,19 @@
if (compInstanceName.equals(instance.getName())) {
className = (classAttr == null) ? null : classAttr.trim();
} else {
- className = this.roleManager.getDefaultClassNameForHint(roleName, instance.getName());
+ className = this.roleManager.getDefaultClassNameForKey(roleName, instance.getName());
}
}
if (className == null) {
- String message = "Unable to determine class name for component named '" + hint +
+ String message = "Unable to determine class name for component named '" + key +
"' at " + instance.getLocation();
getLogger().error(message);
throw new ConfigurationException(message);
}
- this.addComponent( className, hint.toString(), instance );
+ this.addComponent( className, key, instance );
}
}
@@ -340,15 +340,14 @@
}
/** Add a new component to the manager.
- * @param hint the key for the new component.
+ * @param key the key for the new component.
* @param component the class of this component.
* @param configuration the configuration for this component.
*/
- public void addComponent( final Object hint,
+ public void addComponent( final String key,
final Class component,
final Configuration configuration )
throws ServiceException {
- final String key = hint.toString();
if( this.initialized ) {
throw new ServiceException( key,
"Cannot add components to an initialized service selector" );
Modified: cocoon/trunk/src/core/java/org/apache/cocoon/core/container/RoleManager.java
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/core/container/RoleManager.java (original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/container/RoleManager.java Mon Nov 1 02:28:54 2004
@@ -41,10 +41,10 @@
/** Map for role to default classname mapping */
private Map classNames;
- /** Map for role->hint to classname mapping */
- private Map hintClassNames;
+ /** Map for role->key to classname mapping */
+ private Map keyClassNames;
- /** Parent <code>RoleManager</code> for nested resolution */
+ /** Parent role manager for nested resolution */
private final RoleManager parent;
/**
@@ -109,7 +109,7 @@
}
/**
- * Retrieves a default class name for a role/hint combination.
+ * Retrieves a default class name for a role/key combination.
* This is only called when a role is mapped to a
* CocoonServiceSelector, and the configuration elements use
* shorthand names for the type of component. If this RoleManager
@@ -117,32 +117,32 @@
* 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.
+ * @param shorthand The shorthand name for the type of component
+ * @return the FQCN for the role/key combination.
*/
- public final String getDefaultClassNameForHint( final String role,
- final String shorthand ) {
+ public final String getDefaultClassNameForKey( final String role,
+ final String shorthand ) {
if( this.getLogger().isDebugEnabled() ) {
- this.getLogger().debug( "looking up hintmap for role " + role );
+ this.getLogger().debug( "looking up keymap for role " + role );
}
- final Map hintMap = (Map)this.hintClassNames.get( role );
+ final Map keyMap = (Map)this.keyClassNames.get( role );
- if( null == hintMap ) {
+ if( null == keyMap ) {
if( null != this.parent ) {
- return this.parent.getDefaultClassNameForHint( role, shorthand );
+ return this.parent.getDefaultClassNameForKey( role, shorthand );
}
return "";
}
if( this.getLogger().isDebugEnabled() ) {
- this.getLogger().debug( "looking up classname for hint " + shorthand );
+ this.getLogger().debug( "looking up classname for key " + shorthand );
}
- final String s = ( String ) hintMap.get( shorthand );
+ final String s = ( String ) keyMap.get( shorthand );
if( s == null && null != this.parent ) {
- return this.parent.getDefaultClassNameForHint( role, shorthand );
+ return this.parent.getDefaultClassNameForKey( role, shorthand );
}
return s;
}
@@ -158,7 +158,7 @@
throws ConfigurationException {
final Map shorts = new HashMap();
final Map classes = new HashMap();
- final Map hintclasses = new HashMap();
+ final Map keyclasses = new HashMap();
final Configuration[] roles = configuration.getChildren( "role" );
@@ -173,23 +173,23 @@
classes.put( name, defaultClassName );
}
- 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();
- String className = hints[ j ].getAttribute( "class" ).trim();
+ final Configuration[] keys = roles[ i ].getChildren( "hint" );
+ if( keys.length > 0 ) {
+ HashMap keyMap = new HashMap();
+
+ for( int j = 0; j < keys.length; j++ ) {
+ final String shortHand = keys[ j ].getAttribute( "shorthand" ).trim();
+ String className = keys[ j ].getAttribute( "class" ).trim();
- hintMap.put( shortHand, className );
+ keyMap.put( shortHand, className );
if( this.getLogger().isDebugEnabled() ) {
- this.getLogger().debug( "Adding hint type " + shortHand +
+ this.getLogger().debug( "Adding key type " + shortHand +
" associated with role " + name +
" and class " + className );
}
}
- hintclasses.put( name, Collections.unmodifiableMap( hintMap ) );
+ keyclasses.put( name, Collections.unmodifiableMap( keyMap ) );
}
if( this.getLogger().isDebugEnabled() ) {
@@ -200,6 +200,6 @@
this.shorthands = Collections.unmodifiableMap( shorts );
this.classNames = Collections.unmodifiableMap( classes );
- this.hintClassNames = Collections.unmodifiableMap( hintclasses );
+ this.keyClassNames = Collections.unmodifiableMap( keyclasses );
}
}
Modified: cocoon/trunk/src/core/test/org/apache/cocoon/core/container/RoleManagerTestCase.java
==============================================================================
--- cocoon/trunk/src/core/test/org/apache/cocoon/core/container/RoleManagerTestCase.java (original)
+++ cocoon/trunk/src/core/test/org/apache/cocoon/core/container/RoleManagerTestCase.java Mon Nov 1 02:28:54 2004
@@ -69,7 +69,7 @@
child0.verify();
assertEquals("Role name for shorthand incorrect", "testName", rm.getRoleForName("testShorthand"));
assertEquals("Default class for role incorrect", "testClass", rm.getDefaultClassNameForRole("testName"));
- assertEquals("Default class for hint must be empty", "", rm.getDefaultClassNameForHint("testName", "testShorthand"));
+ assertEquals("Default class for key must be empty", "", rm.getDefaultClassNameForKey("testName", "testShorthand"));
}
}
Modified: cocoon/trunk/src/java/org/apache/cocoon/components/container/CocoonServiceManager.java
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/container/CocoonServiceManager.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/container/CocoonServiceManager.java Mon Nov 1 02:28:54 2004
@@ -113,7 +113,7 @@
* @param component the class of this component.
* @param configuration the configuration for this component.
*/
- public void addComponent( final Object role,
+ public void addComponent( final String role,
final Class component,
final Configuration configuration )
throws ServiceException {
Modified: cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/DigestMetaModule.java
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/DigestMetaModule.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/DigestMetaModule.java Mon Nov 1 02:28:54 2004
@@ -40,7 +40,7 @@
* string), "hex" (returns string of hex values).
*
* @author <a href="mailto:haul@apache.org">Christian Haul</a>
- * @version CVS $Id: DigestMetaModule.java,v 1.3 2004/03/05 13:02:48 bdelacretaz Exp $
+ * @version CVS $Id$
*/
public class DigestMetaModule extends AbstractMetaModule implements ThreadSafe {
@@ -287,7 +287,7 @@
case ENCODING_URL:
try {
String str = new String(b, "UTF-8");
- result = URLEncoder.encode(str);
+ result = URLEncoder.encode(str, "utf-8");
} catch (UnsupportedEncodingException uee) {
if (getLogger().isErrorEnabled())
getLogger().error("UTF-8 not supported -- cannot convert message digest to String.");
Modified: cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/ComponentsSelector.java
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/ComponentsSelector.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/ComponentsSelector.java Mon Nov 1 02:28:54 2004
@@ -18,10 +18,10 @@
import java.util.HashSet;
import java.util.Set;
-import org.apache.avalon.framework.activity.Disposable;
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.container.ContainerUtil;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.cocoon.acting.Action;
import org.apache.cocoon.components.pipeline.ProcessingPipeline;
@@ -98,9 +98,12 @@
return (this.roleId == UNKNOWN) ? "class" : "src";
}
+ /* (non-Javadoc)
+ * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
+ */
public void configure(Configuration config) throws ConfigurationException {
// Who are we ?
- String role = getRoleName(config);
+ final String role = getRoleName(config);
this.roleId = UNKNOWN; // unknown
for (int i = 0; i < SELECTOR_ROLES.length; i++) {
if (SELECTOR_ROLES[i].equals(role)) {
@@ -120,58 +123,53 @@
/**
* Add a component in this selector.
*/
- public void addComponent(Object hint, Class clazz, Configuration config) throws ServiceException {
- super.addComponent(hint, clazz, config);
+ public void addComponent(String key, Class clazz, Configuration config) throws ServiceException {
+ super.addComponent(key, clazz, config);
// Add to known hints. This is needed as we cannot call isSelectable() if initialize()
// has not been called, and we cannot add components once it has been called...
- this.knownHints.add(hint);
+ this.knownHints.add(key);
}
/**
* Ensure system-defined components exist (e.g. <aggregator>) and initialize
* the selector.
*/
- public void initialize() /* throws Exception */ {
- // FIXME : need to catch exceptions since ECS doesn't propagate the throws clause of Initializable
- try {
- DefaultConfiguration config = null;
-
- // Ensure all system-defined hints exist.
- // NOTE : checking this here means they can be user-defined in the sitemap
- switch(this.roleId) {
- case GENERATOR :
- config = new DefaultConfiguration(COMPONENT_NAMES[GENERATOR], "autogenerated");
- config.setAttribute("name", "<notifier>");
- ensureExists("<notifier>",
- org.apache.cocoon.sitemap.NotifyingGenerator.class, config);
-
- config = new DefaultConfiguration(COMPONENT_NAMES[GENERATOR], "autogenerated");
- config.setAttribute("name", "<aggregator>");
- ensureExists("<aggregator>",
- org.apache.cocoon.sitemap.ContentAggregator.class, config);
- break;
-
- case TRANSFORMER :
- config = new DefaultConfiguration(COMPONENT_NAMES[TRANSFORMER], "autogenerated");
- config.setAttribute("name", "<translator>");
- ensureExists("<translator>",
- org.apache.cocoon.sitemap.LinkTranslator.class, config);
-
- config = new DefaultConfiguration(COMPONENT_NAMES[TRANSFORMER], "autogenerated");
- config.setAttribute("name", "<gatherer>");
- ensureExists("<gatherer>",
- org.apache.cocoon.sitemap.LinkGatherer.class, config);
- break;
- }
+ public void initialize() throws Exception {
+ DefaultConfiguration config = null;
- super.initialize();
-
- // Don't keep known hints (they're no more needed)
- this.knownHints = null;
- } catch (Exception e) {
- throw new RuntimeException("Cannot setup default components", e);
+ // Ensure all system-defined hints exist.
+ // NOTE : checking this here means they can be user-defined in the sitemap
+ switch(this.roleId) {
+ case GENERATOR :
+ config = new DefaultConfiguration(COMPONENT_NAMES[GENERATOR], "autogenerated");
+ config.setAttribute("name", "<notifier>");
+ ensureExists("<notifier>",
+ org.apache.cocoon.sitemap.NotifyingGenerator.class, config);
+
+ config = new DefaultConfiguration(COMPONENT_NAMES[GENERATOR], "autogenerated");
+ config.setAttribute("name", "<aggregator>");
+ ensureExists("<aggregator>",
+ org.apache.cocoon.sitemap.ContentAggregator.class, config);
+ break;
+
+ case TRANSFORMER :
+ config = new DefaultConfiguration(COMPONENT_NAMES[TRANSFORMER], "autogenerated");
+ config.setAttribute("name", "<translator>");
+ ensureExists("<translator>",
+ org.apache.cocoon.sitemap.LinkTranslator.class, config);
+
+ config = new DefaultConfiguration(COMPONENT_NAMES[TRANSFORMER], "autogenerated");
+ config.setAttribute("name", "<gatherer>");
+ ensureExists("<gatherer>",
+ org.apache.cocoon.sitemap.LinkGatherer.class, config);
+ break;
}
+
+ super.initialize();
+
+ // Don't keep known hints (they're no more needed)
+ this.knownHints = null;
}
/**
@@ -179,10 +177,10 @@
* since it requires to be initialized, and we want to add components, and this must
* be done before initialization.
*/
- private void ensureExists(Object hint, Class clazz, Configuration config) throws ServiceException {
- if (!this.knownHints.contains(hint)) {
- if (this.parentSelector == null || !this.parentSelector.isSelectable(hint)) {
- addComponent(hint, clazz, config);
+ private void ensureExists(String key, Class clazz, Configuration config) throws ServiceException {
+ if (!this.knownHints.contains(key)) {
+ if (this.parentSelector == null || !this.parentSelector.isSelectable(key)) {
+ this.addComponent(key, clazz, config);
}
}
}
@@ -226,27 +224,21 @@
case GENERATOR:
if (component instanceof GeneratorFactory.Instance) {
// Dispose component, if needed
- if (component instanceof Disposable) {
- ((Disposable)component).dispose();
- }
+ ContainerUtil.dispose(component);
component = ((GeneratorFactory.Instance)component).getFactory();
}
break;
case TRANSFORMER:
if (component instanceof TransformerFactory.Instance) {
// Dispose component, if needed
- if (component instanceof Disposable) {
- ((Disposable)component).dispose();
- }
+ ContainerUtil.dispose(component);
component = ((TransformerFactory.Instance)component).getFactory();
}
break;
case SERIALIZER:
if (component instanceof SerializerFactory.Instance) {
// Dispose component, if needed
- if (component instanceof Disposable) {
- ((Disposable)component).dispose();
- }
+ ContainerUtil.dispose(component);
component = ((SerializerFactory.Instance)component).getFactory();
}
break;