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 org.netbeans.tax.spec.DTD;
044: import org.netbeans.tax.spec.ParameterEntityReference;
045: import org.netbeans.tax.spec.DocumentType;
046: import org.netbeans.tax.spec.ConditionalSection;
047:
048: /**
049: *
050: * @author Libor Kramolis
051: * @version 0.1
052: */
053: public class TreeNotationDecl extends TreeNodeDecl implements
054: DTD.Child, ParameterEntityReference.Child, DocumentType.Child,
055: ConditionalSection.Child {
056: /** */
057: public static final String PROP_NAME = "name"; // NOI18N
058: /** */
059: public static final String PROP_PUBLIC_ID = "publicId"; // NOI18N
060: /** */
061: public static final String PROP_SYSTEM_ID = "systemId"; // NOI18N
062:
063: /** */
064: private String name;
065:
066: /** -- can be null. */
067: private String systemId;
068:
069: /** -- can be null. */
070: private String publicId;
071:
072: //
073: // init
074: //
075:
076: /** Creates new TreeNotationDecl.
077: * @throws InvalidArgumentException
078: */
079: public TreeNotationDecl(String name, String publicId,
080: String systemId) throws InvalidArgumentException {
081: super ();
082:
083: checkName(name);
084: this .name = name;
085:
086: checkPublicId(publicId);
087: checkSystemId(systemId);
088: checkExternalId(publicId, systemId);
089: this .systemId = systemId;
090: this .publicId = publicId;
091: }
092:
093: /** Creates new TreeNotationDecl -- copy constructor. */
094: protected TreeNotationDecl(TreeNotationDecl notationDecl) {
095: super (notationDecl);
096:
097: this .name = notationDecl.name;
098: this .publicId = notationDecl.publicId;
099: this .systemId = notationDecl.systemId;
100: }
101:
102: //
103: // from TreeObject
104: //
105:
106: /**
107: */
108: public Object clone() {
109: return new TreeNotationDecl(this );
110: }
111:
112: /**
113: */
114: public boolean equals(Object object, boolean deep) {
115: if (!!!super .equals(object, deep))
116: return false;
117:
118: TreeNotationDecl peer = (TreeNotationDecl) object;
119: if (!!!Util.equals(this .getName(), peer.getName())) {
120: return false;
121: }
122: if (!!!Util.equals(this .getSystemId(), peer.getSystemId())) {
123: return false;
124: }
125: if (!!!Util.equals(this .getPublicId(), peer.getPublicId())) {
126: return false;
127: }
128:
129: return true;
130: }
131:
132: /*
133: * Merges properties: name, system ID and public ID.
134: */
135: public void merge(TreeObject treeObject)
136: throws CannotMergeException {
137: super .merge(treeObject);
138:
139: TreeNotationDecl peer = (TreeNotationDecl) treeObject;
140:
141: setNameImpl(peer.getName());
142: setSystemIdImpl(peer.getSystemId());
143: setPublicIdImpl(peer.getPublicId());
144: }
145:
146: //
147: // itself
148: //
149:
150: /**
151: */
152: public String getName() {
153: return name;
154: }
155:
156: /**
157: */
158: private final void setNameImpl(String newName) {
159: String oldName = this .name;
160:
161: this .name = newName;
162:
163: firePropertyChange(PROP_NAME, oldName, newName);
164: }
165:
166: /**
167: * @throws ReadOnlyException
168: * @throws InvalidArgumentException
169: */
170: public final void setName(String newName) throws ReadOnlyException,
171: InvalidArgumentException {
172: //
173: // check new value
174: //
175: if (Util.equals(this .name, newName))
176: return;
177: checkReadOnly();
178: checkName(newName);
179:
180: //
181: // set new value
182: //
183: setNameImpl(newName);
184: }
185:
186: /**
187: */
188: protected final void checkName(String name)
189: throws InvalidArgumentException {
190: TreeUtilities.checkNotationDeclName(name);
191: }
192:
193: /**
194: */
195: public String getPublicId() {
196: return publicId;
197: }
198:
199: /**
200: */
201: private final void setPublicIdImpl(String newPublicId) {
202: String oldPublicId = this .publicId;
203:
204: this .publicId = newPublicId;
205:
206: firePropertyChange(PROP_PUBLIC_ID, oldPublicId, newPublicId);
207: }
208:
209: /**
210: * @throws ReadOnlyException
211: * @throws InvalidArgumentException
212: */
213: public final void setPublicId(String newPublicId)
214: throws ReadOnlyException, InvalidArgumentException {
215: //
216: // check new value
217: //
218: if (Util.equals(this .publicId, newPublicId))
219: return;
220: checkReadOnly();
221: checkPublicId(newPublicId);
222: checkExternalId(newPublicId, this .systemId);
223:
224: //
225: // set new value
226: //
227: setPublicIdImpl(newPublicId);
228: }
229:
230: /**
231: */
232: protected final void checkPublicId(String publicId)
233: throws InvalidArgumentException {
234: TreeUtilities.checkNotationDeclPublicId(publicId);
235: }
236:
237: /**
238: */
239: public String getSystemId() {
240: return systemId;
241: }
242:
243: /**
244: */
245: private final void setSystemIdImpl(String newSystemId) {
246: String oldSystemId = this .systemId;
247:
248: this .systemId = newSystemId;
249:
250: firePropertyChange(PROP_SYSTEM_ID, oldSystemId, newSystemId);
251: }
252:
253: /**
254: * @throws ReadOnlyException
255: * @throws InvalidArgumentException
256: */
257: public final void setSystemId(String newSystemId)
258: throws ReadOnlyException, InvalidArgumentException {
259: //
260: // check new value
261: //
262: if (Util.equals(this .systemId, newSystemId))
263: return;
264: checkReadOnly();
265: checkSystemId(newSystemId);
266: checkExternalId(this .publicId, newSystemId);
267:
268: //
269: // set new value
270: //
271: setSystemIdImpl(newSystemId);
272: }
273:
274: /**
275: */
276: protected final void checkSystemId(String systemId)
277: throws InvalidArgumentException {
278: TreeUtilities.checkNotationDeclSystemId(systemId);
279: }
280:
281: /**
282: */
283: protected final void checkExternalId(String publicId,
284: String systemId) throws InvalidArgumentException {
285: if ((publicId == null) && (systemId == null)) {
286: throw new InvalidArgumentException(Util.THIS
287: .getString("EXC_invalid_nulls"),
288: new NullPointerException());
289: }
290: }
291:
292: }
|