001: /*
002: * Copyright 2005 Joe Walker
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package jsx3.app;
017:
018: import org.directwebremoting.ScriptBuffer;
019: import org.directwebremoting.proxy.ScriptProxy;
020: import org.directwebremoting.proxy.io.Context;
021:
022: /**
023: * A class that represents a JSX add-in. The JSX system creates an instance of this class for every add-in that
024: is loaded.
025: * @author Joe Walker [joe at getahead dot org]
026: * @author DRAPGEN - Dwr Reverse Ajax Proxy GENerator
027: */
028: public class AddIn extends jsx3.lang.Object {
029: /**
030: * All reverse ajax proxies need context to work from
031: * @param scriptProxy The place we are writing scripts to
032: * @param context The script that got us to where we are now
033: */
034: public AddIn(Context context, String extension,
035: ScriptProxy scriptProxy) {
036: super (context, extension, scriptProxy);
037: }
038:
039: /**
040: *
041: */
042: public static final String PROTOTYPES_DIR = "prototypes/";
043:
044: /**
045: *
046: */
047: @SuppressWarnings("unchecked")
048: public void getId(
049: org.directwebremoting.proxy.Callback<String> callback) {
050: ScriptBuffer script = new ScriptBuffer();
051: String callbackPrefix = "";
052:
053: if (callback != null) {
054: callbackPrefix = "var reply = ";
055: }
056:
057: script.appendCall(callbackPrefix + getContextPath() + "getId");
058:
059: if (callback != null) {
060: String key = org.directwebremoting.extend.CallbackHelper
061: .saveCallback(callback, String.class);
062: script
063: .appendCall("__System.activateCallback", key,
064: "reply");
065: }
066:
067: getScriptProxy().addScript(script);
068: }
069:
070: /**
071: *
072: */
073: @SuppressWarnings("unchecked")
074: public void getName(
075: org.directwebremoting.proxy.Callback<String> callback) {
076: ScriptBuffer script = new ScriptBuffer();
077: String callbackPrefix = "";
078:
079: if (callback != null) {
080: callbackPrefix = "var reply = ";
081: }
082:
083: script
084: .appendCall(callbackPrefix + getContextPath()
085: + "getName");
086:
087: if (callback != null) {
088: String key = org.directwebremoting.extend.CallbackHelper
089: .saveCallback(callback, String.class);
090: script
091: .appendCall("__System.activateCallback", key,
092: "reply");
093: }
094:
095: getScriptProxy().addScript(script);
096: }
097:
098: /**
099: *
100: */
101: @SuppressWarnings("unchecked")
102: public void getDescription(
103: org.directwebremoting.proxy.Callback<String> callback) {
104: ScriptBuffer script = new ScriptBuffer();
105: String callbackPrefix = "";
106:
107: if (callback != null) {
108: callbackPrefix = "var reply = ";
109: }
110:
111: script.appendCall(callbackPrefix + getContextPath()
112: + "getDescription");
113:
114: if (callback != null) {
115: String key = org.directwebremoting.extend.CallbackHelper
116: .saveCallback(callback, String.class);
117: script
118: .appendCall("__System.activateCallback", key,
119: "reply");
120: }
121:
122: getScriptProxy().addScript(script);
123: }
124:
125: /**
126: *
127: */
128: @SuppressWarnings("unchecked")
129: public void getVersion(
130: org.directwebremoting.proxy.Callback<String> callback) {
131: ScriptBuffer script = new ScriptBuffer();
132: String callbackPrefix = "";
133:
134: if (callback != null) {
135: callbackPrefix = "var reply = ";
136: }
137:
138: script.appendCall(callbackPrefix + getContextPath()
139: + "getVersion");
140:
141: if (callback != null) {
142: String key = org.directwebremoting.extend.CallbackHelper
143: .saveCallback(callback, String.class);
144: script
145: .appendCall("__System.activateCallback", key,
146: "reply");
147: }
148:
149: getScriptProxy().addScript(script);
150: }
151:
152: /**
153: *
154: */
155: @SuppressWarnings("unchecked")
156: public void getKey(
157: org.directwebremoting.proxy.Callback<String> callback) {
158: ScriptBuffer script = new ScriptBuffer();
159: String callbackPrefix = "";
160:
161: if (callback != null) {
162: callbackPrefix = "var reply = ";
163: }
164:
165: script.appendCall(callbackPrefix + getContextPath() + "getKey");
166:
167: if (callback != null) {
168: String key = org.directwebremoting.extend.CallbackHelper
169: .saveCallback(callback, String.class);
170: script
171: .appendCall("__System.activateCallback", key,
172: "reply");
173: }
174:
175: getScriptProxy().addScript(script);
176: }
177:
178: /**
179: *
180: */
181: @SuppressWarnings("unchecked")
182: public jsx3.app.Settings getSettings() {
183: String extension = "getSettings().";
184: try {
185: java.lang.reflect.Constructor<jsx3.app.Settings> ctor = jsx3.app.Settings.class
186: .getConstructor(Context.class, String.class,
187: ScriptProxy.class);
188: return ctor.newInstance(this , extension, getScriptProxy());
189: } catch (Exception ex) {
190: throw new IllegalArgumentException("Unsupported type: "
191: + jsx3.app.Settings.class.getName());
192: }
193: }
194:
195: /**
196: *
197: * @param strURI
198: */
199: @SuppressWarnings("unchecked")
200: public void resolveURI(java.net.URI strURI,
201: org.directwebremoting.proxy.Callback<java.net.URI> callback) {
202: ScriptBuffer script = new ScriptBuffer();
203: String callbackPrefix = "";
204:
205: if (callback != null) {
206: callbackPrefix = "var reply = ";
207: }
208:
209: script.appendCall(callbackPrefix + getContextPath()
210: + "resolveURI", strURI);
211:
212: if (callback != null) {
213: String key = org.directwebremoting.extend.CallbackHelper
214: .saveCallback(callback, java.net.URI.class);
215: script
216: .appendCall("__System.activateCallback", key,
217: "reply");
218: }
219:
220: getScriptProxy().addScript(script);
221: }
222:
223: /**
224: *
225: * @param strURI
226: */
227: @SuppressWarnings("unchecked")
228: public void resolveURI(String strURI,
229: org.directwebremoting.proxy.Callback<java.net.URI> callback) {
230: ScriptBuffer script = new ScriptBuffer();
231: String callbackPrefix = "";
232:
233: if (callback != null) {
234: callbackPrefix = "var reply = ";
235: }
236:
237: script.appendCall(callbackPrefix + getContextPath()
238: + "resolveURI", strURI);
239:
240: if (callback != null) {
241: String key = org.directwebremoting.extend.CallbackHelper
242: .saveCallback(callback, java.net.URI.class);
243: script
244: .appendCall("__System.activateCallback", key,
245: "reply");
246: }
247:
248: getScriptProxy().addScript(script);
249: }
250:
251: /**
252: *
253: */
254: @SuppressWarnings("unchecked")
255: public void getUriPrefix(
256: org.directwebremoting.proxy.Callback<String> callback) {
257: ScriptBuffer script = new ScriptBuffer();
258: String callbackPrefix = "";
259:
260: if (callback != null) {
261: callbackPrefix = "var reply = ";
262: }
263:
264: script.appendCall(callbackPrefix + getContextPath()
265: + "getUriPrefix");
266:
267: if (callback != null) {
268: String key = org.directwebremoting.extend.CallbackHelper
269: .saveCallback(callback, String.class);
270: script
271: .appendCall("__System.activateCallback", key,
272: "reply");
273: }
274:
275: getScriptProxy().addScript(script);
276: }
277:
278: /**
279: *
280: * @param strURI
281: * @param bRel
282: */
283: @SuppressWarnings("unchecked")
284: public void relativizeURI(String strURI, boolean bRel,
285: org.directwebremoting.proxy.Callback<java.net.URI> callback) {
286: ScriptBuffer script = new ScriptBuffer();
287: String callbackPrefix = "";
288:
289: if (callback != null) {
290: callbackPrefix = "var reply = ";
291: }
292:
293: script.appendCall(callbackPrefix + getContextPath()
294: + "relativizeURI", strURI, bRel);
295:
296: if (callback != null) {
297: String key = org.directwebremoting.extend.CallbackHelper
298: .saveCallback(callback, java.net.URI.class);
299: script
300: .appendCall("__System.activateCallback", key,
301: "reply");
302: }
303:
304: getScriptProxy().addScript(script);
305: }
306:
307: /**
308: *
309: * @param strURI
310: * @param bRel
311: */
312: @SuppressWarnings("unchecked")
313: public void relativizeURI(java.net.URI strURI, boolean bRel,
314: org.directwebremoting.proxy.Callback<java.net.URI> callback) {
315: ScriptBuffer script = new ScriptBuffer();
316: String callbackPrefix = "";
317:
318: if (callback != null) {
319: callbackPrefix = "var reply = ";
320: }
321:
322: script.appendCall(callbackPrefix + getContextPath()
323: + "relativizeURI", strURI, bRel);
324:
325: if (callback != null) {
326: String key = org.directwebremoting.extend.CallbackHelper
327: .saveCallback(callback, java.net.URI.class);
328: script
329: .appendCall("__System.activateCallback", key,
330: "reply");
331: }
332:
333: getScriptProxy().addScript(script);
334: }
335:
336: }
|