1 19 package org.netbeans.tax; 20 21 import java.util.Map ; 22 import java.util.HashMap ; 23 import java.util.List ; 24 import java.util.LinkedList ; 25 import java.util.StringTokenizer ; 26 27 import org.netbeans.tax.spec.DTD; 28 import org.netbeans.tax.spec.ParameterEntityReference; 29 import org.netbeans.tax.spec.DocumentType; 30 import org.netbeans.tax.spec.ConditionalSection; 31 import org.netbeans.tax.spec.AttlistDecl; 32 33 39 public class TreeAttlistDecl extends TreeNodeDecl implements DTD.Child, ParameterEntityReference.Child, DocumentType.Child, ConditionalSection.Child { 40 41 public static final String PROP_ELEMENT_NAME = "elementName"; 43 public static final String PROP_ATTRIBUTE_DEF_MAP_ADD = "map.add"; 45 public static final String PROP_ATTRIBUTE_DEF_MAP_REMOVE = "map.remove"; 47 public static final String PROP_ATTRIBUTE_DEF_MAP_CONTENT = "map.content"; 49 50 private String elementName; 51 52 53 private TreeNamedObjectMap attributeDefs; 54 55 56 60 63 public TreeAttlistDecl (String elementName) throws InvalidArgumentException { 64 super (); 65 66 checkElementName (elementName); 67 this.elementName = elementName; 68 this.attributeDefs = new TreeNamedObjectMap (createAttlistContentManager ()); 69 } 70 71 72 protected TreeAttlistDecl (TreeAttlistDecl attlistDecl) { 73 super (attlistDecl); 74 75 this.elementName = attlistDecl.elementName; 76 this.attributeDefs = new TreeNamedObjectMap (createAttlistContentManager ()); 77 this.attributeDefs.addAll ((TreeNamedObjectMap)attlistDecl.attributeDefs.clone ()); 78 } 79 80 81 85 87 public Object clone () { 88 return new TreeAttlistDecl (this); 89 } 90 91 93 public boolean equals (Object object, boolean deep) { 94 if (!!! super.equals (object, deep)) 95 return false; 96 97 TreeAttlistDecl peer = (TreeAttlistDecl) object; 98 if (!!! Util.equals (this.getElementName (), peer.getElementName ())) 99 return false; 100 if (!!! Util.equals (this.attributeDefs, peer.attributeDefs)) 101 return false; 102 103 return true; 104 } 105 106 109 public void merge (TreeObject treeObject) throws CannotMergeException { 110 super.merge (treeObject); 111 112 TreeAttlistDecl peer = (TreeAttlistDecl) treeObject; 113 114 setElementNameImpl (peer.getElementName ()); 115 attributeDefs.merge (peer.attributeDefs); 116 } 117 118 119 123 124 126 protected void setReadOnly (boolean newReadOnly) { 127 129 super.setReadOnly (newReadOnly); 130 131 attributeDefs.setReadOnly (newReadOnly); 132 } 133 134 135 139 141 public final String getElementName () { 142 return elementName; 143 } 144 145 147 private final void setElementNameImpl (String newElementName) { 148 String oldElementName = this.elementName; 149 150 this.elementName = newElementName; 151 152 firePropertyChange (PROP_ELEMENT_NAME, oldElementName, newElementName); 153 } 154 155 159 public final void setElementName (String newElementName) throws ReadOnlyException, InvalidArgumentException { 160 if ( Util.equals (this.elementName, newElementName) ) 164 return; 165 checkReadOnly (); 166 checkElementName (newElementName); 167 168 setElementNameImpl (newElementName); 172 } 173 174 176 protected final void checkElementName (String elementName) throws InvalidArgumentException { 177 TreeUtilities.checkAttlistDeclElementName (elementName); 178 } 179 180 182 public final TreeAttlistDeclAttributeDef getAttributeDef (String attributeDefName) { 183 return (TreeAttlistDeclAttributeDef)attributeDefs.get (attributeDefName); 184 } 185 186 188 private final void setAttributeDefImpl (TreeAttlistDeclAttributeDef newAttributeDef) { 189 TreeAttlistDeclAttributeDef oldAttributeDef = (TreeAttlistDeclAttributeDef)attributeDefs.get (newAttributeDef.getName ()); 190 191 attributeDefs.add (newAttributeDef); 192 193 firePropertyChange (PROP_ATTRIBUTE_DEF_MAP_ADD, oldAttributeDef, newAttributeDef); 194 } 195 196 200 public final void setAttributeDef (TreeAttlistDeclAttributeDef newAttributeDef) throws ReadOnlyException, InvalidArgumentException { 201 TreeAttlistDeclAttributeDef oldAttributeDef = (TreeAttlistDeclAttributeDef)attributeDefs.get (newAttributeDef.getName ()); 205 if ( Util.equals (oldAttributeDef, newAttributeDef) ) 206 return; 207 checkReadOnly (); 208 210 setAttributeDefImpl (newAttributeDef); 214 } 215 216 218 private final TreeAttlistDeclAttributeDef removeAttributeDefImpl (String attributeDefName) { 219 TreeAttlistDeclAttributeDef oldAttributeDef = (TreeAttlistDeclAttributeDef)attributeDefs.get (attributeDefName); 220 221 attributeDefs.remove (oldAttributeDef); 222 223 firePropertyChange (PROP_ATTRIBUTE_DEF_MAP_REMOVE, oldAttributeDef, null); 224 225 return oldAttributeDef; 226 } 227 228 231 public final TreeAttlistDeclAttributeDef removeAttributeDef (String attributeDefName) throws ReadOnlyException { 232 checkReadOnly (); 238 239 return removeAttributeDefImpl (attributeDefName); 243 } 244 245 247 public final TreeNamedObjectMap getAttributeDefs () { 248 return attributeDefs; 249 } 250 251 252 256 258 protected TreeNamedObjectMap.ContentManager createAttlistContentManager () { 259 return new AttlistContentManager (); 260 } 261 262 263 266 protected class AttlistContentManager extends TreeNamedObjectMap.ContentManager { 267 268 270 public TreeNode getOwnerNode () { 271 return TreeAttlistDecl.this; 272 } 273 274 276 public void checkAssignableObject (Object obj) { 277 super.checkAssignableObject (obj); 278 checkAssignableClass (TreeAttlistDeclAttributeDef.class, obj); 279 } 280 281 283 public void objectInserted (TreeObject obj) { 284 ((TreeAttlistDeclAttributeDef)obj).setNodeDecl (TreeAttlistDecl.this); 285 } 286 287 289 public void objectRemoved (TreeObject obj) { 290 ((TreeAttlistDeclAttributeDef)obj).setNodeDecl (null); 291 } 292 293 295 public void orderChanged (int[] permutation) { 296 } 297 298 } 300 } 301 | Popular Tags |