Source Code Cross Referenced for Cache.java in  » Ajax » dwr » jsx3 » app » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Ajax » dwr » jsx3.app 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:         * Provides cached access to XML and XSL data.
024:         Events
025:         Cache instances publish two types of events for every operation that modifies the contents of the cache. The
026:         schemas of the two event types are
027:
028:        
029:         subject - Cache.CHANGE
030:        
031:        
032:         id or ids - the ID or array of IDs of the modified documents
033:        
034:         action - Cache.ADD, Cache.CHANGE or Cache.REMOVE
035:        
036:
037:         and
038:
039:        
040:         subject - the cache ID of the modified document
041:        
042:         action - Cache.ADD, Cache.CHANGE or Cache.REMOVE
043:        
044:
045:         Asynchronous Loading
046:         Cache documents can be loaded asychronously with the getOrOpenAsync() method. This method returns
047:         the corresponding document synchronously if it already exists in the cache. If the document does not exist in the
048:         cache, then it is loaded asynchronously and the method returns a placeholder document. The namespace URI of this
049:         placeholder document is Cache.XSDNS and its root node name is "loading".
050:
051:         Since the cache stores this placeholder document until the document finishes loading, subsequent calls to
052:         synchronous APIs (getDocument(), getOrOpenDocument(), etc) may also return the
053:         placeholder document. It is therefore important to check the namespace of the returned document when any code
054:         uses the asynchronous APIs.
055:
056:         Once a document finishes loading asynchronously the placeholder document is replaced with the loaded document.
057:         This change in value causes the cache to publish a pair of events of action Cache.CHANGE. If
058:         loading the document fails or times out the placeholder document is instead replaced with another placeholder
059:         document. This document also has a URI namespace of Cache.XSDNS. Its root node name may be either
060:         "error" or "timeout". If the root node name is "error" then the root node
061:         has an attribute, also named "error", which contains the XML error message.
062:         * @author Joe Walker [joe at getahead dot org]
063:         * @author DRAPGEN - Dwr Reverse Ajax Proxy GENerator
064:         */
065:        public class Cache extends jsx3.lang.Object {
066:            /**
067:             * All reverse ajax proxies need context to work from
068:             * @param scriptProxy The place we are writing scripts to
069:             * @param context The script that got us to where we are now
070:             */
071:            public Cache(Context context, String extension,
072:                    ScriptProxy scriptProxy) {
073:                super (context, extension, scriptProxy);
074:            }
075:
076:            /**
077:             * Creates a new instance of this class.
078:             */
079:            public Cache() {
080:                super ((Context) null, (String) null, (ScriptProxy) null);
081:                ScriptBuffer script = new ScriptBuffer();
082:                script.appendCall("new Cache");
083:                setInitScript(script);
084:            }
085:
086:            /**
087:             * Event action.
088:             */
089:            public static final String REMOVE = "remove";
090:
091:            /**
092:             * Event action.
093:             */
094:            public static final String ADD = "add";
095:
096:            /**
097:             * Event subject and action.
098:             */
099:            public static final String CHANGE = "change";
100:
101:            /**
102:             * The number of milliseconds before asynchronous document loads time out.
103:             */
104:            public static final int ASYNC_TIMEOUT = 60000;
105:
106:            /**
107:             * 
108:             */
109:            public static final String XSDNS = "http://xsd.tns.tibco.com/gi/cache";
110:
111:            /**
112:             * Removes the document stored in this cache under id strId.
113:             * @param strId 
114:             * @return the remove document, if any.
115:             */
116:            @SuppressWarnings("unchecked")
117:            public jsx3.xml.CdfDocument clearById(String strId) {
118:                String extension = "clearById(\"" + strId + "\").";
119:                try {
120:                    java.lang.reflect.Constructor<jsx3.xml.CdfDocument> ctor = jsx3.xml.CdfDocument.class
121:                            .getConstructor(Context.class, String.class,
122:                                    ScriptProxy.class);
123:                    return ctor.newInstance(this , extension, getScriptProxy());
124:                } catch (Exception ex) {
125:                    throw new IllegalArgumentException("Unsupported type: "
126:                            + jsx3.xml.CdfDocument.class.getName());
127:                }
128:            }
129:
130:            /**
131:             * Removes the document stored in this cache under id strId.
132:             * @param strId 
133:             * @param returnType The expected return type
134:             * @return the remove document, if any.
135:             */
136:            @SuppressWarnings("unchecked")
137:            public <T> T clearById(String strId, Class<T> returnType) {
138:                String extension = "clearById(\"" + strId + "\").";
139:                try {
140:                    java.lang.reflect.Constructor<T> ctor = returnType
141:                            .getConstructor(Context.class, String.class,
142:                                    ScriptProxy.class);
143:                    return ctor.newInstance(this , extension, getScriptProxy());
144:                } catch (Exception ex) {
145:                    throw new IllegalArgumentException(
146:                            "Unsupported return type: " + returnType.getName());
147:                }
148:            }
149:
150:            /**
151:             * Removes all documents placed in this cache before intTimestamp.
152:             * @param intTimestamp epoch seconds or a date object.
153:             * @param callback the ids of the removed documents.
154:             */
155:            @SuppressWarnings("unchecked")
156:            public void clearByTimestamp(java.util.Date intTimestamp,
157:                    org.directwebremoting.proxy.Callback<Object[]> 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()
166:                        + "clearByTimestamp", intTimestamp);
167:
168:                if (callback != null) {
169:                    String key = org.directwebremoting.extend.CallbackHelper
170:                            .saveCallback(callback, Object[].class);
171:                    script
172:                            .appendCall("__System.activateCallback", key,
173:                                    "reply");
174:                }
175:
176:                getScriptProxy().addScript(script);
177:            }
178:
179:            /**
180:             * Removes all documents placed in this cache before intTimestamp.
181:             * @param intTimestamp epoch seconds or a date object.
182:             * @param callback the ids of the removed documents.
183:             */
184:            @SuppressWarnings("unchecked")
185:            public void clearByTimestamp(int intTimestamp,
186:                    org.directwebremoting.proxy.Callback<Object[]> callback) {
187:                ScriptBuffer script = new ScriptBuffer();
188:                String callbackPrefix = "";
189:
190:                if (callback != null) {
191:                    callbackPrefix = "var reply = ";
192:                }
193:
194:                script.appendCall(callbackPrefix + getContextPath()
195:                        + "clearByTimestamp", intTimestamp);
196:
197:                if (callback != null) {
198:                    String key = org.directwebremoting.extend.CallbackHelper
199:                            .saveCallback(callback, Object[].class);
200:                    script
201:                            .appendCall("__System.activateCallback", key,
202:                                    "reply");
203:                }
204:
205:                getScriptProxy().addScript(script);
206:            }
207:
208:            /**
209:             * Returns the document stored in this cache under id strId.
210:             * @param strId 
211:             * @return the stored document or <code>null</code> if none exists.
212:             */
213:            @SuppressWarnings("unchecked")
214:            public jsx3.xml.CdfDocument getDocument(String strId) {
215:                String extension = "getDocument(\"" + strId + "\").";
216:                try {
217:                    java.lang.reflect.Constructor<jsx3.xml.CdfDocument> ctor = jsx3.xml.CdfDocument.class
218:                            .getConstructor(Context.class, String.class,
219:                                    ScriptProxy.class);
220:                    return ctor.newInstance(this , extension, getScriptProxy());
221:                } catch (Exception ex) {
222:                    throw new IllegalArgumentException("Unsupported type: "
223:                            + jsx3.xml.CdfDocument.class.getName());
224:                }
225:            }
226:
227:            /**
228:             * Returns the document stored in this cache under id strId.
229:             * @param strId 
230:             * @param returnType The expected return type
231:             * @return the stored document or <code>null</code> if none exists.
232:             */
233:            @SuppressWarnings("unchecked")
234:            public <T> T getDocument(String strId, Class<T> returnType) {
235:                String extension = "getDocument(\"" + strId + "\").";
236:                try {
237:                    java.lang.reflect.Constructor<T> ctor = returnType
238:                            .getConstructor(Context.class, String.class,
239:                                    ScriptProxy.class);
240:                    return ctor.newInstance(this , extension, getScriptProxy());
241:                } catch (Exception ex) {
242:                    throw new IllegalArgumentException(
243:                            "Unsupported return type: " + returnType.getName());
244:                }
245:            }
246:
247:            /**
248:             * Retrieves a document from this cache or, if this cache contains no such document, loads the document
249:            synchronously and returns it.
250:             * @param strURL the URI of the document.
251:             * @param strId the id under which the document is/will be stored. If this parameter is not provided, the
252:            <code>strURL</code> parameter is used as the id.
253:             * @param objClass <code>jsx3.xml.Document</code> (default value) or one of its subclasses. The
254:            class with which to instantiate the new document instance if a new document is opened.
255:             * @return the document retrieved from the cache or loaded.
256:             */
257:            @SuppressWarnings("unchecked")
258:            public jsx3.xml.CdfDocument getOrOpenDocument(String strURL,
259:                    String strId, Class objClass) {
260:                String extension = "getOrOpenDocument(\"" + strURL + "\", \""
261:                        + strId + "\", \"" + objClass + "\").";
262:                try {
263:                    java.lang.reflect.Constructor<jsx3.xml.CdfDocument> ctor = jsx3.xml.CdfDocument.class
264:                            .getConstructor(Context.class, String.class,
265:                                    ScriptProxy.class);
266:                    return ctor.newInstance(this , extension, getScriptProxy());
267:                } catch (Exception ex) {
268:                    throw new IllegalArgumentException("Unsupported type: "
269:                            + jsx3.xml.CdfDocument.class.getName());
270:                }
271:            }
272:
273:            /**
274:             * Retrieves a document from this cache or, if this cache contains no such document, loads the document
275:            synchronously and returns it.
276:             * @param strURL the URI of the document.
277:             * @param strId the id under which the document is/will be stored. If this parameter is not provided, the
278:            <code>strURL</code> parameter is used as the id.
279:             * @param objClass <code>jsx3.xml.Document</code> (default value) or one of its subclasses. The
280:            class with which to instantiate the new document instance if a new document is opened.
281:             * @param returnType The expected return type
282:             * @return the document retrieved from the cache or loaded.
283:             */
284:            @SuppressWarnings("unchecked")
285:            public <T> T getOrOpenDocument(String strURL, String strId,
286:                    Class objClass, Class<T> returnType) {
287:                String extension = "getOrOpenDocument(\"" + strURL + "\", \""
288:                        + strId + "\", \"" + objClass + "\").";
289:                try {
290:                    java.lang.reflect.Constructor<T> ctor = returnType
291:                            .getConstructor(Context.class, String.class,
292:                                    ScriptProxy.class);
293:                    return ctor.newInstance(this , extension, getScriptProxy());
294:                } catch (Exception ex) {
295:                    throw new IllegalArgumentException(
296:                            "Unsupported return type: " + returnType.getName());
297:                }
298:            }
299:
300:            /**
301:             * Retrieves a document from this cache or, if this cache contains no such document, loads the document
302:            synchronously and returns it.
303:             * @param strURL the URI of the document.
304:             * @param strId the id under which the document is/will be stored. If this parameter is not provided, the
305:            <code>strURL</code> parameter is used as the id.
306:             * @param objClass <code>jsx3.xml.Document</code> (default value) or one of its subclasses. The
307:            class with which to instantiate the new document instance if a new document is opened.
308:             * @return the document retrieved from the cache or loaded.
309:             */
310:            @SuppressWarnings("unchecked")
311:            public jsx3.xml.CdfDocument getOrOpenDocument(java.net.URI strURL,
312:                    String strId, Class objClass) {
313:                String extension = "getOrOpenDocument(\"" + strURL + "\", \""
314:                        + strId + "\", \"" + objClass + "\").";
315:                try {
316:                    java.lang.reflect.Constructor<jsx3.xml.CdfDocument> ctor = jsx3.xml.CdfDocument.class
317:                            .getConstructor(Context.class, String.class,
318:                                    ScriptProxy.class);
319:                    return ctor.newInstance(this , extension, getScriptProxy());
320:                } catch (Exception ex) {
321:                    throw new IllegalArgumentException("Unsupported type: "
322:                            + jsx3.xml.CdfDocument.class.getName());
323:                }
324:            }
325:
326:            /**
327:             * Retrieves a document from this cache or, if this cache contains no such document, loads the document
328:            synchronously and returns it.
329:             * @param strURL the URI of the document.
330:             * @param strId the id under which the document is/will be stored. If this parameter is not provided, the
331:            <code>strURL</code> parameter is used as the id.
332:             * @param objClass <code>jsx3.xml.Document</code> (default value) or one of its subclasses. The
333:            class with which to instantiate the new document instance if a new document is opened.
334:             * @param returnType The expected return type
335:             * @return the document retrieved from the cache or loaded.
336:             */
337:            @SuppressWarnings("unchecked")
338:            public <T> T getOrOpenDocument(java.net.URI strURL, String strId,
339:                    Class objClass, Class<T> returnType) {
340:                String extension = "getOrOpenDocument(\"" + strURL + "\", \""
341:                        + strId + "\", \"" + objClass + "\").";
342:                try {
343:                    java.lang.reflect.Constructor<T> ctor = returnType
344:                            .getConstructor(Context.class, String.class,
345:                                    ScriptProxy.class);
346:                    return ctor.newInstance(this , extension, getScriptProxy());
347:                } catch (Exception ex) {
348:                    throw new IllegalArgumentException(
349:                            "Unsupported return type: " + returnType.getName());
350:                }
351:            }
352:
353:            /**
354:             * Synchronously loads an xml document, stores it in this cache, and returns the loaded document.
355:             * @param strURL url (relative or absolute) the URI of the document to open.
356:             * @param strId the id under which to store the document. If this parameter is not provided, the
357:            <code>strURL</code> parameter is used as the id.
358:             * @param objClass <code>jsx3.xml.Document</code> (default value) or one of its subclasses. The
359:            class with which to instantiate the new document instance.
360:             * @return the loaded document object.
361:             */
362:            @SuppressWarnings("unchecked")
363:            public jsx3.xml.CdfDocument openDocument(String strURL,
364:                    String strId, Class objClass) {
365:                String extension = "openDocument(\"" + strURL + "\", \""
366:                        + strId + "\", \"" + objClass + "\").";
367:                try {
368:                    java.lang.reflect.Constructor<jsx3.xml.CdfDocument> ctor = jsx3.xml.CdfDocument.class
369:                            .getConstructor(Context.class, String.class,
370:                                    ScriptProxy.class);
371:                    return ctor.newInstance(this , extension, getScriptProxy());
372:                } catch (Exception ex) {
373:                    throw new IllegalArgumentException("Unsupported type: "
374:                            + jsx3.xml.CdfDocument.class.getName());
375:                }
376:            }
377:
378:            /**
379:             * Synchronously loads an xml document, stores it in this cache, and returns the loaded document.
380:             * @param strURL url (relative or absolute) the URI of the document to open.
381:             * @param strId the id under which to store the document. If this parameter is not provided, the
382:            <code>strURL</code> parameter is used as the id.
383:             * @param objClass <code>jsx3.xml.Document</code> (default value) or one of its subclasses. The
384:            class with which to instantiate the new document instance.
385:             * @param returnType The expected return type
386:             * @return the loaded document object.
387:             */
388:            @SuppressWarnings("unchecked")
389:            public <T> T openDocument(String strURL, String strId,
390:                    Class objClass, Class<T> returnType) {
391:                String extension = "openDocument(\"" + strURL + "\", \""
392:                        + strId + "\", \"" + objClass + "\").";
393:                try {
394:                    java.lang.reflect.Constructor<T> ctor = returnType
395:                            .getConstructor(Context.class, String.class,
396:                                    ScriptProxy.class);
397:                    return ctor.newInstance(this , extension, getScriptProxy());
398:                } catch (Exception ex) {
399:                    throw new IllegalArgumentException(
400:                            "Unsupported return type: " + returnType.getName());
401:                }
402:            }
403:
404:            /**
405:             * Synchronously loads an xml document, stores it in this cache, and returns the loaded document.
406:             * @param strURL url (relative or absolute) the URI of the document to open.
407:             * @param strId the id under which to store the document. If this parameter is not provided, the
408:            <code>strURL</code> parameter is used as the id.
409:             * @param objClass <code>jsx3.xml.Document</code> (default value) or one of its subclasses. The
410:            class with which to instantiate the new document instance.
411:             * @return the loaded document object.
412:             */
413:            @SuppressWarnings("unchecked")
414:            public jsx3.xml.CdfDocument openDocument(java.net.URI strURL,
415:                    String strId, Class objClass) {
416:                String extension = "openDocument(\"" + strURL + "\", \""
417:                        + strId + "\", \"" + objClass + "\").";
418:                try {
419:                    java.lang.reflect.Constructor<jsx3.xml.CdfDocument> ctor = jsx3.xml.CdfDocument.class
420:                            .getConstructor(Context.class, String.class,
421:                                    ScriptProxy.class);
422:                    return ctor.newInstance(this , extension, getScriptProxy());
423:                } catch (Exception ex) {
424:                    throw new IllegalArgumentException("Unsupported type: "
425:                            + jsx3.xml.CdfDocument.class.getName());
426:                }
427:            }
428:
429:            /**
430:             * Synchronously loads an xml document, stores it in this cache, and returns the loaded document.
431:             * @param strURL url (relative or absolute) the URI of the document to open.
432:             * @param strId the id under which to store the document. If this parameter is not provided, the
433:            <code>strURL</code> parameter is used as the id.
434:             * @param objClass <code>jsx3.xml.Document</code> (default value) or one of its subclasses. The
435:            class with which to instantiate the new document instance.
436:             * @param returnType The expected return type
437:             * @return the loaded document object.
438:             */
439:            @SuppressWarnings("unchecked")
440:            public <T> T openDocument(java.net.URI strURL, String strId,
441:                    Class objClass, Class<T> returnType) {
442:                String extension = "openDocument(\"" + strURL + "\", \""
443:                        + strId + "\", \"" + objClass + "\").";
444:                try {
445:                    java.lang.reflect.Constructor<T> ctor = returnType
446:                            .getConstructor(Context.class, String.class,
447:                                    ScriptProxy.class);
448:                    return ctor.newInstance(this , extension, getScriptProxy());
449:                } catch (Exception ex) {
450:                    throw new IllegalArgumentException(
451:                            "Unsupported return type: " + returnType.getName());
452:                }
453:            }
454:
455:            /**
456:             * Asynchronously loads an xml document and stores it in this cache.
457:             * @param strURL url (relative or absolute) the URI of the document to open.
458:             * @param strId the id under which to store the document. If this parameter is not provided, the
459:            <code>strURL</code> parameter is used as the id.
460:             * @param objClass <code>jsx3.xml.Document</code> (default value) or one of its subclasses. The
461:            class with which to instantiate the new document instance.
462:             * @return the document retrieved from the cache or a placeholder document if the document
463:            is in the process of loading asynchronously.
464:             */
465:            @SuppressWarnings("unchecked")
466:            public jsx3.xml.CdfDocument getOrOpenAsync(String strURL,
467:                    String strId, Class objClass) {
468:                String extension = "getOrOpenAsync(\"" + strURL + "\", \""
469:                        + strId + "\", \"" + objClass + "\").";
470:                try {
471:                    java.lang.reflect.Constructor<jsx3.xml.CdfDocument> ctor = jsx3.xml.CdfDocument.class
472:                            .getConstructor(Context.class, String.class,
473:                                    ScriptProxy.class);
474:                    return ctor.newInstance(this , extension, getScriptProxy());
475:                } catch (Exception ex) {
476:                    throw new IllegalArgumentException("Unsupported type: "
477:                            + jsx3.xml.CdfDocument.class.getName());
478:                }
479:            }
480:
481:            /**
482:             * Asynchronously loads an xml document and stores it in this cache.
483:             * @param strURL url (relative or absolute) the URI of the document to open.
484:             * @param strId the id under which to store the document. If this parameter is not provided, the
485:            <code>strURL</code> parameter is used as the id.
486:             * @param objClass <code>jsx3.xml.Document</code> (default value) or one of its subclasses. The
487:            class with which to instantiate the new document instance.
488:             * @param returnType The expected return type
489:             * @return the document retrieved from the cache or a placeholder document if the document
490:            is in the process of loading asynchronously.
491:             */
492:            @SuppressWarnings("unchecked")
493:            public <T> T getOrOpenAsync(String strURL, String strId,
494:                    Class objClass, Class<T> returnType) {
495:                String extension = "getOrOpenAsync(\"" + strURL + "\", \""
496:                        + strId + "\", \"" + objClass + "\").";
497:                try {
498:                    java.lang.reflect.Constructor<T> ctor = returnType
499:                            .getConstructor(Context.class, String.class,
500:                                    ScriptProxy.class);
501:                    return ctor.newInstance(this , extension, getScriptProxy());
502:                } catch (Exception ex) {
503:                    throw new IllegalArgumentException(
504:                            "Unsupported return type: " + returnType.getName());
505:                }
506:            }
507:
508:            /**
509:             * Asynchronously loads an xml document and stores it in this cache.
510:             * @param strURL url (relative or absolute) the URI of the document to open.
511:             * @param strId the id under which to store the document. If this parameter is not provided, the
512:            <code>strURL</code> parameter is used as the id.
513:             * @param objClass <code>jsx3.xml.Document</code> (default value) or one of its subclasses. The
514:            class with which to instantiate the new document instance.
515:             * @return the document retrieved from the cache or a placeholder document if the document
516:            is in the process of loading asynchronously.
517:             */
518:            @SuppressWarnings("unchecked")
519:            public jsx3.xml.CdfDocument getOrOpenAsync(java.net.URI strURL,
520:                    String strId, Class objClass) {
521:                String extension = "getOrOpenAsync(\"" + strURL + "\", \""
522:                        + strId + "\", \"" + objClass + "\").";
523:                try {
524:                    java.lang.reflect.Constructor<jsx3.xml.CdfDocument> ctor = jsx3.xml.CdfDocument.class
525:                            .getConstructor(Context.class, String.class,
526:                                    ScriptProxy.class);
527:                    return ctor.newInstance(this , extension, getScriptProxy());
528:                } catch (Exception ex) {
529:                    throw new IllegalArgumentException("Unsupported type: "
530:                            + jsx3.xml.CdfDocument.class.getName());
531:                }
532:            }
533:
534:            /**
535:             * Asynchronously loads an xml document and stores it in this cache.
536:             * @param strURL url (relative or absolute) the URI of the document to open.
537:             * @param strId the id under which to store the document. If this parameter is not provided, the
538:            <code>strURL</code> parameter is used as the id.
539:             * @param objClass <code>jsx3.xml.Document</code> (default value) or one of its subclasses. The
540:            class with which to instantiate the new document instance.
541:             * @param returnType The expected return type
542:             * @return the document retrieved from the cache or a placeholder document if the document
543:            is in the process of loading asynchronously.
544:             */
545:            @SuppressWarnings("unchecked")
546:            public <T> T getOrOpenAsync(java.net.URI strURL, String strId,
547:                    Class objClass, Class<T> returnType) {
548:                String extension = "getOrOpenAsync(\"" + strURL + "\", \""
549:                        + strId + "\", \"" + objClass + "\").";
550:                try {
551:                    java.lang.reflect.Constructor<T> ctor = returnType
552:                            .getConstructor(Context.class, String.class,
553:                                    ScriptProxy.class);
554:                    return ctor.newInstance(this , extension, getScriptProxy());
555:                } catch (Exception ex) {
556:                    throw new IllegalArgumentException(
557:                            "Unsupported return type: " + returnType.getName());
558:                }
559:            }
560:
561:            /**
562:             * Stores the document objDocument in this cache under id strId. If a document already
563:            exists in this cache under strId then that document is removed from the cache.
564:             * @param strId the id under which to store <code>objDocument</code>.
565:             * @param objDocument 
566:             */
567:            public void setDocument(String strId,
568:                    jsx3.xml.CdfDocument objDocument) {
569:                ScriptBuffer script = new ScriptBuffer();
570:                script.appendCall(getContextPath() + "setDocument", strId,
571:                        objDocument);
572:                getScriptProxy().addScript(script);
573:            }
574:
575:            /**
576:             * Returns the timestamp from when the document stored under id strId was stored in this cache.
577:             * @param strId the id under which the document is stored.
578:             * @param callback the timestamp as an integer (epoch seconds) or <code>null</code> if no such document exists
579:            in this cache.
580:             */
581:            @SuppressWarnings("unchecked")
582:            public void getTimestamp(String strId,
583:                    org.directwebremoting.proxy.Callback<Integer> callback) {
584:                ScriptBuffer script = new ScriptBuffer();
585:                String callbackPrefix = "";
586:
587:                if (callback != null) {
588:                    callbackPrefix = "var reply = ";
589:                }
590:
591:                script.appendCall(callbackPrefix + getContextPath()
592:                        + "getTimestamp", strId);
593:
594:                if (callback != null) {
595:                    String key = org.directwebremoting.extend.CallbackHelper
596:                            .saveCallback(callback, Integer.class);
597:                    script
598:                            .appendCall("__System.activateCallback", key,
599:                                    "reply");
600:                }
601:
602:                getScriptProxy().addScript(script);
603:            }
604:
605:            /**
606:             * Returns a list of all the keys in this cache instance.
607:             */
608:            @SuppressWarnings("unchecked")
609:            public void keys(
610:                    org.directwebremoting.proxy.Callback<Object[]> callback) {
611:                ScriptBuffer script = new ScriptBuffer();
612:                String callbackPrefix = "";
613:
614:                if (callback != null) {
615:                    callbackPrefix = "var reply = ";
616:                }
617:
618:                script.appendCall(callbackPrefix + getContextPath() + "keys");
619:
620:                if (callback != null) {
621:                    String key = org.directwebremoting.extend.CallbackHelper
622:                            .saveCallback(callback, Object[].class);
623:                    script
624:                            .appendCall("__System.activateCallback", key,
625:                                    "reply");
626:                }
627:
628:                getScriptProxy().addScript(script);
629:            }
630:
631:            /**
632:             * Removes all references to documents contained in this cache. This cache is no longer usable after calling this
633:            method.
634:             */
635:            public void destroy() {
636:                ScriptBuffer script = new ScriptBuffer();
637:                script.appendCall(getContextPath() + "destroy");
638:                getScriptProxy().addScript(script);
639:            }
640:
641:            /**
642:             * Publishes an event to all subscribed objects.
643:             * @param objEvent the event, should have at least a field 'subject' that is the event id, another common field is 'target' (target will default to this instance)
644:             * @param callback the number of listeners to which the event was broadcast
645:             */
646:            @SuppressWarnings("unchecked")
647:            public void publish(jsx3.lang.Object objEvent,
648:                    org.directwebremoting.proxy.Callback<Integer> callback) {
649:                ScriptBuffer script = new ScriptBuffer();
650:                String callbackPrefix = "";
651:
652:                if (callback != null) {
653:                    callbackPrefix = "var reply = ";
654:                }
655:
656:                script
657:                        .appendCall(callbackPrefix + getContextPath()
658:                                + "publish", objEvent);
659:
660:                if (callback != null) {
661:                    String key = org.directwebremoting.extend.CallbackHelper
662:                            .saveCallback(callback, Integer.class);
663:                    script
664:                            .appendCall("__System.activateCallback", key,
665:                                    "reply");
666:                }
667:
668:                getScriptProxy().addScript(script);
669:            }
670:
671:            /**
672:             * Subscribes an object or function to a type of event published by this object.
673:
674:            As of version 3.4 a string value for objHandler is deprecated.
675:             * @param strEventId the event type(s).
676:             * @param objHandler if an object, the instance to notify of events (objFunction is required); if a string, the JSX id of the instance to notify of events (objFunction is required), must exist in the same Server; if a function, the function to call to notify of events (objFunction ignored)
677:             * @param objFunction if objHandler is a string or object then the function to call on that instance. either a function or a string that is the name of a method of the instance
678:             */
679:            public void subscribe(String strEventId,
680:                    jsx3.lang.Object objHandler, String objFunction) {
681:                ScriptBuffer script = new ScriptBuffer();
682:                script.appendCall(getContextPath() + "subscribe", strEventId,
683:                        objHandler, objFunction);
684:                getScriptProxy().addScript(script);
685:            }
686:
687:            /**
688:             * Subscribes an object or function to a type of event published by this object.
689:
690:            As of version 3.4 a string value for objHandler is deprecated.
691:             * @param strEventId the event type(s).
692:             * @param objHandler if an object, the instance to notify of events (objFunction is required); if a string, the JSX id of the instance to notify of events (objFunction is required), must exist in the same Server; if a function, the function to call to notify of events (objFunction ignored)
693:             * @param objFunction if objHandler is a string or object then the function to call on that instance. either a function or a string that is the name of a method of the instance
694:             */
695:            public void subscribe(String strEventId,
696:                    org.directwebremoting.proxy.CodeBlock objHandler,
697:                    String objFunction) {
698:                ScriptBuffer script = new ScriptBuffer();
699:                script.appendCall(getContextPath() + "subscribe", strEventId,
700:                        objHandler, objFunction);
701:                getScriptProxy().addScript(script);
702:            }
703:
704:            /**
705:             * Subscribes an object or function to a type of event published by this object.
706:
707:            As of version 3.4 a string value for objHandler is deprecated.
708:             * @param strEventId the event type(s).
709:             * @param objHandler if an object, the instance to notify of events (objFunction is required); if a string, the JSX id of the instance to notify of events (objFunction is required), must exist in the same Server; if a function, the function to call to notify of events (objFunction ignored)
710:             * @param objFunction if objHandler is a string or object then the function to call on that instance. either a function or a string that is the name of a method of the instance
711:             */
712:            public void subscribe(Object[] strEventId,
713:                    jsx3.lang.Object objHandler, String objFunction) {
714:                ScriptBuffer script = new ScriptBuffer();
715:                script.appendCall(getContextPath() + "subscribe", strEventId,
716:                        objHandler, objFunction);
717:                getScriptProxy().addScript(script);
718:            }
719:
720:            /**
721:             * Subscribes an object or function to a type of event published by this object.
722:
723:            As of version 3.4 a string value for objHandler is deprecated.
724:             * @param strEventId the event type(s).
725:             * @param objHandler if an object, the instance to notify of events (objFunction is required); if a string, the JSX id of the instance to notify of events (objFunction is required), must exist in the same Server; if a function, the function to call to notify of events (objFunction ignored)
726:             * @param objFunction if objHandler is a string or object then the function to call on that instance. either a function or a string that is the name of a method of the instance
727:             */
728:            public void subscribe(Object[] strEventId, String objHandler,
729:                    String objFunction) {
730:                ScriptBuffer script = new ScriptBuffer();
731:                script.appendCall(getContextPath() + "subscribe", strEventId,
732:                        objHandler, objFunction);
733:                getScriptProxy().addScript(script);
734:            }
735:
736:            /**
737:             * Subscribes an object or function to a type of event published by this object.
738:
739:            As of version 3.4 a string value for objHandler is deprecated.
740:             * @param strEventId the event type(s).
741:             * @param objHandler if an object, the instance to notify of events (objFunction is required); if a string, the JSX id of the instance to notify of events (objFunction is required), must exist in the same Server; if a function, the function to call to notify of events (objFunction ignored)
742:             * @param objFunction if objHandler is a string or object then the function to call on that instance. either a function or a string that is the name of a method of the instance
743:             */
744:            public void subscribe(Object[] strEventId,
745:                    org.directwebremoting.proxy.CodeBlock objHandler,
746:                    org.directwebremoting.proxy.CodeBlock objFunction) {
747:                ScriptBuffer script = new ScriptBuffer();
748:                script.appendCall(getContextPath() + "subscribe", strEventId,
749:                        objHandler, objFunction);
750:                getScriptProxy().addScript(script);
751:            }
752:
753:            /**
754:             * Subscribes an object or function to a type of event published by this object.
755:
756:            As of version 3.4 a string value for objHandler is deprecated.
757:             * @param strEventId the event type(s).
758:             * @param objHandler if an object, the instance to notify of events (objFunction is required); if a string, the JSX id of the instance to notify of events (objFunction is required), must exist in the same Server; if a function, the function to call to notify of events (objFunction ignored)
759:             * @param objFunction if objHandler is a string or object then the function to call on that instance. either a function or a string that is the name of a method of the instance
760:             */
761:            public void subscribe(Object[] strEventId,
762:                    org.directwebremoting.proxy.CodeBlock objHandler,
763:                    String objFunction) {
764:                ScriptBuffer script = new ScriptBuffer();
765:                script.appendCall(getContextPath() + "subscribe", strEventId,
766:                        objHandler, objFunction);
767:                getScriptProxy().addScript(script);
768:            }
769:
770:            /**
771:             * Subscribes an object or function to a type of event published by this object.
772:
773:            As of version 3.4 a string value for objHandler is deprecated.
774:             * @param strEventId the event type(s).
775:             * @param objHandler if an object, the instance to notify of events (objFunction is required); if a string, the JSX id of the instance to notify of events (objFunction is required), must exist in the same Server; if a function, the function to call to notify of events (objFunction ignored)
776:             * @param objFunction if objHandler is a string or object then the function to call on that instance. either a function or a string that is the name of a method of the instance
777:             */
778:            public void subscribe(String strEventId,
779:                    org.directwebremoting.proxy.CodeBlock objHandler,
780:                    org.directwebremoting.proxy.CodeBlock objFunction) {
781:                ScriptBuffer script = new ScriptBuffer();
782:                script.appendCall(getContextPath() + "subscribe", strEventId,
783:                        objHandler, objFunction);
784:                getScriptProxy().addScript(script);
785:            }
786:
787:            /**
788:             * Subscribes an object or function to a type of event published by this object.
789:
790:            As of version 3.4 a string value for objHandler is deprecated.
791:             * @param strEventId the event type(s).
792:             * @param objHandler if an object, the instance to notify of events (objFunction is required); if a string, the JSX id of the instance to notify of events (objFunction is required), must exist in the same Server; if a function, the function to call to notify of events (objFunction ignored)
793:             * @param objFunction if objHandler is a string or object then the function to call on that instance. either a function or a string that is the name of a method of the instance
794:             */
795:            public void subscribe(String strEventId, String objHandler,
796:                    org.directwebremoting.proxy.CodeBlock objFunction) {
797:                ScriptBuffer script = new ScriptBuffer();
798:                script.appendCall(getContextPath() + "subscribe", strEventId,
799:                        objHandler, objFunction);
800:                getScriptProxy().addScript(script);
801:            }
802:
803:            /**
804:             * Subscribes an object or function to a type of event published by this object.
805:
806:            As of version 3.4 a string value for objHandler is deprecated.
807:             * @param strEventId the event type(s).
808:             * @param objHandler if an object, the instance to notify of events (objFunction is required); if a string, the JSX id of the instance to notify of events (objFunction is required), must exist in the same Server; if a function, the function to call to notify of events (objFunction ignored)
809:             * @param objFunction if objHandler is a string or object then the function to call on that instance. either a function or a string that is the name of a method of the instance
810:             */
811:            public void subscribe(Object[] strEventId,
812:                    jsx3.lang.Object objHandler,
813:                    org.directwebremoting.proxy.CodeBlock objFunction) {
814:                ScriptBuffer script = new ScriptBuffer();
815:                script.appendCall(getContextPath() + "subscribe", strEventId,
816:                        objHandler, objFunction);
817:                getScriptProxy().addScript(script);
818:            }
819:
820:            /**
821:             * Subscribes an object or function to a type of event published by this object.
822:
823:            As of version 3.4 a string value for objHandler is deprecated.
824:             * @param strEventId the event type(s).
825:             * @param objHandler if an object, the instance to notify of events (objFunction is required); if a string, the JSX id of the instance to notify of events (objFunction is required), must exist in the same Server; if a function, the function to call to notify of events (objFunction ignored)
826:             * @param objFunction if objHandler is a string or object then the function to call on that instance. either a function or a string that is the name of a method of the instance
827:             */
828:            public void subscribe(String strEventId,
829:                    jsx3.lang.Object objHandler,
830:                    org.directwebremoting.proxy.CodeBlock objFunction) {
831:                ScriptBuffer script = new ScriptBuffer();
832:                script.appendCall(getContextPath() + "subscribe", strEventId,
833:                        objHandler, objFunction);
834:                getScriptProxy().addScript(script);
835:            }
836:
837:            /**
838:             * Subscribes an object or function to a type of event published by this object.
839:
840:            As of version 3.4 a string value for objHandler is deprecated.
841:             * @param strEventId the event type(s).
842:             * @param objHandler if an object, the instance to notify of events (objFunction is required); if a string, the JSX id of the instance to notify of events (objFunction is required), must exist in the same Server; if a function, the function to call to notify of events (objFunction ignored)
843:             * @param objFunction if objHandler is a string or object then the function to call on that instance. either a function or a string that is the name of a method of the instance
844:             */
845:            public void subscribe(Object[] strEventId, String objHandler,
846:                    org.directwebremoting.proxy.CodeBlock objFunction) {
847:                ScriptBuffer script = new ScriptBuffer();
848:                script.appendCall(getContextPath() + "subscribe", strEventId,
849:                        objHandler, objFunction);
850:                getScriptProxy().addScript(script);
851:            }
852:
853:            /**
854:             * Subscribes an object or function to a type of event published by this object.
855:
856:            As of version 3.4 a string value for objHandler is deprecated.
857:             * @param strEventId the event type(s).
858:             * @param objHandler if an object, the instance to notify of events (objFunction is required); if a string, the JSX id of the instance to notify of events (objFunction is required), must exist in the same Server; if a function, the function to call to notify of events (objFunction ignored)
859:             * @param objFunction if objHandler is a string or object then the function to call on that instance. either a function or a string that is the name of a method of the instance
860:             */
861:            public void subscribe(String strEventId, String objHandler,
862:                    String objFunction) {
863:                ScriptBuffer script = new ScriptBuffer();
864:                script.appendCall(getContextPath() + "subscribe", strEventId,
865:                        objHandler, objFunction);
866:                getScriptProxy().addScript(script);
867:            }
868:
869:            /**
870:             * Unsubscribe an object or function from an event published by this object.
871:
872:            As of version 3.4 a string value for objHandler is deprecated.
873:             * @param strEventId the event type(s).
874:             * @param objHandler the value of objHandler passed to subscribe
875:             */
876:            public void unsubscribe(String strEventId, String objHandler) {
877:                ScriptBuffer script = new ScriptBuffer();
878:                script.appendCall(getContextPath() + "unsubscribe", strEventId,
879:                        objHandler);
880:                getScriptProxy().addScript(script);
881:            }
882:
883:            /**
884:             * Unsubscribe an object or function from an event published by this object.
885:
886:            As of version 3.4 a string value for objHandler is deprecated.
887:             * @param strEventId the event type(s).
888:             * @param objHandler the value of objHandler passed to subscribe
889:             */
890:            public void unsubscribe(Object[] strEventId,
891:                    jsx3.lang.Object objHandler) {
892:                ScriptBuffer script = new ScriptBuffer();
893:                script.appendCall(getContextPath() + "unsubscribe", strEventId,
894:                        objHandler);
895:                getScriptProxy().addScript(script);
896:            }
897:
898:            /**
899:             * Unsubscribe an object or function from an event published by this object.
900:
901:            As of version 3.4 a string value for objHandler is deprecated.
902:             * @param strEventId the event type(s).
903:             * @param objHandler the value of objHandler passed to subscribe
904:             */
905:            public void unsubscribe(Object[] strEventId, String objHandler) {
906:                ScriptBuffer script = new ScriptBuffer();
907:                script.appendCall(getContextPath() + "unsubscribe", strEventId,
908:                        objHandler);
909:                getScriptProxy().addScript(script);
910:            }
911:
912:            /**
913:             * Unsubscribe an object or function from an event published by this object.
914:
915:            As of version 3.4 a string value for objHandler is deprecated.
916:             * @param strEventId the event type(s).
917:             * @param objHandler the value of objHandler passed to subscribe
918:             */
919:            public void unsubscribe(Object[] strEventId,
920:                    org.directwebremoting.proxy.CodeBlock objHandler) {
921:                ScriptBuffer script = new ScriptBuffer();
922:                script.appendCall(getContextPath() + "unsubscribe", strEventId,
923:                        objHandler);
924:                getScriptProxy().addScript(script);
925:            }
926:
927:            /**
928:             * Unsubscribe an object or function from an event published by this object.
929:
930:            As of version 3.4 a string value for objHandler is deprecated.
931:             * @param strEventId the event type(s).
932:             * @param objHandler the value of objHandler passed to subscribe
933:             */
934:            public void unsubscribe(String strEventId,
935:                    jsx3.lang.Object objHandler) {
936:                ScriptBuffer script = new ScriptBuffer();
937:                script.appendCall(getContextPath() + "unsubscribe", strEventId,
938:                        objHandler);
939:                getScriptProxy().addScript(script);
940:            }
941:
942:            /**
943:             * Unsubscribe an object or function from an event published by this object.
944:
945:            As of version 3.4 a string value for objHandler is deprecated.
946:             * @param strEventId the event type(s).
947:             * @param objHandler the value of objHandler passed to subscribe
948:             */
949:            public void unsubscribe(String strEventId,
950:                    org.directwebremoting.proxy.CodeBlock objHandler) {
951:                ScriptBuffer script = new ScriptBuffer();
952:                script.appendCall(getContextPath() + "unsubscribe", strEventId,
953:                        objHandler);
954:                getScriptProxy().addScript(script);
955:            }
956:
957:            /**
958:             * Unsubscribes all subscribed objects to a type of event published by this object.
959:             * @param strEventId the event type
960:             */
961:            public void unsubscribeAll(String strEventId) {
962:                ScriptBuffer script = new ScriptBuffer();
963:                script.appendCall(getContextPath() + "unsubscribeAll",
964:                        strEventId);
965:                getScriptProxy().addScript(script);
966:            }
967:
968:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.