001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /*
019: * WARNING: because java doesn't support multi-inheritance some code is
020: * duplicated. If you're changing this file you probably want to change
021: * DeferredElementImpl.java at the same time.
022: *
023: * @version $Id: DeferredElementNSImpl.java 447266 2006-09-18 05:57:49Z mrglavas $
024: */
025:
026: package org.apache.xerces.dom;
027:
028: import org.apache.xerces.xs.XSTypeDefinition;
029: import org.w3c.dom.NamedNodeMap;
030:
031: /**
032: * DeferredElementNSImpl is to ElementNSImpl, what DeferredElementImpl is to
033: * ElementImpl.
034: *
035: * @xerces.internal
036: *
037: * @see DeferredElementImpl
038: */
039: public class DeferredElementNSImpl extends ElementNSImpl implements
040: DeferredNode {
041:
042: //
043: // Constants
044: //
045:
046: /** Serialization version. */
047: static final long serialVersionUID = -5001885145370927385L;
048:
049: //
050: // Data
051: //
052:
053: /** Node index. */
054: protected transient int fNodeIndex;
055:
056: //
057: // Constructors
058: //
059:
060: /**
061: * This is the deferred constructor. Only the fNodeIndex is given here. All
062: * other data, can be requested from the ownerDocument via the index.
063: */
064: DeferredElementNSImpl(DeferredDocumentImpl ownerDoc, int nodeIndex) {
065: super (ownerDoc, null);
066:
067: fNodeIndex = nodeIndex;
068: needsSyncChildren(true);
069:
070: } // <init>(DocumentImpl,int)
071:
072: //
073: // DeferredNode methods
074: //
075:
076: /** Returns the node index. */
077: public final int getNodeIndex() {
078: return fNodeIndex;
079: }
080:
081: //
082: // Protected methods
083: //
084:
085: /** Synchronizes the data (name and value) for fast nodes. */
086: protected final void synchronizeData() {
087:
088: // no need to sync in the future
089: needsSyncData(false);
090:
091: // fluff data
092: DeferredDocumentImpl ownerDocument = (DeferredDocumentImpl) this .ownerDocument;
093:
094: // we don't want to generate any event for this so turn them off
095: boolean orig = ownerDocument.mutationEvents;
096: ownerDocument.mutationEvents = false;
097:
098: name = ownerDocument.getNodeName(fNodeIndex);
099:
100: // extract local part from QName
101: int index = name.indexOf(':');
102: if (index < 0) {
103: localName = name;
104: } else {
105: localName = name.substring(index + 1);
106: }
107:
108: namespaceURI = ownerDocument.getNodeURI(fNodeIndex);
109: type = (XSTypeDefinition) ownerDocument.getTypeInfo(fNodeIndex);
110:
111: // attributes
112: setupDefaultAttributes();
113: int attrIndex = ownerDocument.getNodeExtra(fNodeIndex);
114: if (attrIndex != -1) {
115: NamedNodeMap attrs = getAttributes();
116: boolean seenSchemaDefault = false;
117: do {
118: AttrImpl attr = (AttrImpl) ownerDocument
119: .getNodeObject(attrIndex);
120: // Take special care of schema defaulted attributes. Calling the
121: // non-namespace aware setAttributeNode() method could overwrite
122: // another attribute with the same local name.
123: if (!attr.getSpecified()
124: && (seenSchemaDefault || (attr
125: .getNamespaceURI() != null && attr
126: .getName().indexOf(':') < 0))) {
127: seenSchemaDefault = true;
128: attrs.setNamedItemNS(attr);
129: } else {
130: attrs.setNamedItem(attr);
131: }
132: attrIndex = ownerDocument.getPrevSibling(attrIndex);
133: } while (attrIndex != -1);
134: }
135:
136: // set mutation events flag back to its original value
137: ownerDocument.mutationEvents = orig;
138:
139: } // synchronizeData()
140:
141: /**
142: * Synchronizes the node's children with the internal structure.
143: * Fluffing the children at once solves a lot of work to keep
144: * the two structures in sync. The problem gets worse when
145: * editing the tree -- this makes it a lot easier.
146: */
147: protected final void synchronizeChildren() {
148: DeferredDocumentImpl ownerDocument = (DeferredDocumentImpl) ownerDocument();
149: ownerDocument.synchronizeChildren(this , fNodeIndex);
150: } // synchronizeChildren()
151:
152: } // class DeferredElementImpl
|