1
2
3
4
5
6
7 package net.kwfgrid.gworkflowdl.structure;
8
9 import org.apache.log4j.Logger;
10 import org.jdom.Element;
11
12 /***
13 * implementation of Data with Jdom element.
14 */
15 public final class JDOMData implements Data {
16
17 /***
18 * Elements.
19 */
20 private Element el;
21
22 static Logger logger = Logger.getLogger(JDOMData.class);
23
24 public JDOMData() {
25 this.el = null;
26 }
27
28 public JDOMData(Object e) throws WorkflowFormatException {
29 this.el = (Element) e;
30 checkElementName();
31
32 el.setNamespace(JdomString.wfSpace);
33 }
34
35 public void set(final Object e) throws WorkflowFormatException {
36 this.el = (Element) e;
37 checkElementName();
38
39 el.setNamespace(JdomString.wfSpace);
40 }
41
42 public Object get() {
43 return el;
44 }
45
46 public boolean equals(final Data d) {
47 return el == d.get();
48 }
49
50 public int hashCode() {
51 return el.hashCode();
52 }
53
54 public String toXML() {
55 String ret = "";
56
57 if (el != null) {
58
59
60
61
62 try {
63 ret = JdomString.element2stringNoHeader(el);
64 } catch (java.io.IOException ex) {
65 logger.error("IOException during toXML()", ex);
66 }
67 }
68 return ret;
69 }
70
71 public void fromXML(final String s) throws WorkflowFormatException {
72 el = JdomString.string2element(s);
73 checkElementName();
74
75 el.setNamespace(JdomString.wfSpace);
76 }
77
78 public Object clone() {
79 try {
80 return Factory.newData(el.clone());
81 } catch (WorkflowFormatException e) {
82 logger.error("exception:\n" + e, e);
83 }
84 return null;
85 }
86
87 private void checkElementName() throws WorkflowFormatException {
88 if (!el.getName().equals("data")) {
89 throw new WorkflowFormatException("Wrong element name for contents of data token. The element name must be <data> but is <"+el.getName()+">.");
90 }
91 }
92
93 }