KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > flow > javascript > fom > FOM_JavaScriptFlowHelper


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.components.flow.javascript.fom;
17
18 import org.apache.cocoon.components.flow.FlowHelper;
19
20 import org.mozilla.javascript.Scriptable;
21
22 import java.util.Map JavaDoc;
23
24 /**
25  * Provides the interface between the JavaScript flow controller layer and the
26  * view layer. A view can obtain the JavaScript "live connect" objects (that
27  * allow access to Java constructors) through this interface, as well as
28  * the FOM objects.
29  *
30  * @version CVS $Id: FOM_JavaScriptFlowHelper.java 54079 2004-10-08 13:30:28Z vgritsenko $
31  */

32 public class FOM_JavaScriptFlowHelper extends FlowHelper {
33
34     // Constants defining keys in the object model used to store the various objects.
35
// These constants are private so that access to these objects only go through the
36
// accessors provided below.
37
//
38
// These objects are stored in the object model rather than as request attributes,
39
// as object model is cloned for subrequests (see EnvironmentWrapper), whereas
40
// request attributes are shared between the "real" request and all of its
41
// child requests.
42
private static final String JavaDoc PACKAGES_OBJECT =
43         "cocoon.flow.js.packages";
44     private static final String JavaDoc JAVA_PACKAGE_OBJECT =
45         "cocoon.flow.js.packages.java";
46     private static final String JavaDoc FOM_REQUEST =
47         "cocoon.flow.js.fom.FOM_Request";
48     private static final String JavaDoc FOM_RESPONSE =
49         "cocoon.flow.js.fom.FOM_Response";
50     private static final String JavaDoc FOM_SESSION =
51         "cocoon.flow.js.fom.FOM_Session";
52     private static final String JavaDoc FOM_CONTEXT =
53         "cocoon.flow.js.fom.FOM_Context";
54     private static final String JavaDoc FOM_WEB_CONTINUATION =
55         "cocoon.flow.js.fom.FOM_WebContinuation";
56     /**
57      * The parent scope to be used by nested scripts (e.g. Woody event handlers)
58      */

59     private static final String JavaDoc FOM_SCOPE =
60         "cocoon.flow.js.fom.FOM_Scope";
61
62     /**
63      * Return the JS "Packages" property (that gives access to Java
64      * packages) for use by the view layer
65      * @param objectModel The Cocoon Environment's object model
66      * @return The Packages property
67      */

68     public static Scriptable getPackages(Map JavaDoc objectModel) {
69         return (Scriptable)objectModel.get(PACKAGES_OBJECT);
70     }
71
72     /**
73      * Set the JS "Packages" property in the current request
74      * @param objectModel The Cocoon Environment's object model
75      */

76     public static void setPackages(Map JavaDoc objectModel, Scriptable pkgs) {
77         objectModel.put(PACKAGES_OBJECT, pkgs);
78     }
79
80     /**
81      * Return the JS "java" property (that gives access to the "java"
82      * package) for use by the view layer
83      * @param objectModel The Cocoon Environment's object model
84      * @return The java package property
85      */

86     public static Scriptable getJavaPackage(Map JavaDoc objectModel) {
87         return (Scriptable)objectModel.get(JAVA_PACKAGE_OBJECT);
88     }
89
90     /**
91      * Set the JS "java" property in the current request
92      * @param objectModel The Cocoon Environment's object model
93      */

94     public static void setJavaPackage(Map JavaDoc objectModel, Scriptable javaPkg) {
95         objectModel.put(JAVA_PACKAGE_OBJECT, javaPkg);
96     }
97
98     public static Scriptable getFOM_Request(Map JavaDoc objectModel) {
99         return (Scriptable)objectModel.get(FOM_REQUEST);
100     }
101
102     public static void setFOM_Request(Map JavaDoc objectModel, Scriptable fom_request) {
103         objectModel.put(FOM_REQUEST, fom_request);
104     }
105
106     public static Scriptable getFOM_Response(Map JavaDoc objectModel) {
107         return (Scriptable)objectModel.get(FOM_RESPONSE);
108     }
109
110     public static void setFOM_Response(Map JavaDoc objectModel, Scriptable fom_response) {
111         objectModel.put(FOM_RESPONSE, fom_response);
112     }
113
114     public static Scriptable getFOM_Session(Map JavaDoc objectModel) {
115         return (Scriptable)objectModel.get(FOM_SESSION);
116     }
117
118     public static void setFOM_Session(Map JavaDoc objectModel, Scriptable fom_session) {
119         objectModel.put(FOM_SESSION, fom_session);
120     }
121
122     public static Scriptable getFOM_Context(Map JavaDoc objectModel) {
123         return (Scriptable)objectModel.get(FOM_CONTEXT);
124     }
125
126     public static void setFOM_Context(Map JavaDoc objectModel, Scriptable fom_context) {
127         objectModel.put(FOM_CONTEXT, fom_context);
128     }
129
130     public static Scriptable getFOM_WebContinuation(Map JavaDoc objectModel) {
131         return (Scriptable)objectModel.get(FOM_WEB_CONTINUATION);
132     }
133
134     public static void setFOM_WebContinuation(Map JavaDoc objectModel,
135                                               Scriptable fom_webContinuation) {
136         objectModel.put(FOM_WEB_CONTINUATION, fom_webContinuation);
137     }
138     
139     /**
140      * Get the flowscript scope, usable by JS snippets part of the control layer, such
141      * as forms event listeners.
142      *
143      * @param objectModel the object model where the scope is stored
144      * @return the flowscript scope
145      */

146     public static Scriptable getFOM_FlowScope(Map JavaDoc objectModel) {
147         return (Scriptable)objectModel.get(FOM_SCOPE);
148     }
149     
150     /**
151      * Set the flowscript scope usable by JS snippets.
152      *
153      * @see #getFOM_FlowScope(Map)
154      * @param objectModel
155      * @param fom_scope
156      */

157     public static void setFOM_FlowScope(Map JavaDoc objectModel, Scriptable fom_scope) {
158         objectModel.put(FOM_SCOPE, fom_scope);
159     }
160 }
161
Popular Tags