1 19 package org.netbeans.tax; 20 21 import org.netbeans.tax.spec.DocumentFragment; 22 import org.netbeans.tax.spec.Element; 23 import org.netbeans.tax.spec.GeneralEntityReference; 24 import org.netbeans.tax.spec.Attribute; 25 26 31 public class TreeCharacterReference extends TreeChild implements TreeReference, TreeCharacterData, DocumentFragment.Child, Element.Child, GeneralEntityReference.Child, Attribute.Value { 32 33 public static final String PROP_NAME = "name"; 35 36 37 private String name; 39 43 46 public TreeCharacterReference (String name) throws InvalidArgumentException { 47 super (); 48 49 checkName (name); 50 this.name = name; 51 } 52 53 54 protected TreeCharacterReference (TreeCharacterReference characterReference) { 55 super (characterReference); 56 57 this.name = characterReference.name; 58 } 59 60 61 65 67 public Object clone () { 68 return new TreeCharacterReference (this); 69 } 70 71 73 public boolean equals (Object object, boolean deep) { 74 if (!!! super.equals (object, deep)) 75 return false; 76 77 TreeCharacterReference peer = (TreeCharacterReference) object; 78 if (!!! Util.equals (this.getName (), peer.getName ())) 79 return false; 80 81 return true; 82 } 83 84 87 public void merge (TreeObject treeObject) throws CannotMergeException { 88 super.merge (treeObject); 89 90 TreeCharacterReference peer = (TreeCharacterReference) treeObject; 91 setNameImpl (peer.getName ()); 92 } 93 94 98 public final String getName () { 99 return name; 100 } 101 102 104 private final void setNameImpl (String newName) { 105 String oldName = this.name; 106 107 this.name = newName; 108 109 firePropertyChange (PROP_NAME, oldName, newName); 110 } 111 112 116 public final void setName (String newName) throws ReadOnlyException, InvalidArgumentException { 117 if ( Util.equals (this.name, newName) ) 121 return; 122 checkReadOnly (); 123 checkName (newName); 124 125 setNameImpl (newName); 129 } 130 131 132 134 protected final void checkName (String name) throws InvalidArgumentException { 135 TreeUtilities.checkCharacterReferenceName (name); 136 } 137 138 141 public final String getData () { 142 143 145 short val; 146 147 if (name.startsWith ("#x")) { val = Short.parseShort (name.substring (2), 16); 149 } else { 150 val = Short.parseShort (name.substring (1)); 151 } 152 return new String (new char[] {(char) val}); 153 } 154 155 } 156 | Popular Tags |