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.xml;
017:
018: import org.directwebremoting.ScriptBuffer;
019: import org.directwebremoting.proxy.ScriptProxy;
020: import org.directwebremoting.proxy.io.Context;
021:
022: /**
023: * A mixin interface that provides the following capabilities to implementing classes:
024:
025: fetching and caching of an XML document from an XML string, URL, or cache id
026: fetching and caching of an XSL document from an XSL string, URL, or cache id
027: transformation of the XML document by the XSL document
028: XSL parameterization via setXSLParam/getXSLParams
029: management of cached resources
030:
031: A class that implement this interface should usually be a subclass of jsx3.app.Model since this
032: interface assumes that its instances have methods in that class (in particular getId() and
033: getServer()).
034:
035: As of version 3.2 using custom XSL templates for built-in GUI classes implementing this interface is deprecated.
036: Therefore, several methods related to storing per-instance XSL documents are deprecated.
037: * @author Joe Walker [joe at getahead dot org]
038: * @author DRAPGEN - Dwr Reverse Ajax Proxy GENerator
039: */
040: public class Cacheable extends jsx3.lang.Object {
041: /**
042: * All reverse ajax proxies need context to work from
043: * @param scriptProxy The place we are writing scripts to
044: * @param context The script that got us to where we are now
045: */
046: public Cacheable(Context context, String extension,
047: ScriptProxy scriptProxy) {
048: super (context, extension, scriptProxy);
049: }
050:
051: /**
052: * JSX/xsl/xml.xsl
053: */
054: public static final String DEFAULTSTYLESHEET = null;
055:
056: /**
057: * Value of the shareResources property for an object that removes its XML and XSL
058: documents from the server XML cache when it is destroyed.
059: */
060: public static final int CLEANUPRESOURCES = 0;
061:
062: /**
063: * Value of the shareResources property for an object that leaves its XML and XSL
064: documents in the server XML cache when it is destroyed.
065: */
066: public static final int SHARERESOURCES = 1;
067:
068: /**
069: * Returns a map containing all the parameters to pass to the XSL stylesheet during transformation.
070: */
071: @SuppressWarnings("unchecked")
072: public jsx3.lang.Object getXSLParams() {
073: String extension = "getXSLParams().";
074: try {
075: java.lang.reflect.Constructor<jsx3.lang.Object> ctor = jsx3.lang.Object.class
076: .getConstructor(Context.class, String.class,
077: ScriptProxy.class);
078: return ctor.newInstance(this , extension, getScriptProxy());
079: } catch (Exception ex) {
080: throw new IllegalArgumentException("Unsupported type: "
081: + jsx3.lang.Object.class.getName());
082: }
083: }
084:
085: /**
086: * Returns a map containing all the parameters to pass to the XSL stylesheet during transformation.
087: * @param returnType The expected return type
088: */
089: @SuppressWarnings("unchecked")
090: public <T> T getXSLParams(Class<T> returnType) {
091: String extension = "getXSLParams().";
092: try {
093: java.lang.reflect.Constructor<T> ctor = returnType
094: .getConstructor(Context.class, String.class,
095: ScriptProxy.class);
096: return ctor.newInstance(this , extension, getScriptProxy());
097: } catch (Exception ex) {
098: throw new IllegalArgumentException(
099: "Unsupported return type: " + returnType.getName());
100: }
101: }
102:
103: /**
104: * Adds a name/value pair to the list of parameters to pass to the XSL stylesheet during transformation. If
105: strValue is null the parameter is removed.
106: * @param strName the name of the XSL parameter to add.
107: * @param strValue the value of the XSL parameter to add.
108: * @return this object.
109: */
110: public jsx3.xml.Cacheable setXSLParam(String strName,
111: String strValue) {
112: ScriptBuffer script = new ScriptBuffer();
113: script.appendCall(getContextPath() + "setXSLParam", strName,
114: strValue);
115: getScriptProxy().addScript(script);
116: return this ;
117: }
118:
119: /**
120: * Removes a parameter from the list of parameters to pass to the XSL stylesheet during transformation.
121: * @param strName the name of the XSL parameter to remove.
122: * @return this object.
123: */
124: @SuppressWarnings("unchecked")
125: public jsx3.xml.Cacheable removeXSLParam(String strName) {
126: String extension = "removeXSLParam(\"" + strName + "\").";
127: try {
128: java.lang.reflect.Constructor<jsx3.xml.Cacheable> ctor = jsx3.xml.Cacheable.class
129: .getConstructor(Context.class, String.class,
130: ScriptProxy.class);
131: return ctor.newInstance(this , extension, getScriptProxy());
132: } catch (Exception ex) {
133: throw new IllegalArgumentException("Unsupported type: "
134: + jsx3.xml.Cacheable.class.getName());
135: }
136: }
137:
138: /**
139: * Removes a parameter from the list of parameters to pass to the XSL stylesheet during transformation.
140: * @param strName the name of the XSL parameter to remove.
141: * @param returnType The expected return type
142: * @return this object.
143: */
144: @SuppressWarnings("unchecked")
145: public <T> T removeXSLParam(String strName, Class<T> returnType) {
146: String extension = "removeXSLParam(\"" + strName + "\").";
147: try {
148: java.lang.reflect.Constructor<T> ctor = returnType
149: .getConstructor(Context.class, String.class,
150: ScriptProxy.class);
151: return ctor.newInstance(this , extension, getScriptProxy());
152: } catch (Exception ex) {
153: throw new IllegalArgumentException(
154: "Unsupported return type: " + returnType.getName());
155: }
156: }
157:
158: /**
159: * Removes all parameters from the list of parameters to pass to the XSL stylesheet during transformation.
160: * @return this object.
161: */
162: @SuppressWarnings("unchecked")
163: public jsx3.xml.Cacheable removeXSLParams() {
164: String extension = "removeXSLParams().";
165: try {
166: java.lang.reflect.Constructor<jsx3.xml.Cacheable> ctor = jsx3.xml.Cacheable.class
167: .getConstructor(Context.class, String.class,
168: ScriptProxy.class);
169: return ctor.newInstance(this , extension, getScriptProxy());
170: } catch (Exception ex) {
171: throw new IllegalArgumentException("Unsupported type: "
172: + jsx3.xml.Cacheable.class.getName());
173: }
174: }
175:
176: /**
177: * Removes all parameters from the list of parameters to pass to the XSL stylesheet during transformation.
178: * @param returnType The expected return type
179: * @return this object.
180: */
181: @SuppressWarnings("unchecked")
182: public <T> T removeXSLParams(Class<T> returnType) {
183: String extension = "removeXSLParams().";
184: try {
185: java.lang.reflect.Constructor<T> ctor = returnType
186: .getConstructor(Context.class, String.class,
187: ScriptProxy.class);
188: return ctor.newInstance(this , extension, getScriptProxy());
189: } catch (Exception ex) {
190: throw new IllegalArgumentException(
191: "Unsupported return type: " + returnType.getName());
192: }
193: }
194:
195: /**
196: * Removes the XML and XSL source documents from the server cache.
197: * @param objServer the server owning the cache to modify. This is a required argument only if
198: <code>this.getServer()</code> does not returns a server instance.
199: */
200: public void resetCacheData(jsx3.app.Server objServer) {
201: ScriptBuffer script = new ScriptBuffer();
202: script.appendCall(getContextPath() + "resetCacheData",
203: objServer);
204: getScriptProxy().addScript(script);
205: }
206:
207: /**
208: * Removes the XML source document stored under the XML ID of this object from the server cache.
209: * @param objServer the server owning the cache to modify. This is a required argument only if
210: <code>this.getServer()</code> does not returns a server instance.
211: */
212: public void resetXmlCacheData(jsx3.app.Server objServer) {
213: ScriptBuffer script = new ScriptBuffer();
214: script.appendCall(getContextPath() + "resetXmlCacheData",
215: objServer);
216: getScriptProxy().addScript(script);
217: }
218:
219: /**
220: * Resets the XML source document stored in the server cache under the XML ID of this object to an empty CDF
221: document.
222: */
223: public void clearXmlData() {
224: ScriptBuffer script = new ScriptBuffer();
225: script.appendCall(getContextPath() + "clearXmlData");
226: getScriptProxy().addScript(script);
227: }
228:
229: /**
230: * Returns whether this object removes its XML and XSL source documents from the cache of its server when it
231: is destroyed.
232: * @param callback <code>CLEANUPRESOURCES</code> or <code>SHARERESOURCES</code>.
233: */
234: @SuppressWarnings("unchecked")
235: public void getShareResources(
236: org.directwebremoting.proxy.Callback<Integer> callback) {
237: ScriptBuffer script = new ScriptBuffer();
238: String callbackPrefix = "";
239:
240: if (callback != null) {
241: callbackPrefix = "var reply = ";
242: }
243:
244: script.appendCall(callbackPrefix + getContextPath()
245: + "getShareResources");
246:
247: if (callback != null) {
248: String key = org.directwebremoting.extend.CallbackHelper
249: .saveCallback(callback, Integer.class);
250: script
251: .appendCall("__System.activateCallback", key,
252: "reply");
253: }
254:
255: getScriptProxy().addScript(script);
256: }
257:
258: /**
259: * Sets whether this object removes its XML and XSL source documents from the cache of its server when it
260: is destroyed.
261: * @param intShare <code>CLEANUPRESOURCES</code> or <code>SHARERESOURCES</code>. <code>CLEANUPRESOURCES</code>
262: is the default value if the property is <code>null</code>.
263: * @return this object.
264: */
265: public jsx3.xml.Cacheable setShareResources(int intShare) {
266: ScriptBuffer script = new ScriptBuffer();
267: script.appendCall(getContextPath() + "setShareResources",
268: intShare);
269: getScriptProxy().addScript(script);
270: return this ;
271: }
272:
273: /**
274: * Returns the XML source document of this object. The XML document is determined by the following steps:
275:
276: If an XML document exists in the server cache under an ID equal to the XML ID of this object, that
277: document is returned.
278: If the XML string of this object is not empty, a new document is created by parsing this string.
279: If the XML URL of this object is not empty, a new document is created by parsing the file at the location
280: specified by the URL resolved against the server owning this object.
281: Otherwise, an empty CDF document is returned.
282:
283: If a new document is created for this object (any of the steps listed above except for the first one), the
284: following actions are also taken:
285:
286: If creating the document resulted in an error (XML parsing error, file not found error, etc) the offending
287: document is returned immediately.
288: Otherwise, setSourceXML is called on this object, passing in the created document.
289: */
290: @SuppressWarnings("unchecked")
291: public jsx3.xml.CdfDocument getXML() {
292: String extension = "getXML().";
293: try {
294: java.lang.reflect.Constructor<jsx3.xml.CdfDocument> ctor = jsx3.xml.CdfDocument.class
295: .getConstructor(Context.class, String.class,
296: ScriptProxy.class);
297: return ctor.newInstance(this , extension, getScriptProxy());
298: } catch (Exception ex) {
299: throw new IllegalArgumentException("Unsupported type: "
300: + jsx3.xml.CdfDocument.class.getName());
301: }
302: }
303:
304: /**
305: * Returns the XML source document of this object. The XML document is determined by the following steps:
306:
307: If an XML document exists in the server cache under an ID equal to the XML ID of this object, that
308: document is returned.
309: If the XML string of this object is not empty, a new document is created by parsing this string.
310: If the XML URL of this object is not empty, a new document is created by parsing the file at the location
311: specified by the URL resolved against the server owning this object.
312: Otherwise, an empty CDF document is returned.
313:
314: If a new document is created for this object (any of the steps listed above except for the first one), the
315: following actions are also taken:
316:
317: If creating the document resulted in an error (XML parsing error, file not found error, etc) the offending
318: document is returned immediately.
319: Otherwise, setSourceXML is called on this object, passing in the created document.
320: * @param returnType The expected return type
321: */
322: @SuppressWarnings("unchecked")
323: public <T> T getXML(Class<T> returnType) {
324: String extension = "getXML().";
325: try {
326: java.lang.reflect.Constructor<T> ctor = returnType
327: .getConstructor(Context.class, String.class,
328: ScriptProxy.class);
329: return ctor.newInstance(this , extension, getScriptProxy());
330: } catch (Exception ex) {
331: throw new IllegalArgumentException(
332: "Unsupported return type: " + returnType.getName());
333: }
334: }
335:
336: /**
337: * Sets the source document of this object as though objDoc were retrieved from the XML URL or XML
338: string of this object. This method executes the following steps:
339:
340: The document is transformed serially by each XML transformers of this object.
341: The XML document is saved in the server cache under the XML ID of this object.
342: If this object is an instance of jsx3.xml.CDF and the root node is a <data> element
343: and its jsxassignids attribute is equal to 1, all <record> elements without a
344: jsxid attribute are assigned a unique jsxid.
345: If this object is an instance of jsx3.xml.CDF, convertProperties() is called
346: on this object.
347: * @param objDoc
348: * @param objCache
349: * @return the document stored in the server cache as the data source of this object. If
350: transformers were run, this value will not be equal to the <code>objDoc</code> parameter.
351: */
352: @SuppressWarnings("unchecked")
353: public jsx3.xml.CdfDocument setSourceXML(
354: jsx3.xml.CdfDocument objDoc, jsx3.app.Cache objCache) {
355: String extension = "setSourceXML(\"" + objDoc + "\", \""
356: + objCache + "\").";
357: try {
358: java.lang.reflect.Constructor<jsx3.xml.CdfDocument> ctor = jsx3.xml.CdfDocument.class
359: .getConstructor(Context.class, String.class,
360: ScriptProxy.class);
361: return ctor.newInstance(this , extension, getScriptProxy());
362: } catch (Exception ex) {
363: throw new IllegalArgumentException("Unsupported type: "
364: + jsx3.xml.CdfDocument.class.getName());
365: }
366: }
367:
368: /**
369: * Sets the source document of this object as though objDoc were retrieved from the XML URL or XML
370: string of this object. This method executes the following steps:
371:
372: The document is transformed serially by each XML transformers of this object.
373: The XML document is saved in the server cache under the XML ID of this object.
374: If this object is an instance of jsx3.xml.CDF and the root node is a <data> element
375: and its jsxassignids attribute is equal to 1, all <record> elements without a
376: jsxid attribute are assigned a unique jsxid.
377: If this object is an instance of jsx3.xml.CDF, convertProperties() is called
378: on this object.
379: * @param objDoc
380: * @param objCache
381: * @param returnType The expected return type
382: * @return the document stored in the server cache as the data source of this object. If
383: transformers were run, this value will not be equal to the <code>objDoc</code> parameter.
384: */
385: @SuppressWarnings("unchecked")
386: public <T> T setSourceXML(jsx3.xml.CdfDocument objDoc,
387: jsx3.app.Cache objCache, Class<T> returnType) {
388: String extension = "setSourceXML(\"" + objDoc + "\", \""
389: + objCache + "\").";
390: try {
391: java.lang.reflect.Constructor<T> ctor = returnType
392: .getConstructor(Context.class, String.class,
393: ScriptProxy.class);
394: return ctor.newInstance(this , extension, getScriptProxy());
395: } catch (Exception ex) {
396: throw new IllegalArgumentException(
397: "Unsupported return type: " + returnType.getName());
398: }
399: }
400:
401: /**
402: * Returns the XML ID of this object.
403: * @param callback the XML ID.
404: */
405: @SuppressWarnings("unchecked")
406: public void getXMLId(
407: org.directwebremoting.proxy.Callback<String> callback) {
408: ScriptBuffer script = new ScriptBuffer();
409: String callbackPrefix = "";
410:
411: if (callback != null) {
412: callbackPrefix = "var reply = ";
413: }
414:
415: script.appendCall(callbackPrefix + getContextPath()
416: + "getXMLId");
417:
418: if (callback != null) {
419: String key = org.directwebremoting.extend.CallbackHelper
420: .saveCallback(callback, String.class);
421: script
422: .appendCall("__System.activateCallback", key,
423: "reply");
424: }
425:
426: getScriptProxy().addScript(script);
427: }
428:
429: /**
430: * Sets the XML ID of this object. This value is the key under which the XML source document of this object is
431: saved in the cache of the server owning this object. The developer may specify either a unique or shared value.
432: If no value is specified, a unique id is generated.
433: * @param strXMLId
434: * @return this object.
435: */
436: public jsx3.xml.Cacheable setXMLId(String strXMLId) {
437: ScriptBuffer script = new ScriptBuffer();
438: script.appendCall(getContextPath() + "setXMLId", strXMLId);
439: getScriptProxy().addScript(script);
440: return this ;
441: }
442:
443: /**
444: * Returns the XML string of this object.
445: */
446: @SuppressWarnings("unchecked")
447: public void getXMLString(
448: org.directwebremoting.proxy.Callback<String> callback) {
449: ScriptBuffer script = new ScriptBuffer();
450: String callbackPrefix = "";
451:
452: if (callback != null) {
453: callbackPrefix = "var reply = ";
454: }
455:
456: script.appendCall(callbackPrefix + getContextPath()
457: + "getXMLString");
458:
459: if (callback != null) {
460: String key = org.directwebremoting.extend.CallbackHelper
461: .saveCallback(callback, String.class);
462: script
463: .appendCall("__System.activateCallback", key,
464: "reply");
465: }
466:
467: getScriptProxy().addScript(script);
468: }
469:
470: /**
471: * Sets the XML string of this object. Setting this value to the string serialization of an XML document is one
472: way of specifying the source XML document of this object.
473: * @param strXML <code>null</code> or a well-formed serialized XML element.
474: * @return this object.
475: */
476: public jsx3.xml.Cacheable setXMLString(String strXML) {
477: ScriptBuffer script = new ScriptBuffer();
478: script.appendCall(getContextPath() + "setXMLString", strXML);
479: getScriptProxy().addScript(script);
480: return this ;
481: }
482:
483: /**
484: * Returns the XML URL of this object.
485: */
486: @SuppressWarnings("unchecked")
487: public void getXMLURL(
488: org.directwebremoting.proxy.Callback<String> callback) {
489: ScriptBuffer script = new ScriptBuffer();
490: String callbackPrefix = "";
491:
492: if (callback != null) {
493: callbackPrefix = "var reply = ";
494: }
495:
496: script.appendCall(callbackPrefix + getContextPath()
497: + "getXMLURL");
498:
499: if (callback != null) {
500: String key = org.directwebremoting.extend.CallbackHelper
501: .saveCallback(callback, String.class);
502: script
503: .appendCall("__System.activateCallback", key,
504: "reply");
505: }
506:
507: getScriptProxy().addScript(script);
508: }
509:
510: /**
511: * Sets the XML URL of this object. Settings this value to the URI of an XML document is one way of specifying the
512: source XML document of this object.
513: * @param strXMLURL <code>null</code> or a URI that when resolved against the server owning this object
514: specifies a valid XML document.
515: * @return this object.
516: */
517: public jsx3.xml.Cacheable setXMLURL(String strXMLURL) {
518: ScriptBuffer script = new ScriptBuffer();
519: script.appendCall(getContextPath() + "setXMLURL", strXMLURL);
520: getScriptProxy().addScript(script);
521: return this ;
522: }
523:
524: /**
525: * Returns whether the XML data source of this object is loaded asynchronously.
526: * @param callback <code>0</code> or <code>1</code>.
527: */
528: @SuppressWarnings("unchecked")
529: public void getXmlAsync(
530: org.directwebremoting.proxy.Callback<Integer> callback) {
531: ScriptBuffer script = new ScriptBuffer();
532: String callbackPrefix = "";
533:
534: if (callback != null) {
535: callbackPrefix = "var reply = ";
536: }
537:
538: script.appendCall(callbackPrefix + getContextPath()
539: + "getXmlAsync");
540:
541: if (callback != null) {
542: String key = org.directwebremoting.extend.CallbackHelper
543: .saveCallback(callback, Integer.class);
544: script
545: .appendCall("__System.activateCallback", key,
546: "reply");
547: }
548:
549: getScriptProxy().addScript(script);
550: }
551:
552: /**
553: * Sets whether the XML data source of this object is loaded asynchronously. This setting only applies to
554: data sources loaded from an XML URL.
555: * @param bAsync
556: * @return this object.
557: */
558: public jsx3.xml.Cacheable setXmlAsync(boolean bAsync) {
559: ScriptBuffer script = new ScriptBuffer();
560: script.appendCall(getContextPath() + "setXmlAsync", bAsync);
561: getScriptProxy().addScript(script);
562: return this ;
563: }
564:
565: /**
566: * Returns whether this object is bound to the XML document stored in the data cache.
567: * @param callback <code>0</code> or <code>1</code>.
568: */
569: @SuppressWarnings("unchecked")
570: public void getXmlBind(
571: org.directwebremoting.proxy.Callback<Integer> callback) {
572: ScriptBuffer script = new ScriptBuffer();
573: String callbackPrefix = "";
574:
575: if (callback != null) {
576: callbackPrefix = "var reply = ";
577: }
578:
579: script.appendCall(callbackPrefix + getContextPath()
580: + "getXmlBind");
581:
582: if (callback != null) {
583: String key = org.directwebremoting.extend.CallbackHelper
584: .saveCallback(callback, Integer.class);
585: script
586: .appendCall("__System.activateCallback", key,
587: "reply");
588: }
589:
590: getScriptProxy().addScript(script);
591: }
592:
593: /**
594: * Sets whether this object is bound to the XML document stored in the data cache. If this object is bound to the
595: cache, then the onXmlBinding() method of this object is called any time the document stored in
596: the cache under the XML Id of this object changes.
597: * @param bBind
598: * @param callback <code>0</code> or <code>1</code>.
599: */
600: @SuppressWarnings("unchecked")
601: public void setXmlBind(boolean bBind,
602: org.directwebremoting.proxy.Callback<Integer> callback) {
603: ScriptBuffer script = new ScriptBuffer();
604: String callbackPrefix = "";
605:
606: if (callback != null) {
607: callbackPrefix = "var reply = ";
608: }
609:
610: script.appendCall(callbackPrefix + getContextPath()
611: + "setXmlBind", bBind);
612:
613: if (callback != null) {
614: String key = org.directwebremoting.extend.CallbackHelper
615: .saveCallback(callback, Integer.class);
616: script
617: .appendCall("__System.activateCallback", key,
618: "reply");
619: }
620:
621: getScriptProxy().addScript(script);
622: }
623:
624: /**
625: * This method is called in two situations:
626:
627: When the datasource of this object finishes loading (success, error, or timeout), if the
628: xmlAsync property of this object is true, its datasource is specified as an
629: XML URL, and the first time doTransform() was called the datasource was still loading.
630: Any time the value stored in the server XML cache under the key equal to the XML Id of this object
631: changes, if the xmlBind property of this object is true.
632:
633: Any methods overriding this method should begin with a call to jsxsupermix().
634: * @param objEvent the event published by the cache.
635: */
636: public void onXmlBinding(jsx3.lang.Object objEvent) {
637: ScriptBuffer script = new ScriptBuffer();
638: script.appendCall(getContextPath() + "onXmlBinding", objEvent);
639: getScriptProxy().addScript(script);
640: }
641:
642: /**
643: * Returns the XSL source document of this object. The XSL document is determined by the following steps:
644:
645: If an XSL document exists in the server cache under an ID equal to the XSL ID of this object, that
646: document is returned.
647: (Deprecated) If the XSL string of this object is not null, a new document is created by parsing this string.
648: (Deprecated) If the XSL URL of this object is not null, a new document is created by parsing the file at the location
649: specified by the URL resolved against the server owning this object.
650: Otherwise, the default stylesheet (Cacheable.DEFAULTSTYLESHEET) is returned.
651: * @return the XSL source document.
652: */
653: @SuppressWarnings("unchecked")
654: public jsx3.xml.CdfDocument getXSL() {
655: String extension = "getXSL().";
656: try {
657: java.lang.reflect.Constructor<jsx3.xml.CdfDocument> ctor = jsx3.xml.CdfDocument.class
658: .getConstructor(Context.class, String.class,
659: ScriptProxy.class);
660: return ctor.newInstance(this , extension, getScriptProxy());
661: } catch (Exception ex) {
662: throw new IllegalArgumentException("Unsupported type: "
663: + jsx3.xml.CdfDocument.class.getName());
664: }
665: }
666:
667: /**
668: * Returns the XSL source document of this object. The XSL document is determined by the following steps:
669:
670: If an XSL document exists in the server cache under an ID equal to the XSL ID of this object, that
671: document is returned.
672: (Deprecated) If the XSL string of this object is not null, a new document is created by parsing this string.
673: (Deprecated) If the XSL URL of this object is not null, a new document is created by parsing the file at the location
674: specified by the URL resolved against the server owning this object.
675: Otherwise, the default stylesheet (Cacheable.DEFAULTSTYLESHEET) is returned.
676: * @param returnType The expected return type
677: * @return the XSL source document.
678: */
679: @SuppressWarnings("unchecked")
680: public <T> T getXSL(Class<T> returnType) {
681: String extension = "getXSL().";
682: try {
683: java.lang.reflect.Constructor<T> ctor = returnType
684: .getConstructor(Context.class, String.class,
685: ScriptProxy.class);
686: return ctor.newInstance(this , extension, getScriptProxy());
687: } catch (Exception ex) {
688: throw new IllegalArgumentException(
689: "Unsupported return type: " + returnType.getName());
690: }
691: }
692:
693: /**
694: * Returns the XSL ID of this object.
695: */
696: @SuppressWarnings("unchecked")
697: public void getXSLId(
698: org.directwebremoting.proxy.Callback<String> callback) {
699: ScriptBuffer script = new ScriptBuffer();
700: String callbackPrefix = "";
701:
702: if (callback != null) {
703: callbackPrefix = "var reply = ";
704: }
705:
706: script.appendCall(callbackPrefix + getContextPath()
707: + "getXSLId");
708:
709: if (callback != null) {
710: String key = org.directwebremoting.extend.CallbackHelper
711: .saveCallback(callback, String.class);
712: script
713: .appendCall("__System.activateCallback", key,
714: "reply");
715: }
716:
717: getScriptProxy().addScript(script);
718: }
719:
720: /**
721: * Returns the list of XML transformers of this object.
722: */
723: @SuppressWarnings("unchecked")
724: public void getXMLTransformers(
725: org.directwebremoting.proxy.Callback<Object[]> callback) {
726: ScriptBuffer script = new ScriptBuffer();
727: String callbackPrefix = "";
728:
729: if (callback != null) {
730: callbackPrefix = "var reply = ";
731: }
732:
733: script.appendCall(callbackPrefix + getContextPath()
734: + "getXMLTransformers");
735:
736: if (callback != null) {
737: String key = org.directwebremoting.extend.CallbackHelper
738: .saveCallback(callback, Object[].class);
739: script
740: .appendCall("__System.activateCallback", key,
741: "reply");
742: }
743:
744: getScriptProxy().addScript(script);
745: }
746:
747: /**
748: * Sets the list of XML transformers of this object. The XML source document of this object is transformed
749: serially by each of these transformers before it is placed in the XML cache.
750:
751: Each transformer is either the URI of an XSLT document (which will be resolved against the
752: the server of this object) or the cache id of a XSLT document in the XML cache of the server
753: of this object. When any transformer is loaded from a URI it is placed in the server cache under the id
754: equal to its resolved URI. Any transformer that does not correspond to a valid XSLT document will be skipped
755: without throwing an error.
756: * @param arrTrans
757: */
758: public void setXMLTransformers(Object[] arrTrans) {
759: ScriptBuffer script = new ScriptBuffer();
760: script.appendCall(getContextPath() + "setXMLTransformers",
761: arrTrans);
762: getScriptProxy().addScript(script);
763: }
764:
765: }
|