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: * DeferredElementNSImpl.java at the same time.
022: */
023:
024: package org.apache.xerces.dom;
025:
026: import org.w3c.dom.NamedNodeMap;
027:
028: /**
029: * Elements represent most of the "markup" and structure of the
030: * document. They contain both the data for the element itself
031: * (element name and attributes), and any contained nodes, including
032: * document text (as children).
033: * <P>
034: * Elements may have Attributes associated with them; the API for this is
035: * defined in Node, but the function is implemented here. In general, XML
036: * applications should retrive Attributes as Nodes, since they may contain
037: * entity references and hence be a fairly complex sub-tree. HTML users will
038: * be dealing with simple string values, and convenience methods are provided
039: * to work in terms of Strings.
040: * <P>
041: * DeferredElementImpl inherits from ElementImpl which does not support
042: * Namespaces. DeferredElementNSImpl, which inherits from ElementNSImpl, does.
043: * @see DeferredElementNSImpl
044: *
045: * @xerces.internal
046: *
047: * @version $Id: DeferredElementImpl.java 447266 2006-09-18 05:57:49Z mrglavas $
048: * @since PR-DOM-Level-1-19980818.
049: */
050: public class DeferredElementImpl extends ElementImpl implements
051: DeferredNode {
052:
053: //
054: // Constants
055: //
056:
057: /** Serialization version. */
058: static final long serialVersionUID = -7670981133940934842L;
059:
060: //
061: // Data
062: //
063:
064: /** Node index. */
065: protected transient int fNodeIndex;
066:
067: //
068: // Constructors
069: //
070:
071: /**
072: * This is the deferred constructor. Only the fNodeIndex is given here. All
073: * other data, can be requested from the ownerDocument via the index.
074: */
075: DeferredElementImpl(DeferredDocumentImpl ownerDoc, int nodeIndex) {
076: super (ownerDoc, null);
077:
078: fNodeIndex = nodeIndex;
079: needsSyncChildren(true);
080:
081: } // <init>(DocumentImpl,int)
082:
083: //
084: // DeferredNode methods
085: //
086:
087: /** Returns the node index. */
088: public final int getNodeIndex() {
089: return fNodeIndex;
090: }
091:
092: //
093: // Protected methods
094: //
095:
096: /** Synchronizes the data (name and value) for fast nodes. */
097: protected final void synchronizeData() {
098:
099: // no need to sync in the future
100: needsSyncData(false);
101:
102: // fluff data
103: DeferredDocumentImpl ownerDocument = (DeferredDocumentImpl) this .ownerDocument;
104:
105: // we don't want to generate any event for this so turn them off
106: boolean orig = ownerDocument.mutationEvents;
107: ownerDocument.mutationEvents = false;
108:
109: name = ownerDocument.getNodeName(fNodeIndex);
110:
111: // attributes
112: setupDefaultAttributes();
113: int index = ownerDocument.getNodeExtra(fNodeIndex);
114: if (index != -1) {
115: NamedNodeMap attrs = getAttributes();
116: do {
117: NodeImpl attr = (NodeImpl) ownerDocument
118: .getNodeObject(index);
119: attrs.setNamedItem(attr);
120: index = ownerDocument.getPrevSibling(index);
121: } while (index != -1);
122: }
123:
124: // set mutation events flag back to its original value
125: ownerDocument.mutationEvents = orig;
126:
127: } // synchronizeData()
128:
129: protected final void synchronizeChildren() {
130: DeferredDocumentImpl ownerDocument = (DeferredDocumentImpl) ownerDocument();
131: ownerDocument.synchronizeChildren(this , fNodeIndex);
132: } // synchronizeChildren()
133:
134: } // class DeferredElementImpl
|