KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 1999-2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.xerces.dom;
18
19
20 /**
21  * Entity nodes hold the reference data for an XML Entity -- either
22  * parsed or unparsed. The nodeName (inherited from Node) will contain
23  * the name (if any) of the Entity. Its data will be contained in the
24  * Entity's children, in exactly the structure which an
25  * EntityReference to this name will present within the document's
26  * body.
27  * <P>
28  * Note that this object models the actual entity, _not_ the entity
29  * declaration or the entity reference.
30  * <P>
31  * An XML processor may choose to completely expand entities before
32  * the structure model is passed to the DOM; in this case, there will
33  * be no EntityReferences in the DOM tree.
34  * <P>
35  * Quoting the 10/01 DOM Proposal,
36  * <BLOCKQUOTE>
37  * "The DOM Level 1 does not support editing Entity nodes; if a user
38  * wants to make changes to the contents of an Entity, every related
39  * EntityReference node has to be replaced in the structure model by
40  * a clone of the Entity's contents, and then the desired changes
41  * must be made to each of those clones instead. All the
42  * descendants of an Entity node are readonly."
43  * </BLOCKQUOTE>
44  * I'm interpreting this as: It is the parser's responsibilty to call
45  * the non-DOM operation setReadOnly(true,true) after it constructs
46  * the Entity. Since the DOM explicitly decided not to deal with this,
47  * _any_ answer will involve a non-DOM operation, and this is the
48  * simplest solution.
49  *
50  * @xerces.internal
51  *
52  * @version $Id: DeferredEntityImpl.java,v 1.19 2004/10/05 17:12:51 mrglavas Exp $
53  * @since PR-DOM-Level-1-19980818.
54  */

55 public class DeferredEntityImpl
56     extends EntityImpl
57     implements DeferredNode {
58
59     //
60
// Constants
61
//
62

63     /** Serialization version. */
64     static final long serialVersionUID = 4760180431078941638L;
65
66     //
67
// Data
68
//
69

70     /** Node index. */
71     protected transient int fNodeIndex;
72
73     //
74
// Constructors
75
//
76

77     /**
78      * This is the deferred constructor. Only the fNodeIndex is given here.
79      * All other data, can be requested from the ownerDocument via the index.
80      */

81     DeferredEntityImpl(DeferredDocumentImpl ownerDocument, int nodeIndex) {
82         super(ownerDocument, null);
83
84         fNodeIndex = nodeIndex;
85         needsSyncData(true);
86         needsSyncChildren(true);
87
88     } // <init>(DeferredDocumentImpl,int)
89

90     //
91
// DeferredNode methods
92
//
93

94     /** Returns the node index. */
95     public int getNodeIndex() {
96         return fNodeIndex;
97     }
98
99     //
100
// Protected methods
101
//
102

103     /**
104      * Synchronize the entity data. This is special because of the way
105      * that the "fast" version stores the information.
106      */

107     protected void synchronizeData() {
108
109         // no need to sychronize again
110
needsSyncData(false);
111
112         // get the node data
113
DeferredDocumentImpl ownerDocument =
114             (DeferredDocumentImpl)this.ownerDocument;
115         name = ownerDocument.getNodeName(fNodeIndex);
116
117         // get the entity data
118
publicId = ownerDocument.getNodeValue(fNodeIndex);
119         systemId = ownerDocument.getNodeURI(fNodeIndex);
120         int extraDataIndex = ownerDocument.getNodeExtra(fNodeIndex);
121         ownerDocument.getNodeType(extraDataIndex);
122
123         notationName = ownerDocument.getNodeName(extraDataIndex);
124
125         // encoding and version DOM L3
126
version = ownerDocument.getNodeValue(extraDataIndex);
127         encoding = ownerDocument.getNodeURI(extraDataIndex);
128
129         // baseURI, actualEncoding DOM L3
130
int extraIndex2 = ownerDocument.getNodeExtra(extraDataIndex);
131         baseURI = ownerDocument.getNodeName(extraIndex2);
132         inputEncoding = ownerDocument.getNodeValue(extraIndex2);
133
134     } // synchronizeData()
135

136     /** Synchronize the children. */
137     protected void synchronizeChildren() {
138
139         // no need to synchronize again
140
needsSyncChildren(false);
141
142         isReadOnly(false);
143         DeferredDocumentImpl ownerDocument =
144             (DeferredDocumentImpl) ownerDocument();
145         ownerDocument.synchronizeChildren(this, fNodeIndex);
146         setReadOnly(true, true);
147
148     } // synchronizeChildren()
149

150 } // class DeferredEntityImpl
151
Popular Tags