1 19 package org.netbeans.tax; 20 21 import org.netbeans.tax.event.TreeEventManager; 22 23 import org.netbeans.tax.spec.DTD; 24 25 30 public class TreeDTD extends AbstractTreeDTD implements TreeDocumentRoot, TreeDTDRoot { 31 32 33 public static final String PROP_VERSION = "version"; 35 public static final String PROP_ENCODING = "encoding"; 37 38 private TreeEventManager eventManager; 39 40 41 private String version; 42 43 44 private String encoding; 45 46 47 51 55 public TreeDTD (String version, String encoding) throws InvalidArgumentException { 56 super (); 57 58 checkVersion (version); 59 checkEncoding (encoding); 60 checkHeader (version, encoding); 61 62 this.version = version; 63 this.encoding = encoding; 64 65 if ( Util.THIS.isLoggable() ) Util.THIS.debug ("TreeDTD::init: encoding = " + this.encoding); 67 this.eventManager = new TreeEventManager (); 68 } 69 70 73 public TreeDTD () throws InvalidArgumentException { 74 this (null, null); 75 } 76 77 78 protected TreeDTD (TreeDTD dtd, boolean deep) { 79 super (dtd, deep); 80 81 this.version = dtd.version; 82 this.encoding = dtd.encoding; 83 84 if ( Util.THIS.isLoggable() ) Util.THIS.debug ("TreeDTD::init [copy]: encoding = " + this.encoding); 86 this.eventManager = new TreeEventManager (dtd.eventManager); 87 } 88 89 90 94 96 public Object clone (boolean deep) { 97 return new TreeDTD (this, deep); 98 } 99 100 102 public boolean equals (Object object, boolean deep) { 103 if (!!! super.equals (object, deep)) 104 return false; 105 106 TreeDTD peer = (TreeDTD) object; 107 if (!!! Util.equals (this.getVersion (), peer.getVersion ())) 108 return false; 109 if (!!! Util.equals (this.getEncoding (), peer.getEncoding ())) 110 return false; 111 112 return true; 113 } 114 115 118 public void merge (TreeObject treeObject) throws CannotMergeException { 119 super.merge (treeObject); 120 121 TreeDTD peer = (TreeDTD) treeObject; 122 123 try { 124 setVersionImpl (peer.getVersion ()); 125 setEncodingImpl (peer.getEncoding ()); 126 } catch (Exception exc) { 127 throw new CannotMergeException (treeObject, exc); 128 } 129 } 130 131 135 137 public String getVersion () { 138 return version; 139 } 140 141 143 private final void setVersionImpl (String newVersion) { 144 String oldVersion = this.version; 145 146 this.version = newVersion; 147 148 firePropertyChange (PROP_VERSION, oldVersion, newVersion); 149 } 150 151 155 public final void setVersion (String newVersion) throws ReadOnlyException, InvalidArgumentException { 156 if ( Util.equals (this.version, newVersion) ) 160 return; 161 checkReadOnly (); 162 checkVersion (newVersion); 163 checkHeader (newVersion, this.encoding); 164 165 setVersionImpl (newVersion); 169 } 170 171 173 protected final void checkVersion (String version) throws InvalidArgumentException { 174 TreeUtilities.checkDTDVersion (version); 175 } 176 177 178 180 public String getEncoding () { 181 return encoding; 182 } 183 184 186 private final void setEncodingImpl (String newEncoding) { 187 String oldEncoding = this.encoding; 188 189 this.encoding = newEncoding; 190 191 if ( Util.THIS.isLoggable() ) Util.THIS.debug ("TreeDTD::setEncodingImpl: encoding = " + this.encoding); 193 firePropertyChange (PROP_ENCODING, oldEncoding, newEncoding); 194 } 195 196 200 public final void setEncoding (String newEncoding) throws ReadOnlyException, InvalidArgumentException { 201 if ( Util.equals (this.encoding, newEncoding) ) 205 return; 206 checkReadOnly (); 207 checkEncoding (newEncoding); 208 checkHeader (this.version, newEncoding); 209 210 setEncodingImpl (newEncoding); 214 } 215 216 218 protected final void checkEncoding (String encoding) throws InvalidArgumentException { 219 TreeUtilities.checkDTDEncoding (encoding); 220 } 221 222 226 public final void setHeader (String newVersion, String newEncoding) throws ReadOnlyException, InvalidArgumentException { 227 boolean setVersion = !!! Util.equals (this.version, newVersion); 231 boolean setEncoding = !!! Util.equals (this.encoding, newEncoding); 232 if ( !!! setVersion && 233 !!! setEncoding ) { 234 return; 235 } 236 checkReadOnly (); 237 if ( setVersion ) { 238 checkVersion (newVersion); 239 } 240 if ( setEncoding ) { 241 checkEncoding (newEncoding); 242 } 243 checkHeader (newVersion, newEncoding); 244 245 if ( setVersion ) { 249 setVersionImpl (newVersion); 250 } 251 if ( setEncoding ) { 252 setEncodingImpl (newEncoding); 253 } 254 } 255 256 258 protected final void checkHeader (String version, String encoding) throws InvalidArgumentException { 259 if ((version != null) && (encoding == null)) { 260 throw new InvalidArgumentException 261 (Util.THIS.getString ("EXC_invalid_dtd_header"), 262 new NullPointerException ()); 263 } 264 } 265 266 267 271 273 public TreeEventManager getRootEventManager () { 274 return eventManager; 275 } 276 277 278 282 284 protected TreeObjectList.ContentManager createChildListContentManager () { 285 return new ChildListContentManager (); 286 } 287 288 289 292 protected class ChildListContentManager extends AbstractTreeDTD.ChildListContentManager { 293 294 296 public TreeNode getOwnerNode () { 297 return TreeDTD.this; 298 } 299 300 302 public void checkAssignableObject (Object obj) { 303 super.checkAssignableObject (obj); 304 checkAssignableClass (DTD.Child.class, obj); 305 } 306 307 } 309 } 310 | Popular Tags |