KickJava   Java API By Example, From Geeks To Geeks.

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


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

30 public class TreeDTD extends AbstractTreeDTD implements TreeDocumentRoot, TreeDTDRoot {
31
32     /** */
33     public static final String JavaDoc PROP_VERSION = "version"; // NOI18N
34
/** */
35     public static final String JavaDoc PROP_ENCODING = "encoding"; // NOI18N
36

37     /** Own event manager. */
38     private TreeEventManager eventManager;
39
40     /** -- can be null. */
41     private String JavaDoc version;
42     
43     /** -- can be null. */
44     private String JavaDoc encoding;
45     
46     
47     //
48
// init
49
//
50

51     /**
52      * Creates new TreeDTD.
53      * @throws InvalidArgumentException
54      */

55     public TreeDTD (String JavaDoc version, String JavaDoc encoding) throws InvalidArgumentException {
56         super ();
57         
58         checkVersion (version);
59         checkEncoding (encoding);
60         checkHeader (version, encoding);
61         
62         this.version = version;
63         this.encoding = encoding;
64         
65         if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("TreeDTD::init: encoding = " + this.encoding); // NOI18N
66

67         this.eventManager = new TreeEventManager ();
68     }
69     
70     /** Creates new TreeDTD.
71      * @throws InvalidArgumentException
72      */

73     public TreeDTD () throws InvalidArgumentException {
74         this (null, null);
75     }
76     
77     /** Creates new TreeDTD -- copy constructor. */
78     protected TreeDTD (TreeDTD dtd, boolean deep) {
79         super (dtd, deep);
80         
81         this.version = dtd.version;
82         this.encoding = dtd.encoding;
83         
84         if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("TreeDTD::init [copy]: encoding = " + this.encoding); // NOI18N
85

86         this.eventManager = new TreeEventManager (dtd.eventManager);
87     }
88     
89     
90     //
91
// from TreeObject
92
//
93

94     /**
95      */

96     public Object JavaDoc clone (boolean deep) {
97         return new TreeDTD (this, deep);
98     }
99     
100     /**
101      */

102     public boolean equals (Object JavaDoc object, boolean deep) {
103         if (!!! super.equals (object, deep))
104             return false;
105         
106         TreeDTD peer = (TreeDTD) object;
107         if (!!! Util.equals (this.getVersion (), peer.getVersion ()))
108             return false;
109         if (!!! Util.equals (this.getEncoding (), peer.getEncoding ()))
110             return false;
111         
112         return true;
113     }
114     
115     /*
116      * Merges version and encoding properties.
117      */

118     public void merge (TreeObject treeObject) throws CannotMergeException {
119         super.merge (treeObject);
120         
121         TreeDTD peer = (TreeDTD) treeObject;
122         
123         try {
124             setVersionImpl (peer.getVersion ());
125             setEncodingImpl (peer.getEncoding ());
126         } catch (Exception JavaDoc exc) {
127             throw new CannotMergeException (treeObject, exc);
128         }
129     }
130     
131     //
132
// from TreeDocumentRoot
133
//
134

135     /**
136      */

137     public String JavaDoc getVersion () {
138         return version;
139     }
140     
141     /**
142      */

143     private final void setVersionImpl (String JavaDoc newVersion) {
144         String JavaDoc oldVersion = this.version;
145         
146         this.version = newVersion;
147         
148         firePropertyChange (PROP_VERSION, oldVersion, newVersion);
149     }
150     
151     /**
152      * @throws ReadOnlyException
153      * @throws InvalidArgumentException
154      */

155     public final void setVersion (String JavaDoc newVersion) throws ReadOnlyException, InvalidArgumentException {
156         //
157
// check new value
158
//
159
if ( Util.equals (this.version, newVersion) )
160             return;
161         checkReadOnly ();
162         checkVersion (newVersion);
163         checkHeader (newVersion, this.encoding);
164         
165         //
166
// set new value
167
//
168
setVersionImpl (newVersion);
169     }
170     
171     /**
172      */

173     protected final void checkVersion (String JavaDoc version) throws InvalidArgumentException {
174         TreeUtilities.checkDTDVersion (version);
175     }
176     
177     
178     /**
179      */

180     public String JavaDoc getEncoding () {
181         return encoding;
182     }
183     
184     /**
185      */

186     private final void setEncodingImpl (String JavaDoc newEncoding) {
187         String JavaDoc oldEncoding = this.encoding;
188         
189         this.encoding = newEncoding;
190         
191         if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("TreeDTD::setEncodingImpl: encoding = " + this.encoding); // NOI18N
192

193         firePropertyChange (PROP_ENCODING, oldEncoding, newEncoding);
194     }
195     
196     /**
197      * @throws ReadOnlyException
198      * @throws InvalidArgumentException
199      */

200     public final void setEncoding (String JavaDoc newEncoding) throws ReadOnlyException, InvalidArgumentException {
201         //
202
// check new value
203
//
204
if ( Util.equals (this.encoding, newEncoding) )
205             return;
206         checkReadOnly ();
207         checkEncoding (newEncoding);
208         checkHeader (this.version, newEncoding);
209         
210         //
211
// set new value
212
//
213
setEncodingImpl (newEncoding);
214     }
215     
216     /**
217      */

218     protected final void checkEncoding (String JavaDoc encoding) throws InvalidArgumentException {
219         TreeUtilities.checkDTDEncoding (encoding);
220     }
221     
222     /**
223      * @throws ReadOnlyException
224      * @throws InvalidArgumentException
225      */

226     public final void setHeader (String JavaDoc newVersion, String JavaDoc newEncoding) throws ReadOnlyException, InvalidArgumentException {
227         //
228
// check new value
229
//
230
boolean setVersion = !!! Util.equals (this.version, newVersion);
231         boolean setEncoding = !!! Util.equals (this.encoding, newEncoding);
232         if ( !!! setVersion &&
233              !!! setEncoding ) {
234             return;
235         }
236         checkReadOnly ();
237         if ( setVersion ) {
238             checkVersion (newVersion);
239         }
240         if ( setEncoding ) {
241             checkEncoding (newEncoding);
242         }
243         checkHeader (newVersion, newEncoding);
244         
245         //
246
// set new value
247
//
248
if ( setVersion ) {
249             setVersionImpl (newVersion);
250         }
251         if ( setEncoding ) {
252             setEncodingImpl (newEncoding);
253         }
254     }
255     
256     /**
257      */

258     protected final void checkHeader (String JavaDoc version, String JavaDoc encoding) throws InvalidArgumentException {
259         if ((version != null) && (encoding == null)) {
260             throw new InvalidArgumentException
261             (Util.THIS.getString ("EXC_invalid_dtd_header"),
262             new NullPointerException JavaDoc ());
263         }
264     }
265     
266     
267     //
268
// event model
269
//
270

271     /**
272      */

273     public TreeEventManager getRootEventManager () {
274         return eventManager;
275     }
276     
277     
278     //
279
// TreeObjectList.ContentManager
280
//
281

282     /**
283      */

284     protected TreeObjectList.ContentManager createChildListContentManager () {
285         return new ChildListContentManager ();
286     }
287     
288     
289     /**
290      *
291      */

292     protected class ChildListContentManager extends AbstractTreeDTD.ChildListContentManager {
293         
294         /**
295          */

296         public TreeNode getOwnerNode () {
297             return TreeDTD.this;
298         }
299         
300         /**
301          */

302         public void checkAssignableObject (Object JavaDoc obj) {
303             super.checkAssignableObject (obj);
304             checkAssignableClass (DTD.Child.class, obj);
305         }
306         
307     } // end: class ChildListContentManager
308

309 }
310
Popular Tags