001: /*
002: * The Apache Software License, Version 1.1
003: *
004: *
005: * Copyright (c) 1999 The Apache Software Foundation. All rights
006: * reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Apache Software Foundation (http://www.apache.org/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The names "Xerces" and "Apache Software Foundation" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact apache@apache.org.
031: *
032: * 5. Products derived from this software may not be called "Apache",
033: * nor may "Apache" appear in their name, without prior written
034: * permission of the Apache Software Foundation.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the Apache Software Foundation and was
052: * originally based on software copyright (c) 1999, International
053: * Business Machines, Inc., http://www.apache.org. For more
054: * information on the Apache Software Foundation, please see
055: * <http://www.apache.org/>.
056: */
057:
058: package org.apache.xerces.dom;
059:
060: import org.w3c.dom.Entity;
061: import org.w3c.dom.Node;
062:
063: /**
064: * Entity nodes hold the reference data for an XML Entity -- either
065: * parsed or unparsed. The nodeName (inherited from Node) will contain
066: * the name (if any) of the Entity. Its data will be contained in the
067: * Entity's children, in exactly the structure which an
068: * EntityReference to this name will present within the document's
069: * body.
070: * <P>
071: * Note that this object models the actual entity, _not_ the entity
072: * declaration or the entity reference.
073: * <P>
074: * An XML processor may choose to completely expand entities before
075: * the structure model is passed to the DOM; in this case, there will
076: * be no EntityReferences in the DOM tree.
077: * <P>
078: * Quoting the 10/01 DOM Proposal,
079: * <BLOCKQUOTE>
080: * "The DOM Level 1 does not support editing Entity nodes; if a user
081: * wants to make changes to the contents of an Entity, every related
082: * EntityReference node has to be replaced in the structure model by
083: * a clone of the Entity's contents, and then the desired changes
084: * must be made to each of those clones instead. All the
085: * descendants of an Entity node are readonly."
086: * </BLOCKQUOTE>
087: * I'm interpreting this as: It is the parser's responsibilty to call
088: * the non-DOM operation setReadOnly(true,true) after it constructs
089: * the Entity. Since the DOM explicitly decided not to deal with this,
090: * _any_ answer will involve a non-DOM operation, and this is the
091: * simplest solution.
092: *
093: *
094: * @version
095: * @since PR-DOM-Level-1-19980818.
096: */
097: public class EntityImpl extends ParentNode implements Entity {
098:
099: //
100: // Constants
101: //
102:
103: /** Serialization version. */
104: static final long serialVersionUID = -3575760943444303423L;
105:
106: //
107: // Data
108: //
109:
110: /** Entity name. */
111: protected String name;
112:
113: /** Public identifier. */
114: protected String publicId;
115:
116: /** System identifier. */
117: protected String systemId;
118:
119: /** Encoding */
120: protected String encoding;
121:
122: /** Version */
123: protected String version;
124:
125: /** Notation name. */
126: protected String notationName;
127:
128: //
129: // Constructors
130: //
131:
132: /** Factory constructor. */
133: public EntityImpl(CoreDocumentImpl ownerDoc, String name) {
134: super (ownerDoc);
135: this .name = name;
136: isReadOnly(true);
137: }
138:
139: //
140: // Node methods
141: //
142:
143: /**
144: * A short integer indicating what type of node this is. The named
145: * constants for this value are defined in the org.w3c.dom.Node interface.
146: */
147: public short getNodeType() {
148: return Node.ENTITY_NODE;
149: }
150:
151: /**
152: * Returns the entity name
153: */
154: public String getNodeName() {
155: if (needsSyncData()) {
156: synchronizeData();
157: }
158: return name;
159: }
160:
161: /** Clone node. */
162: public Node cloneNode(boolean deep) {
163: EntityImpl newentity = (EntityImpl) super .cloneNode(deep);
164: return newentity;
165: }
166:
167: //
168: // Entity methods
169: //
170:
171: /**
172: * The public identifier associated with the entity. If not specified,
173: * this will be null.
174: */
175: public String getPublicId() {
176:
177: if (needsSyncData()) {
178: synchronizeData();
179: }
180: return publicId;
181:
182: } // getPublicId():String
183:
184: /**
185: * The system identifier associated with the entity. If not specified,
186: * this will be null.
187: */
188: public String getSystemId() {
189:
190: if (needsSyncData()) {
191: synchronizeData();
192: }
193: return systemId;
194:
195: } // getSystemId():String
196:
197: /**
198: * DOM Level 3 WD - experimental
199: * the version number of this entity, when it is an external parsed entity.
200: */
201: public String getVersion() {
202:
203: if (needsSyncData()) {
204: synchronizeData();
205: }
206: return version;
207:
208: } // getVersion():String
209:
210: /**
211: * DOM Level 3 WD - experimental
212: * the encoding of this entity, when it is an external parsed entity.
213: */
214: public String getEncoding() {
215:
216: if (needsSyncData()) {
217: synchronizeData();
218: }
219: return encoding;
220:
221: } // getVersion():String
222:
223: /**
224: * Unparsed entities -- which contain non-XML data -- have a
225: * "notation name" which tells applications how to deal with them.
226: * Parsed entities, which <em>are</em> in XML format, don't need this and
227: * set it to null.
228: */
229: public String getNotationName() {
230:
231: if (needsSyncData()) {
232: synchronizeData();
233: }
234: return notationName;
235:
236: } // getNotationName():String
237:
238: //
239: // Public methods
240: //
241:
242: /**
243: * DOM Level 2: The public identifier associated with the entity. If not specified,
244: * this will be null. */
245: public void setPublicId(String id) {
246:
247: if (needsSyncData()) {
248: synchronizeData();
249: }
250: publicId = id;
251:
252: } // setPublicId(String)
253:
254: /**
255: * DOM Level 3 WD - experimental
256: * encoding - An attribute specifying, as part of the text declaration,
257: * the encoding of this entity, when it is an external parsed entity.
258: * This is null otherwise
259: */
260: public void setEncoding(String value) {
261:
262: if (needsSyncData()) {
263: synchronizeData();
264: }
265: encoding = value;
266:
267: } // setEncoding (String)
268:
269: /**
270: * DOM Level 3 WD - experimental
271: * version - An attribute specifying, as part of the text declaration,
272: * the version number of this entity, when it is an external parsed entity.
273: * This is null otherwise
274: */
275: public void setVersion(String value) {
276:
277: if (needsSyncData()) {
278: synchronizeData();
279: }
280: version = value;
281:
282: } // setVersion (String)
283:
284: /**
285: * DOM Level 2: The system identifier associated with the entity. If not
286: * specified, this will be null.
287: */
288: public void setSystemId(String id) {
289:
290: if (needsSyncData()) {
291: synchronizeData();
292: }
293: systemId = id;
294:
295: } // setSystemId(String)
296:
297: /**
298: * DOM Level 2: Unparsed entities -- which contain non-XML data -- have a
299: * "notation name" which tells applications how to deal with them.
300: * Parsed entities, which <em>are</em> in XML format, don't need this and
301: * set it to null.
302: */
303: public void setNotationName(String name) {
304:
305: if (needsSyncData()) {
306: synchronizeData();
307: }
308: notationName = name;
309:
310: } // setNotationName(String)
311:
312: } // class EntityImpl
|