You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by sy...@apache.org on 2003/12/09 22:21:08 UTC
cvs commit: cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/fom FOM_Cocoon.java
sylvain 2003/12/09 13:21:08
Modified: src/java/org/apache/cocoon/components/flow/javascript/fom
FOM_Cocoon.java
Log:
Adding createObject & disposeObject. I think setupObject is no more needed.
Revision Changes Path
1.21 +48 -1 cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java
Index: FOM_Cocoon.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- FOM_Cocoon.java 24 Nov 2003 12:12:44 -0000 1.20
+++ FOM_Cocoon.java 9 Dec 2003 21:21:07 -0000 1.21
@@ -66,6 +66,7 @@
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.cocoon.components.LifecycleHelper;
import org.apache.cocoon.components.flow.ContinuationsManager;
+import org.apache.cocoon.components.flow.FlowHelper;
import org.apache.cocoon.components.flow.WebContinuation;
import org.apache.cocoon.components.flow.Interpreter.Argument;
import org.apache.cocoon.components.treeprocessor.sitemap.PipelinesNode;
@@ -76,7 +77,9 @@
import org.apache.cocoon.environment.Response;
import org.apache.cocoon.environment.Session;
import org.apache.cocoon.environment.http.HttpResponse;
+import org.apache.cocoon.util.ClassUtils;
import org.mozilla.javascript.JavaScriptException;
+import org.mozilla.javascript.NativeJavaClass;
import org.mozilla.javascript.NativeJavaObject;
import org.mozilla.javascript.Script;
import org.mozilla.javascript.Scriptable;
@@ -321,6 +324,50 @@
null,// configuration
true);
return obj;
+ }
+
+ /**
+ * Create and setup an object so that it can access the information provided to regular components.
+ * This is done by calling the various Avalon lifecycle interfaces implemented by the object, which
+ * are <code>LogEnabled</code>, <code>Contextualizable</code>, <code>ServiceManageable</code>,
+ * <code>Composable</code> (even if deprecated) and <code>Initializable</code>.
+ * <p>
+ * <code>Contextualizable</code> is of primary importance as it gives access to the whole object model
+ * (request, response, etc.) through the {@link org.apache.cocoon.components.ContextHelper} class.
+ * <p>
+ * Note that <code>Configurable</code> is ignored, as no configuration exists in a flowscript that
+ * can be passed to the object.
+ *
+ * @param classObj the class to instantiate, either as a String or a Rhino NativeJavaClass object
+ * @return an set up instance of <code>clazz</code>
+ * @throws Exception if something goes wrong either during instantiation or setup.
+ */
+ public Object jsFunction_createObject(Object classObj) throws Exception {
+ Object result;
+
+ if (classObj instanceof String) {
+ result = ClassUtils.newInstance((String)classObj);
+
+ } else if (classObj instanceof NativeJavaClass) {
+ Class clazz = ((NativeJavaClass)classObj).getClassObject();
+ result = clazz.newInstance();
+
+ } else {
+ throw new IllegalArgumentException("cocoon.createObject expects either a String or Class argument, but got "
+ + classObj.getClass());
+ }
+
+ return jsFunction_setupObject(result);
+ }
+
+ /**
+ * Dispose an object that has been created using {@link #jsFunction_createObject(Class)}.
+ *
+ * @param obj
+ * @throws Exception
+ */
+ public void jsFunction_disposeObject(Object obj) throws Exception {
+ LifecycleHelper.decommission(obj);
}
public static class FOM_Request extends ScriptableObject {