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 TreeEntityDecl extends TreeNodeDecl implements DTD.Child,
054: ParameterEntityReference.Child, DocumentType.Child,
055: ConditionalSection.Child {
056: /** */
057: public static final String PROP_PARAMETER = "parameter"; // NOI18N
058: /** */
059: public static final String PROP_NAME = "name"; // NOI18N
060: /** */
061: public static final String PROP_TYPE = "type"; // NOI18N
062: /** */
063: public static final String PROP_INTERNAL_TEXT = "internalText"; // NOI18N
064: /** */
065: public static final String PROP_PUBLIC_ID = "publicId"; // NOI18N
066: /** */
067: public static final String PROP_SYSTEM_ID = "systemId"; // NOI18N
068: /** */
069: public static final String PROP_NOTATION_NAME = "notationName"; // NOI18N
070:
071: /** */
072: public static final short TYPE_INTERNAL = 1;
073: /** */
074: public static final short TYPE_EXTERNAL = 2;
075: /** */
076: public static final short TYPE_UNPARSED = 3;
077:
078: /** */
079: public static final boolean GENERAL_DECL = false;
080: /** */
081: public static final boolean PARAMETER_DECL = true;
082:
083: /** */
084: private boolean parameter;
085:
086: /** */
087: private String name;
088:
089: /** */
090: private short type;
091:
092: /** -- can be null. */
093: private String internalText;
094:
095: /** -- can be null. */
096: private String publicId;
097:
098: /** -- can be null. */
099: private String systemId;
100:
101: /** -- can be null. */
102: private String notationName;
103:
104: //
105: // init
106: //
107:
108: /** Creates new TreeEntityDecl.
109: * @throws InvalidArgumentException
110: */
111: private TreeEntityDecl(boolean parameter, String name)
112: throws InvalidArgumentException {
113: super ();
114:
115: checkName(name);
116: this .name = name;
117: this .parameter = parameter;
118: }
119:
120: /** Creates new TreeEntityDecl.
121: * @throws InvalidArgumentException
122: */
123: public TreeEntityDecl(boolean parameter, String name,
124: String internalText) throws InvalidArgumentException {
125: this (parameter, name);
126:
127: checkInternalText(internalText);
128: this .type = TYPE_INTERNAL;
129: this .internalText = internalText;
130: this .publicId = null;
131: this .systemId = null;
132: this .notationName = null;
133: }
134:
135: /** Creates new TreeEntityDecl.
136: * @throws InvalidArgumentException
137: */
138: public TreeEntityDecl(String name, String internalText)
139: throws InvalidArgumentException {
140: this (GENERAL_DECL, name, internalText);
141: }
142:
143: /** Creates new TreeEntityDecl.
144: * @throws InvalidArgumentException
145: */
146: public TreeEntityDecl(boolean parameter, String name,
147: String publicId, String systemId)
148: throws InvalidArgumentException {
149: this (parameter, name);
150:
151: checkExternalDecl(publicId, systemId);
152: this .type = TYPE_EXTERNAL;
153: this .internalText = null;
154: this .publicId = publicId;
155: this .systemId = systemId;
156: this .notationName = null;
157: }
158:
159: /** Creates new TreeEntityDecl.
160: * @throws InvalidArgumentException
161: */
162: public TreeEntityDecl(String name, String publicId, String systemId)
163: throws InvalidArgumentException {
164: this (GENERAL_DECL, name, publicId, systemId);
165: }
166:
167: /** Creates new TreeEntityDecl.
168: * @throws InvalidArgumentException
169: */
170: public TreeEntityDecl(String name, String publicId,
171: String systemId, String notationName)
172: throws InvalidArgumentException {
173: this (GENERAL_DECL, name);
174:
175: checkUnparsedDecl(publicId, systemId, notationName);
176:
177: this .type = TYPE_UNPARSED;
178: this .internalText = null;
179: this .publicId = publicId;
180: this .systemId = systemId;
181: this .notationName = notationName;
182: }
183:
184: /** Creates new TreeEntityDecl -- copy constructor. */
185: protected TreeEntityDecl(TreeEntityDecl entityDecl) {
186: super (entityDecl);
187:
188: this .parameter = entityDecl.parameter;
189: this .name = entityDecl.name;
190: this .type = entityDecl.type;
191: this .internalText = entityDecl.internalText;
192: this .publicId = entityDecl.publicId;
193: this .systemId = entityDecl.systemId;
194: this .notationName = entityDecl.notationName;
195: }
196:
197: //
198: // from TreeObject
199: //
200:
201: /**
202: */
203: public Object clone() {
204: return new TreeEntityDecl(this );
205: }
206:
207: /**
208: */
209: public boolean equals(Object object, boolean deep) {
210: if (!!!super .equals(object, deep))
211: return false;
212:
213: TreeEntityDecl peer = (TreeEntityDecl) object;
214: if (!!!Util.equals(this .getName(), peer.getName()))
215: return false;
216: if (this .isParameter() != peer.isParameter())
217: return false;
218: if (this .getType() != peer.getType())
219: return false;
220: if (!!!Util.equals(this .getPublicId(), peer.getPublicId()))
221: return false;
222: if (!!!Util.equals(this .getSystemId(), peer.getSystemId()))
223: return false;
224: if (!!!Util.equals(this .getInternalText(), peer
225: .getInternalText()))
226: return false;
227: if (!!!Util.equals(this .getNotationName(), peer
228: .getNotationName()))
229: return false;
230:
231: return true;
232: }
233:
234: /*
235: * Wisely according peer type merge relevant properties.
236: */
237: public void merge(TreeObject treeObject)
238: throws CannotMergeException {
239: super .merge(treeObject);
240:
241: TreeEntityDecl peer = (TreeEntityDecl) treeObject;
242:
243: setNameImpl(peer.getName());
244: setParameterImpl(peer.isParameter());
245:
246: short peerType = peer.getType();
247: switch (peerType) {
248: case TYPE_EXTERNAL:
249: setExternalDeclImpl(peer.getPublicId(), peer.getSystemId());
250: break;
251: case TYPE_INTERNAL:
252: setInternalTextImpl(peer.getInternalText());
253: break;
254: case TYPE_UNPARSED:
255: setUnparsedDeclImpl(peer.getPublicId(), peer.getSystemId(),
256: peer.getNotationName());
257: break;
258: }
259: }
260:
261: //
262: // itself
263: //
264:
265: /**
266: */
267: public final boolean isParameter() {
268: return parameter;
269: }
270:
271: /**
272: */
273: private final void setParameterImpl(boolean newParameter) {
274: boolean oldParameter = this .parameter;
275:
276: this .parameter = newParameter;
277:
278: firePropertyChange(PROP_PARAMETER, oldParameter ? Boolean.TRUE
279: : Boolean.FALSE, newParameter ? Boolean.TRUE
280: : Boolean.FALSE);
281: }
282:
283: /**
284: * @throws ReadOnlyException
285: * @throws InvalidStateException
286: * @throws InvalidArgumentException
287: */
288: public final void setParameter(boolean newParameter)
289: throws ReadOnlyException, InvalidStateException,
290: InvalidArgumentException {
291: //
292: // check new value
293: //
294: if (this .parameter == newParameter)
295: return;
296: checkReadOnly();
297: if ((newParameter == PARAMETER_DECL) && (type == TYPE_UNPARSED)) {
298: throw new InvalidStateException(Util.THIS
299: .getString("EXC_ted_parameter_unparsed"));
300: }
301:
302: //
303: // set new value
304: //
305: setParameterImpl(newParameter);
306: }
307:
308: /**
309: */
310: public final String getName() {
311: return name;
312: }
313:
314: /**
315: */
316: private final void setNameImpl(String newName) {
317: String oldName = this .name;
318:
319: this .name = newName;
320:
321: firePropertyChange(PROP_NAME, oldName, newName);
322: }
323:
324: /**
325: * @throws ReadOnlyException
326: * @throws InvalidArgumentException
327: */
328: public final void setName(String newName) throws ReadOnlyException,
329: InvalidArgumentException {
330: //
331: // check new value
332: //
333: if (Util.equals(this .name, newName))
334: return;
335: checkReadOnly();
336: checkName(newName);
337:
338: //
339: // set new value
340: //
341: setNameImpl(newName);
342: }
343:
344: /**
345: */
346: protected final void checkName(String name)
347: throws InvalidArgumentException {
348: TreeUtilities.checkEntityDeclName(name);
349: }
350:
351: /**
352: */
353: public final short getType() {
354: return type;
355: }
356:
357: /**
358: */
359: public final String getInternalText() {
360: return internalText;
361: }
362:
363: /**
364: */
365: private final void setInternalTextImpl(String newInternalText) {
366: short oldType = this .type;
367: String oldInternalText = this .internalText;
368: String oldPublicId = this .publicId;
369: String oldSystemId = this .systemId;
370: String oldNotationName = this .notationName;
371:
372: this .type = TYPE_INTERNAL;
373: this .internalText = newInternalText;
374: this .publicId = null;
375: this .systemId = null;
376: this .notationName = null;
377:
378: firePropertyChange(PROP_TYPE, new Short(oldType), new Short(
379: this .type));
380: firePropertyChange(PROP_INTERNAL_TEXT, oldInternalText,
381: newInternalText);
382: firePropertyChange(PROP_PUBLIC_ID, oldPublicId, this .publicId);
383: firePropertyChange(PROP_SYSTEM_ID, oldSystemId, this .systemId);
384: firePropertyChange(PROP_NOTATION_NAME, oldNotationName,
385: this .notationName);
386: }
387:
388: /**
389: * @throws ReadOnlyException
390: * @throws InvalidArgumentException
391: */
392: public final void setInternalText(String newInternalText)
393: throws ReadOnlyException, InvalidArgumentException {
394: //
395: // check new value
396: //
397: if (Util.equals(this .internalText, newInternalText))
398: return;
399: checkReadOnly();
400: checkInternalText(newInternalText);
401:
402: //
403: // set new value
404: //
405: setInternalTextImpl(newInternalText);
406: }
407:
408: /**
409: */
410: protected final void checkInternalText(String internalText)
411: throws InvalidArgumentException {
412: TreeUtilities.checkEntityDeclInternalText(internalText);
413: }
414:
415: /**
416: */
417: public final String getPublicId() {
418: return publicId;
419: }
420:
421: /**
422: */
423: private final void setPublicIdImpl(String newPublicId) {
424: String oldPublicId = this .publicId;
425:
426: this .publicId = newPublicId;
427:
428: firePropertyChange(PROP_PUBLIC_ID, oldPublicId, newPublicId);
429: }
430:
431: /**
432: * @throws ReadOnlyException
433: * @throws InvalidStateException
434: * @throws InvalidArgumentException
435: */
436: public final void setPublicId(String newPublicId)
437: throws ReadOnlyException, InvalidStateException,
438: InvalidArgumentException {
439: //
440: // check new value
441: //
442: if (Util.equals(this .publicId, newPublicId))
443: return;
444: checkReadOnly();
445: if (type == TYPE_INTERNAL) {
446: throw new InvalidStateException(Util.THIS
447: .getString("EXC_ted_internal_public"));
448: }
449: checkPublicId(newPublicId);
450:
451: //
452: // set new value
453: //
454: setPublicIdImpl(newPublicId);
455: }
456:
457: /**
458: */
459: protected final void checkPublicId(String publicId)
460: throws InvalidArgumentException {
461: TreeUtilities.checkEntityDeclPublicId(publicId);
462:
463: checkExternalId(publicId, this .systemId);
464: }
465:
466: /**
467: */
468: public final String getSystemId() {
469: return systemId;
470: }
471:
472: /**
473: */
474: private final void setSystemIdImpl(String newSystemId) {
475: String oldSystemId = this .systemId;
476:
477: this .systemId = newSystemId;
478:
479: firePropertyChange(PROP_SYSTEM_ID, oldSystemId, newSystemId);
480: }
481:
482: /**
483: * @throws ReadOnlyException
484: * @throws InvalidStateException
485: * @throws InvalidArgumentException
486: */
487: public final void setSystemId(String newSystemId)
488: throws ReadOnlyException, InvalidStateException,
489: InvalidArgumentException {
490: //
491: // check new value
492: //
493: if (Util.equals(this .systemId, newSystemId))
494: return;
495: checkReadOnly();
496: if (type == TYPE_INTERNAL) {
497: throw new InvalidStateException(Util.THIS
498: .getString("EXC_ted_internal_system"));
499: }
500: checkSystemId(newSystemId);
501:
502: //
503: // set new value
504: //
505: setSystemIdImpl(newSystemId);
506: }
507:
508: /**
509: */
510: protected final void checkSystemId(String systemId)
511: throws InvalidArgumentException {
512: TreeUtilities.checkEntityDeclSystemId(systemId);
513:
514: checkExternalId(this .publicId, systemId);
515: }
516:
517: /**
518: */
519: private final void setExternalDeclImpl(String newPublicId,
520: String newSystemId) {
521: short oldType = this .type;
522: String oldInternalText = this .internalText;
523: String oldPublicId = this .publicId;
524: String oldSystemId = this .systemId;
525: String oldNotationName = this .notationName;
526:
527: this .type = TYPE_EXTERNAL;
528: this .internalText = null;
529: this .publicId = newPublicId;
530: this .systemId = newSystemId;
531: this .notationName = null;
532:
533: firePropertyChange(PROP_TYPE, new Short(oldType), new Short(
534: this .type));
535: firePropertyChange(PROP_INTERNAL_TEXT, oldInternalText,
536: this .internalText);
537: firePropertyChange(PROP_PUBLIC_ID, oldPublicId, newPublicId);
538: firePropertyChange(PROP_SYSTEM_ID, oldSystemId, newSystemId);
539: firePropertyChange(PROP_NOTATION_NAME, oldNotationName,
540: this .notationName);
541: }
542:
543: /**
544: * @throws ReadOnlyException
545: * @throws InvalidArgumentException
546: */
547: public final void setExternalDecl(String newPublicId,
548: String newSystemId) throws ReadOnlyException,
549: InvalidArgumentException {
550: //
551: // check new value
552: //
553: boolean setPublicId = !!!Util
554: .equals(this .publicId, newPublicId);
555: boolean setSystemId = !!!Util
556: .equals(this .systemId, newSystemId);
557: if (!!!setPublicId && !!!setSystemId) {
558: return;
559: }
560: checkReadOnly();
561: checkExternalDecl(newPublicId, newSystemId);
562:
563: //
564: // set new value
565: //
566: setExternalDeclImpl(newPublicId, newSystemId);
567: }
568:
569: /**
570: */
571: protected final void checkExternalDecl(String publicId,
572: String systemId) throws InvalidArgumentException {
573: TreeUtilities.checkEntityDeclPublicId(publicId);
574: TreeUtilities.checkEntityDeclSystemId(systemId);
575:
576: checkExternalId(publicId, systemId);
577: }
578:
579: /**
580: */
581: public final String getNotationName() {
582: return notationName;
583: }
584:
585: /**
586: */
587: private final void setNotationNameImpl(String newNotationName) {
588: short oldType = this .type;
589: String oldNotationName = this .notationName;
590:
591: if (newNotationName == null) {
592: this .type = TYPE_EXTERNAL;
593: } else {
594: this .type = TYPE_UNPARSED;
595: }
596: this .notationName = newNotationName;
597:
598: firePropertyChange(PROP_TYPE, new Short(oldType), new Short(
599: this .type));
600: firePropertyChange(PROP_NOTATION_NAME, oldNotationName,
601: newNotationName);
602: }
603:
604: /**
605: * @throws ReadOnlyException
606: * @throws InvalidStateException
607: * @throws InvalidArgumentException
608: */
609: public final void setNotationName(String newNotationName)
610: throws ReadOnlyException, InvalidStateException,
611: InvalidArgumentException {
612: //
613: // check new value
614: //
615: if (Util.equals(this .notationName, newNotationName))
616: return;
617: checkReadOnly();
618: if (type == TYPE_INTERNAL) {
619: throw new InvalidStateException(Util.THIS
620: .getString("EXC_internal_notation"));
621: }
622: if (parameter == PARAMETER_DECL) {
623: throw new InvalidStateException(Util.THIS
624: .getString("EXC_ted_parameter_unparsed"));
625: }
626: checkNotationName(newNotationName);
627:
628: //
629: // set new value
630: //
631: setNotationNameImpl(newNotationName);
632: }
633:
634: /**
635: */
636: protected final void checkNotationName(String notationName)
637: throws InvalidArgumentException {
638: TreeUtilities.checkEntityDeclNotationName(notationName);
639: }
640:
641: /**
642: */
643: private final void setUnparsedDeclImpl(String newPublicId,
644: String newSystemId, String newNotationName) {
645: short oldType = this .type;
646: String oldInternalText = this .internalText;
647: String oldPublicId = this .publicId;
648: String oldSystemId = this .systemId;
649: String oldNotationName = this .notationName;
650:
651: this .type = TYPE_UNPARSED;
652: this .internalText = null;
653: this .publicId = newPublicId;
654: this .systemId = newSystemId;
655: this .notationName = newNotationName;
656:
657: firePropertyChange(PROP_TYPE, new Short(oldType), new Short(
658: this .type));
659: firePropertyChange(PROP_INTERNAL_TEXT, oldInternalText,
660: this .internalText);
661: firePropertyChange(PROP_PUBLIC_ID, oldPublicId, newPublicId);
662: firePropertyChange(PROP_SYSTEM_ID, oldSystemId, newSystemId);
663: firePropertyChange(PROP_NOTATION_NAME, oldNotationName,
664: newNotationName);
665: }
666:
667: /**
668: * @throws ReadOnlyException
669: * @throws InvalidStateException
670: * @throws InvalidArgumentException
671: */
672: public final void setUnparsedDecl(String newPublicId,
673: String newSystemId, String newNotationName)
674: throws ReadOnlyException, InvalidStateException,
675: InvalidArgumentException {
676: //
677: // check new value
678: //
679: boolean setPublicId = !!!Util
680: .equals(this .publicId, newPublicId);
681: boolean setSystemId = !!!Util
682: .equals(this .systemId, newSystemId);
683: boolean setNotationName = !!!Util.equals(this .notationName,
684: newNotationName);
685: if (!!!setPublicId && !!!setSystemId && !!!setNotationName) {
686: return;
687: }
688: checkReadOnly();
689: if (parameter == PARAMETER_DECL) {
690: throw new InvalidStateException(Util.THIS
691: .getString("EXC_ted_parameter_unparsed"));
692: }
693: checkUnparsedDecl(newPublicId, newSystemId, newNotationName);
694:
695: //
696: // set new value
697: //
698: setUnparsedDeclImpl(newPublicId, newSystemId, newNotationName);
699: }
700:
701: /**
702: */
703: protected final void checkUnparsedDecl(String publicId,
704: String systemId, String notationName)
705: throws InvalidArgumentException {
706: TreeUtilities.checkEntityDeclPublicId(publicId);
707: TreeUtilities.checkEntityDeclSystemId(systemId);
708:
709: checkExternalId(publicId, systemId);
710:
711: TreeUtilities.checkEntityDeclNotationName(notationName);
712: if (notationName == null) {
713: throw new InvalidArgumentException(Util.THIS
714: .getString("EXC_ted_unparsed_must_notation"),
715: new NullPointerException());
716: }
717: }
718:
719: /**
720: */
721: protected final void checkExternalId(String publicId,
722: String systemId) throws InvalidArgumentException {
723: if (systemId == null) {
724: if (publicId == null) {
725: throw new InvalidArgumentException(Util.THIS
726: .getString("EXC_ted_system_required"),
727: new NullPointerException());
728: } else {
729: throw new InvalidArgumentException(Util.THIS
730: .getString("EXC_ted_system_required"),
731: new NullPointerException());
732: }
733: }
734: }
735:
736: }
|