01: /*
02: * Created on Dec 8, 2003
03: *
04: * To change the template for this generated file go to
05: * Window>Preferences>Java>Code Generation>Code and Comments
06: */
07: package org.xdev.base.xssl.text.xml;
08:
09: import java.io.StringReader;
10: import java.util.HashMap;
11:
12: import org.jdom.Document;
13: import org.jdom.Element;
14: import org.jdom.input.SAXBuilder;
15: import org.xdev.base.xssl.XSSLObject;
16: import org.xdev.base.xssl.XSSLReturn;
17:
18: /**
19: * @author AYegorov
20: *
21: * To change the template for this generated type comment go to
22: * Window>Preferences>Java>Code Generation>Code and Comments
23: */
24: public abstract class AbstractXmlElement extends XSSLObject {
25: protected Element elm = null;
26:
27: /**
28: * @param id
29: */
30: public AbstractXmlElement(String id) {
31: super (id);
32: // TODO Auto-generated constructor stub
33: }
34:
35: /**
36: * @param id
37: * @param properties
38: */
39: public AbstractXmlElement(String id, HashMap properties) {
40: super (id, properties);
41: // TODO Auto-generated constructor stub
42: }
43:
44: protected abstract Object doXmlTransaction(Element elm)
45: throws Exception;
46:
47: /* (non-Javadoc)
48: * @see org.xdev.base.xssl.XSSLObject#processObject(java.lang.Object)
49: */
50: protected Object processObject(Object obj) throws Exception {
51:
52: if (obj == null && this .getCount() > 0) {
53: XSSLReturn val = (XSSLReturn) this .getElement(0);
54:
55: if (val.execute(this )) {
56: obj = val.getObjectValue();
57: }
58: }
59:
60: this .logDebug("XML-like object received: " + obj);
61:
62: if (obj instanceof Element) {
63: this .elm = (Element) obj;
64: } else if (obj instanceof Document) {
65: this .elm = ((Document) obj).getRootElement();
66: } else {
67: SAXBuilder builder = new SAXBuilder();
68:
69: Document doc = builder.build(new StringReader(obj
70: .toString()));
71:
72: this.elm = doc.getRootElement();
73: }
74:
75: return this.doXmlTransaction(this.elm);
76: }
77: }
|