KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > woody > flow > javascript > Woody


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.woody.flow.javascript;
17
18 import org.mozilla.javascript.ScriptableObject;
19 import org.mozilla.javascript.Undefined;
20 import org.mozilla.javascript.Wrapper;
21 import org.mozilla.javascript.continuations.Continuation;
22 import org.apache.cocoon.components.flow.javascript.fom.FOM_Cocoon;
23 import org.apache.cocoon.components.flow.javascript.fom.FOM_WebContinuation;
24 import org.apache.cocoon.environment.Request;
25
26 /**
27  * Woody-flowscript integration helper class.
28  * @version $Id: Woody.java 30932 2004-07-29 17:35:38Z vgritsenko $
29  */

30 public class Woody extends ScriptableObject {
31     FOM_Cocoon cocoon;
32
33     public String JavaDoc getClassName() {
34         return "Woody";
35     }
36
37     private FOM_Cocoon getCocoon() {
38         if (cocoon == null) {
39             cocoon = (FOM_Cocoon)getProperty(getTopLevelScope(this), "cocoon");
40         }
41         return cocoon;
42     }
43
44     public FOM_WebContinuation jsFunction_makeWebContinuation(Object JavaDoc k,
45                                                               Object JavaDoc lastContinuation,
46                                                               int ttl)
47         throws Exception JavaDoc {
48         Continuation kont = (Continuation)unwrap(k);
49         FOM_WebContinuation fom_wk =
50             (FOM_WebContinuation)unwrap(lastContinuation);
51         FOM_Cocoon cocoon = getCocoon();
52         return cocoon.makeWebContinuation(kont, fom_wk, ttl);
53     }
54
55     public void jsFunction_forwardTo(String JavaDoc uri,
56                                      Object JavaDoc bizData,
57                                      Object JavaDoc continuation)
58         throws Exception JavaDoc {
59         FOM_Cocoon cocoon = getCocoon();
60         FOM_WebContinuation fom_wk =
61             (FOM_WebContinuation)unwrap(continuation);
62         cocoon.forwardTo(uri,
63                          unwrap(bizData),
64                          fom_wk);
65
66     }
67
68     public Request jsGet_request() {
69         FOM_Cocoon cocoon = getCocoon();
70         return cocoon.getRequest();
71     }
72
73     private Object JavaDoc unwrap(Object JavaDoc obj) {
74         if (obj == Undefined.instance) {
75             return null;
76         }
77         if (obj instanceof Wrapper) {
78             return ((Wrapper)obj).unwrap();
79         }
80         return obj;
81     }
82 }
83
Popular Tags