1 package org.enhydra.shark.xpdl; 2 3 import java.io.Serializable ; 4 5 10 public abstract class XMLElement implements Serializable , Cloneable { 11 12 15 private String name; 16 17 20 private boolean isRequired = false; 21 22 26 protected String value; 27 28 31 protected boolean isReadOnly = false; 32 33 36 protected XMLElement parent; 37 38 45 public XMLElement(XMLElement parent, boolean isRequired) { 46 this.parent = parent; 47 this.isRequired = isRequired; 48 this.name = getClass().getName(); 49 this.name = XMLUtil.getShortClassName(name); 50 this.value = new String (); 51 } 52 53 59 public XMLElement(XMLElement parent, String name, boolean isRequired) { 60 this.parent = parent; 61 this.name = name; 62 this.isRequired = isRequired; 63 this.value = new String (); 64 } 65 66 74 public void setReadOnly(boolean ro) { 75 this.isReadOnly = ro; 76 } 77 78 84 public boolean isReadOnly() { 85 return isReadOnly; 86 } 87 88 93 public boolean isRequired() { 94 return isRequired; 95 } 96 97 100 public boolean isEmpty() { 101 return !(value != null && value.trim().length() > 0); 102 } 103 104 110 public void setValue(String v) { 111 if (isReadOnly) { 112 throw new RuntimeException ("Can't set the value of read only element!"); 113 } 114 this.value = v; 115 } 116 117 120 public String toValue() { 121 return value; 122 } 123 124 127 public String toName() { 128 return name; 129 } 130 131 132 public XMLElement getParent() { 133 return parent; 134 } 135 136 142 public void setParent(XMLElement el) { 143 this.parent = el; 144 } 145 146 149 public Object clone() { 150 XMLElement d = null; 151 try { 152 d = (XMLElement) super.clone(); 154 d.name = new String (this.name); 155 d.value = new String (this.value); 156 d.isRequired = this.isRequired; 157 d.isReadOnly = this.isReadOnly; 158 d.parent = this.parent; 159 } catch (CloneNotSupportedException ex) { 160 throw new Error (ex.toString()); 162 } 163 return d; 164 } 165 166 public boolean equals(Object e) { 167 if (this == e) 168 return true; 169 if (e != null && e instanceof XMLElement && e.getClass().equals(this.getClass())) { 171 XMLElement el = (XMLElement) e; 173 return (this.name.equals(el.name) && 175 this.value.equals(el.value) && 176 this.isRequired == el.isRequired); 177 } 182 return false; 183 } 184 185 } 186 187 | Popular Tags |