|
BEA Systems, Inc. | |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object weblogic.apache.xerces.dom.NodeImpl weblogic.apache.xerces.dom.AttrImpl
Attribute represents an XML-style attribute of an Element. Typically, the allowable values are controlled by its declaration in the Document Type Definition (DTD) governing this kind of document.
If the attribute has not been explicitly assigned a value, but has been declared in the DTD, it will exist and have that default. Only if neither the document nor the DTD specifies a value will the Attribute really be considered absent and have no value; in that case, querying the attribute will return null.
Attributes may have multiple children that contain their data. (XML allows attributes to contain entity references, and tokenized attribute types such as NMTOKENS may have a child for each token.) For convenience, the Attribute object's getValue() method returns the string version of the attribute's value.
Attributes are not children of the Elements they belong to, in the usual sense, and have no valid Parent reference. However, the spec says they _do_ belong to a specific Element, and an INUSE exception is to be thrown if the user attempts to explicitly share them between elements.
Note that Elements do not permit attributes to appear to be shared (see the INUSE exception), so this object's mutability is officially not an issue.
Note: The ownerNode attribute is used to store the Element the Attr node is associated with. Attr nodes do not have parent nodes. Besides, the getOwnerElement() method can be used to get the element node this attribute is associated with.
AttrImpl does not support Namespaces. AttrNSImpl, which inherits from it, does.
AttrImpl used to inherit from ParentNode. It now directly inherits from NodeImpl and provide its own implementation of the ParentNode's behavior. The reason is that we now try and avoid to always create a Text node to hold the value of an attribute. The DOM spec requires it, so we still have to do it in case getFirstChild() is called for instance. The reason attribute values are stored as a list of nodes is so that they can carry more than a simple string. They can also contain EntityReference nodes. However, most of the times people only have a single string that they only set and get through Element.set/getAttribute or Attr.set/getValue. In this new version, the Attr node has a value pointer which can either be the String directly or a pointer to the first ChildNode. A flag tells which one it currently is. Note that while we try to stick with the direct String as much as possible once we've switched to a node there is no going back. This is because we have no way to know whether the application keeps referring to the node we once returned.
The gain in memory varies on the density of attributes in the document. But in the tests I've run I've seen up to 12% of memory gain. And the good thing is that it also leads to a slight gain in speed because we allocate fewer objects! I mean, that's until we have to actually create the node...
To avoid too much duplicated code, I got rid of ParentNode and renamed ChildAndParentNode, which I never really liked, to ParentNode for simplicity, this doesn't make much of a difference in memory usage because there are only very few objects that are only a Parent. This is only true now because AttrImpl now inherits directly from NodeImpl and has its own implementation of the ParentNode's node behavior. So there is still some duplicated code there.
This class doesn't directly support mutation events, however, it notifies the document when mutations are performed so that the document class do so.
WARNING: Some of the code here is partially duplicated in ParentNode, be careful to keep these two classes in sync!
AttrNSImpl
,
Serialized FormField Summary | |
protected String |
name
Deprecated. Attribute name. |
protected static TextImpl |
textNode
Deprecated. |
protected Object |
value
Deprecated. This can either be a String or the first child node. |
Fields inherited from class weblogic.apache.xerces.dom.NodeImpl |
ELEMENT_DEFINITION_NODE, FIRSTCHILD, flags, HASSTRING, IDATTRIBUTE, IGNORABLEWS, OWNED, ownerNode, READONLY, SPECIFIED, SYNCCHILDREN, SYNCDATA, TREE_POSITION_ANCESTOR, TREE_POSITION_DESCENDANT, TREE_POSITION_DISCONNECTED, TREE_POSITION_EQUIVALENT, TREE_POSITION_FOLLOWING, TREE_POSITION_PRECEDING, TREE_POSITION_SAME_NODE, UNNORMALIZED |
Constructor Summary | |
protected |
AttrImpl()
Deprecated. |
protected |
AttrImpl(CoreDocumentImpl ownerDocument,
String name)
Deprecated. Attribute has no public constructor. |
Method Summary | |
Node |
cloneNode(boolean deep)
Deprecated. Returns a duplicate of a given node. |
NodeList |
getChildNodes()
Deprecated. Obtain a NodeList enumerating all children of this node. |
Element |
getElement()
Deprecated. Previous working draft of DOM Level 2. New method is getOwnerElement(). |
Node |
getFirstChild()
Deprecated. The first child of this Node, or null if none. |
Node |
getLastChild()
Deprecated. The last child of this Node, or null if none. |
int |
getLength()
Deprecated. NodeList method: Count the immediate children of this node |
String |
getName()
Deprecated. In Attributes, NodeName is considered a synonym for the attribute's Name |
String |
getNodeName()
Deprecated. Returns the attribute name |
short |
getNodeType()
Deprecated. A short integer indicating what type of node this is. |
String |
getNodeValue()
Deprecated. In Attribute objects, NodeValue is considered a synonym for Value. |
Element |
getOwnerElement()
Deprecated. Returns the element node that this attribute is associated with, or null if the attribute has not been added to an element. |
boolean |
getSpecified()
Deprecated. The "specified" flag is true if and only if this attribute's value was explicitly specified in the original document. |
String |
getValue()
Deprecated. The "string value" of an Attribute is its text representation, which in turn is a concatenation of the string values of its children. |
boolean |
hasChildNodes()
Deprecated. Test whether this node has any children. |
Node |
insertBefore(Node newChild,
Node refChild)
Deprecated. Move one or more node(s) to our list of children. |
boolean |
isEqualNode(Node arg)
Deprecated. DOM Level 3 WD- Experimental. |
Node |
item(int index)
Deprecated. NodeList method: Return the Nth immediate child of this node, or null if the index is out of bounds. |
protected void |
makeChildNode()
Deprecated. |
void |
normalize()
Deprecated. Puts all Text nodes in the full depth of the sub-tree
underneath this Node , including attribute nodes, into a
"normal" form where only markup (e.g., tags, comments, processing
instructions, CDATA sections, and entity references) separates
Text nodes, i.e., there are no adjacent Text
nodes. |
Node |
removeChild(Node oldChild)
Deprecated. Remove a child from this Node. |
Node |
replaceChild(Node newChild,
Node oldChild)
Deprecated. Make newChild occupy the location that oldChild used to have. |
void |
setIdAttribute(boolean id)
Deprecated. NON-DOM: set the type of this attribute to be ID type. |
void |
setNodeValue(String value)
Deprecated. Implicit in the rerouting of getNodeValue to getValue is the need to redefine setNodeValue, for symmetry's sake. |
void |
setReadOnly(boolean readOnly,
boolean deep)
Deprecated. Override default behavior so that if deep is true, children are also toggled. |
void |
setSpecified(boolean arg)
Deprecated. NON-DOM, for use by parser |
void |
setValue(String newvalue)
Deprecated. The DOM doesn't clearly define what setValue(null) means. |
protected void |
synchronizeChildren()
Deprecated. Override this method in subclass to hook in efficient internal data structure. |
String |
toString()
Deprecated. NON-DOM method for debugging convenience |
Methods inherited from class weblogic.apache.xerces.dom.NodeImpl |
addEventListener, appendChild, changed, changes, compareTreePosition, dispatchEvent, getAttributes, getBaseURI, getInterface, getLocalName, getNamespaceURI, getNextSibling, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, getReadOnly, getTextContent, getUserData, getUserData, hasAttributes, isDefaultNamespace, isSameNode, isSupported, lookupNamespacePrefix, lookupNamespaceURI, needsSyncChildren, removeEventListener, setPrefix, setTextContent, setUserData, setUserData, synchronizeData |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.w3c.dom.Node |
appendChild, getAttributes, getBaseURI, getLocalName, getNamespaceURI, getNextSibling, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, getTextContent, getUserData, hasAttributes, isDefaultNamespace, isSameNode, isSupported, lookupNamespaceURI, setPrefix, setTextContent |
Field Detail |
protected String name
protected static TextImpl textNode
protected Object value
Constructor Detail |
protected AttrImpl()
protected AttrImpl(CoreDocumentImpl ownerDocument, String name)
Method Detail |
public Node cloneNode(boolean deep)
NodeImpl
Note: since we never have any children deep is meaningless here, ParentNode overrides this behavior.
cloneNode
in interface Node
cloneNode
in class NodeImpl
Example: Cloning a Text node will copy both the node and the text it
contains.
Example: Cloning something that has children -- Element or Attr, for
example -- will _not_ clone those children unless a "deep clone"
has been requested. A shallow clone of an Attr node will yield an
empty Attr of the same name.
NOTE: Clones will always be read/write, even if the node being cloned
is read-only, to permit applications using only the DOM API to obtain
editable copies of locked portions of the tree.
public NodeList getChildNodes()
NodeLists are "live"; as children are added/removed the NodeList will immediately reflect those changes. Also, the NodeList refers to the actual nodes, so changes to those nodes made via the DOM tree will be reflected in the NodeList and vice versa.
In this implementation, Nodes implement the NodeList interface and provide their own getChildNodes() support. Other DOMs may solve this differently.
getChildNodes
in interface Node
getChildNodes
in class NodeImpl
public Element getElement()
getOwnerElement()
public Node getFirstChild()
getFirstChild
in interface Node
getFirstChild
in class NodeImpl
ParentNode
public Node getLastChild()
getLastChild
in interface Node
getLastChild
in class NodeImpl
ParentNode
public int getLength()
getLength
in interface NodeList
getLength
in class NodeImpl
ParentNode
public String getName()
getName
in interface Attr
public String getNodeName()
getNodeName
in interface Node
getNodeName
in class NodeImpl
public short getNodeType()
getNodeType
in interface Node
getNodeType
in class NodeImpl
public String getNodeValue()
getNodeValue
in interface Node
getNodeValue
in class NodeImpl
getValue()
public Element getOwnerElement()
getOwnerElement
in interface Attr
public boolean getSpecified()
getSpecified
in interface Attr
public String getValue()
getValue
in interface Attr
public boolean hasChildNodes()
hasChildNodes
in interface Node
hasChildNodes
in class NodeImpl
ParentNode
public Node insertBefore(Node newChild, Node refChild) throws DOMException
insertBefore
in interface Node
insertBefore
in class NodeImpl
newChild
- The Node to be moved to our subtree. As a
convenience feature, inserting a DocumentNode will instead insert
all its children.refChild
- Current child which newChild should be placed
immediately before. If refChild is null, the insertion occurs
after all existing Nodes, like appendChild().
DOMException(HIERARCHY_REQUEST_ERR)
- if newChild is of a
type that shouldn't be a child of this node, or if newChild is an
ancestor of this node.
DOMException(WRONG_DOCUMENT_ERR)
- if newChild has a
different owner document than we do.
DOMException(NOT_FOUND_ERR)
- if refChild is not a child of
this node.
DOMException(NO_MODIFICATION_ALLOWED_ERR)
- if this node is
read-only.
DOMException
ParentNode
public boolean isEqualNode(Node arg)
isEqualNode
in interface Node
isEqualNode
in class NodeImpl
arg
- The node to compare equality with.
true
otherwise false
.public Node item(int index)
item
in interface NodeList
item
in class NodeImpl
ParentNode
protected void makeChildNode()
public void normalize()
NodeImpl
Text
nodes in the full depth of the sub-tree
underneath this Node
, including attribute nodes, into a
"normal" form where only markup (e.g., tags, comments, processing
instructions, CDATA sections, and entity references) separates
Text
nodes, i.e., there are no adjacent Text
nodes. This can be used to ensure that the DOM view of a document is
the same as if it were saved and re-loaded, and is useful when
operations (such as XPointer lookups) that depend on a particular
document tree structure are to be used.In cases where the document
contains CDATASections
, the normalize operation alone may
not be sufficient, since XPointers do not differentiate between
Text
nodes and CDATASection
nodes.
Note that this implementation simply calls normalize() on this Node's children. It is up to implementors or Node to override normalize() to take action.
normalize
in interface Node
normalize
in class NodeImpl
public Node removeChild(Node oldChild) throws DOMException
removeChild
in interface Node
removeChild
in class NodeImpl
DOMException(NOT_FOUND_ERR)
- if oldChild is not a child of
this node.
DOMException(NO_MODIFICATION_ALLOWED_ERR)
- if this node is
read-only.
DOMException
ParentNode
public Node replaceChild(Node newChild, Node oldChild) throws DOMException
replaceChild
in interface Node
replaceChild
in class NodeImpl
DOMException(HIERARCHY_REQUEST_ERR)
- if newChild is of a
type that shouldn't be a child of this node, or if newChild is
one of our ancestors.
DOMException(WRONG_DOCUMENT_ERR)
- if newChild has a
different owner document than we do.
DOMException(NOT_FOUND_ERR)
- if oldChild is not a child of
this node.
DOMException(NO_MODIFICATION_ALLOWED_ERR)
- if this node is
read-only.
DOMException
ParentNode
public void setIdAttribute(boolean id)
id
- public void setNodeValue(String value) throws DOMException
setNodeValue
in interface Node
setNodeValue
in class NodeImpl
DOMException
public void setReadOnly(boolean readOnly, boolean deep)
setReadOnly
in class NodeImpl
readOnly
- True or false as desired.deep
- If true, children are also toggled. Note that this will
not change the state of an EntityReference or its children,
which are always read-only.
Note: this will not change the state of an EntityReference or its
children, which are always read-only.
public void setSpecified(boolean arg)
public void setValue(String newvalue)
setValue
in interface Attr
protected void synchronizeChildren()
public String toString()
toString
in class NodeImpl
|
Documentation is available at http://download.oracle.com/docs/cd/E13222_01/wls/docs91 Copyright 2005 BEA Systems Inc. |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |