KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jawe > xml > elements > Condition


1 /* Condition.java
2  *
3  * Authors:
4  * Stefanovic Nenad chupo@iis.ns.ac.yu
5  * Bojanic Sasa sasaboy@neobee.net
6  * Puskas Vladimir vpuskas@eunet.yu
7  * Pilipovic Goran zboniek@uns.ac.yu
8  *
9  */

10
11 package org.enhydra.jawe.xml.elements;
12
13 import org.enhydra.jawe.xml.*;
14 import org.enhydra.jawe.xml.panels.*;
15 import org.w3c.dom.*;
16
17 /**
18 * Represents a WfMC DTD element that has the similar name.
19 *
20 * @see XML
21 */

22 public class Condition extends XMLComplexElement {
23    public static String JavaDoc CONDITION_TYPE_CONDITION="CONDITION";
24    public static String JavaDoc CONDITION_TYPE_OTHERWISE="OTHERWISE";
25    public static String JavaDoc CONDITION_TYPE_EXCEPTION="EXCEPTION";
26    public static String JavaDoc CONDITION_TYPE_DEFAULTEXCEPTION="DEFAULTEXCEPTION";
27
28    //private Set refXpression=new HashSet(); // min=0, max=unbounded
29
private Xpression refXpression=new Xpression(); // min=0, max=unbounded
30

31    private XMLAttribute attrType=new XMLAttribute("Type",
32       new String JavaDoc[] {
33          "",
34          "CONDITION",
35          "OTHERWISE",
36          "EXCEPTION",
37          "DEFAULTEXCEPTION"
38       },1);
39
40    /**
41    * Creates a new instance of the class.
42    */

43    public Condition () {
44       super();
45
46       fillStructure ();
47    }
48
49    /**
50    * Defines the super-class method. Read the explanation for
51    * this method within XMLComplexElement class.
52    */

53    protected void fillStructure () {
54       complexStructure.add(attrType);
55       attributes.add(attrType);
56       complexStructure.add(refXpression);
57    }
58
59    /**
60    * Overrides super-class method to retrieve the defined
61    * condition.
62    *
63    * @return The condition of transition.
64    */

65    public String JavaDoc toString () {
66       return refXpression.toString();
67    }
68
69    public Object JavaDoc toValue () {
70       return refXpression.toValue();
71    }
72
73    /**
74    * Overrides super-class method to indicate the emptiness of element.
75    * Here we use a trick: we temporarily remove the attribute 'Type' from
76    * structure, so we can claim that element is empty although it's 'Type'
77    * attribute is not.
78    *
79    * @return The state of emptiness of element. The element
80    * is empty if all of it's members, except 'Type'
81    * attribute, are.
82    */

83    public boolean isEmpty () {
84       complexStructure.remove(0);
85       boolean isEmpty=super.isEmpty();
86       complexStructure.add(0,attrType);
87       if (isEmpty && !attrType.toValue().toString().equals("CONDITION")) {
88          isEmpty=false;
89       }
90       return isEmpty;
91    }
92
93    // NOTE: this must be corrected in a future, now, the Xpression
94
// element is used only visualy to enter simple text, and when
95
// writing to XML, this text is put into XML value and Xpression
96
// tags aren't.
97
// NOTE: maybe it should be defined the new basic class to suport
98
// elements like Condition and Xpression
99
/**
100    * Overrides super-class method to realize this class specific
101    * writting to XML file.
102    *
103    * @return The string for a WfMC DTD Condition element tag.
104    */

105    public void toXML (Node parent) throws DOMException {
106       if (isEmpty()) return;
107       Node node = (parent.getOwnerDocument()).createElement(name);
108       attrType.toXML(node);
109       Node textNode=parent.getOwnerDocument().createTextNode(refXpression.toString());
110       node.appendChild(textNode);
111       parent.appendChild(node);
112    }
113
114    // this is just temporarily, when we implement expressions as
115
// it should be, this must be changed
116
/**
117    * Overrides super-class method to realize this class specific
118    * reading from XML file.
119    *
120    * @param node root node
121    */

122    public void fromXML (Node node) {
123       attrType.setValue("");
124
125       // getting Type attrib.
126
if (node.hasAttributes()) {
127          NamedNodeMap attribs = node.getAttributes();
128          Node type=attribs.getNamedItem("Type");
129          if (type!=null) {
130             attrType.fromXML(type);
131          }
132       }
133       // getting the node with text
134
Object JavaDoc newVal;
135       if (node.hasChildNodes()) {
136          newVal=node.getChildNodes().item(0).getNodeValue();
137       } else {
138          newVal=node.getNodeValue();
139       }
140       if (newVal!=null) {
141          value=newVal;
142       }
143       // passing the node content to Xpression
144
refXpression.setValue(value);
145    }
146
147
148    /**
149    * Used to create exact copy of instance of this class.
150    * The newly created instance will have all the properties
151    * same as the copied one.
152    *
153    * @return The newly created instance of this class.
154    */

155    public Object JavaDoc clone () {
156       Condition c=(Condition)super.clone();
157
158       c.attrType=(XMLAttribute)this.attrType.clone();
159       c.refXpression=(Xpression)this.refXpression.clone();
160       c.fillStructure();
161
162       return c;
163    }
164
165 }
166
Popular Tags