1/*
2 * reserved comment block
3 * DO NOT REMOVE OR ALTER!
4 */
5/*
6 * Licensed to the Apache Software Foundation (ASF) under one or more
7 * contributor license agreements.  See the NOTICE file distributed with
8 * this work for additional information regarding copyright ownership.
9 * The ASF licenses this file to You under the Apache License, Version 2.0
10 * (the "License"); you may not use this file except in compliance with
11 * the License.  You may obtain a copy of the License at
12 *
13 *      http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21
22/*
23 * WARNING: because java doesn't support multi-inheritance some code is
24 * duplicated. If you're changing this file you probably want to change
25 * DeferredElementNSImpl.java at the same time.
26 */
27
28package com.sun.org.apache.xerces.internal.dom;
29
30import org.w3c.dom.NamedNodeMap;
31
32/**
33 * Elements represent most of the "markup" and structure of the
34 * document.  They contain both the data for the element itself
35 * (element name and attributes), and any contained nodes, including
36 * document text (as children).
37 * <P>
38 * Elements may have Attributes associated with them; the API for this is
39 * defined in Node, but the function is implemented here. In general, XML
40 * applications should retrive Attributes as Nodes, since they may contain
41 * entity references and hence be a fairly complex sub-tree. HTML users will
42 * be dealing with simple string values, and convenience methods are provided
43 * to work in terms of Strings.
44 * <P>
45 * DeferredElementImpl inherits from ElementImpl which does not support
46 * Namespaces. DeferredElementNSImpl, which inherits from ElementNSImpl, does.
47 * @see DeferredElementNSImpl
48 *
49 * @xerces.internal
50 *
51 * @since  PR-DOM-Level-1-19980818.
52 */
53public class DeferredElementImpl
54    extends ElementImpl
55    implements DeferredNode {
56
57    //
58    // Constants
59    //
60
61    /** Serialization version. */
62    static final long serialVersionUID = -7670981133940934842L;
63
64    //
65    // Data
66    //
67
68    /** Node index. */
69    protected transient int fNodeIndex;
70
71    //
72    // Constructors
73    //
74
75    /**
76     * This is the deferred constructor. Only the fNodeIndex is given here. All
77     * other data, can be requested from the ownerDocument via the index.
78     */
79    DeferredElementImpl(DeferredDocumentImpl ownerDoc, int nodeIndex) {
80        super(ownerDoc, null);
81
82        fNodeIndex = nodeIndex;
83        needsSyncChildren(true);
84
85    } // <init>(DocumentImpl,int)
86
87    //
88    // DeferredNode methods
89    //
90
91    /** Returns the node index. */
92    public final int getNodeIndex() {
93        return fNodeIndex;
94    }
95
96    //
97    // Protected methods
98    //
99
100    /** Synchronizes the data (name and value) for fast nodes. */
101    protected final void synchronizeData() {
102
103        // no need to sync in the future
104        needsSyncData(false);
105
106        // fluff data
107        DeferredDocumentImpl ownerDocument =
108            (DeferredDocumentImpl)this.ownerDocument;
109
110        // we don't want to generate any event for this so turn them off
111        boolean orig = ownerDocument.mutationEvents;
112        ownerDocument.mutationEvents = false;
113
114        name = ownerDocument.getNodeName(fNodeIndex);
115
116        // attributes
117        setupDefaultAttributes();
118        int index = ownerDocument.getNodeExtra(fNodeIndex);
119        if (index != -1) {
120            NamedNodeMap attrs = getAttributes();
121            do {
122                NodeImpl attr = (NodeImpl)ownerDocument.getNodeObject(index);
123                attrs.setNamedItem(attr);
124                index = ownerDocument.getPrevSibling(index);
125            } while (index != -1);
126        }
127
128        // set mutation events flag back to its original value
129        ownerDocument.mutationEvents = orig;
130
131    } // synchronizeData()
132
133    protected final void synchronizeChildren() {
134        DeferredDocumentImpl ownerDocument =
135            (DeferredDocumentImpl) ownerDocument();
136        ownerDocument.synchronizeChildren(this, fNodeIndex);
137    } // synchronizeChildren()
138
139} // class DeferredElementImpl
140