1 19 package org.netbeans.tax; 20 21 import org.netbeans.tax.spec.DTD; 22 import org.netbeans.tax.spec.ParameterEntityReference; 23 import org.netbeans.tax.spec.DocumentType; 24 import org.netbeans.tax.spec.ConditionalSection; 25 26 31 public class TreeEntityDecl extends TreeNodeDecl implements DTD.Child, ParameterEntityReference.Child, DocumentType.Child, ConditionalSection.Child { 32 33 public static final String PROP_PARAMETER = "parameter"; 35 public static final String PROP_NAME = "name"; 37 public static final String PROP_TYPE = "type"; 39 public static final String PROP_INTERNAL_TEXT = "internalText"; 41 public static final String PROP_PUBLIC_ID = "publicId"; 43 public static final String PROP_SYSTEM_ID = "systemId"; 45 public static final String PROP_NOTATION_NAME = "notationName"; 47 48 public static final short TYPE_INTERNAL = 1; 49 50 public static final short TYPE_EXTERNAL = 2; 51 52 public static final short TYPE_UNPARSED = 3; 53 54 55 public static final boolean GENERAL_DECL = false; 56 57 public static final boolean PARAMETER_DECL = true; 58 59 60 61 private boolean parameter; 62 63 64 private String name; 65 66 67 private short type; 68 69 70 private String internalText; 71 72 73 private String publicId; 74 75 76 private String systemId; 77 78 79 private String notationName; 80 81 82 86 89 private TreeEntityDecl (boolean parameter, String name) throws InvalidArgumentException { 90 super (); 91 92 checkName (name); 93 this.name = name; 94 this.parameter = parameter; 95 } 96 97 98 101 public TreeEntityDecl (boolean parameter, String name, String internalText) throws InvalidArgumentException { 102 this (parameter, name); 103 104 checkInternalText (internalText); 105 this.type = TYPE_INTERNAL; 106 this.internalText = internalText; 107 this.publicId = null; 108 this.systemId = null; 109 this.notationName = null; 110 } 111 112 113 116 public TreeEntityDecl (String name, String internalText) throws InvalidArgumentException { 117 this (GENERAL_DECL, name, internalText); 118 } 119 120 121 124 public TreeEntityDecl (boolean parameter, String name, String publicId, String systemId) throws InvalidArgumentException { 125 this (parameter, name); 126 127 checkExternalDecl (publicId, systemId); 128 this.type = TYPE_EXTERNAL; 129 this.internalText = null; 130 this.publicId = publicId; 131 this.systemId = systemId; 132 this.notationName = null; 133 } 134 135 136 139 public TreeEntityDecl (String name, String publicId, String systemId) throws InvalidArgumentException { 140 this (GENERAL_DECL, name, publicId, systemId); 141 } 142 143 144 147 public TreeEntityDecl (String name, String publicId, String systemId, String notationName) throws InvalidArgumentException { 148 this (GENERAL_DECL, name); 149 150 checkUnparsedDecl (publicId, systemId, notationName); 151 152 this.type = TYPE_UNPARSED; 153 this.internalText = null; 154 this.publicId = publicId; 155 this.systemId = systemId; 156 this.notationName = notationName; 157 } 158 159 160 161 162 protected TreeEntityDecl (TreeEntityDecl entityDecl) { 163 super (entityDecl); 164 165 this.parameter = entityDecl.parameter; 166 this.name = entityDecl.name; 167 this.type = entityDecl.type; 168 this.internalText = entityDecl.internalText; 169 this.publicId = entityDecl.publicId; 170 this.systemId = entityDecl.systemId; 171 this.notationName = entityDecl.notationName; 172 } 173 174 175 179 181 public Object clone () { 182 return new TreeEntityDecl (this); 183 } 184 185 187 public boolean equals (Object object, boolean deep) { 188 if (!!! super.equals (object, deep)) 189 return false; 190 191 TreeEntityDecl peer = (TreeEntityDecl) object; 192 if (!!! Util.equals (this.getName (), peer.getName ())) 193 return false; 194 if ( this.isParameter () != peer.isParameter ()) 195 return false; 196 if ( this.getType () != peer.getType ()) 197 return false; 198 if (!!! Util.equals (this.getPublicId (), peer.getPublicId ())) 199 return false; 200 if (!!! Util.equals (this.getSystemId (), peer.getSystemId ())) 201 return false; 202 if (!!! Util.equals (this.getInternalText (), peer.getInternalText ())) 203 return false; 204 if (!!! Util.equals (this.getNotationName (), peer.getNotationName ())) 205 return false; 206 207 return true; 208 } 209 210 213 public void merge (TreeObject treeObject) throws CannotMergeException { 214 super.merge (treeObject); 215 216 TreeEntityDecl peer = (TreeEntityDecl) treeObject; 217 218 setNameImpl (peer.getName ()); 219 setParameterImpl (peer.isParameter ()); 220 221 short peerType = peer.getType (); 222 switch (peerType) { 223 case TYPE_EXTERNAL: 224 setExternalDeclImpl (peer.getPublicId (), peer.getSystemId ()); 225 break; 226 case TYPE_INTERNAL: 227 setInternalTextImpl (peer.getInternalText ()); 228 break; 229 case TYPE_UNPARSED: 230 setUnparsedDeclImpl (peer.getPublicId (), peer.getSystemId (), peer.getNotationName ()); 231 break; 232 } 233 } 234 235 236 240 242 public final boolean isParameter () { 243 return parameter; 244 } 245 246 248 private final void setParameterImpl (boolean newParameter) { 249 boolean oldParameter = this.parameter; 250 251 this.parameter = newParameter; 252 253 firePropertyChange (PROP_PARAMETER, oldParameter ? Boolean.TRUE : Boolean.FALSE, newParameter ? Boolean.TRUE : Boolean.FALSE); 254 } 255 256 261 public final void setParameter (boolean newParameter) throws ReadOnlyException, InvalidStateException, InvalidArgumentException { 262 if ( this.parameter == newParameter ) 266 return; 267 checkReadOnly (); 268 if ( (newParameter == PARAMETER_DECL) && (type == TYPE_UNPARSED) ) { 269 throw new InvalidStateException (Util.THIS.getString ("EXC_ted_parameter_unparsed")); 270 } 271 272 setParameterImpl (newParameter); 276 } 277 278 280 public final String getName () { 281 return name; 282 } 283 284 286 private final void setNameImpl (String newName) { 287 String oldName = this.name; 288 289 this.name = newName; 290 291 firePropertyChange (PROP_NAME, oldName, newName); 292 } 293 294 298 public final void setName (String newName) throws ReadOnlyException, InvalidArgumentException { 299 if ( Util.equals (this.name, newName) ) 303 return; 304 checkReadOnly (); 305 checkName (newName); 306 307 setNameImpl (newName); 311 } 312 313 315 protected final void checkName (String name) throws InvalidArgumentException { 316 TreeUtilities.checkEntityDeclName (name); 317 } 318 319 321 public final short getType () { 322 return type; 323 } 324 325 327 public final String getInternalText () { 328 return internalText; 329 } 330 331 333 private final void setInternalTextImpl (String newInternalText) { 334 short oldType = this.type; 335 String oldInternalText = this.internalText; 336 String oldPublicId = this.publicId; 337 String oldSystemId = this.systemId; 338 String oldNotationName = this.notationName; 339 340 this.type = TYPE_INTERNAL; 341 this.internalText = newInternalText; 342 this.publicId = null; 343 this.systemId = null; 344 this.notationName = null; 345 346 firePropertyChange (PROP_TYPE, new Short (oldType), new Short (this.type)); 347 firePropertyChange (PROP_INTERNAL_TEXT, oldInternalText, newInternalText); 348 firePropertyChange (PROP_PUBLIC_ID, oldPublicId, this.publicId); 349 firePropertyChange (PROP_SYSTEM_ID, oldSystemId, this.systemId); 350 firePropertyChange (PROP_NOTATION_NAME, oldNotationName, this.notationName); 351 } 352 353 357 public final void setInternalText (String newInternalText) throws ReadOnlyException, InvalidArgumentException { 358 if ( Util.equals (this.internalText, newInternalText) ) 362 return; 363 checkReadOnly (); 364 checkInternalText (newInternalText); 365 366 setInternalTextImpl (newInternalText); 370 } 371 372 374 protected final void checkInternalText (String internalText) throws InvalidArgumentException { 375 TreeUtilities.checkEntityDeclInternalText (internalText); 376 } 377 378 380 public final String getPublicId () { 381 return publicId; 382 } 383 384 386 private final void setPublicIdImpl (String newPublicId) { 387 String oldPublicId = this.publicId; 388 389 this.publicId = newPublicId; 390 391 firePropertyChange (PROP_PUBLIC_ID, oldPublicId, newPublicId); 392 } 393 394 399 public final void setPublicId (String newPublicId) throws ReadOnlyException, InvalidStateException, InvalidArgumentException { 400 if ( Util.equals (this.publicId, newPublicId) ) 404 return; 405 checkReadOnly (); 406 if ( type == TYPE_INTERNAL ) { 407 throw new InvalidStateException (Util.THIS.getString ("EXC_ted_internal_public")); 408 } 409 checkPublicId (newPublicId); 410 411 setPublicIdImpl (newPublicId); 415 } 416 417 419 protected final void checkPublicId (String publicId) throws InvalidArgumentException { 420 TreeUtilities.checkEntityDeclPublicId (publicId); 421 422 checkExternalId (publicId, this.systemId); 423 } 424 425 427 public final String getSystemId () { 428 return systemId; 429 } 430 431 433 private final void setSystemIdImpl (String newSystemId) { 434 String oldSystemId = this.systemId; 435 436 this.systemId = newSystemId; 437 438 firePropertyChange (PROP_SYSTEM_ID, oldSystemId, newSystemId); 439 } 440 441 446 public final void setSystemId (String newSystemId) throws ReadOnlyException, InvalidStateException, InvalidArgumentException { 447 if ( Util.equals (this.systemId, newSystemId) ) 451 return; 452 checkReadOnly (); 453 if ( type == TYPE_INTERNAL ) { 454 throw new InvalidStateException (Util.THIS.getString ("EXC_ted_internal_system")); 455 } 456 checkSystemId (newSystemId); 457 458 setSystemIdImpl (newSystemId); 462 } 463 464 466 protected final void checkSystemId (String systemId) throws InvalidArgumentException { 467 TreeUtilities.checkEntityDeclSystemId (systemId); 468 469 checkExternalId (this.publicId, systemId); 470 } 471 472 473 475 private final void setExternalDeclImpl (String newPublicId, String newSystemId) { 476 short oldType = this.type; 477 String oldInternalText = this.internalText; 478 String oldPublicId = this.publicId; 479 String oldSystemId = this.systemId; 480 String oldNotationName = this.notationName; 481 482 this.type = TYPE_EXTERNAL; 483 this.internalText = null; 484 this.publicId = newPublicId; 485 this.systemId = newSystemId; 486 this.notationName = null; 487 488 firePropertyChange (PROP_TYPE, new Short (oldType), new Short (this.type)); 489 firePropertyChange (PROP_INTERNAL_TEXT, oldInternalText, this.internalText); 490 firePropertyChange (PROP_PUBLIC_ID, oldPublicId, newPublicId); 491 firePropertyChange (PROP_SYSTEM_ID, oldSystemId, newSystemId); 492 firePropertyChange (PROP_NOTATION_NAME, oldNotationName, this.notationName); 493 } 494 495 499 public final void setExternalDecl (String newPublicId, String newSystemId) throws ReadOnlyException, InvalidArgumentException { 500 boolean setPublicId = !!! Util.equals (this.publicId, newPublicId); 504 boolean setSystemId = !!! Util.equals (this.systemId, newSystemId); 505 if ( !!! setPublicId && 506 !!! setSystemId ) { 507 return; 508 } 509 checkReadOnly (); 510 checkExternalDecl (newPublicId, newSystemId); 511 512 setExternalDeclImpl (newPublicId, newSystemId); 516 } 517 518 520 protected final void checkExternalDecl (String publicId, String systemId) throws InvalidArgumentException { 521 TreeUtilities.checkEntityDeclPublicId (publicId); 522 TreeUtilities.checkEntityDeclSystemId (systemId); 523 524 checkExternalId (publicId, systemId); 525 } 526 527 529 public final String getNotationName () { 530 return notationName; 531 } 532 533 535 private final void setNotationNameImpl (String newNotationName) { 536 short oldType = this.type; 537 String oldNotationName = this.notationName; 538 539 if ( newNotationName == null ) { 540 this.type = TYPE_EXTERNAL; 541 } else { 542 this.type = TYPE_UNPARSED; 543 } 544 this.notationName = newNotationName; 545 546 firePropertyChange (PROP_TYPE, new Short (oldType), new Short (this.type)); 547 firePropertyChange (PROP_NOTATION_NAME, oldNotationName, newNotationName); 548 } 549 550 555 public final void setNotationName (String newNotationName) throws ReadOnlyException, InvalidStateException, InvalidArgumentException { 556 if ( Util.equals (this.notationName, newNotationName) ) 560 return; 561 checkReadOnly (); 562 if ( type == TYPE_INTERNAL ) { 563 throw new InvalidStateException (Util.THIS.getString ("EXC_internal_notation")); 564 } 565 if ( parameter == PARAMETER_DECL ) { 566 throw new InvalidStateException (Util.THIS.getString ("EXC_ted_parameter_unparsed")); 567 } 568 checkNotationName (newNotationName); 569 570 setNotationNameImpl (newNotationName); 574 } 575 576 578 protected final void checkNotationName (String notationName) throws InvalidArgumentException { 579 TreeUtilities.checkEntityDeclNotationName (notationName); 580 } 581 582 584 private final void setUnparsedDeclImpl (String newPublicId, String newSystemId, String newNotationName) { 585 short oldType = this.type; 586 String oldInternalText = this.internalText; 587 String oldPublicId = this.publicId; 588 String oldSystemId = this.systemId; 589 String oldNotationName = this.notationName; 590 591 this.type = TYPE_UNPARSED; 592 this.internalText = null; 593 this.publicId = newPublicId; 594 this.systemId = newSystemId; 595 this.notationName = newNotationName; 596 597 firePropertyChange (PROP_TYPE, new Short (oldType), new Short (this.type)); 598 firePropertyChange (PROP_INTERNAL_TEXT, oldInternalText, this.internalText); 599 firePropertyChange (PROP_PUBLIC_ID, oldPublicId, newPublicId); 600 firePropertyChange (PROP_SYSTEM_ID, oldSystemId, newSystemId); 601 firePropertyChange (PROP_NOTATION_NAME, oldNotationName, newNotationName); 602 } 603 604 609 public final void setUnparsedDecl (String newPublicId, String newSystemId, String newNotationName) throws ReadOnlyException, InvalidStateException, InvalidArgumentException { 610 boolean setPublicId = !!! Util.equals (this.publicId, newPublicId); 614 boolean setSystemId = !!! Util.equals (this.systemId, newSystemId); 615 boolean setNotationName = !!! Util.equals (this.notationName, newNotationName); 616 if ( !!! setPublicId && 617 !!! setSystemId && 618 !!! setNotationName ) { 619 return; 620 } 621 checkReadOnly (); 622 if ( parameter == PARAMETER_DECL ) { 623 throw new InvalidStateException (Util.THIS.getString ("EXC_ted_parameter_unparsed")); 624 } 625 checkUnparsedDecl (newPublicId, newSystemId, newNotationName); 626 627 setUnparsedDeclImpl (newPublicId, newSystemId, newNotationName); 631 } 632 633 635 protected final void checkUnparsedDecl (String publicId, String systemId, String notationName) throws InvalidArgumentException { 636 TreeUtilities.checkEntityDeclPublicId (publicId); 637 TreeUtilities.checkEntityDeclSystemId (systemId); 638 639 checkExternalId (publicId, systemId); 640 641 TreeUtilities.checkEntityDeclNotationName (notationName); 642 if ( notationName == null ) { 643 throw new InvalidArgumentException (Util.THIS.getString ("EXC_ted_unparsed_must_notation"), 644 new NullPointerException ()); 645 } 646 } 647 648 649 651 protected final void checkExternalId (String publicId, String systemId) throws InvalidArgumentException { 652 if ( systemId == null ) { 653 if ( publicId == null ) { 654 throw new InvalidArgumentException (Util.THIS.getString ("EXC_ted_system_required"), 655 new NullPointerException ()); 656 } else { 657 throw new InvalidArgumentException (Util.THIS.getString ("EXC_ted_system_required"), 658 new NullPointerException ()); 659 } 660 } 661 } 662 663 } 664 | Popular Tags |