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: package org.apache.xerces.dom;
019:
020: import org.w3c.dom.Node;
021:
022: /**
023: * NON-DOM CLASS: Describe one of the Elements (and its associated
024: * Attributes) defined in this Document Type.
025: * <p>
026: * I've included this in Level 1 purely as an anchor point for default
027: * attributes. In Level 2 it should enable the ChildRule support.
028: *
029: * @xerces.internal
030: *
031: * @version $Id: DeferredElementDefinitionImpl.java 447266 2006-09-18 05:57:49Z mrglavas $
032: */
033: public class DeferredElementDefinitionImpl extends
034: ElementDefinitionImpl implements DeferredNode {
035:
036: //
037: // Constants
038: //
039:
040: /** Serialization version. */
041: static final long serialVersionUID = 6703238199538041591L;
042:
043: //
044: // Data
045: //
046:
047: /** Node index. */
048: protected transient int fNodeIndex;
049:
050: //
051: // Constructors
052: //
053:
054: /**
055: * This is the deferred constructor. Only the fNodeIndex is given here.
056: * All other data, can be requested from the ownerDocument via the index.
057: */
058: DeferredElementDefinitionImpl(DeferredDocumentImpl ownerDocument,
059: int nodeIndex) {
060: super (ownerDocument, null);
061:
062: fNodeIndex = nodeIndex;
063: needsSyncData(true);
064: needsSyncChildren(true);
065:
066: } // <init>(DeferredDocumentImpl,int)
067:
068: //
069: // DeferredNode methods
070: //
071:
072: /** Returns the node index. */
073: public int getNodeIndex() {
074: return fNodeIndex;
075: }
076:
077: //
078: // Protected methods
079: //
080:
081: /** Synchronizes the data (name and value) for fast nodes. */
082: protected void synchronizeData() {
083:
084: // no need to sync in the future
085: needsSyncData(false);
086:
087: // fluff data
088: DeferredDocumentImpl ownerDocument = (DeferredDocumentImpl) this .ownerDocument;
089: name = ownerDocument.getNodeName(fNodeIndex);
090:
091: } // synchronizeData()
092:
093: /** Synchronizes the default attribute values. */
094: protected void synchronizeChildren() {
095:
096: // we don't want to generate any event for this so turn them off
097: boolean orig = ownerDocument.getMutationEvents();
098: ownerDocument.setMutationEvents(false);
099:
100: // attributes are now synced
101: needsSyncChildren(false);
102:
103: // create attributes node map
104: DeferredDocumentImpl ownerDocument = (DeferredDocumentImpl) this .ownerDocument;
105: attributes = new NamedNodeMapImpl(ownerDocument);
106:
107: // Default attributes dangle as children of the element
108: // definition "node" in the internal fast table.
109: for (int nodeIndex = ownerDocument.getLastChild(fNodeIndex); nodeIndex != -1; nodeIndex = ownerDocument
110: .getPrevSibling(nodeIndex)) {
111: Node attr = ownerDocument.getNodeObject(nodeIndex);
112: attributes.setNamedItem(attr);
113: }
114:
115: // set mutation events flag back to its original value
116: ownerDocument.setMutationEvents(orig);
117:
118: } // synchronizeChildren()
119:
120: } // class DeferredElementDefinitionImpl
|