1/* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5/* 6 * Licensed to the Apache Software Foundation (ASF) under one or more 7 * contributor license agreements. See the NOTICE file distributed with 8 * this work for additional information regarding copyright ownership. 9 * The ASF licenses this file to You under the Apache License, Version 2.0 10 * (the "License"); you may not use this file except in compliance with 11 * the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 22/* 23 * WARNING: because java doesn't support multi-inheritance some code is 24 * duplicated. If you're changing this file you probably want to change 25 * DeferredAttrNSImpl.java at the same time. 26 */ 27 28package com.sun.org.apache.xerces.internal.dom; 29 30/** 31 * Attribute represents an XML-style attribute of an 32 * Element. Typically, the allowable values are controlled by its 33 * declaration in the Document Type Definition (DTD) governing this 34 * kind of document. 35 * <P> 36 * If the attribute has not been explicitly assigned a value, but has 37 * been declared in the DTD, it will exist and have that default. Only 38 * if neither the document nor the DTD specifies a value will the 39 * Attribute really be considered absent and have no value; in that 40 * case, querying the attribute will return null. 41 * <P> 42 * Attributes may have multiple children that contain their data. (XML 43 * allows attributes to contain entity references, and tokenized 44 * attribute types such as NMTOKENS may have a child for each token.) 45 * For convenience, the Attribute object's getValue() method returns 46 * the string version of the attribute's value. 47 * <P> 48 * Attributes are not children of the Elements they belong to, in the 49 * usual sense, and have no valid Parent reference. However, the spec 50 * says they _do_ belong to a specific Element, and an INUSE exception 51 * is to be thrown if the user attempts to explicitly share them 52 * between elements. 53 * <P> 54 * Note that Elements do not permit attributes to appear to be shared 55 * (see the INUSE exception), so this object's mutability is 56 * officially not an issue. 57 * <P> 58 * DeferredAttrImpl inherits from AttrImpl which does not support 59 * Namespaces. DeferredAttrNSImpl, which inherits from AttrNSImpl, does. 60 * @see DeferredAttrNSImpl 61 * 62 * @xerces.internal 63 * 64 * @author Andy Clark, IBM 65 * @author Arnaud Le Hors, IBM 66 * @since PR-DOM-Level-1-19980818. 67 */ 68public final class DeferredAttrImpl 69 extends AttrImpl 70 implements DeferredNode { 71 72 // 73 // Constants 74 // 75 76 /** Serialization version. */ 77 static final long serialVersionUID = 6903232312469148636L; 78 79 // 80 // Data 81 // 82 83 /** Node index. */ 84 protected transient int fNodeIndex; 85 86 // 87 // Constructors 88 // 89 90 /** 91 * This is the deferred constructor. Only the fNodeIndex is given here. 92 * All other data, can be requested from the ownerDocument via the index. 93 */ 94 DeferredAttrImpl(DeferredDocumentImpl ownerDocument, int nodeIndex) { 95 super(ownerDocument, null); 96 97 fNodeIndex = nodeIndex; 98 needsSyncData(true); 99 needsSyncChildren(true); 100 101 } // <init>(DeferredDocumentImpl,int) 102 103 // 104 // DeferredNode methods 105 // 106 107 /** Returns the node index. */ 108 public int getNodeIndex() { 109 return fNodeIndex; 110 } 111 112 // 113 // Protected methods 114 // 115 116 /** Synchronizes the data (name and value) for fast nodes. */ 117 protected void synchronizeData() { 118 119 // no need to sync in the future 120 needsSyncData(false); 121 122 // fluff data 123 DeferredDocumentImpl ownerDocument = 124 (DeferredDocumentImpl) ownerDocument(); 125 name = ownerDocument.getNodeName(fNodeIndex); 126 int extra = ownerDocument.getNodeExtra(fNodeIndex); 127 isSpecified((extra & SPECIFIED) != 0); 128 isIdAttribute((extra & ID) != 0); 129 130 int extraNode = ownerDocument.getLastChild(fNodeIndex); 131 type = ownerDocument.getTypeInfo(extraNode); 132 } // synchronizeData() 133 134 /** 135 * Synchronizes the node's children with the internal structure. 136 * Fluffing the children at once solves a lot of work to keep 137 * the two structures in sync. The problem gets worse when 138 * editing the tree -- this makes it a lot easier. 139 */ 140 protected void synchronizeChildren() { 141 DeferredDocumentImpl ownerDocument = 142 (DeferredDocumentImpl) ownerDocument(); 143 ownerDocument.synchronizeChildren(this, fNodeIndex); 144 } // synchronizeChildren() 145 146} // class DeferredAttrImpl 147