KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > tax > TreeCharacterReference


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

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 /**
27  *
28  * @author Libor Kramolis
29  * @version 0.1
30  */

31 public class TreeCharacterReference extends TreeChild implements TreeReference, TreeCharacterData, DocumentFragment.Child, Element.Child, GeneralEntityReference.Child, Attribute.Value {
32     /** */
33     public static final String JavaDoc PROP_NAME = "name"; // NOI18N
34

35
36     /** */
37     private String JavaDoc name; //literal occuring in document "#99" // NOI18N
38

39     //
40
// init
41
//
42

43     /** Creates new TreeCharacterReference.
44      * @throws InvalidArgumentException
45      */

46     public TreeCharacterReference (String JavaDoc name) throws InvalidArgumentException {
47         super ();
48         
49         checkName (name);
50         this.name = name;
51     }
52     
53     /** Creates new TreeCharacterReference -- copy constructor. */
54     protected TreeCharacterReference (TreeCharacterReference characterReference) {
55         super (characterReference);
56         
57         this.name = characterReference.name;
58     }
59     
60     
61     //
62
// from TreeObject
63
//
64

65     /**
66      */

67     public Object JavaDoc clone () {
68         return new TreeCharacterReference (this);
69     }
70     
71     /**
72      */

73     public boolean equals (Object JavaDoc 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     /*
85      * Merge name property.
86      */

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     //
95
// itself
96
//
97

98     public final String JavaDoc getName () {
99         return name;
100     }
101     
102     /**
103      */

104     private final void setNameImpl (String JavaDoc newName) {
105         String JavaDoc oldName = this.name;
106         
107         this.name = newName;
108         
109         firePropertyChange (PROP_NAME, oldName, newName);
110     }
111     
112     /**
113      * @throws ReadOnlyException
114      * @throws InvalidArgumentException
115      */

116     public final void setName (String JavaDoc newName) throws ReadOnlyException, InvalidArgumentException {
117         //
118
// check new value
119
//
120
if ( Util.equals (this.name, newName) )
121             return;
122         checkReadOnly ();
123         checkName (newName);
124         
125         //
126
// set new value
127
//
128
setNameImpl (newName);
129     }
130     
131     
132     /**
133      */

134     protected final void checkName (String JavaDoc name) throws InvalidArgumentException {
135         TreeUtilities.checkCharacterReferenceName (name);
136     }
137     
138     /**
139      * @return string representing value (may be a surrogate)
140      */

141     public final String JavaDoc getData () {
142         
143         //!!! does not work for surrogates
144

145         short val;
146         
147         if (name.startsWith ("#x")) { // NOI18N
148
val = Short.parseShort (name.substring (2), 16);
149         } else {
150             val = Short.parseShort (name.substring (1));
151         }
152         return new String JavaDoc (new char[] {(char) val});
153     }
154     
155 }
156
Popular Tags