KickJava   Java API By Example, From Geeks To Geeks.

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


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 /*
59  * WARNING: because java doesn't support multi-inheritance some code is
60  * duplicated. If you're changing this file you probably want to change
61  * DeferredElementNSImpl.java at the same time.
62  */

63
64 package com.sun.org.apache.xerces.internal.dom;
65
66 import org.w3c.dom.NamedNodeMap JavaDoc;
67
68 /**
69  * Elements represent most of the "markup" and structure of the
70  * document. They contain both the data for the element itself
71  * (element name and attributes), and any contained nodes, including
72  * document text (as children).
73  * <P>
74  * Elements may have Attributes associated with them; the API for this is
75  * defined in Node, but the function is implemented here. In general, XML
76  * applications should retrive Attributes as Nodes, since they may contain
77  * entity references and hence be a fairly complex sub-tree. HTML users will
78  * be dealing with simple string values, and convenience methods are provided
79  * to work in terms of Strings.
80  * <P>
81  * DeferredElementImpl inherits from ElementImpl which does not support
82  * Namespaces. DeferredElementNSImpl, which inherits from ElementNSImpl, does.
83  * @see DeferredElementNSImpl
84  *
85  * @version $Id: DeferredElementImpl.java,v 1.2 2003/11/18 00:22:50 kk122374 Exp $
86  * @since PR-DOM-Level-1-19980818.
87  */

88 public class DeferredElementImpl
89     extends ElementImpl
90     implements DeferredNode {
91
92     //
93
// Constants
94
//
95

96     /** Serialization version. */
97     static final long serialVersionUID = -7670981133940934842L;
98
99     //
100
// Data
101
//
102

103     /** Node index. */
104     protected transient int fNodeIndex;
105
106     //
107
// Constructors
108
//
109

110     /**
111      * This is the deferred constructor. Only the fNodeIndex is given here. All
112      * other data, can be requested from the ownerDocument via the index.
113      */

114     DeferredElementImpl(DeferredDocumentImpl ownerDoc, int nodeIndex) {
115         super(ownerDoc, null);
116
117         fNodeIndex = nodeIndex;
118         needsSyncChildren(true);
119
120     } // <init>(DocumentImpl,int)
121

122     //
123
// DeferredNode methods
124
//
125

126     /** Returns the node index. */
127     public final int getNodeIndex() {
128         return fNodeIndex;
129     }
130
131     //
132
// Protected methods
133
//
134

135     /** Synchronizes the data (name and value) for fast nodes. */
136     protected final void synchronizeData() {
137
138         // no need to sync in the future
139
needsSyncData(false);
140
141         // fluff data
142
DeferredDocumentImpl ownerDocument =
143             (DeferredDocumentImpl)this.ownerDocument;
144
145         // we don't want to generate any event for this so turn them off
146
boolean orig = ownerDocument.mutationEvents;
147         ownerDocument.mutationEvents = false;
148
149         name = ownerDocument.getNodeName(fNodeIndex);
150         type = ownerDocument.getTypeInfo(fNodeIndex);
151
152         // attributes
153
setupDefaultAttributes();
154         int index = ownerDocument.getNodeExtra(fNodeIndex);
155         if (index != -1) {
156             NamedNodeMap JavaDoc attrs = getAttributes();
157             do {
158                 NodeImpl attr = (NodeImpl)ownerDocument.getNodeObject(index);
159                 attrs.setNamedItem(attr);
160                 index = ownerDocument.getPrevSibling(index);
161             } while (index != -1);
162         }
163
164         // set mutation events flag back to its original value
165
ownerDocument.mutationEvents = orig;
166
167     } // synchronizeData()
168

169     protected final void synchronizeChildren() {
170         DeferredDocumentImpl ownerDocument =
171             (DeferredDocumentImpl) ownerDocument();
172         ownerDocument.synchronizeChildren(this, fNodeIndex);
173     } // synchronizeChildren()
174

175 } // class DeferredElementImpl
176
Popular Tags