1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xerces" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, International
  53. * Business Machines, Inc., http://www.apache.org. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. /*
  58. * WARNING: because java doesn't support multi-inheritance some code is
  59. * duplicated. If you're changing this file you probably want to change
  60. * DeferredAttrNSImpl.java at the same time.
  61. */
  62. package com.sun.org.apache.xerces.internal.dom;
  63. /**
  64. * Attribute represents an XML-style attribute of an
  65. * Element. Typically, the allowable values are controlled by its
  66. * declaration in the Document Type Definition (DTD) governing this
  67. * kind of document.
  68. * <P>
  69. * If the attribute has not been explicitly assigned a value, but has
  70. * been declared in the DTD, it will exist and have that default. Only
  71. * if neither the document nor the DTD specifies a value will the
  72. * Attribute really be considered absent and have no value; in that
  73. * case, querying the attribute will return null.
  74. * <P>
  75. * Attributes may have multiple children that contain their data. (XML
  76. * allows attributes to contain entity references, and tokenized
  77. * attribute types such as NMTOKENS may have a child for each token.)
  78. * For convenience, the Attribute object's getValue() method returns
  79. * the string version of the attribute's value.
  80. * <P>
  81. * Attributes are not children of the Elements they belong to, in the
  82. * usual sense, and have no valid Parent reference. However, the spec
  83. * says they _do_ belong to a specific Element, and an INUSE exception
  84. * is to be thrown if the user attempts to explicitly share them
  85. * between elements.
  86. * <P>
  87. * Note that Elements do not permit attributes to appear to be shared
  88. * (see the INUSE exception), so this object's mutability is
  89. * officially not an issue.
  90. * <P>
  91. * DeferredAttrImpl inherits from AttrImpl which does not support
  92. * Namespaces. DeferredAttrNSImpl, which inherits from AttrNSImpl, does.
  93. * @see DeferredAttrNSImpl
  94. *
  95. *
  96. * @author Andy Clark, IBM
  97. * @author Arnaud Le Hors, IBM
  98. * @version $Id: DeferredAttrImpl.java,v 1.19 2003/01/16 22:53:44 elena Exp $
  99. * @since PR-DOM-Level-1-19980818.
  100. */
  101. public final class DeferredAttrImpl
  102. extends AttrImpl
  103. implements DeferredNode {
  104. //
  105. // Constants
  106. //
  107. /** Serialization version. */
  108. static final long serialVersionUID = 6903232312469148636L;
  109. //
  110. // Data
  111. //
  112. /** Node index. */
  113. protected transient int fNodeIndex;
  114. //
  115. // Constructors
  116. //
  117. /**
  118. * This is the deferred constructor. Only the fNodeIndex is given here.
  119. * All other data, can be requested from the ownerDocument via the index.
  120. */
  121. DeferredAttrImpl(DeferredDocumentImpl ownerDocument, int nodeIndex) {
  122. super(ownerDocument, null);
  123. fNodeIndex = nodeIndex;
  124. needsSyncData(true);
  125. needsSyncChildren(true);
  126. } // <init>(DeferredDocumentImpl,int)
  127. //
  128. // DeferredNode methods
  129. //
  130. /** Returns the node index. */
  131. public int getNodeIndex() {
  132. return fNodeIndex;
  133. }
  134. //
  135. // Protected methods
  136. //
  137. /** Synchronizes the data (name and value) for fast nodes. */
  138. protected void synchronizeData() {
  139. // no need to sync in the future
  140. needsSyncData(false);
  141. // fluff data
  142. DeferredDocumentImpl ownerDocument =
  143. (DeferredDocumentImpl) ownerDocument();
  144. name = ownerDocument.getNodeName(fNodeIndex);
  145. int extra = ownerDocument.getNodeExtra(fNodeIndex);
  146. isSpecified((extra & SPECIFIED) != 0);
  147. isIdAttribute((extra & ID) != 0);
  148. int extraNode = ownerDocument.getLastChild(fNodeIndex);
  149. type = ownerDocument.getTypeInfo(extraNode);
  150. } // synchronizeData()
  151. /**
  152. * Synchronizes the node's children with the internal structure.
  153. * Fluffing the children at once solves a lot of work to keep
  154. * the two structures in sync. The problem gets worse when
  155. * editing the tree -- this makes it a lot easier.
  156. */
  157. protected void synchronizeChildren() {
  158. DeferredDocumentImpl ownerDocument =
  159. (DeferredDocumentImpl) ownerDocument();
  160. ownerDocument.synchronizeChildren(this, fNodeIndex);
  161. } // synchronizeChildren()
  162. } // class DeferredAttrImpl