01: package org.enhydra.shark.xpdl.elements;
02:
03: import org.enhydra.shark.xpdl.XMLAttribute;
04: import org.enhydra.shark.xpdl.XMLComplexElement;
05: import org.enhydra.shark.xpdl.XMLElement;
06: import org.enhydra.shark.xpdl.XMLElementChangeInfo;
07: import org.enhydra.shark.xpdl.XPDLConstants;
08:
09: /**
10: * Represents coresponding element from XPDL schema.
11: *
12: * @author Sasa Bojanic
13: */
14: public class Condition extends XMLComplexElement {
15:
16: public Condition(Transition parent) {
17: super (parent, false);
18: }
19:
20: protected void fillStructure() {
21: XMLAttribute attrType = new XMLAttribute(
22: this ,
23: "Type",
24: false,
25: new String[] { XPDLConstants.CONDITION_TYPE_NONE,
26: XPDLConstants.CONDITION_TYPE_CONDITION,
27: XPDLConstants.CONDITION_TYPE_OTHERWISE,
28: XPDLConstants.CONDITION_TYPE_EXCEPTION,
29: XPDLConstants.CONDITION_TYPE_DEFAULTEXCEPTION },
30: 0);
31:
32: add(attrType);
33: }
34:
35: public void makeAs(XMLElement el) {
36: super .makeAs(el);
37: setValue(el.toValue());
38: }
39:
40: public void setValue(String v) {
41: if (isReadOnly) {
42: throw new RuntimeException(
43: "Can't set the value of read only element!");
44: }
45: boolean notify = false;
46: String oldValue = value;
47: if (!this .value.equals(v)) {
48: notify = true;
49: }
50:
51: this .value = v;
52:
53: if (notify && (notifyMainListeners || notifyListeners)) {
54: XMLElementChangeInfo info = createInfo(oldValue, value,
55: null, XMLElementChangeInfo.UPDATED);
56: if (notifyListeners) {
57: notifyListeners(info);
58: }
59: if (notifyMainListeners) {
60: notifyMainListeners(info);
61: }
62: }
63: }
64:
65: public XMLAttribute getTypeAttribute() {
66: return (XMLAttribute) get("Type");
67: }
68:
69: public String getType() {
70: return getTypeAttribute().toValue();
71: }
72:
73: public void setTypeNONE() {
74: getTypeAttribute().setValue(XPDLConstants.CONDITION_TYPE_NONE);
75: }
76:
77: public void setTypeCONDITION() {
78: getTypeAttribute().setValue(
79: XPDLConstants.CONDITION_TYPE_CONDITION);
80: }
81:
82: public void setTypeOTHERWISE() {
83: getTypeAttribute().setValue(
84: XPDLConstants.CONDITION_TYPE_OTHERWISE);
85: }
86:
87: public void setTypeEXCEPTION() {
88: getTypeAttribute().setValue(
89: XPDLConstants.CONDITION_TYPE_EXCEPTION);
90: }
91:
92: public void setTypeDEFAULTEXCEPTION() {
93: getTypeAttribute().setValue(
94: XPDLConstants.CONDITION_TYPE_DEFAULTEXCEPTION);
95: }
96:
97: }
|