KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > apache > xerces > dom > DeferredEntityImpl


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 1999 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Xerces" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 1999, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58 package org.enhydra.apache.xerces.dom;
59
60 import org.enhydra.apache.xerces.utils.StringPool;
61
62 /**
63  * Entity nodes hold the reference data for an XML Entity -- either
64  * parsed or unparsed. The nodeName (inherited from Node) will contain
65  * the name (if any) of the Entity. Its data will be contained in the
66  * Entity's children, in exactly the structure which an
67  * EntityReference to this name will present within the document's
68  * body.
69  * <P>
70  * Note that this object models the actual entity, _not_ the entity
71  * declaration or the entity reference.
72  * <P>
73  * An XML processor may choose to completely expand entities before
74  * the structure model is passed to the DOM; in this case, there will
75  * be no EntityReferences in the DOM tree.
76  * <P>
77  * Quoting the 10/01 DOM Proposal,
78  * <BLOCKQUOTE>
79  * "The DOM Level 1 does not support editing Entity nodes; if a user
80  * wants to make changes to the contents of an Entity, every related
81  * EntityReference node has to be replaced in the structure model by
82  * a clone of the Entity's contents, and then the desired changes
83  * must be made to each of those clones instead. All the
84  * descendants of an Entity node are readonly."
85  * </BLOCKQUOTE>
86  * I'm interpreting this as: It is the parser's responsibilty to call
87  * the non-DOM operation setReadOnly(true,true) after it constructs
88  * the Entity. Since the DOM explicitly decided not to deal with this,
89  * _any_ answer will involve a non-DOM operation, and this is the
90  * simplest solution.
91  *
92  *
93  * @version
94  * @since PR-DOM-Level-1-19980818.
95  */

96 public class DeferredEntityImpl
97     extends EntityImpl
98     implements DeferredNode {
99
100     //
101
// Constants
102
//
103

104     /** Serialization version. */
105     static final long serialVersionUID = 4760180431078941638L;
106
107     //
108
// Data
109
//
110

111     /** Node index. */
112     protected transient int fNodeIndex;
113
114     //
115
// Constructors
116
//
117

118     /**
119      * This is the deferred constructor. Only the fNodeIndex is given here.
120      * All other data, can be requested from the ownerDocument via the index.
121      */

122     DeferredEntityImpl(DeferredDocumentImpl ownerDocument, int nodeIndex) {
123         super(ownerDocument, null);
124
125         fNodeIndex = nodeIndex;
126         needsSyncData(true);
127         needsSyncChildren(true);
128
129     } // <init>(DeferredDocumentImpl,int)
130

131     //
132
// DeferredNode methods
133
//
134

135     /** Returns the node index. */
136     public int getNodeIndex() {
137         return fNodeIndex;
138     }
139
140     //
141
// Protected methods
142
//
143

144     /**
145      * Synchronize the entity data. This is special because of the way
146      * that the "fast" version stores the information.
147      */

148     protected void synchronizeData() {
149
150         // no need to sychronize again
151
needsSyncData(false);
152
153         // get the node data
154
DeferredDocumentImpl ownerDocument = (DeferredDocumentImpl)this.ownerDocument;
155         name = ownerDocument.getNodeNameString(fNodeIndex);
156
157         // get the entity data
158
StringPool pool = ownerDocument.getStringPool();
159         int extraDataIndex = ownerDocument.getNodeValue(fNodeIndex);
160         ownerDocument.getNodeType(extraDataIndex);
161         publicId = pool.toString(ownerDocument.getNodeName(extraDataIndex));
162         notationName = pool.toString(ownerDocument.getLastChild(extraDataIndex));
163
164         // DOM Level 3 adding experimental features -el
165
extraDataIndex = ownerDocument.getNodeValue(extraDataIndex);
166         systemId = pool.toString(ownerDocument.getNodeName(extraDataIndex));
167         version = pool.toString(ownerDocument.getNodeValue(extraDataIndex));
168         encoding = pool.toString(ownerDocument.getLastChild(extraDataIndex));
169          
170     } // synchronizeData()
171

172     /** Synchronize the children. */
173     protected void synchronizeChildren() {
174
175         // no need to synchronize again
176
needsSyncChildren(false);
177
178         isReadOnly(false);
179         DeferredDocumentImpl ownerDocument =
180             (DeferredDocumentImpl) ownerDocument();
181         ownerDocument.synchronizeChildren(this, fNodeIndex);
182         setReadOnly(true, true);
183
184     } // synchronizeChildren()
185

186 } // class DeferredEntityImpl
187
Popular Tags