1 19 package org.netbeans.tax; 20 21 import org.netbeans.tax.event.TreeEventManager; 22 23 import org.netbeans.tax.spec.DocumentFragment; 24 import org.netbeans.tax.spec.DTD; 25 26 34 public class TreeDocumentFragment extends AbstractTreeDocument implements TreeDocumentRoot { 35 36 public static final String PROP_VERSION = "version"; 38 public static final String PROP_ENCODING = "encoding"; 40 41 private TreeEventManager eventManager; 42 43 44 private String version; 45 46 47 private String encoding; 48 49 50 54 58 public TreeDocumentFragment (String version, String encoding) throws InvalidArgumentException { 59 super (); 60 61 checkVersion (version); 62 checkEncoding (encoding); 63 checkHeader (version, encoding); 64 65 this.version = version; 66 this.encoding = encoding; 67 this.eventManager = new TreeEventManager (); 68 } 69 70 71 75 public TreeDocumentFragment () throws InvalidArgumentException { 76 this (null, null); } 78 79 80 81 protected TreeDocumentFragment (TreeDocumentFragment documentFragment, boolean deep) { 82 super (documentFragment, deep); 83 84 this.version = documentFragment.version; 85 this.encoding = documentFragment.encoding; 86 this.eventManager = new TreeEventManager (documentFragment.eventManager); 87 } 88 89 90 94 96 public Object clone (boolean deep) { 97 return new TreeDocumentFragment (this, deep); 98 } 99 100 102 public boolean equals (Object object, boolean deep) { 103 if (!!! super.equals (object, deep)) 104 return false; 105 106 TreeDocumentFragment peer = (TreeDocumentFragment) 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 TreeDocumentFragment peer = (TreeDocumentFragment) 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 132 136 138 public String getVersion () { 139 return version; 140 } 141 142 144 private final void setVersionImpl (String newVersion) { 145 String oldVersion = this.version; 146 147 this.version = newVersion; 148 149 firePropertyChange (PROP_VERSION, oldVersion, newVersion); 150 } 151 152 156 public final void setVersion (String newVersion) throws ReadOnlyException, InvalidArgumentException { 157 if ( Util.equals (this.version, newVersion) ) 161 return; 162 checkReadOnly (); 163 checkVersion (newVersion); 164 checkHeader (newVersion, this.encoding); 165 166 setVersionImpl (newVersion); 170 } 171 172 174 protected final void checkVersion (String version) throws InvalidArgumentException { 175 TreeUtilities.checkDocumentFragmentVersion (version); 176 } 177 178 179 181 public String getEncoding () { 182 return encoding; 183 } 184 185 187 private void setEncodingImpl (String newEncoding) { 188 String oldEncoding = this.encoding; 189 190 this.encoding = newEncoding; 191 192 firePropertyChange (PROP_ENCODING, oldEncoding, newEncoding); 193 } 194 195 199 public final void setEncoding (String newEncoding) throws ReadOnlyException, InvalidArgumentException { 200 if ( Util.equals (this.encoding, newEncoding) ) 204 return; 205 checkReadOnly (); 206 checkEncoding (newEncoding); 207 checkHeader (this.version, newEncoding); 208 209 setEncodingImpl (newEncoding); 213 } 214 215 217 protected final void checkEncoding (String encoding) throws InvalidArgumentException { 218 TreeUtilities.checkDocumentFragmentEncoding (encoding); 219 } 220 221 225 public final void setHeader (String newVersion, String newEncoding) throws ReadOnlyException, InvalidArgumentException { 226 boolean setVersion = !!! Util.equals (this.version, newVersion); 230 boolean setEncoding = !!! Util.equals (this.encoding, newEncoding); 231 if ( !!! setVersion && 232 !!! setEncoding ) { 233 return; 234 } 235 checkReadOnly (); 236 if ( setVersion ) { 237 checkVersion (newVersion); 238 } 239 if ( setEncoding ) { 240 checkEncoding (newEncoding); 241 } 242 checkHeader (newVersion, newEncoding); 243 244 if ( setVersion ) { 248 setVersionImpl (newVersion); 249 } 250 if ( setEncoding ) { 251 setEncodingImpl (newEncoding); 252 } 253 } 254 255 257 protected final void checkHeader (String version, String encoding) throws InvalidArgumentException { 258 if ((version != null) && (encoding == null)) { 259 throw new InvalidArgumentException 260 (Util.THIS.getString ("EXC_invalid_document_fragment_header"), 261 new NullPointerException ()); 262 } 263 } 264 265 266 270 272 public TreeEventManager getRootEventManager () { 273 return eventManager; 274 } 275 276 277 281 283 protected TreeObjectList.ContentManager createChildListContentManager () { 284 return new ChildListContentManager (); 285 } 286 287 288 291 protected class ChildListContentManager extends AbstractTreeDocument.ChildListContentManager { 292 293 295 public TreeNode getOwnerNode () { 296 return TreeDocumentFragment.this; 297 } 298 299 301 public void checkAssignableObject (Object obj) { 302 super.checkAssignableObject (obj); 303 checkAssignableClass (DocumentFragment.Child.class, obj); 304 } 305 306 } 308 309 } 310 | Popular Tags |