1 /*
2 * reserved comment block
3 * DO NOT REMOVE OR ALTER!
4 */
5 /*
6 * Copyright 1999-2002,2004 The Apache Software Foundation.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21 package com.sun.org.apache.xerces.internal.dom;
22
23 import org.w3c.dom.Node;
24
25 /**
26 * NON-DOM CLASS: Describe one of the Elements (and its associated
27 * Attributes) defined in this Document Type.
28 * <p>
29 * I've included this in Level 1 purely as an anchor point for default
30 * attributes. In Level 2 it should enable the ChildRule support.
31 *
32 * @xerces.internal
33 *
34 */
35 public class DeferredElementDefinitionImpl
36 extends ElementDefinitionImpl
37 implements DeferredNode {
38
39 //
40 // Constants
41 //
42
43 /** Serialization version. */
44 static final long serialVersionUID = 6703238199538041591L;
45
46 //
47 // Data
48 //
49
50 /** Node index. */
51 protected transient int fNodeIndex;
52
53 //
54 // Constructors
55 //
56
57 /**
58 * This is the deferred constructor. Only the fNodeIndex is given here.
59 * All other data, can be requested from the ownerDocument via the index.
60 */
61 DeferredElementDefinitionImpl(DeferredDocumentImpl ownerDocument,
62 int nodeIndex) {
63 super(ownerDocument, null);
64
65 fNodeIndex = nodeIndex;
66 needsSyncData(true);
67 needsSyncChildren(true);
68
69 } // <init>(DeferredDocumentImpl,int)
70
71 //
72 // DeferredNode methods
73 //
74
75 /** Returns the node index. */
76 public int getNodeIndex() {
77 return fNodeIndex;
78 }
79
80 //
81 // Protected methods
82 //
83
84 /** Synchronizes the data (name and value) for fast nodes. */
85 protected void synchronizeData() {
86
87 // no need to sync in the future
88 needsSyncData(false);
89
90 // fluff data
91 DeferredDocumentImpl ownerDocument =
92 (DeferredDocumentImpl)this.ownerDocument;
93 name = ownerDocument.getNodeName(fNodeIndex);
94
95 } // synchronizeData()
96
97 /** Synchronizes the default attribute values. */
98 protected void synchronizeChildren() {
99
100 // we don't want to generate any event for this so turn them off
101 boolean orig = ownerDocument.getMutationEvents();
102 ownerDocument.setMutationEvents(false);
103
104 // attributes are now synced
105 needsSyncChildren(false);
106
107 // create attributes node map
108 DeferredDocumentImpl ownerDocument =
109 (DeferredDocumentImpl)this.ownerDocument;
110 attributes = new NamedNodeMapImpl(ownerDocument);
111
112 // Default attributes dangle as children of the element
113 // definition "node" in the internal fast table.
114 for (int nodeIndex = ownerDocument.getLastChild(fNodeIndex);
115 nodeIndex != -1;
116 nodeIndex = ownerDocument.getPrevSibling(nodeIndex)) {
117 Node attr = ownerDocument.getNodeObject(nodeIndex);
118 attributes.setNamedItem(attr);
119 }
120
121 // set mutation events flag back to its original value
122 ownerDocument.setMutationEvents(orig);
123
124 } // synchronizeChildren()
125
126 } // class DeferredElementDefinitionImpl