286N/A * reserved comment block 286N/A * DO NOT REMOVE OR ALTER! 286N/A * Copyright 1999-2004 The Apache Software Foundation. 286N/A * Licensed under the Apache License, Version 2.0 (the "License"); 286N/A * you may not use this file except in compliance with the License. 286N/A * You may obtain a copy of the License at 286N/A * Unless required by applicable law or agreed to in writing, software 286N/A * distributed under the License is distributed on an "AS IS" BASIS, 286N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 286N/A * See the License for the specific language governing permissions and 286N/A * limitations under the License. 286N/A * Attribute represents an XML-style attribute of an 286N/A * Element. Typically, the allowable values are controlled by its 286N/A * declaration in the Document Type Definition (DTD) governing this 286N/A * If the attribute has not been explicitly assigned a value, but has 286N/A * been declared in the DTD, it will exist and have that default. Only 286N/A * if neither the document nor the DTD specifies a value will the 286N/A * Attribute really be considered absent and have no value; in that 286N/A * case, querying the attribute will return null. 286N/A * Attributes may have multiple children that contain their data. (XML 286N/A * allows attributes to contain entity references, and tokenized 286N/A * attribute types such as NMTOKENS may have a child for each token.) 286N/A * For convenience, the Attribute object's getValue() method returns 286N/A * the string version of the attribute's value. 286N/A * Attributes are not children of the Elements they belong to, in the 286N/A * usual sense, and have no valid Parent reference. However, the spec 286N/A * says they _do_ belong to a specific Element, and an INUSE exception 286N/A * is to be thrown if the user attempts to explicitly share them 286N/A * Note that Elements do not permit attributes to appear to be shared 286N/A * (see the INUSE exception), so this object's mutability is 286N/A * officially not an issue. 286N/A * Note: The ownerNode attribute is used to store the Element the Attr 286N/A * node is associated with. Attr nodes do not have parent nodes. 286N/A * Besides, the getOwnerElement() method can be used to get the element node 286N/A * this attribute is associated with. 286N/A * AttrImpl does not support Namespaces. AttrNSImpl, which inherits from 286N/A * <p>AttrImpl used to inherit from ParentNode. It now directly inherits from 286N/A * NodeImpl and provide its own implementation of the ParentNode's behavior. 286N/A * The reason is that we now try and avoid to always create a Text node to 286N/A * hold the value of an attribute. The DOM spec requires it, so we still have 286N/A * to do it in case getFirstChild() is called for instance. The reason 286N/A * attribute values are stored as a list of nodes is so that they can carry 286N/A * more than a simple string. They can also contain EntityReference nodes. 286N/A * However, most of the times people only have a single string that they only 286N/A * new version, the Attr node has a value pointer which can either be the 286N/A * String directly or a pointer to the first ChildNode. A flag tells which one 286N/A * it currently is. Note that while we try to stick with the direct String as 286N/A * much as possible once we've switched to a node there is no going back. This 286N/A * is because we have no way to know whether the application keeps referring to 286N/A * the node we once returned. 286N/A * <p> The gain in memory varies on the density of attributes in the document. 286N/A * But in the tests I've run I've seen up to 12% of memory gain. And the good 286N/A * thing is that it also leads to a slight gain in speed because we allocate 286N/A * fewer objects! I mean, that's until we have to actually create the node... 286N/A * To avoid too much duplicated code, I got rid of ParentNode and renamed 286N/A * ChildAndParentNode, which I never really liked, to ParentNode for 286N/A * simplicity, this doesn't make much of a difference in memory usage because 286N/A * there are only very few objects that are only a Parent. This is only true 286N/A * now because AttrImpl now inherits directly from NodeImpl and has its own 286N/A * implementation of the ParentNode's node behavior. So there is still some 286N/A * duplicated code there. 286N/A * This class doesn't directly support mutation events, however, it notifies 286N/A * the document when mutations are performed so that the document class do so. 286N/A * <p><b>WARNING</b>: Some of the code here is partially duplicated in 286N/A * ParentNode, be careful to keep these two classes in sync! 286N/A * @author Arnaud Le Hors, IBM 286N/A * @author Joe Kesselman, IBM 286N/A * @author Andy Clark, IBM 286N/A * @since PR-DOM-Level-1-19980818. 286N/A /** Serialization version. */ 286N/A /** This can either be a String or the first child node. */ 286N/A /** Type information */ 286N/A // REVISIT: we are losing the type information in DOM during serialization 286N/A * Attribute has no public constructor. Please use the factory 286N/A * method in the Document class. 286N/A /** False for default attributes. */ 286N/A // Support for DOM Level 3 renameNode method. 286N/A // Note: This only deals with part of the pb. It is expected to be 286N/A // called after the Attr has been detached for one thing. 286N/A // CoreDocumentImpl does all the work. 286N/A // create a real text node as child if we don't have one yet 286N/A * set the ownerDocument of this node and its children 286N/A * NON-DOM: set the type of this attribute to be ID type. 286N/A /** DOM Level 3: isId*/ 286N/A // REVISIT: should an attribute that is not in the tree return 286N/A // take care of case where there are kids 286N/A // Need to break the association w/ original kids 286N/A // Cloning an Attribute always clones its children, 286N/A // since they represent its value, no matter whether this 286N/A // is a deep clone or not 286N/A * A short integer indicating what type of node this is. The named 286N/A * constants for this value are defined in the org.w3c.dom.Node interface. 286N/A * Returns the attribute name 286N/A * Implicit in the rerouting of getNodeValue to getValue is the 286N/A * need to redefine setNodeValue, for symmetry's sake. Note that 286N/A * since we're explicitly providing a value, Specified should be set 286N/A * true.... even if that value equals the default. 286N/A * @see org.w3c.dom.TypeInfo#getTypeName() 286N/A * @see org.w3c.dom.TypeInfo#getTypeNamespace() 286N/A * Method getSchemaTypeInfo. 286N/A * In Attribute objects, NodeValue is considered a synonym for 286N/A * In Attributes, NodeName is considered a synonym for the 286N/A * The DOM doesn't clearly define what setValue(null) means. I've taken it 286N/A * as "remove all children", which from outside should appear 286N/A * similar to setting it to the empty string. 286N/A // Can no longer just discard the kids; they may have 286N/A // event listeners waiting for them to disconnect. 286N/A // create an actual text node as our child so 286N/A // that we can use it in the event 286N/A // simply discard children if any 286N/A // remove ref from first child to last child 286N/A // then remove ref to current value 286N/A // Create and add the new one, generating only non-aggregate events 286N/A // (There are no listeners on the new Text, but there may be 286N/A // Note that aggregate events are NOT dispatched here, 286N/A // since we need to combine the remove and insert. 286N/A // if there are any event handlers create a real node 286N/A // directly store the string 286N/A * The "string value" of an Attribute is its text representation, 286N/A * which in turn is a concatenation of the string values of its children. 286N/A * The "specified" flag is true if and only if this attribute's 286N/A * value was explicitly specified in the original document. Note that 286N/A * the implementation, not the user, is in charge of this 286N/A * property. If the user asserts an Attribute value (even if it ends 286N/A * up having the same value as the default), it is considered a 286N/A * specified attribute. If you really want to revert to the default, 286N/A * delete the attribute from the Element, and the Implementation will 286N/A * re-assert the default (if any) in its place, with the appropriate 286N/A * specified=false setting. 286N/A }
// getSpecified():boolean 286N/A * Returns the element node that this attribute is associated with, 286N/A * or null if the attribute has not been added to an element. 286N/A * @see #getOwnerElement 286N/A * @deprecated Previous working draft of DOM Level 2. New method 286N/A * is <tt>getOwnerElement()</tt>. 286N/A // if we have an owner, ownerNode is our ownerElement, otherwise it's 286N/A // our ownerDocument and we don't have an ownerElement 286N/A * Returns the element node that this attribute is associated with, 286N/A * or null if the attribute has not been added to an element. 286N/A * @since WD-DOM-Level-2-19990719 286N/A // if we have an owner, ownerNode is our ownerElement, otherwise it's 286N/A // our ownerDocument and we don't have an ownerElement 286N/A // No need to normalize if already normalized or 286N/A // if value is kept as a String. 286N/A // If kid is a text node, we need to check for one of two 286N/A // 1) There is an adjacent text node 286N/A // 2) There is no adjacent text node, but kid is 286N/A // If an adjacent text node, merge it with kid 286N/A // If kid is empty, remove it 286N/A /** NON-DOM, for use by parser */ 286N/A }
// setSpecified(boolean) 286N/A * NON-DOM: used by the parser 286N/A /** NON-DOM method for debugging convenience */ 286N/A * Test whether this node has any children. Convenience shorthand 286N/A * for (Node.getFirstChild()!=null) 286N/A * Obtain a NodeList enumerating all children of this node. If there 286N/A * are none, an (initially) empty NodeList is returned. 286N/A * will immediately reflect those changes. Also, the NodeList refers 286N/A * to the actual nodes, so changes to those nodes made via the DOM tree 286N/A * will be reflected in the NodeList and vice versa. 286N/A * In this implementation, Nodes implement the NodeList interface and 286N/A * provide their own getChildNodes() support. Other DOMs may solve this 286N/A // JKESS: KNOWN ISSUE HERE 286N/A }
// getChildNodes():NodeList 286N/A /** The first child of this Node, or null if none. */ 286N/A }
// getFirstChild():Node 286N/A /** The last child of this Node, or null if none. */ 286N/A }
// getLastChild():Node 286N/A // last child is stored as the previous sibling of first child 286N/A // store lastChild as previous sibling of first child 286N/A * Move one or more node(s) to our list of children. Note that this 286N/A * implicitly removes them from their previous parent. 286N/A * @param newChild The Node to be moved to our subtree. As a 286N/A * convenience feature, inserting a DocumentNode will instead insert 286N/A * @param refChild Current child which newChild should be placed 286N/A * immediately before. If refChild is null, the insertion occurs 286N/A * after all existing Nodes, like appendChild(). 286N/A * @return newChild, in its new state (relocated, or emptied in the case of 286N/A * @throws DOMException(HIERARCHY_REQUEST_ERR) if newChild is of a 286N/A * type that shouldn't be a child of this node, or if newChild is an 286N/A * ancestor of this node. 286N/A * @throws DOMException(WRONG_DOCUMENT_ERR) if newChild has a 286N/A * different owner document than we do. 286N/A * @throws DOMException(NOT_FOUND_ERR) if refChild is not a child of 286N/A * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if this node is 286N/A // Tail-call; optimizer should be able to do good things with. 286N/A }
// insertBefore(Node,Node):Node 286N/A /** NON-DOM INTERNAL: Within DOM actions,we sometimes need to be able 286N/A * to control which mutation events are spawned. This version of the 286N/A * insertBefore operation allows us to do so. It is not intended 286N/A * for use by application programs. 286N/A // SLOW BUT SAFE: We could insert the whole subtree without 286N/A // parent's child-list, patch the parent pointers, set the 286N/A // ends of the list.) But we know some subclasses have special- 286N/A // case behavior they add to insertBefore(), so we don't risk it. 286N/A // This approch also takes fewer bytecodes. 286N/A // NOTE: If one of the children is not a legal child of this 286N/A // node, throw HIERARCHY_REQUEST_ERR before _any_ of the children 286N/A // have been transferred. (Alternative behaviors would be to 286N/A // reparent up to the first failure point or reparent all those 286N/A // which are acceptable to the target node, neither of which is 286N/A // as robust. PR-DOM-0818 isn't entirely clear on which it 286N/A // No need to check kids for right-document; if they weren't, 286N/A // they wouldn't be kids of that DocFrag. 286N/A // stupid case that must be handled as a no-op triggering events... 286N/A // refChild must be a child of this node (or null) 286N/A // Prevent cycles in the tree 286N/A // newChild cannot be ancestor of this Node, 286N/A // and actually cannot be this 286N/A // Convert to internal type, to avoid repeated casting 286N/A // Convert to internal type, to avoid repeated casting 286N/A // Attach before and after 286N/A // Note: firstChild.previousSibling == lastChild!! 286N/A // this our first and only child 286N/A // at the head of the list 286N/A // somewhere in the middle 286N/A }
// internalInsertBefore(Node,Node,int):Node 286N/A * Remove a child from this Node. The removed child's subtree 286N/A * remains intact so it may be re-inserted elsewhere. 286N/A * @return oldChild, in its new state (removed). 286N/A * @throws DOMException(NOT_FOUND_ERR) if oldChild is not a child of 286N/A * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if this node is 286N/A // Tail-call, should be optimizable 286N/A // we don't have any child per say so it can't be one of them! 286N/A }
// removeChild(Node) :Node 286N/A /** NON-DOM INTERNAL: Within DOM actions,we sometimes need to be able 286N/A * to control which mutation events are spawned. This version of the 286N/A * removeChild operation allows us to do so. It is not intended 286N/A * for use by application programs. 286N/A // Patch linked list around oldChild 286N/A // Note: lastChild == firstChild.previousSibling 286N/A // removing first child 286N/A // next line is: firstChild = oldInternal.nextSibling 286N/A // removing some other child in the middle 286N/A // Save previous sibling for normalization checking. 286N/A // Remove oldInternal's references to tree 286N/A }
// internalRemoveChild(Node,int):Node 286N/A * Make newChild occupy the location that oldChild used to 286N/A * have. Note that newChild will first be removed from its previous 286N/A * parent, if any. Equivalent to inserting newChild before oldChild, 286N/A * then removing oldChild. 286N/A * @return oldChild, in its new state (removed). 286N/A * @throws DOMException(HIERARCHY_REQUEST_ERR) if newChild is of a 286N/A * type that shouldn't be a child of this node, or if newChild is 286N/A * one of our ancestors. 286N/A * @throws DOMException(WRONG_DOCUMENT_ERR) if newChild has a 286N/A * different owner document than we do. 286N/A * @throws DOMException(NOT_FOUND_ERR) if oldChild is not a child of 286N/A * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if this node is 286N/A // If Mutation Events are being generated, this operation might 286N/A // throw aggregate events twice when modifying an Attr -- once 286N/A // on insertion and once on removal. DOM Level 2 does not specify 286N/A // this as either desirable or undesirable, but hints that 286N/A // aggregations should be issued only once per user request. 286N/A * NodeList method: Count the immediate children of this node 286N/A * NodeList method: Return the Nth immediate child of this node, or 286N/A * null if the index is out of bounds. 286N/A * @return org.w3c.dom.Node 286N/A * DOM Level 3 WD- Experimental. 286N/A * Override inherited behavior from ParentNode to support deep equal. 286N/A * isEqualNode is always deep on Attr nodes. 286N/A * Introduced in DOM Level 3. <p> 286N/A * Checks if a type is derived from another by restriction. See: 286N/A * The namspace of the ancestor type declaration 286N/A * The name of the ancestor type declaration 286N/A * The reference type definition 286N/A * @return boolean True if the type is derived by restriciton for the 286N/A * Override default behavior so that if deep is true, children are also 286N/A * Note: this will not change the state of an EntityReference or its 286N/A * children, which are always read-only. 286N/A // Recursively set kids 286N/A }
// setReadOnly(boolean,boolean) 286N/A * Override this method in subclass to hook in efficient 286N/A * internal data structure. 286N/A // By default just change the flag to avoid calling this method again 286N/A * Checks the normalized state of this node after inserting a child. 286N/A * If the inserted child causes this node to be unnormalized, then this 286N/A * node is flagged accordingly. 286N/A * The conditions for changing the normalized state are: 286N/A * <li>The inserted child is a text node and one of its adjacent siblings 286N/A * <li>The inserted child is is itself unnormalized. 286N/A * @param insertedChild the child node that was inserted into this node 286N/A * @throws NullPointerException if the inserted child is <code>null</code> 286N/A // See if insertion caused this node to be unnormalized. 286N/A // If an adjacent sibling of the new child is a text node, 286N/A // flag this node as unnormalized. 286N/A // If the new child is not normalized, 286N/A // then this node is inherently not normalized. 286N/A }
// checkNormalizationAfterInsert(ChildNode) 286N/A * Checks the normalized of this node after removing a child. 286N/A * If the removed child causes this node to be unnormalized, then this 286N/A * node is flagged accordingly. 286N/A * The conditions for changing the normalized state are: 286N/A * <li>The removed child had two adjacent siblings that were text nodes. 286N/A * @param previousSibling the previous sibling of the removed child, or 286N/A // See if removal caused this node to be unnormalized. 286N/A // If the adjacent siblings of the removed child were both text nodes, 286N/A // flag this node as unnormalized. 286N/A }
// checkNormalizationAfterRemove(ChildNode) 286N/A // Serialization methods 286N/A /** Serialize object. */ 286N/A }
// writeObject(ObjectOutputStream) 286N/A /** Deserialize object. */ 286N/A // perform default deseralization 286N/A // hardset synchildren - so we don't try to sync - 286N/A // it does not make any sense to try to synchildren when we just 286N/A }
// readObject(ObjectInputStream)