KickJava   Java API By Example, From Geeks To Geeks.

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


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 /*
19  * WARNING: because java doesn't support multi-inheritance some code is
20  * duplicated. If you're changing this file you probably want to change
21  * DeferredElementImpl.java at the same time.
22  *
23  * @version $Id: DeferredElementNSImpl.java,v 1.20 2004/10/14 03:49:33 mrglavas Exp $
24  */

25
26 package org.apache.xerces.dom;
27
28 import org.apache.xerces.xs.XSTypeDefinition;
29 import org.w3c.dom.NamedNodeMap JavaDoc;
30
31 /**
32  * DeferredElementNSImpl is to ElementNSImpl, what DeferredElementImpl is to
33  * ElementImpl.
34  *
35  * @xerces.internal
36  *
37  * @see DeferredElementImpl
38  */

39 public class DeferredElementNSImpl
40     extends ElementNSImpl
41     implements DeferredNode {
42
43     //
44
// Constants
45
//
46

47     /** Serialization version. */
48     static final long serialVersionUID = -5001885145370927385L;
49
50     //
51
// Data
52
//
53

54     /** Node index. */
55     protected transient int fNodeIndex;
56
57     //
58
// Constructors
59
//
60

61     /**
62      * This is the deferred constructor. Only the fNodeIndex is given here. All
63      * other data, can be requested from the ownerDocument via the index.
64      */

65     DeferredElementNSImpl(DeferredDocumentImpl ownerDoc, int nodeIndex) {
66         super(ownerDoc, null);
67
68         fNodeIndex = nodeIndex;
69         needsSyncChildren(true);
70
71     } // <init>(DocumentImpl,int)
72

73     //
74
// DeferredNode methods
75
//
76

77     /** Returns the node index. */
78     public final int getNodeIndex() {
79         return fNodeIndex;
80     }
81
82     //
83
// Protected methods
84
//
85

86     /** Synchronizes the data (name and value) for fast nodes. */
87     protected final void synchronizeData() {
88
89         // no need to sync in the future
90
needsSyncData(false);
91
92         // fluff data
93
DeferredDocumentImpl ownerDocument =
94             (DeferredDocumentImpl) this.ownerDocument;
95
96         // we don't want to generate any event for this so turn them off
97
boolean orig = ownerDocument.mutationEvents;
98         ownerDocument.mutationEvents = false;
99
100         name = ownerDocument.getNodeName(fNodeIndex);
101
102         // extract local part from QName
103
int index = name.indexOf(':');
104         if (index < 0) {
105             localName = name;
106         }
107         else {
108             localName = name.substring(index + 1);
109         }
110
111         namespaceURI = ownerDocument.getNodeURI(fNodeIndex);
112         type = (XSTypeDefinition)ownerDocument.getTypeInfo(fNodeIndex);
113
114         // attributes
115
setupDefaultAttributes();
116         int attrIndex = ownerDocument.getNodeExtra(fNodeIndex);
117         if (attrIndex != -1) {
118             NamedNodeMap JavaDoc attrs = getAttributes();
119             do {
120                 NodeImpl attr =
121                     (NodeImpl)ownerDocument.getNodeObject(attrIndex);
122                 attrs.setNamedItem(attr);
123                 attrIndex = ownerDocument.getPrevSibling(attrIndex);
124             } while (attrIndex != -1);
125         }
126
127         // set mutation events flag back to its original value
128
ownerDocument.mutationEvents = orig;
129
130     } // synchronizeData()
131

132     /**
133      * Synchronizes the node's children with the internal structure.
134      * Fluffing the children at once solves a lot of work to keep
135      * the two structures in sync. The problem gets worse when
136      * editing the tree -- this makes it a lot easier.
137      */

138     protected final void synchronizeChildren() {
139         DeferredDocumentImpl ownerDocument =
140             (DeferredDocumentImpl) ownerDocument();
141         ownerDocument.synchronizeChildren(this, fNodeIndex);
142     } // synchronizeChildren()
143

144 } // class DeferredElementImpl
145
Popular Tags