You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by bl...@apache.org on 2001/01/17 19:33:35 UTC
cvs commit: xml-cocoon/src/org/apache/cocoon Cocoon.java CocoonComponentSelector.java DefaultComponentManager.java
bloritsch 01/01/17 10:33:35
Modified: src/org/apache/cocoon Tag: xml-cocoon2 Cocoon.java
CocoonComponentSelector.java
DefaultComponentManager.java
Log:
Fixed conceptual error with ComponentManager heirarchy
Revision Changes Path
No revision
No revision
1.4.2.44 +3 -49 xml-cocoon/src/org/apache/cocoon/Cocoon.java
Index: Cocoon.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Cocoon.java,v
retrieving revision 1.4.2.43
retrieving revision 1.4.2.44
diff -u -r1.4.2.43 -r1.4.2.44
--- Cocoon.java 2001/01/16 15:26:59 1.4.2.43
+++ Cocoon.java 2001/01/17 18:33:35 1.4.2.44
@@ -34,7 +34,6 @@
import org.apache.cocoon.sitemap.Manager;
import org.apache.cocoon.util.ClassUtils;
import org.apache.cocoon.util.NetUtils;
-import org.apache.cocoon.util.RoleUtils;
import org.apache.cocoon.DefaultComponentManager;
import org.apache.log.Logger;
@@ -47,7 +46,7 @@
* @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
* (Apache Software Foundation, Exoffice Technologies)
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @version CVS $Revision: 1.4.2.43 $ $Date: 2001/01/16 15:26:59 $
+ * @version CVS $Revision: 1.4.2.44 $ $Date: 2001/01/17 18:33:35 $
*/
public class Cocoon
implements Component, Configurable, ComponentManager, Modifiable, Processor, Constants {
@@ -185,54 +184,9 @@
}
log.debug("Setting up components...");
- // Set components
- Iterator e = conf.getChildren("component");
- while (e.hasNext()) {
- Configuration co = (Configuration) e.next();
- String type = co.getAttribute("type", "");
- String role = co.getAttribute("role", "");
- String className = co.getAttribute("class", "");
-
- if (! type.equals("")) {
- role = RoleUtils.lookup(type);
- }
-
- if (className.equals("")) {
- className = RoleUtils.defaultClass(role);
- }
-
- try {
- log.debug("Adding component (" + role + " = " + className + ")");
- componentManager.addComponent(role,ClassUtils.loadClass(className),co);
- } catch ( Exception ex ) {
- log.error("Could not load class " + className, ex);
- throw new ConfigurationException("Could not get class " + className
- + " for role " + role, ex);
- }
- }
-
- e = RoleUtils.shorthandNames();
- while (e.hasNext()) {
- Configuration co = conf.getChild((String) e.next());
- if (! co.getLocation().equals("-")) {
- String role = RoleUtils.lookup(co.getName());
- String className = co.getAttribute("class", "");
-
- if (className.equals("")) {
- className = RoleUtils.defaultClass(role);
- }
-
- try {
- log.debug("Adding component (" + role + " = " + className + ")");
- componentManager.addComponent(role, ClassUtils.loadClass(className), co);
- } catch ( Exception ex ) {
- log.error("Could not load class " + className, ex);
- throw new ConfigurationException("Could not get class " + className
- + " for role " + role, ex);
- }
- }
- }
+ this.componentManager.configure(conf);
+ log.debug("Setting up the sitemap.");
// Create the sitemap
Configuration sconf = conf.getChild("sitemap");
1.1.2.11 +39 -17 xml-cocoon/src/org/apache/cocoon/Attic/CocoonComponentSelector.java
Index: CocoonComponentSelector.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Attic/CocoonComponentSelector.java,v
retrieving revision 1.1.2.10
retrieving revision 1.1.2.11
diff -u -r1.1.2.10 -r1.1.2.11
--- CocoonComponentSelector.java 2001/01/08 20:20:44 1.1.2.10
+++ CocoonComponentSelector.java 2001/01/17 18:33:35 1.1.2.11
@@ -11,6 +11,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Collections;
+import java.util.Iterator;
import org.apache.avalon.ComponentManager;
import org.apache.avalon.ComponentSelector;
@@ -18,6 +19,9 @@
import org.apache.avalon.ComponentManagerException;
import org.apache.avalon.ComponentNotFoundException;
import org.apache.avalon.ComponentNotAccessibleException;
+import org.apache.avalon.Configurable;
+import org.apache.avalon.Configuration;
+import org.apache.avalon.ConfigurationException;
import org.apache.avalon.SingleThreaded;
import org.apache.avalon.ThreadSafe;
import org.apache.avalon.Poolable;
@@ -36,9 +40,9 @@
/** Default component manager for Cocoon's non sitemap components.
* @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
* @author <a href="mailto:paul@luminas.co.uk">Paul Russell</a>
- * @version CVS $Revision: 1.1.2.10 $ $Date: 2001/01/08 20:20:44 $
+ * @version CVS $Revision: 1.1.2.11 $ $Date: 2001/01/17 18:33:35 $
*/
-public class CocoonComponentSelector implements ComponentSelector, Composer, ThreadSafe {
+public class CocoonComponentSelector implements ComponentSelector, Composer, Configurable, ThreadSafe {
protected Logger log = LogKit.getLoggerFor("cocoon");
/** Hashmap of all components which this ComponentManager knows about.
*/
@@ -91,7 +95,7 @@
Component component;
if ( hint == null ) {
- log.error("Attempted to retrieve component with null hint.");
+ log.error("CocoonComponentSelector Attempted to retrieve component with null hint.");
throw new ComponentNotFoundException("Attempted to retrieve component with null hint.");
}
@@ -101,7 +105,7 @@
if ( componentClass == null ) {
component = (Component)this.instances.get(hint);
if ( component == null ) {
- log.error("Could not find component for hint '" + hint.toString() + "'.");
+ log.error("CocoonComponentSelector Could not find component for hint '" + hint.toString() + "'.");
throw new ComponentNotFoundException("Could not find component for hint '" + hint.toString() + "'.");
} else {
// we found an individual instance of a component.
@@ -110,7 +114,7 @@
}
if ( !Component.class.isAssignableFrom(componentClass) ) {
- log.error("Component with hint '" + hint.toString() + "' (" + componentClass.getName() + ")does not implement Component.");
+ log.error("CocoonComponentSelector Component with hint '" + hint.toString() + "' (" + componentClass.getName() + ")does not implement Component.");
throw new ComponentNotAccessibleException(
"Component with hint '" + hint.toString() + "' (" + componentClass.getName() + ")does not implement Component.",
null
@@ -119,20 +123,20 @@
// Work out what class of component we're dealing with.
if ( ThreadSafe.class.isAssignableFrom(componentClass)) {
- component = getThreadsafeComponent(componentClass);
+ component = getThreadsafeComponent(hint, componentClass);
} else if ( Poolable.class.isAssignableFrom(componentClass) ) {
- component = getPooledComponent(componentClass);
+ component = getPooledComponent(hint, componentClass);
} else if ( SingleThreaded.class.isAssignableFrom(componentClass) ) {
try {
component = (Component)componentClass.newInstance();
} catch ( InstantiationException e ) {
- log.error("Could not access class " + componentClass.getName(), e);
+ log.error("CocoonComponentSelector Could not access class " + componentClass.getName(), e);
throw new ComponentNotAccessibleException(
"Could not instantiate component " + componentClass.getName() + ": " + e.getMessage(),
e
);
} catch ( IllegalAccessException e ) {
- log.error("Could not access class " + componentClass.getName(), e);
+ log.error("CocoonComponentSelector Could not access class " + componentClass.getName(), e);
throw new ComponentNotAccessibleException(
"Could not access class " + componentClass.getName() + ": " + e.getMessage(),
e
@@ -146,13 +150,13 @@
try {
component = (Component)componentClass.newInstance();
} catch ( InstantiationException e ) {
- log.error("Could not instantiate component " + componentClass.getName(), e);
+ log.error("CocoonComponentSelector Could not instantiate component " + componentClass.getName(), e);
throw new ComponentNotAccessibleException(
"Could not instantiate component " + componentClass.getName() + ": " + e.getMessage(),
e
);
} catch ( IllegalAccessException e ) {
- log.error("Could not access class " + componentClass.getName(), e);
+ log.error("CocoonComponentSelector Could not access class " + componentClass.getName(), e);
throw new ComponentNotAccessibleException(
"Could not access class " + componentClass.getName() + ": " + e.getMessage(),
e
@@ -164,11 +168,29 @@
return component;
}
+ public void configure(Configuration conf) throws ConfigurationException {
+ log.debug("CocoonComponentSelector setting up with root element: " + conf.getName());
+ Iterator instances = conf.getChildren("component-instance");
+
+ while (instances.hasNext()) {
+ Configuration current = (Configuration) instances.next();
+ Object hint = current.getAttribute("name");
+ String className = (String) current.getAttribute("class");
+
+ try {
+ this.addComponent(hint, ClassUtils.loadClass(className), current);
+ } catch (Exception e) {
+ log.error("CocoonComponentSelector The component instance for \"" + hint + "\" has an invalid class name.", e);
+ throw new ConfigurationException("The component instance for '" + hint + "' has an invalid class name.", e);
+ }
+ }
+ }
+
/** Retrieve an instance of a threadsafe component.
* @param componentClass the class to retrieve an instance of.
* @return and instance of the component.
*/
- private Component getThreadsafeComponent(Class componentClass)
+ private Component getThreadsafeComponent(Object hint, Class componentClass)
throws ComponentManagerException {
Component component = (Component)threadSafeInstances.get(componentClass);
@@ -189,7 +211,7 @@
);
}
setupComponent(component);
- threadSafeInstances.put(componentClass,component);
+ threadSafeInstances.put(hint,component);
}
return component;
}
@@ -197,7 +219,7 @@
/** Return an instance of a component from its associated pool.
* @param componentClass the class of the component of which we need an instance.
*/
- private Component getPooledComponent(Class componentClass)
+ private Component getPooledComponent(Object hint, Class componentClass)
throws ComponentManagerException {
ComponentPool pool = (ComponentPool)pools.get(componentClass);
@@ -214,7 +236,7 @@
e
);
}
- pools.put(componentClass,pool);
+ pools.put(hint,pool);
}
Component component;
@@ -243,7 +265,7 @@
(Configuration)this.configurations.get(c.getClass())
);
} catch (ConfigurationException e) {
- log.error("Could not configure component " + c.getClass().getName(), e);
+ log.error("CocoonComponentSelector Could not configure component " + c.getClass().getName(), e);
throw new ComponentNotAccessibleException(
"Could not configure component " + c.getClass().getName() + ".",
e
@@ -261,7 +283,7 @@
* @param component the class of this component.
* @param Configuration the configuration for this component.
*/
- public void addComponent(Object hint, Class component, Configuration config) {
+ private void addComponent(Object hint, Class component, Configuration config) {
this.components.put(hint,component);
if ( config != null ) {
this.configurations.put(component,config);
1.1.2.10 +63 -35 xml-cocoon/src/org/apache/cocoon/Attic/DefaultComponentManager.java
Index: DefaultComponentManager.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Attic/DefaultComponentManager.java,v
retrieving revision 1.1.2.9
retrieving revision 1.1.2.10
diff -u -r1.1.2.9 -r1.1.2.10
--- DefaultComponentManager.java 2001/01/16 15:27:00 1.1.2.9
+++ DefaultComponentManager.java 2001/01/17 18:33:35 1.1.2.10
@@ -38,9 +38,9 @@
/** Default component manager for Cocoon's non sitemap components.
* @author <a href="mailto:paul@luminas.co.uk">Paul Russell</a>
- * @version CVS $Revision: 1.1.2.9 $ $Date: 2001/01/16 15:27:00 $
+ * @version CVS $Revision: 1.1.2.10 $ $Date: 2001/01/17 18:33:35 $
*/
-public class DefaultComponentManager implements ComponentManager {
+public class DefaultComponentManager implements ComponentManager, Configurable {
protected Logger log = LogKit.getLoggerFor("cocoon");
@@ -125,7 +125,7 @@
// Work out what class of component we're dealing with.
if ( ThreadSafe.class.isAssignableFrom(componentClass) ) {
log.debug("DefaultComponentManager using threadsafe instance of " + componentClass.getName() + " for role " + role + ".");
- component = getThreadsafeComponent(componentClass);
+ component = getThreadsafeComponent(role, componentClass);
} else if ( Poolable.class.isAssignableFrom(componentClass) ) {
log.debug("DefaultComponentManager using poolable instance of "
+ componentClass.getName() + " for role " + role + "."
@@ -150,7 +150,7 @@
e
);
}
- setupComponent(component);
+ setupComponent(role, component);
} else {
/* The component doesn't implement any of the Avalon marker
* classes, treat as normal.
@@ -173,19 +173,69 @@
e
);
}
- setupComponent(component);
+ setupComponent(role, component);
}
return component;
}
+ public void configure(Configuration conf) throws ConfigurationException {
+ // Set components
+ Iterator e = conf.getChildren("component");
+ while (e.hasNext()) {
+ Configuration co = (Configuration) e.next();
+ String type = co.getAttribute("type", "");
+ String role = co.getAttribute("role", "");
+ String className = co.getAttribute("class", "");
+
+ if (! type.equals("")) {
+ role = RoleUtils.lookup(type);
+ }
+
+ if (className.equals("")) {
+ className = RoleUtils.defaultClass(role);
+ }
+
+ try {
+ log.debug("Adding component (" + role + " = " + className + ")");
+ this.addComponent(role,ClassUtils.loadClass(className),co);
+ } catch ( Exception ex ) {
+ log.error("Could not load class " + className, ex);
+ throw new ConfigurationException("Could not get class " + className
+ + " for role " + role, ex);
+ }
+ }
+
+ e = RoleUtils.shorthandNames();
+ while (e.hasNext()) {
+ Configuration co = conf.getChild((String) e.next());
+ if (! co.getLocation().equals("-")) {
+ String role = RoleUtils.lookup(co.getName());
+ String className = co.getAttribute("class", "");
+
+ if (className.equals("")) {
+ className = RoleUtils.defaultClass(role);
+ }
+
+ try {
+ log.debug("Adding component (" + role + " = " + className + ")");
+ this.addComponent(role, ClassUtils.loadClass(className), co);
+ } catch ( Exception ex ) {
+ log.error("Could not load class " + className, ex);
+ throw new ConfigurationException("Could not get class " + className
+ + " for role " + role, ex);
+ }
+ }
+ }
+ }
+
/** Retrieve an instance of a threadsafe component.
* @param componentClass the class to retrieve an instance of.
* @return and instance of the component.
*/
- private Component getThreadsafeComponent(Class componentClass)
+ private Component getThreadsafeComponent(String role, Class componentClass)
throws ComponentManagerException {
- Component component = (Component)threadSafeInstances.get(componentClass);
+ Component component = (Component)threadSafeInstances.get(role);
if ( component == null ) {
try {
@@ -203,8 +253,8 @@
e
);
}
- setupComponent(component);
- threadSafeInstances.put(componentClass,component);
+ setupComponent(role, component);
+ threadSafeInstances.put(role, component);
}
return component;
}
@@ -251,12 +301,12 @@
/** Configure a new component.
* @param c the component to configure.
*/
- private void setupComponent(Component c)
+ private void setupComponent(String role, Component c)
throws ComponentManagerException {
if ( c instanceof Configurable ) {
try {
((Configurable)c).configure(
- (Configuration)this.configurations.get(c.getClass())
+ (Configuration)this.configurations.get(role)
);
} catch (ConfigurationException e) {
log.error("Could not configure component " + c.getClass().getName(), e);
@@ -277,34 +327,12 @@
* @param component the class of this component.
* @param Configuration the configuration for this component.
*/
- public void addComponent(String role, Class component, Configuration config)
+ protected void addComponent(String role, Class component, Configuration config)
throws ConfigurationException,
ComponentManagerException {
- if (component.equals(CocoonComponentSelector.class)) {
- CocoonComponentSelector selector = new CocoonComponentSelector();
- Iterator instances = config.getChildren("component-instance");
-
- selector.compose(this);
-
- while (instances.hasNext()) {
- Configuration current = (Configuration) instances.next();
- Object hint = current.getAttribute("name");
- String className = (String) current.getAttribute("class");
- try {
- selector.addComponent(hint, ClassUtils.loadClass(className), current);
- } catch (Exception e) {
- log.error("The component instance for \"" + hint + "\" has an invalid class name.", e);
- throw new ConfigurationException("The component instance for '" + hint + "' has an invalid class name.", e);
- }
- }
-
- this.addComponentInstance(role, selector);
- return;
- }
-
this.components.put(role,component);
if ( config != null ) {
- this.configurations.put(component,config);
+ this.configurations.put(role, config);
}
}