KickJava   Java API By Example, From Geeks To Geeks.

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


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.DTD;
22 import org.netbeans.tax.spec.ParameterEntityReference;
23 import org.netbeans.tax.spec.DocumentType;
24 import org.netbeans.tax.spec.ConditionalSection;
25
26 /**
27  *
28  * @author Libor Kramolis
29  * @version 0.1
30  */

31 public class TreeEntityDecl extends TreeNodeDecl implements DTD.Child, ParameterEntityReference.Child, DocumentType.Child, ConditionalSection.Child {
32     /** */
33     public static final String JavaDoc PROP_PARAMETER = "parameter"; // NOI18N
34
/** */
35     public static final String JavaDoc PROP_NAME = "name"; // NOI18N
36
/** */
37     public static final String JavaDoc PROP_TYPE = "type"; // NOI18N
38
/** */
39     public static final String JavaDoc PROP_INTERNAL_TEXT = "internalText"; // NOI18N
40
/** */
41     public static final String JavaDoc PROP_PUBLIC_ID = "publicId"; // NOI18N
42
/** */
43     public static final String JavaDoc PROP_SYSTEM_ID = "systemId"; // NOI18N
44
/** */
45     public static final String JavaDoc PROP_NOTATION_NAME = "notationName"; // NOI18N
46

47     /** */
48     public static final short TYPE_INTERNAL = 1;
49     /** */
50     public static final short TYPE_EXTERNAL = 2;
51     /** */
52     public static final short TYPE_UNPARSED = 3;
53     
54     /** */
55     public static final boolean GENERAL_DECL = false;
56     /** */
57     public static final boolean PARAMETER_DECL = true;
58     
59     
60     /** */
61     private boolean parameter;
62     
63     /** */
64     private String JavaDoc name;
65     
66     /** */
67     private short type;
68     
69     /** -- can be null. */
70     private String JavaDoc internalText;
71     
72     /** -- can be null. */
73     private String JavaDoc publicId;
74     
75     /** -- can be null. */
76     private String JavaDoc systemId;
77     
78     /** -- can be null. */
79     private String JavaDoc notationName;
80     
81     
82     //
83
// init
84
//
85

86     /** Creates new TreeEntityDecl.
87      * @throws InvalidArgumentException
88      */

89     private TreeEntityDecl (boolean parameter, String JavaDoc name) throws InvalidArgumentException {
90         super ();
91         
92         checkName (name);
93         this.name = name;
94         this.parameter = parameter;
95     }
96     
97     
98     /** Creates new TreeEntityDecl.
99      * @throws InvalidArgumentException
100      */

101     public TreeEntityDecl (boolean parameter, String JavaDoc name, String JavaDoc internalText) throws InvalidArgumentException {
102         this (parameter, name);
103         
104         checkInternalText (internalText);
105         this.type = TYPE_INTERNAL;
106         this.internalText = internalText;
107         this.publicId = null;
108         this.systemId = null;
109         this.notationName = null;
110     }
111     
112     
113     /** Creates new TreeEntityDecl.
114      * @throws InvalidArgumentException
115      */

116     public TreeEntityDecl (String JavaDoc name, String JavaDoc internalText) throws InvalidArgumentException {
117         this (GENERAL_DECL, name, internalText);
118     }
119     
120     
121     /** Creates new TreeEntityDecl.
122      * @throws InvalidArgumentException
123      */

124     public TreeEntityDecl (boolean parameter, String JavaDoc name, String JavaDoc publicId, String JavaDoc systemId) throws InvalidArgumentException {
125         this (parameter, name);
126         
127         checkExternalDecl (publicId, systemId);
128         this.type = TYPE_EXTERNAL;
129         this.internalText = null;
130         this.publicId = publicId;
131         this.systemId = systemId;
132         this.notationName = null;
133     }
134     
135     
136     /** Creates new TreeEntityDecl.
137      * @throws InvalidArgumentException
138      */

139     public TreeEntityDecl (String JavaDoc name, String JavaDoc publicId, String JavaDoc systemId) throws InvalidArgumentException {
140         this (GENERAL_DECL, name, publicId, systemId);
141     }
142     
143     
144     /** Creates new TreeEntityDecl.
145      * @throws InvalidArgumentException
146      */

147     public TreeEntityDecl (String JavaDoc name, String JavaDoc publicId, String JavaDoc systemId, String JavaDoc notationName) throws InvalidArgumentException {
148         this (GENERAL_DECL, name);
149         
150         checkUnparsedDecl (publicId, systemId, notationName);
151         
152         this.type = TYPE_UNPARSED;
153         this.internalText = null;
154         this.publicId = publicId;
155         this.systemId = systemId;
156         this.notationName = notationName;
157     }
158     
159     
160     
161     /** Creates new TreeEntityDecl -- copy constructor. */
162     protected TreeEntityDecl (TreeEntityDecl entityDecl) {
163         super (entityDecl);
164         
165         this.parameter = entityDecl.parameter;
166         this.name = entityDecl.name;
167         this.type = entityDecl.type;
168         this.internalText = entityDecl.internalText;
169         this.publicId = entityDecl.publicId;
170         this.systemId = entityDecl.systemId;
171         this.notationName = entityDecl.notationName;
172     }
173     
174     
175     //
176
// from TreeObject
177
//
178

179     /**
180      */

181     public Object JavaDoc clone () {
182         return new TreeEntityDecl (this);
183     }
184     
185     /**
186      */

187     public boolean equals (Object JavaDoc object, boolean deep) {
188         if (!!! super.equals (object, deep))
189             return false;
190         
191         TreeEntityDecl peer = (TreeEntityDecl) object;
192         if (!!! Util.equals (this.getName (), peer.getName ()))
193             return false;
194         if ( this.isParameter () != peer.isParameter ())
195             return false;
196         if ( this.getType () != peer.getType ())
197             return false;
198         if (!!! Util.equals (this.getPublicId (), peer.getPublicId ()))
199             return false;
200         if (!!! Util.equals (this.getSystemId (), peer.getSystemId ()))
201             return false;
202         if (!!! Util.equals (this.getInternalText (), peer.getInternalText ()))
203             return false;
204         if (!!! Util.equals (this.getNotationName (), peer.getNotationName ()))
205             return false;
206         
207         return true;
208     }
209     
210     /*
211      * Wisely according peer type merge relevant properties.
212      */

213     public void merge (TreeObject treeObject) throws CannotMergeException {
214         super.merge (treeObject);
215         
216         TreeEntityDecl peer = (TreeEntityDecl) treeObject;
217         
218         setNameImpl (peer.getName ());
219         setParameterImpl (peer.isParameter ());
220         
221         short peerType = peer.getType ();
222         switch (peerType) {
223             case TYPE_EXTERNAL:
224                 setExternalDeclImpl (peer.getPublicId (), peer.getSystemId ());
225                 break;
226             case TYPE_INTERNAL:
227                 setInternalTextImpl (peer.getInternalText ());
228                 break;
229             case TYPE_UNPARSED:
230                 setUnparsedDeclImpl (peer.getPublicId (), peer.getSystemId (), peer.getNotationName ());
231                 break;
232         }
233     }
234     
235     
236     //
237
// itself
238
//
239

240     /**
241      */

242     public final boolean isParameter () {
243         return parameter;
244     }
245     
246     /**
247      */

248     private final void setParameterImpl (boolean newParameter) {
249         boolean oldParameter = this.parameter;
250         
251         this.parameter = newParameter;
252         
253         firePropertyChange (PROP_PARAMETER, oldParameter ? Boolean.TRUE : Boolean.FALSE, newParameter ? Boolean.TRUE : Boolean.FALSE);
254     }
255     
256     /**
257      * @throws ReadOnlyException
258      * @throws InvalidStateException
259      * @throws InvalidArgumentException
260      */

261     public final void setParameter (boolean newParameter) throws ReadOnlyException, InvalidStateException, InvalidArgumentException {
262         //
263
// check new value
264
//
265
if ( this.parameter == newParameter )
266             return;
267         checkReadOnly ();
268         if ( (newParameter == PARAMETER_DECL) && (type == TYPE_UNPARSED) ) {
269             throw new InvalidStateException (Util.THIS.getString ("EXC_ted_parameter_unparsed"));
270         }
271         
272         //
273
// set new value
274
//
275
setParameterImpl (newParameter);
276     }
277     
278     /**
279      */

280     public final String JavaDoc getName () {
281         return name;
282     }
283     
284     /**
285      */

286     private final void setNameImpl (String JavaDoc newName) {
287         String JavaDoc oldName = this.name;
288         
289         this.name = newName;
290         
291         firePropertyChange (PROP_NAME, oldName, newName);
292     }
293     
294     /**
295      * @throws ReadOnlyException
296      * @throws InvalidArgumentException
297      */

298     public final void setName (String JavaDoc newName) throws ReadOnlyException, InvalidArgumentException {
299         //
300
// check new value
301
//
302
if ( Util.equals (this.name, newName) )
303             return;
304         checkReadOnly ();
305         checkName (newName);
306         
307         //
308
// set new value
309
//
310
setNameImpl (newName);
311     }
312     
313     /**
314      */

315     protected final void checkName (String JavaDoc name) throws InvalidArgumentException {
316         TreeUtilities.checkEntityDeclName (name);
317     }
318     
319     /**
320      */

321     public final short getType () {
322         return type;
323     }
324     
325     /**
326      */

327     public final String JavaDoc getInternalText () {
328         return internalText;
329     }
330     
331     /**
332      */

333     private final void setInternalTextImpl (String JavaDoc newInternalText) {
334         short oldType = this.type;
335         String JavaDoc oldInternalText = this.internalText;
336         String JavaDoc oldPublicId = this.publicId;
337         String JavaDoc oldSystemId = this.systemId;
338         String JavaDoc oldNotationName = this.notationName;
339         
340         this.type = TYPE_INTERNAL;
341         this.internalText = newInternalText;
342         this.publicId = null;
343         this.systemId = null;
344         this.notationName = null;
345         
346         firePropertyChange (PROP_TYPE, new Short JavaDoc (oldType), new Short JavaDoc (this.type));
347         firePropertyChange (PROP_INTERNAL_TEXT, oldInternalText, newInternalText);
348         firePropertyChange (PROP_PUBLIC_ID, oldPublicId, this.publicId);
349         firePropertyChange (PROP_SYSTEM_ID, oldSystemId, this.systemId);
350         firePropertyChange (PROP_NOTATION_NAME, oldNotationName, this.notationName);
351     }
352     
353     /**
354      * @throws ReadOnlyException
355      * @throws InvalidArgumentException
356      */

357     public final void setInternalText (String JavaDoc newInternalText) throws ReadOnlyException, InvalidArgumentException {
358         //
359
// check new value
360
//
361
if ( Util.equals (this.internalText, newInternalText) )
362             return;
363         checkReadOnly ();
364         checkInternalText (newInternalText);
365         
366         //
367
// set new value
368
//
369
setInternalTextImpl (newInternalText);
370     }
371     
372     /**
373      */

374     protected final void checkInternalText (String JavaDoc internalText) throws InvalidArgumentException {
375         TreeUtilities.checkEntityDeclInternalText (internalText);
376     }
377     
378     /**
379      */

380     public final String JavaDoc getPublicId () {
381         return publicId;
382     }
383     
384     /**
385      */

386     private final void setPublicIdImpl (String JavaDoc newPublicId) {
387         String JavaDoc oldPublicId = this.publicId;
388         
389         this.publicId = newPublicId;
390         
391         firePropertyChange (PROP_PUBLIC_ID, oldPublicId, newPublicId);
392     }
393     
394     /**
395      * @throws ReadOnlyException
396      * @throws InvalidStateException
397      * @throws InvalidArgumentException
398      */

399     public final void setPublicId (String JavaDoc newPublicId) throws ReadOnlyException, InvalidStateException, InvalidArgumentException {
400         //
401
// check new value
402
//
403
if ( Util.equals (this.publicId, newPublicId) )
404             return;
405         checkReadOnly ();
406         if ( type == TYPE_INTERNAL ) {
407             throw new InvalidStateException (Util.THIS.getString ("EXC_ted_internal_public"));
408         }
409         checkPublicId (newPublicId);
410         
411         //
412
// set new value
413
//
414
setPublicIdImpl (newPublicId);
415     }
416     
417     /**
418      */

419     protected final void checkPublicId (String JavaDoc publicId) throws InvalidArgumentException {
420         TreeUtilities.checkEntityDeclPublicId (publicId);
421         
422         checkExternalId (publicId, this.systemId);
423     }
424     
425     /**
426      */

427     public final String JavaDoc getSystemId () {
428         return systemId;
429     }
430     
431     /**
432      */

433     private final void setSystemIdImpl (String JavaDoc newSystemId) {
434         String JavaDoc oldSystemId = this.systemId;
435         
436         this.systemId = newSystemId;
437         
438         firePropertyChange (PROP_SYSTEM_ID, oldSystemId, newSystemId);
439     }
440     
441     /**
442      * @throws ReadOnlyException
443      * @throws InvalidStateException
444      * @throws InvalidArgumentException
445      */

446     public final void setSystemId (String JavaDoc newSystemId) throws ReadOnlyException, InvalidStateException, InvalidArgumentException {
447         //
448
// check new value
449
//
450
if ( Util.equals (this.systemId, newSystemId) )
451             return;
452         checkReadOnly ();
453         if ( type == TYPE_INTERNAL ) {
454             throw new InvalidStateException (Util.THIS.getString ("EXC_ted_internal_system"));
455         }
456         checkSystemId (newSystemId);
457         
458         //
459
// set new value
460
//
461
setSystemIdImpl (newSystemId);
462     }
463     
464     /**
465      */

466     protected final void checkSystemId (String JavaDoc systemId) throws InvalidArgumentException {
467         TreeUtilities.checkEntityDeclSystemId (systemId);
468         
469         checkExternalId (this.publicId, systemId);
470     }
471     
472     
473     /**
474      */

475     private final void setExternalDeclImpl (String JavaDoc newPublicId, String JavaDoc newSystemId) {
476         short oldType = this.type;
477         String JavaDoc oldInternalText = this.internalText;
478         String JavaDoc oldPublicId = this.publicId;
479         String JavaDoc oldSystemId = this.systemId;
480         String JavaDoc oldNotationName = this.notationName;
481         
482         this.type = TYPE_EXTERNAL;
483         this.internalText = null;
484         this.publicId = newPublicId;
485         this.systemId = newSystemId;
486         this.notationName = null;
487         
488         firePropertyChange (PROP_TYPE, new Short JavaDoc (oldType), new Short JavaDoc (this.type));
489         firePropertyChange (PROP_INTERNAL_TEXT, oldInternalText, this.internalText);
490         firePropertyChange (PROP_PUBLIC_ID, oldPublicId, newPublicId);
491         firePropertyChange (PROP_SYSTEM_ID, oldSystemId, newSystemId);
492         firePropertyChange (PROP_NOTATION_NAME, oldNotationName, this.notationName);
493     }
494     
495     /**
496      * @throws ReadOnlyException
497      * @throws InvalidArgumentException
498      */

499     public final void setExternalDecl (String JavaDoc newPublicId, String JavaDoc newSystemId) throws ReadOnlyException, InvalidArgumentException {
500         //
501
// check new value
502
//
503
boolean setPublicId = !!! Util.equals (this.publicId, newPublicId);
504         boolean setSystemId = !!! Util.equals (this.systemId, newSystemId);
505         if ( !!! setPublicId &&
506              !!! setSystemId ) {
507             return;
508         }
509         checkReadOnly ();
510         checkExternalDecl (newPublicId, newSystemId);
511         
512         //
513
// set new value
514
//
515
setExternalDeclImpl (newPublicId, newSystemId);
516     }
517     
518     /**
519      */

520     protected final void checkExternalDecl (String JavaDoc publicId, String JavaDoc systemId) throws InvalidArgumentException {
521         TreeUtilities.checkEntityDeclPublicId (publicId);
522         TreeUtilities.checkEntityDeclSystemId (systemId);
523         
524         checkExternalId (publicId, systemId);
525     }
526     
527     /**
528      */

529     public final String JavaDoc getNotationName () {
530         return notationName;
531     }
532     
533     /**
534      */

535     private final void setNotationNameImpl (String JavaDoc newNotationName) {
536         short oldType = this.type;
537         String JavaDoc oldNotationName = this.notationName;
538         
539         if ( newNotationName == null ) {
540             this.type = TYPE_EXTERNAL;
541         } else {
542             this.type = TYPE_UNPARSED;
543         }
544         this.notationName = newNotationName;
545         
546         firePropertyChange (PROP_TYPE, new Short JavaDoc (oldType), new Short JavaDoc (this.type));
547         firePropertyChange (PROP_NOTATION_NAME, oldNotationName, newNotationName);
548     }
549     
550     /**
551      * @throws ReadOnlyException
552      * @throws InvalidStateException
553      * @throws InvalidArgumentException
554      */

555     public final void setNotationName (String JavaDoc newNotationName) throws ReadOnlyException, InvalidStateException, InvalidArgumentException {
556         //
557
// check new value
558
//
559
if ( Util.equals (this.notationName, newNotationName) )
560             return;
561         checkReadOnly ();
562         if ( type == TYPE_INTERNAL ) {
563             throw new InvalidStateException (Util.THIS.getString ("EXC_internal_notation"));
564         }
565         if ( parameter == PARAMETER_DECL ) {
566             throw new InvalidStateException (Util.THIS.getString ("EXC_ted_parameter_unparsed"));
567         }
568         checkNotationName (newNotationName);
569         
570         //
571
// set new value
572
//
573
setNotationNameImpl (newNotationName);
574     }
575     
576     /**
577      */

578     protected final void checkNotationName (String JavaDoc notationName) throws InvalidArgumentException {
579         TreeUtilities.checkEntityDeclNotationName (notationName);
580     }
581     
582     /**
583      */

584     private final void setUnparsedDeclImpl (String JavaDoc newPublicId, String JavaDoc newSystemId, String JavaDoc newNotationName) {
585         short oldType = this.type;
586         String JavaDoc oldInternalText = this.internalText;
587         String JavaDoc oldPublicId = this.publicId;
588         String JavaDoc oldSystemId = this.systemId;
589         String JavaDoc oldNotationName = this.notationName;
590         
591         this.type = TYPE_UNPARSED;
592         this.internalText = null;
593         this.publicId = newPublicId;
594         this.systemId = newSystemId;
595         this.notationName = newNotationName;
596         
597         firePropertyChange (PROP_TYPE, new Short JavaDoc (oldType), new Short JavaDoc (this.type));
598         firePropertyChange (PROP_INTERNAL_TEXT, oldInternalText, this.internalText);
599         firePropertyChange (PROP_PUBLIC_ID, oldPublicId, newPublicId);
600         firePropertyChange (PROP_SYSTEM_ID, oldSystemId, newSystemId);
601         firePropertyChange (PROP_NOTATION_NAME, oldNotationName, newNotationName);
602     }
603     
604     /**
605      * @throws ReadOnlyException
606      * @throws InvalidStateException
607      * @throws InvalidArgumentException
608      */

609     public final void setUnparsedDecl (String JavaDoc newPublicId, String JavaDoc newSystemId, String JavaDoc newNotationName) throws ReadOnlyException, InvalidStateException, InvalidArgumentException {
610         //
611
// check new value
612
//
613
boolean setPublicId = !!! Util.equals (this.publicId, newPublicId);
614         boolean setSystemId = !!! Util.equals (this.systemId, newSystemId);
615         boolean setNotationName = !!! Util.equals (this.notationName, newNotationName);
616         if ( !!! setPublicId &&
617              !!! setSystemId &&
618              !!! setNotationName ) {
619             return;
620         }
621         checkReadOnly ();
622         if ( parameter == PARAMETER_DECL ) {
623             throw new InvalidStateException (Util.THIS.getString ("EXC_ted_parameter_unparsed"));
624         }
625         checkUnparsedDecl (newPublicId, newSystemId, newNotationName);
626         
627         //
628
// set new value
629
//
630
setUnparsedDeclImpl (newPublicId, newSystemId, newNotationName);
631     }
632     
633     /**
634      */

635     protected final void checkUnparsedDecl (String JavaDoc publicId, String JavaDoc systemId, String JavaDoc notationName) throws InvalidArgumentException {
636         TreeUtilities.checkEntityDeclPublicId (publicId);
637         TreeUtilities.checkEntityDeclSystemId (systemId);
638         
639         checkExternalId (publicId, systemId);
640         
641         TreeUtilities.checkEntityDeclNotationName (notationName);
642         if ( notationName == null ) {
643             throw new InvalidArgumentException (Util.THIS.getString ("EXC_ted_unparsed_must_notation"),
644             new NullPointerException JavaDoc ());
645         }
646     }
647     
648     
649     /**
650      */

651     protected final void checkExternalId (String JavaDoc publicId, String JavaDoc systemId) throws InvalidArgumentException {
652         if ( systemId == null ) {
653             if ( publicId == null ) {
654                 throw new InvalidArgumentException (Util.THIS.getString ("EXC_ted_system_required"),
655                 new NullPointerException JavaDoc ());
656             } else {
657                 throw new InvalidArgumentException (Util.THIS.getString ("EXC_ted_system_required"),
658                 new NullPointerException JavaDoc ());
659             }
660         }
661     }
662     
663 }
664
Popular Tags