001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.tax;
042:
043: import java.util.Map;
044: import java.util.HashMap;
045: import java.util.List;
046: import java.util.LinkedList;
047: import java.util.StringTokenizer;
048:
049: import org.netbeans.tax.spec.DTD;
050: import org.netbeans.tax.spec.ParameterEntityReference;
051: import org.netbeans.tax.spec.DocumentType;
052: import org.netbeans.tax.spec.ConditionalSection;
053: import org.netbeans.tax.spec.AttlistDecl;
054:
055: /**
056: * Holds DTD attribute declarations for some element.
057: *
058: * @author Libor Kramolis
059: * @version 0.1
060: */
061: public class TreeAttlistDecl extends TreeNodeDecl implements DTD.Child,
062: ParameterEntityReference.Child, DocumentType.Child,
063: ConditionalSection.Child {
064: /** */
065: public static final String PROP_ELEMENT_NAME = "elementName"; // NOI18N
066: /** */
067: public static final String PROP_ATTRIBUTE_DEF_MAP_ADD = "map.add"; // NOI18N
068: /** */
069: public static final String PROP_ATTRIBUTE_DEF_MAP_REMOVE = "map.remove"; // NOI18N
070: /** */
071: public static final String PROP_ATTRIBUTE_DEF_MAP_CONTENT = "map.content"; // NOI18N
072:
073: /** */
074: private String elementName;
075:
076: /** */
077: private TreeNamedObjectMap attributeDefs;
078:
079: //
080: // init
081: //
082:
083: /** Creates new TreeAttlistDecl.
084: * @throws InvalidArgumentException
085: */
086: public TreeAttlistDecl(String elementName)
087: throws InvalidArgumentException {
088: super ();
089:
090: checkElementName(elementName);
091: this .elementName = elementName;
092: this .attributeDefs = new TreeNamedObjectMap(
093: createAttlistContentManager());
094: }
095:
096: /** Creates new TreeAttlistDecl -- copy constructor. */
097: protected TreeAttlistDecl(TreeAttlistDecl attlistDecl) {
098: super (attlistDecl);
099:
100: this .elementName = attlistDecl.elementName;
101: this .attributeDefs = new TreeNamedObjectMap(
102: createAttlistContentManager());
103: this .attributeDefs
104: .addAll((TreeNamedObjectMap) attlistDecl.attributeDefs
105: .clone());
106: }
107:
108: //
109: // from TreeObject
110: //
111:
112: /**
113: */
114: public Object clone() {
115: return new TreeAttlistDecl(this );
116: }
117:
118: /**
119: */
120: public boolean equals(Object object, boolean deep) {
121: if (!!!super .equals(object, deep))
122: return false;
123:
124: TreeAttlistDecl peer = (TreeAttlistDecl) object;
125: if (!!!Util
126: .equals(this .getElementName(), peer.getElementName()))
127: return false;
128: if (!!!Util.equals(this .attributeDefs, peer.attributeDefs))
129: return false;
130:
131: return true;
132: }
133:
134: /*
135: * Merge element name property and delegate attributeDefs merging.
136: */
137: public void merge(TreeObject treeObject)
138: throws CannotMergeException {
139: super .merge(treeObject);
140:
141: TreeAttlistDecl peer = (TreeAttlistDecl) treeObject;
142:
143: setElementNameImpl(peer.getElementName());
144: attributeDefs.merge(peer.attributeDefs);
145: }
146:
147: //
148: // read only
149: //
150:
151: /**
152: */
153: protected void setReadOnly(boolean newReadOnly) {
154: //if (newReadOnly) Util.saveContext("TreeAttlistDecl.setReadOnly(true)"); // NOI18N
155:
156: super .setReadOnly(newReadOnly);
157:
158: attributeDefs.setReadOnly(newReadOnly);
159: }
160:
161: //
162: // itself
163: //
164:
165: /**
166: */
167: public final String getElementName() {
168: return elementName;
169: }
170:
171: /**
172: */
173: private final void setElementNameImpl(String newElementName) {
174: String oldElementName = this .elementName;
175:
176: this .elementName = newElementName;
177:
178: firePropertyChange(PROP_ELEMENT_NAME, oldElementName,
179: newElementName);
180: }
181:
182: /**
183: * @throws ReadOnlyException
184: * @throws InvalidArgumentException
185: */
186: public final void setElementName(String newElementName)
187: throws ReadOnlyException, InvalidArgumentException {
188: //
189: // check new value
190: //
191: if (Util.equals(this .elementName, newElementName))
192: return;
193: checkReadOnly();
194: checkElementName(newElementName);
195:
196: //
197: // set new value
198: //
199: setElementNameImpl(newElementName);
200: }
201:
202: /**
203: */
204: protected final void checkElementName(String elementName)
205: throws InvalidArgumentException {
206: TreeUtilities.checkAttlistDeclElementName(elementName);
207: }
208:
209: /**
210: */
211: public final TreeAttlistDeclAttributeDef getAttributeDef(
212: String attributeDefName) {
213: return (TreeAttlistDeclAttributeDef) attributeDefs
214: .get(attributeDefName);
215: }
216:
217: /**
218: */
219: private final void setAttributeDefImpl(
220: TreeAttlistDeclAttributeDef newAttributeDef) {
221: TreeAttlistDeclAttributeDef oldAttributeDef = (TreeAttlistDeclAttributeDef) attributeDefs
222: .get(newAttributeDef.getName());
223:
224: attributeDefs.add(newAttributeDef);
225:
226: firePropertyChange(PROP_ATTRIBUTE_DEF_MAP_ADD, oldAttributeDef,
227: newAttributeDef);
228: }
229:
230: /**
231: * @throws ReadOnlyException
232: * @throws InvalidArgumentException
233: */
234: public final void setAttributeDef(
235: TreeAttlistDeclAttributeDef newAttributeDef)
236: throws ReadOnlyException, InvalidArgumentException {
237: //
238: // check new value
239: //
240: TreeAttlistDeclAttributeDef oldAttributeDef = (TreeAttlistDeclAttributeDef) attributeDefs
241: .get(newAttributeDef.getName());
242: if (Util.equals(oldAttributeDef, newAttributeDef))
243: return;
244: checkReadOnly();
245: // checkAttributeDef (newAttributeDef);
246:
247: //
248: // set new value
249: //
250: setAttributeDefImpl(newAttributeDef);
251: }
252:
253: /**
254: */
255: private final TreeAttlistDeclAttributeDef removeAttributeDefImpl(
256: String attributeDefName) {
257: TreeAttlistDeclAttributeDef oldAttributeDef = (TreeAttlistDeclAttributeDef) attributeDefs
258: .get(attributeDefName);
259:
260: attributeDefs.remove(oldAttributeDef);
261:
262: firePropertyChange(PROP_ATTRIBUTE_DEF_MAP_REMOVE,
263: oldAttributeDef, null);
264:
265: return oldAttributeDef;
266: }
267:
268: /**
269: * @throws ReadOnlyException
270: */
271: public final TreeAttlistDeclAttributeDef removeAttributeDef(
272: String attributeDefName) throws ReadOnlyException {
273: //
274: // check new value
275: //
276: // if ( Util.equals (this.???, new???) )
277: // return;
278: checkReadOnly();
279:
280: //
281: // set new value
282: //
283: return removeAttributeDefImpl(attributeDefName);
284: }
285:
286: /**
287: */
288: public final TreeNamedObjectMap getAttributeDefs() {
289: return attributeDefs;
290: }
291:
292: //
293: // TreeObjectList.ContentManager
294: //
295:
296: /**
297: */
298: protected TreeNamedObjectMap.ContentManager createAttlistContentManager() {
299: return new AttlistContentManager();
300: }
301:
302: /**
303: *
304: */
305: protected class AttlistContentManager extends
306: TreeNamedObjectMap.ContentManager {
307:
308: /**
309: */
310: public TreeNode getOwnerNode() {
311: return TreeAttlistDecl.this ;
312: }
313:
314: /**
315: */
316: public void checkAssignableObject(Object obj) {
317: super .checkAssignableObject(obj);
318: checkAssignableClass(TreeAttlistDeclAttributeDef.class, obj);
319: }
320:
321: /**
322: */
323: public void objectInserted(TreeObject obj) {
324: ((TreeAttlistDeclAttributeDef) obj)
325: .setNodeDecl(TreeAttlistDecl.this );
326: }
327:
328: /**
329: */
330: public void objectRemoved(TreeObject obj) {
331: ((TreeAttlistDeclAttributeDef) obj).setNodeDecl(null);
332: }
333:
334: /**
335: */
336: public void orderChanged(int[] permutation) {
337: }
338:
339: } // end: class ChildListContentManager
340:
341: }
|