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: * DeferredAttrNSImpl.java at the same time.
022: */
023:
024: package org.apache.xerces.dom;
025:
026: /**
027: * Attribute represents an XML-style attribute of an
028: * Element. Typically, the allowable values are controlled by its
029: * declaration in the Document Type Definition (DTD) governing this
030: * kind of document.
031: * <P>
032: * If the attribute has not been explicitly assigned a value, but has
033: * been declared in the DTD, it will exist and have that default. Only
034: * if neither the document nor the DTD specifies a value will the
035: * Attribute really be considered absent and have no value; in that
036: * case, querying the attribute will return null.
037: * <P>
038: * Attributes may have multiple children that contain their data. (XML
039: * allows attributes to contain entity references, and tokenized
040: * attribute types such as NMTOKENS may have a child for each token.)
041: * For convenience, the Attribute object's getValue() method returns
042: * the string version of the attribute's value.
043: * <P>
044: * Attributes are not children of the Elements they belong to, in the
045: * usual sense, and have no valid Parent reference. However, the spec
046: * says they _do_ belong to a specific Element, and an INUSE exception
047: * is to be thrown if the user attempts to explicitly share them
048: * between elements.
049: * <P>
050: * Note that Elements do not permit attributes to appear to be shared
051: * (see the INUSE exception), so this object's mutability is
052: * officially not an issue.
053: * <P>
054: * DeferredAttrImpl inherits from AttrImpl which does not support
055: * Namespaces. DeferredAttrNSImpl, which inherits from AttrNSImpl, does.
056: * @see DeferredAttrNSImpl
057: *
058: * @xerces.internal
059: *
060: * @author Andy Clark, IBM
061: * @author Arnaud Le Hors, IBM
062: * @version $Id: DeferredAttrImpl.java 447266 2006-09-18 05:57:49Z mrglavas $
063: * @since PR-DOM-Level-1-19980818.
064: */
065: public final class DeferredAttrImpl extends AttrImpl implements
066: DeferredNode {
067:
068: //
069: // Constants
070: //
071:
072: /** Serialization version. */
073: static final long serialVersionUID = 6903232312469148636L;
074:
075: //
076: // Data
077: //
078:
079: /** Node index. */
080: protected transient int fNodeIndex;
081:
082: //
083: // Constructors
084: //
085:
086: /**
087: * This is the deferred constructor. Only the fNodeIndex is given here.
088: * All other data, can be requested from the ownerDocument via the index.
089: */
090: DeferredAttrImpl(DeferredDocumentImpl ownerDocument, int nodeIndex) {
091: super (ownerDocument, null);
092:
093: fNodeIndex = nodeIndex;
094: needsSyncData(true);
095: needsSyncChildren(true);
096:
097: } // <init>(DeferredDocumentImpl,int)
098:
099: //
100: // DeferredNode methods
101: //
102:
103: /** Returns the node index. */
104: public int getNodeIndex() {
105: return fNodeIndex;
106: }
107:
108: //
109: // Protected methods
110: //
111:
112: /** Synchronizes the data (name and value) for fast nodes. */
113: protected void synchronizeData() {
114:
115: // no need to sync in the future
116: needsSyncData(false);
117:
118: // fluff data
119: DeferredDocumentImpl ownerDocument = (DeferredDocumentImpl) ownerDocument();
120: name = ownerDocument.getNodeName(fNodeIndex);
121: int extra = ownerDocument.getNodeExtra(fNodeIndex);
122: isSpecified((extra & SPECIFIED) != 0);
123: isIdAttribute((extra & ID) != 0);
124:
125: int extraNode = ownerDocument.getLastChild(fNodeIndex);
126: type = ownerDocument.getTypeInfo(extraNode);
127: } // synchronizeData()
128:
129: /**
130: * Synchronizes the node's children with the internal structure.
131: * Fluffing the children at once solves a lot of work to keep
132: * the two structures in sync. The problem gets worse when
133: * editing the tree -- this makes it a lot easier.
134: */
135: protected void synchronizeChildren() {
136: DeferredDocumentImpl ownerDocument = (DeferredDocumentImpl) ownerDocument();
137: ownerDocument.synchronizeChildren(this , fNodeIndex);
138: } // synchronizeChildren()
139:
140: } // class DeferredAttrImpl
|