KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > xml > dom > ParamEntity


1 /**
2  * org/ozone-db/xml/dom/ParamEntity.java
3  *
4  * The contents of this file are subject to the OpenXML Public
5  * License Version 1.0; you may not use this file except in compliance
6  * with the License. You may obtain a copy of the License at
7  * http://www.openxml.org/license.html
8  *
9  * THIS SOFTWARE IS DISTRIBUTED ON AN "AS IS" BASIS WITHOUT WARRANTY
10  * OF ANY KIND, EITHER EXPRESSED OR IMPLIED. THE INITIAL DEVELOPER
11  * AND ALL CONTRIBUTORS SHALL NOT BE LIABLE FOR ANY DAMAGES AS A
12  * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
13  * DERIVATIVES. SEE THE LICENSE FOR THE SPECIFIC LANGUAGE GOVERNING
14  * RIGHTS AND LIMITATIONS UNDER THE LICENSE.
15  *
16  * The Initial Developer of this code under the License is Assaf Arkin.
17  * Portions created by Assaf Arkin are Copyright (C) 1998, 1999.
18  * All Rights Reserved.
19  */

20
21 /**
22  * Changes for Persistent DOM running with ozone are
23  * Copyright 1999 by SMB GmbH. All rights reserved.
24  */

25
26 package org.ozoneDB.xml.dom;
27
28 import org.w3c.dom.*;
29
30
31 /**
32  * Implements a parameter entity.
33  * <P>
34  * Notes:
35  * <OL>
36  * <LI>Node type is {@link NodeImpl#PARAM_ENTITY_NODE}
37  * <LI>Node supports childern
38  * <LI>Node does not have a value
39  * <LI>Node only accessible from {@link org.w3c.dom.DocumentType}
40  * </OL>
41  *
42  *
43  * @version $Revision: 1.2 $ $Date: 2003/11/20 23:18:42 $
44  * @author <a HREF="mailto:arkin@trendline.co.il">Assaf Arkin</a>
45  * @see NodeImpl
46  */

47 public class ParamEntity extends NodeImpl implements ParamEntityProxy {
48
49     final static long serialVersionUID = 1;
50
51
52     public short getNodeType() {
53         return PARAM_ENTITY_NODE;
54     }
55
56
57     public String JavaDoc getPublicId() {
58         return _publicId;
59     }
60
61
62     public void setPublicId( String JavaDoc publicId ) {
63         _publicId = publicId;
64     }
65
66
67     public String JavaDoc getSystemId() {
68         return _systemId;
69     }
70
71
72     public void setSystemId( String JavaDoc systemId ) {
73         _systemId = systemId;
74     }
75
76
77     /**
78      * Returns true if entity is an internal entity. An internal entity is one
79      * for which a value has been defined. An external entity is one for which
80      * an external entity has been assigned through either system or public
81      * identifiers.
82      *
83      * @return True if internal entity
84      */

85     public boolean isInternal() {
86         return _internalValue != null;
87     }
88
89
90     /**
91      * Returns the parsing state of this entity.
92      *
93      * @return State of entity
94      */

95     public short getState() {
96         return _state;
97     }
98
99
100     /**
101      * Changes the parsing state of this entity. Note that only some changes
102      * are allowed: from declared to parsing, parsed or not found; from parsing
103      * to parsed or not found; from not found to declared.
104      *
105      * @param newState New state of entity
106      */

107     public void setState( short newState ) {
108         if (_state == STATE_DECLARED && newState == STATE_PARSING || _state == STATE_NOT_FOUND && newState
109                 == STATE_DECLARED) {
110             _state = newState;
111         } else if ((_state == STATE_DECLARED || _state == STATE_PARSING) && (newState == STATE_PARSED || newState
112                 == STATE_NOT_FOUND)) {
113             _state = newState;
114         } else {
115             throw new IllegalStateException JavaDoc( "Cannot switch from state " + _state + " to state " + newState + "." );
116         }
117     }
118
119
120     public final String JavaDoc getInternal() {
121         return _internalValue;
122     }
123
124
125     public final void setInternal( String JavaDoc internalValue ) {
126         _internalValue = internalValue;
127     }
128
129
130     public synchronized boolean equals( Object JavaDoc other ) {
131         ParamEntityProxy otherX;
132
133         // Test for node equality (this covers entity name and all its children)
134
// and then test for specific entity qualities.
135
if (super.equals( other )) {
136             otherX = (ParamEntityProxy)other;
137             // If this entity is internal, both entities must be internal and have
138
// equal internal value.
139
if (this.isInternal()) {
140                 return otherX.isInternal() && this.getInternal().equals( otherX.getInternal() );
141             }
142             // External or unparsed: either public id are both null, or public id
143
// equals in both (and same for system id).
144
return
145                     (this.getPublicId() == null && otherX.getPublicId() == null || this.getPublicId() != null
146                     && this.getPublicId().equals( otherX.getPublicId() )) && (this.getSystemId() == null
147                     && otherX.getSystemId() == null || this.getSystemId() != null && this.getSystemId().equals(
148                     otherX.getSystemId() ));
149         }
150         return false;
151     }
152
153
154     public final Object JavaDoc clone() {
155         ParamEntityProxy clone = null;
156         try {
157             clone = (ParamEntityProxy)database().createObject( ParamEntity.class.getName() );
158             clone.init( _ownerDocument, getNodeName(), null, true );
159             cloneInto( clone, true );
160         } catch (Exception JavaDoc except) {
161         }
162         return clone;
163     }
164
165
166     public final Node cloneNode( boolean deep ) {
167         ParamEntityProxy clone = null;
168         try {
169             clone = (ParamEntityProxy)database().createObject( ParamEntity.class.getName() );
170             (clone).init( _ownerDocument, getNodeName(), null, true );
171             cloneInto( clone, deep );
172         } catch (Exception JavaDoc except) {
173         }
174         return clone;
175     }
176
177
178     public String JavaDoc toString() {
179         String JavaDoc name;
180         String JavaDoc value;
181
182         name = getNodeName();
183         if (name.length() > 32) {
184             name = name.substring( 0, 32 ) + "..";
185         }
186         if (isInternal()) {
187             value = getInternal();
188             if (value.length() > 64) {
189                 value = value.substring( 0, 64 ) + "..";
190             }
191             name = name + "] [" + value;
192         } else {
193             if (getSystemId() != null) {
194                 name = name + "] SYSTEM [" + getSystemId();
195             }
196             if (getPublicId() != null) {
197                 name = name + "] PUBLIC [" + getPublicId();
198             }
199         }
200         return "PEntity decl: [" + name + "]";
201     }
202
203
204     public synchronized void cloneInto( NodeProxy into, boolean deep ) {
205         super.cloneInto( into, deep );
206         ((ParamEntityProxy)into).setSystemId( this.getSystemId() );
207         ((ParamEntityProxy)into).setPublicId( this.getPublicId() );
208         ((ParamEntityProxy)into).setInternal( this.getInternal() );
209         ((ParamEntityProxy)into).setState( this.getState() );
210     }
211
212
213     /**
214      * Constructs an external parameter entity. Entity system identifier must be
215      * provided, public identifier is optional.
216      *
217      * @param owner The owner document
218      * @param name The entity name
219      * @param systemId The system identifier
220      * @param publicId The public identifier, if specified
221      */

222     public ParamEntity( DocumentImpl owner, String JavaDoc name, String JavaDoc systemId, String JavaDoc publicId ) {
223         super( owner, name, null, true );
224         if (systemId == null) {
225             throw new NullPointerException JavaDoc( "Argument 'systemId' cannot be null." );
226         }
227         _systemId = systemId;
228         _publicId = publicId;
229         _state = STATE_DECLARED;
230     }
231
232
233     /**
234      * Constructs an internal parameter entity. Entity value must be provided.
235      *
236      * @param owner The owner document
237      * @param name The entity name
238      * @param internalValue The unparsed entity value
239      */

240     public ParamEntity( DocumentImpl owner, String JavaDoc name, String JavaDoc internalValue ) {
241         super( owner, name, null, true );
242         init( owner, name, internalValue );
243     }
244
245
246     private ParamEntity( DocumentImpl owner, String JavaDoc name ) {
247         super( owner, name, null, true );
248     }
249
250
251     public ParamEntity() {
252         super();
253     }
254
255
256     public void init( DocumentProxy owner, String JavaDoc name ) {
257         super.init( owner, name, null, true );
258     }
259
260
261     public void init( DocumentProxy owner, String JavaDoc name, String JavaDoc value ) {
262         super.init( owner, name, null, true );
263         if (value == null) {
264             throw new NullPointerException JavaDoc( "Argument 'internalValue' cannot be null." );
265         }
266         _systemId = null;
267         _publicId = null;
268         _state = STATE_DECLARED;
269         _internalValue = value;
270     }
271
272
273     public void init( DocumentProxy owner, String JavaDoc name, String JavaDoc systemId, String JavaDoc publicId ) {
274     }
275
276     /**
277      * The system identifier of this entity, if specified.
278      */

279     private String JavaDoc _systemId;
280
281
282     /**
283      * The public identifier of this entity, if specified.
284      */

285     private String JavaDoc _publicId;
286
287
288     /**
289      * Identifies the state of this entity as yet to be parsed, being parsed,
290      * has been parsed, or cannot be found.
291      */

292     private short _state;
293
294
295     /**
296      * Holds the internal value of the entity.
297      */

298     private String JavaDoc _internalValue;
299
300
301     /**
302      * Entity has been declared but not parsed. This is the initial state for
303      * an entity after it has been declared in the DTD but before it is used
304      * in the document contents.
305      */

306     public final static short STATE_DECLARED = 0;
307
308
309     /**
310      * Entity is being parsed. This state designates that the entity is being
311      * parsed right now. State is used to identify circular references.
312      */

313     public final static short STATE_PARSING = 1;
314
315
316     /**
317      * Entity has been parsed. This state indicates that entity has been parsed
318      * and it's parsed contents is contained in its child nodes.
319      */

320     public final static short STATE_PARSED = 2;
321
322
323     /**
324      * Entity not found. The entity could not be parsed before.
325      */

326     public final static short STATE_NOT_FOUND = 3;
327
328 }
329
Popular Tags