KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > dom > DeferredEntityReferenceImpl


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 1999-2002 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 com.sun.org.apache.xerces.internal.dom;
59
60 /**
61  * EntityReference models the XML &entityname; syntax, when used for
62  * entities defined by the DOM. Entities hardcoded into XML, such as
63  * character entities, should instead have been translated into text
64  * by the code which generated the DOM tree.
65  * <P>
66  * An XML processor has the alternative of fully expanding Entities
67  * into the normal document tree. If it does so, no EntityReference nodes
68  * will appear.
69  * <P>
70  * Similarly, non-validating XML processors are not required to read
71  * or process entity declarations made in the external subset or
72  * declared in external parameter entities. Hence, some applications
73  * may not make the replacement value available for Parsed Entities
74  * of these types.
75  * <P>
76  * EntityReference behaves as a read-only node, and the children of
77  * the EntityReference (which reflect those of the Entity, and should
78  * also be read-only) give its replacement value, if any. They are
79  * supposed to automagically stay in synch if the DocumentType is
80  * updated with new values for the Entity.
81  * <P>
82  * The defined behavior makes efficient storage difficult for the DOM
83  * implementor. We can't just look aside to the Entity's definition
84  * in the DocumentType since those nodes have the wrong parent (unless
85  * we can come up with a clever "imaginary parent" mechanism). We
86  * must at least appear to clone those children... which raises the
87  * issue of keeping the reference synchronized with its parent.
88  * This leads me back to the "cached image of centrally defined data"
89  * solution, much as I dislike it.
90  * <P>
91  * For now I have decided, since REC-DOM-Level-1-19980818 doesn't
92  * cover this in much detail, that synchronization doesn't have to be
93  * considered while the user is deep in the tree. That is, if you're
94  * looking within one of the EntityReferennce's children and the Entity
95  * changes, you won't be informed; instead, you will continue to access
96  * the same object -- which may or may not still be part of the tree.
97  * This is the same behavior that obtains elsewhere in the DOM if the
98  * subtree you're looking at is deleted from its parent, so it's
99  * acceptable here. (If it really bothers folks, we could set things
100  * up so deleted subtrees are walked and marked invalid, but that's
101  * not part of the DOM's defined behavior.)
102  * <P>
103  * As a result, only the EntityReference itself has to be aware of
104  * changes in the Entity. And it can take advantage of the same
105  * structure-change-monitoring code I implemented to support
106  * DeepNodeList.
107  *
108  * @version $Id: DeferredEntityReferenceImpl.java,v 1.19 2003/05/08 19:52:40 elena Exp $
109  * @since PR-DOM-Level-1-19980818.
110  */

111 public class DeferredEntityReferenceImpl
112     extends EntityReferenceImpl
113     implements DeferredNode {
114
115     //
116
// Constants
117
//
118

119     /** Serialization version. */
120     static final long serialVersionUID = 390319091370032223L;
121     
122     //
123
// Data
124
//
125

126     /** Node index. */
127     protected transient int fNodeIndex;
128
129     //
130
// Constructors
131
//
132

133     /**
134      * This is the deferred constructor. Only the fNodeIndex is given here.
135      * All other data, can be requested from the ownerDocument via the index.
136      */

137     DeferredEntityReferenceImpl(DeferredDocumentImpl ownerDocument,
138                                 int nodeIndex) {
139         super(ownerDocument, null);
140
141         fNodeIndex = nodeIndex;
142         needsSyncData(true);
143
144     } // <init>(DeferredDocumentImpl,int)
145

146     //
147
// DeferredNode methods
148
//
149

150     /** Returns the node index. */
151     public int getNodeIndex() {
152         return fNodeIndex;
153     }
154
155     //
156
// Protected methods
157
//
158

159     /**
160      * Synchronize the entity data. This is special because of the way
161      * that the "fast" version stores the information.
162      */

163     protected void synchronizeData() {
164
165         // no need to sychronize again
166
needsSyncData(false);
167
168         // get the node data
169
DeferredDocumentImpl ownerDocument =
170             (DeferredDocumentImpl)this.ownerDocument;
171         name = ownerDocument.getNodeName(fNodeIndex);
172         baseURI = ownerDocument.getNodeValue(fNodeIndex);
173         
174     } // synchronizeData()
175

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

191 } // class DeferredEntityReferenceImpl
192
Popular Tags