KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > directwebremoting > proxy > dwr > Engine


1 /*
2  * Copyright 2005 Joe Walker
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.directwebremoting.proxy.dwr;
17
18 import java.util.Collection JavaDoc;
19
20 import org.directwebremoting.ScriptBuffer;
21 import org.directwebremoting.ScriptSession;
22 import org.directwebremoting.proxy.ScriptProxy;
23
24 /**
25  * Engine is a server-side proxy that allows Java programmers to call client
26  * side Javascript from Java.
27  * @see Util for more documenation on server-side proxies
28  * @author Joe Walker [joe at getahead dot ltd dot uk]
29  */

30 public class Engine extends ScriptProxy
31 {
32     /**
33      * Http thread constructor, that affects no browsers.
34      * Calls to {@link Engine#addScriptSession(ScriptSession)} or to
35      * {@link Engine#addScriptSessions(Collection)} will be needed
36      */

37     public Engine()
38     {
39         super();
40     }
41
42     /**
43      * Http thread constructor that alters a single browser
44      * @param scriptSession The browser to alter
45      */

46     public Engine(ScriptSession scriptSession)
47     {
48         super(scriptSession);
49     }
50
51     /**
52      * Http thread constructor that alters a number of browsers
53      * @param scriptSessions A collection of ScriptSessions that we should act on.
54      */

55     public Engine(Collection JavaDoc scriptSessions)
56     {
57         super(scriptSessions);
58     }
59
60     /**
61      * XHR remoting type constant. See dwr.engine.set[Rpc|Poll]Type()
62      */

63     public static final int XMLHttpRequest = 1;
64
65     /**
66      * XHR remoting type constant. See dwr.engine.set[Rpc|Poll]Type()
67      */

68     public static final int IFrame = 2;
69
70     /**
71      * XHR remoting type constant. See dwr.engine.setRpcType()
72      */

73     public static final int ScriptTag = 3;
74
75     /**
76      * Set a default timeout value for all calls. 0 (the default) turns timeouts off.
77      * @param timeout The time to wait in milliseconds
78      * @see <a HREF="http://getahead.org/dwr/browser/engine/errors">Error handling documentation</a>
79      */

80     public void setTimeout(int timeout)
81     {
82         ScriptBuffer script = new ScriptBuffer();
83         script.appendScript("dwr.engine.setTimeout(")
84               .appendData(timeout)
85               .appendScript(");");
86         addScript(script);
87     }
88
89     /**
90      * Set the preferred remoting type.
91      * @param newType One of dwr.engine.XMLHttpRequest or dwr.engine.IFrame or dwr.engine.ScriptTag
92      * @see <a HREF="http://getahead.org/dwr/browser/engine/options">Options documentation</a>
93      */

94     public void setRpcType(int newType)
95     {
96         ScriptBuffer script = new ScriptBuffer();
97         script.appendScript("dwr.engine.setRpcType(")
98               .appendData(newType)
99               .appendScript(");");
100         addScript(script);
101     }
102
103     /**
104      * Which HTTP method do we use to send results? Must be one of "GET" or "POST".
105      * @param httpMethod One of {@link #XMLHttpRequest}, {@link #IFrame} or {@link #ScriptTag}
106      * @see <a HREF="http://getahead.org/dwr/browser/engine/options">Options documentation</a>
107      */

108     public void setHttpMethod(String JavaDoc httpMethod)
109     {
110         ScriptBuffer script = new ScriptBuffer();
111         script.appendScript("dwr.engine.setHttpMethod(")
112               .appendData(httpMethod)
113               .appendScript(");");
114         addScript(script);
115     }
116
117     /**
118      * Ensure that remote calls happen in the order in which they were sent? (Default: false)
119      * @param ordered True to set call ordering.
120      * @see <a HREF="http://getahead.org/dwr/browser/engine/ordering">Ordering documentation</a>
121      */

122     public void setOrdered(boolean ordered)
123     {
124         ScriptBuffer script = new ScriptBuffer();
125         script.appendScript("dwr.engine.setOrdered(")
126               .appendData(ordered)
127               .appendScript(");");
128         addScript(script);
129     }
130
131     /**
132      * Do we ask the XHR object to be asynchronous? (Default: true)
133      * @param async False to become synchronous (not recommended)
134      * @see <a HREF="http://getahead.org/dwr/browser/engine/options">Options documentation</a>
135      */

136     public void setAsync(boolean async)
137     {
138         ScriptBuffer script = new ScriptBuffer();
139         script.appendScript("dwr.engine.setAsync(")
140               .appendData(async)
141               .appendScript(");");
142         addScript(script);
143     }
144
145     /**
146      * Does DWR poll the server for updates? (Default: false)
147      * @param activeReverseAjax True/False to turn RA on/off
148      * @see <a HREF="http://getahead.org/dwr/browser/engine/options">Options documentation</a>
149      */

150     public void setActiveReverseAjax(boolean activeReverseAjax)
151     {
152         ScriptBuffer script = new ScriptBuffer();
153         script.appendScript("dwr.engine.setActiveReverseAjax(")
154               .appendData(activeReverseAjax)
155               .appendScript(");");
156         addScript(script);
157     }
158
159     /**
160      * Does DWR us comet polling? (Default: true)
161      * @param pollComet True/False to use Comet where supported
162      * @see <a HREF="http://getahead.org/dwr/browser/engine/options">Options documentation</a>
163      */

164     public void setPollUsingComet(boolean pollComet)
165     {
166         ScriptBuffer script = new ScriptBuffer();
167         script.appendScript("dwr.engine.setPollUsingComet(")
168               .appendData(pollComet)
169               .appendScript(");");
170         addScript(script);
171     }
172
173     /**
174      * Set the preferred polling type.
175      * @param newPollType One of {@link #XMLHttpRequest}, {@link #IFrame} or {@link #ScriptTag}
176      * @see <a HREF="http://getahead.org/dwr/browser/engine/options">Options documentation</a>
177      */

178     public void setPollType(int newPollType)
179     {
180         ScriptBuffer script = new ScriptBuffer();
181         script.appendScript("dwr.engine.setPollUsingComet(")
182               .appendData(newPollType)
183               .appendScript(");");
184         addScript(script);
185     }
186 }
187
Popular Tags