KickJava   Java API By Example, From Geeks To Geeks.

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


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

22
23 package org.apache.xerces.dom;
24
25 import org.w3c.dom.NamedNodeMap JavaDoc;
26
27 /**
28  * Elements represent most of the "markup" and structure of the
29  * document. They contain both the data for the element itself
30  * (element name and attributes), and any contained nodes, including
31  * document text (as children).
32  * <P>
33  * Elements may have Attributes associated with them; the API for this is
34  * defined in Node, but the function is implemented here. In general, XML
35  * applications should retrive Attributes as Nodes, since they may contain
36  * entity references and hence be a fairly complex sub-tree. HTML users will
37  * be dealing with simple string values, and convenience methods are provided
38  * to work in terms of Strings.
39  * <P>
40  * DeferredElementImpl inherits from ElementImpl which does not support
41  * Namespaces. DeferredElementNSImpl, which inherits from ElementNSImpl, does.
42  * @see DeferredElementNSImpl
43  *
44  * @xerces.internal
45  *
46  * @version $Id: DeferredElementImpl.java,v 1.18 2004/10/05 17:12:51 mrglavas Exp $
47  * @since PR-DOM-Level-1-19980818.
48  */

49 public class DeferredElementImpl
50     extends ElementImpl
51     implements DeferredNode {
52
53     //
54
// Constants
55
//
56

57     /** Serialization version. */
58     static final long serialVersionUID = -7670981133940934842L;
59
60     //
61
// Data
62
//
63

64     /** Node index. */
65     protected transient int fNodeIndex;
66
67     //
68
// Constructors
69
//
70

71     /**
72      * This is the deferred constructor. Only the fNodeIndex is given here. All
73      * other data, can be requested from the ownerDocument via the index.
74      */

75     DeferredElementImpl(DeferredDocumentImpl ownerDoc, int nodeIndex) {
76         super(ownerDoc, null);
77
78         fNodeIndex = nodeIndex;
79         needsSyncChildren(true);
80
81     } // <init>(DocumentImpl,int)
82

83     //
84
// DeferredNode methods
85
//
86

87     /** Returns the node index. */
88     public final int getNodeIndex() {
89         return fNodeIndex;
90     }
91
92     //
93
// Protected methods
94
//
95

96     /** Synchronizes the data (name and value) for fast nodes. */
97     protected final void synchronizeData() {
98
99         // no need to sync in the future
100
needsSyncData(false);
101
102         // fluff data
103
DeferredDocumentImpl ownerDocument =
104             (DeferredDocumentImpl)this.ownerDocument;
105
106         // we don't want to generate any event for this so turn them off
107
boolean orig = ownerDocument.mutationEvents;
108         ownerDocument.mutationEvents = false;
109
110         name = ownerDocument.getNodeName(fNodeIndex);
111
112         // attributes
113
setupDefaultAttributes();
114         int index = ownerDocument.getNodeExtra(fNodeIndex);
115         if (index != -1) {
116             NamedNodeMap JavaDoc attrs = getAttributes();
117             do {
118                 NodeImpl attr = (NodeImpl)ownerDocument.getNodeObject(index);
119                 attrs.setNamedItem(attr);
120                 index = ownerDocument.getPrevSibling(index);
121             } while (index != -1);
122         }
123
124         // set mutation events flag back to its original value
125
ownerDocument.mutationEvents = orig;
126
127     } // synchronizeData()
128

129     protected final void synchronizeChildren() {
130         DeferredDocumentImpl ownerDocument =
131             (DeferredDocumentImpl) ownerDocument();
132         ownerDocument.synchronizeChildren(this, fNodeIndex);
133     } // synchronizeChildren()
134

135 } // class DeferredElementImpl
136
Popular Tags