cziegeler 2003/10/21 06:26:04
Modified: src/java/org/apache/cocoon/components/language/markup/xsp
XSPModuleHelper.java
Log:
Moving to Serviceable
Revision Changes Path
1.7 +52 -48
cocoon-2.2/src/java/org/apache/cocoon/components/language/markup/xsp/XSPModuleHelper.java
Index: XSPModuleHelper.java
===================================================================
RCS file:
/home/cvs/cocoon-2.2/src/java/org/apache/cocoon/components/language/markup/xsp/XSPModuleHelper.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XSPModuleHelper.java 16 Oct 2003 14:57:59 -0000 1.6
+++ XSPModuleHelper.java 21 Oct 2003 13:26:04 -0000 1.7
@@ -56,10 +56,9 @@
import java.util.Map;
import org.apache.avalon.framework.CascadingRuntimeException;
-import org.apache.avalon.framework.service.ServiceSelector;
-import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.ServiceSelector;
import org.apache.cocoon.components.modules.input.InputModule;
@@ -88,12 +87,37 @@
private final static int OP_VALUES = 1;
private final static int OP_NAMES = 2;
- Map inputModules = null;
- ServiceManager manager = null;
- ServiceSelector inputSelector = null;
-
+ private Map inputModules;
+ private ServiceManager serviceManager;
+ private ServiceSelector serviceInputSelector;
+
/**
+ * Get the input module
+ */
+ private InputModule getInputModule(String name)
+ throws CascadingRuntimeException {
+ if ( this.inputModules == null ) {
+ throw new RuntimeException("ModuleHelper is not setup
correctly.");
+ }
+ InputModule module = (InputModule) this.inputModules.get(name);
+ if ( module == null ) {
+ try {
+ if (this.serviceInputSelector.isSelectable(name)) {
+ module = (InputModule)
this.serviceInputSelector.select(name);
+ }
+ } catch (Exception e) {
+ throw new CascadingRuntimeException("Unable to lookup input
module " + name, e);
+ }
+ if ( module == null ) {
+ throw new RuntimeException("No such InputModule: "+name);
+ }
+ this.inputModules.put(name, module);
+ }
+ return module;
+ }
+
+ /**
* Capsules use of an InputModule. Does all the lookups and so
* on. Returns either an Object, an Object[], or an Iterator,
* depending on the method called i.e. the op specified. The
@@ -115,30 +139,12 @@
private Object get(int op, String name, String attr, Map objectModel,
Configuration conf) throws CascadingRuntimeException {
Object value = null;
- InputModule input = null;
-
- if (this.inputModules == null)
- this.inputModules = new HashMap();
- else
- if (this.inputModules.containsKey(name))
- input = (InputModule) this.inputModules.get(name);
+ final InputModule input = this.getInputModule(name);
try {
- if (this.inputSelector == null)
- this.inputSelector = (ServiceSelector)
this.manager.lookup(INPUT_MODULE_SELECTOR);
-
- if (input == null) {
- if (this.inputSelector.isSelectable(name)) {
- input = (InputModule) this.inputSelector.select(name);
- this.inputModules.put(name, input);
- } else {
- throw new RuntimeException("No such InputModule: "+name);
- }
- }
-
switch (op) {
- case OP_GET:
+ case OP_GET:
value = input.getAttribute(attr, conf, objectModel);
break;
case OP_VALUES:
@@ -160,29 +166,25 @@
return get(op, name, attr, objectModel, null);
}
-
-
/**
* Initializes the instance for first use. Stores references to
- * component manager and component selector in instance if
- * ThreadSafe.
+ * service manager and service selector in instance
*
- * @param manager a <code>ComponentManager</code> value
+ * @param manager a <code>ServiceManager</code> value
* @exception RuntimeException if an error occurs
*/
public void setup(ServiceManager manager) throws RuntimeException {
this.inputModules = new HashMap();
- this.manager = manager;
+ this.serviceManager = manager;
try {
- this.inputSelector=(ServiceSelector)
this.manager.lookup(INPUT_MODULE_SELECTOR);
+ this.serviceInputSelector = (ServiceSelector)
this.serviceManager.lookup(INPUT_MODULE_SELECTOR);
} catch (Exception e) {
throw new CascadingRuntimeException("Could not obtain selector
for InputModule.",e);
}
}
-
/**
* Get a single attribute value from a module. Uses cached
* reference if existing.
@@ -326,19 +328,21 @@
*/
public void releaseAll() throws RuntimeException {
- if (this.manager != null && this.inputModules != null) {
- try {
- if (this.inputSelector == null) {
- this.inputSelector=(ServiceSelector)
this.manager.lookup(INPUT_MODULE_SELECTOR);
- }
- Iterator iter = this.inputModules.keySet().iterator();
- while (iter.hasNext()) {
- this.inputSelector.release((InputModule)
this.inputModules.get(iter.next()));
+ if ( this.inputModules != null ) {
+ if ( this.serviceManager != null ) {
+ try {
+ Iterator iter = this.inputModules.keySet().iterator();
+ while (iter.hasNext()) {
+
this.serviceInputSelector.release(this.inputModules.get(iter.next()));
+ }
+ this.inputModules = null;
+ this.serviceManager.release(this.serviceInputSelector);
+ this.serviceManager = null;
+ this.inputModules = null;
+ } catch (Exception e) {
+ throw new CascadingRuntimeException("Could not release
InputModules.",e);
}
- this.inputModules = null;
- this.manager.release(this.inputSelector);
- } catch (Exception e) {
- throw new CascadingRuntimeException("Could not release
InputModules.",e);
+
}
}
}