1 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 22 public class Condition extends XMLComplexElement { 23 public static String CONDITION_TYPE_CONDITION="CONDITION"; 24 public static String CONDITION_TYPE_OTHERWISE="OTHERWISE"; 25 public static String CONDITION_TYPE_EXCEPTION="EXCEPTION"; 26 public static String CONDITION_TYPE_DEFAULTEXCEPTION="DEFAULTEXCEPTION"; 27 28 private Xpression refXpression=new Xpression(); 31 private XMLAttribute attrType=new XMLAttribute("Type", 32 new String [] { 33 "", 34 "CONDITION", 35 "OTHERWISE", 36 "EXCEPTION", 37 "DEFAULTEXCEPTION" 38 },1); 39 40 43 public Condition () { 44 super(); 45 46 fillStructure (); 47 } 48 49 53 protected void fillStructure () { 54 complexStructure.add(attrType); 55 attributes.add(attrType); 56 complexStructure.add(refXpression); 57 } 58 59 65 public String toString () { 66 return refXpression.toString(); 67 } 68 69 public Object toValue () { 70 return refXpression.toValue(); 71 } 72 73 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 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 122 public void fromXML (Node node) { 123 attrType.setValue(""); 124 125 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 Object 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 refXpression.setValue(value); 145 } 146 147 148 155 public Object 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 |