KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.apache.xerces.dom;
18
19 import org.w3c.dom.Node JavaDoc;
20
21 /**
22  * NON-DOM CLASS: Describe one of the Elements (and its associated
23  * Attributes) defined in this Document Type.
24  * <p>
25  * I've included this in Level 1 purely as an anchor point for default
26  * attributes. In Level 2 it should enable the ChildRule support.
27  *
28  * @xerces.internal
29  *
30  * @version $Id: DeferredElementDefinitionImpl.java,v 1.14 2004/10/05 17:12:51 mrglavas Exp $
31  */

32 public class DeferredElementDefinitionImpl
33     extends ElementDefinitionImpl
34     implements DeferredNode {
35
36     //
37
// Constants
38
//
39

40     /** Serialization version. */
41     static final long serialVersionUID = 6703238199538041591L;
42     
43     //
44
// Data
45
//
46

47     /** Node index. */
48     protected transient int fNodeIndex;
49
50     //
51
// Constructors
52
//
53

54     /**
55      * This is the deferred constructor. Only the fNodeIndex is given here.
56      * All other data, can be requested from the ownerDocument via the index.
57      */

58     DeferredElementDefinitionImpl(DeferredDocumentImpl ownerDocument,
59                                   int nodeIndex) {
60         super(ownerDocument, null);
61         
62         fNodeIndex = nodeIndex;
63         needsSyncData(true);
64         needsSyncChildren(true);
65
66     } // <init>(DeferredDocumentImpl,int)
67

68     //
69
// DeferredNode methods
70
//
71

72     /** Returns the node index. */
73     public int getNodeIndex() {
74         return fNodeIndex;
75     }
76
77     //
78
// Protected methods
79
//
80

81     /** Synchronizes the data (name and value) for fast nodes. */
82     protected void synchronizeData() {
83
84         // no need to sync in the future
85
needsSyncData(false);
86
87         // fluff data
88
DeferredDocumentImpl ownerDocument =
89             (DeferredDocumentImpl)this.ownerDocument;
90         name = ownerDocument.getNodeName(fNodeIndex);
91
92     } // synchronizeData()
93

94     /** Synchronizes the default attribute values. */
95     protected void synchronizeChildren() {
96
97         // we don't want to generate any event for this so turn them off
98
boolean orig = ownerDocument.getMutationEvents();
99         ownerDocument.setMutationEvents(false);
100
101         // attributes are now synced
102
needsSyncChildren(false);
103
104         // create attributes node map
105
DeferredDocumentImpl ownerDocument =
106             (DeferredDocumentImpl)this.ownerDocument;
107         attributes = new NamedNodeMapImpl(ownerDocument);
108
109         // Default attributes dangle as children of the element
110
// definition "node" in the internal fast table.
111
for (int nodeIndex = ownerDocument.getLastChild(fNodeIndex);
112              nodeIndex != -1;
113              nodeIndex = ownerDocument.getPrevSibling(nodeIndex)) {
114             Node JavaDoc attr = ownerDocument.getNodeObject(nodeIndex);
115             attributes.setNamedItem(attr);
116         }
117
118         // set mutation events flag back to its original value
119
ownerDocument.setMutationEvents(orig);
120
121     } // synchronizeChildren()
122

123 } // class DeferredElementDefinitionImpl
124
Popular Tags