KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Map JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.LinkedList JavaDoc;
25 import java.util.StringTokenizer JavaDoc;
26
27 import org.netbeans.tax.spec.DTD;
28 import org.netbeans.tax.spec.ParameterEntityReference;
29 import org.netbeans.tax.spec.DocumentType;
30 import org.netbeans.tax.spec.ConditionalSection;
31 import org.netbeans.tax.spec.AttlistDecl;
32
33 /**
34  * Holds DTD attribute declarations for some element.
35  *
36  * @author Libor Kramolis
37  * @version 0.1
38  */

39 public class TreeAttlistDecl extends TreeNodeDecl implements DTD.Child, ParameterEntityReference.Child, DocumentType.Child, ConditionalSection.Child {
40     /** */
41     public static final String JavaDoc PROP_ELEMENT_NAME = "elementName"; // NOI18N
42
/** */
43     public static final String JavaDoc PROP_ATTRIBUTE_DEF_MAP_ADD = "map.add"; // NOI18N
44
/** */
45     public static final String JavaDoc PROP_ATTRIBUTE_DEF_MAP_REMOVE = "map.remove"; // NOI18N
46
/** */
47     public static final String JavaDoc PROP_ATTRIBUTE_DEF_MAP_CONTENT = "map.content"; // NOI18N
48

49     /** */
50     private String JavaDoc elementName;
51     
52     /** */
53     private TreeNamedObjectMap attributeDefs;
54     
55     
56     //
57
// init
58
//
59

60     /** Creates new TreeAttlistDecl.
61      * @throws InvalidArgumentException
62      */

63     public TreeAttlistDecl (String JavaDoc elementName) throws InvalidArgumentException {
64         super ();
65         
66         checkElementName (elementName);
67         this.elementName = elementName;
68         this.attributeDefs = new TreeNamedObjectMap (createAttlistContentManager ());
69     }
70     
71     /** Creates new TreeAttlistDecl -- copy constructor. */
72     protected TreeAttlistDecl (TreeAttlistDecl attlistDecl) {
73         super (attlistDecl);
74         
75         this.elementName = attlistDecl.elementName;
76         this.attributeDefs = new TreeNamedObjectMap (createAttlistContentManager ());
77         this.attributeDefs.addAll ((TreeNamedObjectMap)attlistDecl.attributeDefs.clone ());
78     }
79     
80     
81     //
82
// from TreeObject
83
//
84

85     /**
86      */

87     public Object JavaDoc clone () {
88         return new TreeAttlistDecl (this);
89     }
90     
91     /**
92      */

93     public boolean equals (Object JavaDoc object, boolean deep) {
94         if (!!! super.equals (object, deep))
95             return false;
96         
97         TreeAttlistDecl peer = (TreeAttlistDecl) object;
98         if (!!! Util.equals (this.getElementName (), peer.getElementName ()))
99             return false;
100         if (!!! Util.equals (this.attributeDefs, peer.attributeDefs))
101             return false;
102         
103         return true;
104     }
105     
106     /*
107      * Merge element name property and delegate attributeDefs merging.
108      */

109     public void merge (TreeObject treeObject) throws CannotMergeException {
110         super.merge (treeObject);
111         
112         TreeAttlistDecl peer = (TreeAttlistDecl) treeObject;
113         
114         setElementNameImpl (peer.getElementName ());
115         attributeDefs.merge (peer.attributeDefs);
116     }
117     
118     
119     //
120
// read only
121
//
122

123     
124     /**
125      */

126     protected void setReadOnly (boolean newReadOnly) {
127         //if (newReadOnly) Util.saveContext("TreeAttlistDecl.setReadOnly(true)"); // NOI18N
128

129         super.setReadOnly (newReadOnly);
130         
131         attributeDefs.setReadOnly (newReadOnly);
132     }
133     
134     
135     //
136
// itself
137
//
138

139     /**
140      */

141     public final String JavaDoc getElementName () {
142         return elementName;
143     }
144     
145     /**
146      */

147     private final void setElementNameImpl (String JavaDoc newElementName) {
148         String JavaDoc oldElementName = this.elementName;
149         
150         this.elementName = newElementName;
151         
152         firePropertyChange (PROP_ELEMENT_NAME, oldElementName, newElementName);
153     }
154     
155     /**
156      * @throws ReadOnlyException
157      * @throws InvalidArgumentException
158      */

159     public final void setElementName (String JavaDoc newElementName) throws ReadOnlyException, InvalidArgumentException {
160         //
161
// check new value
162
//
163
if ( Util.equals (this.elementName, newElementName) )
164             return;
165         checkReadOnly ();
166         checkElementName (newElementName);
167         
168         //
169
// set new value
170
//
171
setElementNameImpl (newElementName);
172     }
173     
174     /**
175      */

176     protected final void checkElementName (String JavaDoc elementName) throws InvalidArgumentException {
177         TreeUtilities.checkAttlistDeclElementName (elementName);
178     }
179     
180     /**
181      */

182     public final TreeAttlistDeclAttributeDef getAttributeDef (String JavaDoc attributeDefName) {
183         return (TreeAttlistDeclAttributeDef)attributeDefs.get (attributeDefName);
184     }
185     
186     /**
187      */

188     private final void setAttributeDefImpl (TreeAttlistDeclAttributeDef newAttributeDef) {
189         TreeAttlistDeclAttributeDef oldAttributeDef = (TreeAttlistDeclAttributeDef)attributeDefs.get (newAttributeDef.getName ());
190         
191         attributeDefs.add (newAttributeDef);
192         
193         firePropertyChange (PROP_ATTRIBUTE_DEF_MAP_ADD, oldAttributeDef, newAttributeDef);
194     }
195     
196     /**
197      * @throws ReadOnlyException
198      * @throws InvalidArgumentException
199      */

200     public final void setAttributeDef (TreeAttlistDeclAttributeDef newAttributeDef) throws ReadOnlyException, InvalidArgumentException {
201         //
202
// check new value
203
//
204
TreeAttlistDeclAttributeDef oldAttributeDef = (TreeAttlistDeclAttributeDef)attributeDefs.get (newAttributeDef.getName ());
205         if ( Util.equals (oldAttributeDef, newAttributeDef) )
206             return;
207         checkReadOnly ();
208 // checkAttributeDef (newAttributeDef);
209

210         //
211
// set new value
212
//
213
setAttributeDefImpl (newAttributeDef);
214     }
215     
216     /**
217      */

218     private final TreeAttlistDeclAttributeDef removeAttributeDefImpl (String JavaDoc attributeDefName) {
219         TreeAttlistDeclAttributeDef oldAttributeDef = (TreeAttlistDeclAttributeDef)attributeDefs.get (attributeDefName);
220         
221         attributeDefs.remove (oldAttributeDef);
222         
223         firePropertyChange (PROP_ATTRIBUTE_DEF_MAP_REMOVE, oldAttributeDef, null);
224         
225         return oldAttributeDef;
226     }
227     
228     /**
229      * @throws ReadOnlyException
230      */

231     public final TreeAttlistDeclAttributeDef removeAttributeDef (String JavaDoc attributeDefName) throws ReadOnlyException {
232         //
233
// check new value
234
//
235
// if ( Util.equals (this.???, new???) )
236
// return;
237
checkReadOnly ();
238         
239         //
240
// set new value
241
//
242
return removeAttributeDefImpl (attributeDefName);
243     }
244     
245     /**
246      */

247     public final TreeNamedObjectMap getAttributeDefs () {
248         return attributeDefs;
249     }
250     
251     
252     //
253
// TreeObjectList.ContentManager
254
//
255

256     /**
257      */

258     protected TreeNamedObjectMap.ContentManager createAttlistContentManager () {
259         return new AttlistContentManager ();
260     }
261     
262     
263     /**
264      *
265      */

266     protected class AttlistContentManager extends TreeNamedObjectMap.ContentManager {
267         
268         /**
269          */

270         public TreeNode getOwnerNode () {
271             return TreeAttlistDecl.this;
272         }
273         
274         /**
275          */

276         public void checkAssignableObject (Object JavaDoc obj) {
277             super.checkAssignableObject (obj);
278             checkAssignableClass (TreeAttlistDeclAttributeDef.class, obj);
279         }
280         
281         /**
282          */

283         public void objectInserted (TreeObject obj) {
284             ((TreeAttlistDeclAttributeDef)obj).setNodeDecl (TreeAttlistDecl.this);
285         }
286         
287         /**
288          */

289         public void objectRemoved (TreeObject obj) {
290             ((TreeAttlistDeclAttributeDef)obj).setNodeDecl (null);
291         }
292         
293         /**
294          */

295         public void orderChanged (int[] permutation) {
296         }
297         
298     } // end: class ChildListContentManager
299

300 }
301
Popular Tags