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 package com.sun.org.apache.xerces.internal.dom;
23 
24 import org.w3c.dom.Node;
25 
26 /**
27  * NON-DOM CLASS: Describe one of the Elements (and its associated
28  * Attributes) defined in this Document Type.
29  * <p>
30  * I've included this in Level 1 purely as an anchor point for default
31  * attributes. In Level 2 it should enable the ChildRule support.
32  *
33  * @xerces.internal
34  *
35  */
36 public class DeferredElementDefinitionImpl
37     extends ElementDefinitionImpl
38     implements DeferredNode {
39 
40     //
41     // Constants
42     //
43 
44     /** Serialization version. */
45     static final long serialVersionUID = 6703238199538041591L;
46 
47     //
48     // Data
49     //
50 
51     /** Node index. */
52     protected transient int fNodeIndex;
53 
54     //
55     // Constructors
56     //
57 
58     /**
59      * This is the deferred constructor. Only the fNodeIndex is given here.
60      * All other data, can be requested from the ownerDocument via the index.
61      */
DeferredElementDefinitionImpl(DeferredDocumentImpl ownerDocument, int nodeIndex)62     DeferredElementDefinitionImpl(DeferredDocumentImpl ownerDocument,
63                                   int nodeIndex) {
64         super(ownerDocument, null);
65 
66         fNodeIndex = nodeIndex;
67         needsSyncData(true);
68         needsSyncChildren(true);
69 
70     } // <init>(DeferredDocumentImpl,int)
71 
72     //
73     // DeferredNode methods
74     //
75 
76     /** Returns the node index. */
getNodeIndex()77     public int getNodeIndex() {
78         return fNodeIndex;
79     }
80 
81     //
82     // Protected methods
83     //
84 
85     /** Synchronizes the data (name and value) for fast nodes. */
synchronizeData()86     protected void synchronizeData() {
87 
88         // no need to sync in the future
89         needsSyncData(false);
90 
91         // fluff data
92         DeferredDocumentImpl ownerDocument =
93             (DeferredDocumentImpl)this.ownerDocument;
94         name = ownerDocument.getNodeName(fNodeIndex);
95 
96     } // synchronizeData()
97 
98     /** Synchronizes the default attribute values. */
synchronizeChildren()99     protected void synchronizeChildren() {
100 
101         // we don't want to generate any event for this so turn them off
102         boolean orig = ownerDocument.getMutationEvents();
103         ownerDocument.setMutationEvents(false);
104 
105         // attributes are now synced
106         needsSyncChildren(false);
107 
108         // create attributes node map
109         DeferredDocumentImpl ownerDocument =
110             (DeferredDocumentImpl)this.ownerDocument;
111         attributes = new NamedNodeMapImpl(ownerDocument);
112 
113         // Default attributes dangle as children of the element
114         // definition "node" in the internal fast table.
115         for (int nodeIndex = ownerDocument.getLastChild(fNodeIndex);
116              nodeIndex != -1;
117              nodeIndex = ownerDocument.getPrevSibling(nodeIndex)) {
118             Node attr = ownerDocument.getNodeObject(nodeIndex);
119             attributes.setNamedItem(attr);
120         }
121 
122         // set mutation events flag back to its original value
123         ownerDocument.setMutationEvents(orig);
124 
125     } // synchronizeChildren()
126 
127 } // class DeferredElementDefinitionImpl
128