|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.xerces.dom.NodeImpl | +--org.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 java.lang.String |
name
Attribute name. |
protected static TextImpl |
textNode
|
protected java.lang.Object |
value
This can either be a String or the first child node. |
Fields inherited from interface org.w3c.dom.Node |
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE |
Fields inherited from interface org.w3c.dom.TypeInfo |
DERIVATION_EXTENSION, DERIVATION_LIST, DERIVATION_RESTRICTION, DERIVATION_UNION |
Constructor Summary | |
protected |
AttrImpl()
|
protected |
AttrImpl(CoreDocumentImpl ownerDocument,
java.lang.String name)
Attribute has no public constructor. |
Method Summary | |
org.w3c.dom.Node |
cloneNode(boolean deep)
Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes. |
org.w3c.dom.NodeList |
getChildNodes()
Obtain a NodeList enumerating all children of this node. |
org.w3c.dom.Element |
getElement()
Deprecated. Previous working draft of DOM Level 2. New method is getOwnerElement(). |
org.w3c.dom.Node |
getFirstChild()
The first child of this Node, or null if none. |
org.w3c.dom.Node |
getLastChild()
The last child of this Node, or null if none. |
int |
getLength()
NodeList method: Count the immediate children of this node |
java.lang.String |
getName()
In Attributes, NodeName is considered a synonym for the attribute's Name |
java.lang.String |
getNodeName()
Returns the attribute name |
short |
getNodeType()
A short integer indicating what type of node this is. |
java.lang.String |
getNodeValue()
In Attribute objects, NodeValue is considered a synonym for Value. |
org.w3c.dom.Element |
getOwnerElement()
Returns the element node that this attribute is associated with, or null if the attribute has not been added to an element. |
org.w3c.dom.TypeInfo |
getSchemaTypeInfo()
Method getSchemaTypeInfo. |
boolean |
getSpecified()
The "specified" flag is true if and only if this attribute's value was explicitly specified in the original document. |
java.lang.String |
getTypeName()
The name of a type declared for the associated element or attribute, or null if unknown. |
java.lang.String |
getTypeNamespace()
The namespace of the type declared for the associated element or attribute or null if the element does not have
declaration or if no namespace information is available. |
java.lang.String |
getValue()
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()
Test whether this node has any children. |
org.w3c.dom.Node |
insertBefore(org.w3c.dom.Node newChild,
org.w3c.dom.Node refChild)
Move one or more node(s) to our list of children. |
boolean |
isDerivedFrom(java.lang.String typeNamespaceArg,
java.lang.String typeNameArg,
int derivationMethod)
Introduced in DOM Level 3. |
boolean |
isEqualNode(org.w3c.dom.Node arg)
DOM Level 3 WD- Experimental. |
boolean |
isId()
DOM Level 3: isId |
org.w3c.dom.Node |
item(int index)
NodeList method: Return the Nth immediate child of this node, or null if the index is out of bounds. |
protected void |
makeChildNode()
|
void |
normalize()
Puts all Text nodes in the full depth of the sub-tree
underneath this Node , including attribute nodes, into a
"normal" form where only structure (e.g., elements, comments,
processing instructions, CDATA sections, and entity references)
separates Text nodes, i.e., there are neither adjacent
Text nodes nor empty Text nodes. |
org.w3c.dom.Node |
removeChild(org.w3c.dom.Node oldChild)
Remove a child from this Node. |
org.w3c.dom.Node |
replaceChild(org.w3c.dom.Node newChild,
org.w3c.dom.Node oldChild)
Make newChild occupy the location that oldChild used to have. |
void |
setIdAttribute(boolean id)
NON-DOM: set the type of this attribute to be ID type. |
void |
setNodeValue(java.lang.String value)
Implicit in the rerouting of getNodeValue to getValue is the need to redefine setNodeValue, for symmetry's sake. |
void |
setReadOnly(boolean readOnly,
boolean deep)
Override default behavior so that if deep is true, children are also toggled. |
void |
setSpecified(boolean arg)
NON-DOM, for use by parser |
void |
setType(java.lang.Object type)
NON-DOM: used by the parser |
void |
setValue(java.lang.String newvalue)
The DOM doesn't clearly define what setValue(null) means. |
protected void |
synchronizeChildren()
Override this method in subclass to hook in efficient internal data structure. |
java.lang.String |
toString()
NON-DOM method for debugging convenience |
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, compareDocumentPosition, getAttributes, getBaseURI, getFeature, getLocalName, getNamespaceURI, getNextSibling, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, getTextContent, getUserData, hasAttributes, isDefaultNamespace, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, setPrefix, setTextContent, setUserData |
Field Detail |
protected java.lang.Object value
protected java.lang.String name
protected static TextImpl textNode
Constructor Detail |
protected AttrImpl(CoreDocumentImpl ownerDocument, java.lang.String name)
protected AttrImpl()
Method Detail |
protected void makeChildNode()
public void setIdAttribute(boolean id)
id
- public boolean isId()
isId
in interface org.w3c.dom.Attr
public org.w3c.dom.Node cloneNode(boolean deep)
org.w3c.dom.Node
parentNode
is null
) and no user data. User
data associated to the imported node is not carried over. However, if
any UserDataHandlers
has been specified along with the
associated data these handlers will be called with the appropriate
parameters before this method returns.
Element
copies all attributes and their
values, including those generated by the XML processor to represent
defaulted attributes, but this method does not copy any children it
contains unless it is a deep clone. This includes text contained in
an the Element
since the text is contained in a child
Text
node. Cloning an Attr
directly, as
opposed to be cloned as part of an Element
cloning
operation, returns a specified attribute (specified
is
true
). Cloning an Attr
always clones its
children, since they represent its value, no matter whether this is a
deep clone or not. Cloning an EntityReference
automatically constructs its subtree if a corresponding
Entity
is available, no matter whether this is a deep
clone or not. Cloning any other type of node simply returns a copy of
this node.
EntityReference
clone are readonly
. In addition, clones of unspecified Attr
nodes are
specified. And, cloning Document
,
DocumentType
, Entity
, and
Notation
nodes is implementation dependent.cloneNode
in interface org.w3c.dom.Node
cloneNode
in class NodeImpl
org.w3c.dom.Node
deep
- If true
, recursively clone the subtree under
the specified node; if false
, clone only the node
itself (and its attributes, if it is an Element
).public short getNodeType()
getNodeType
in interface org.w3c.dom.Node
getNodeType
in class NodeImpl
public java.lang.String getNodeName()
getNodeName
in interface org.w3c.dom.Node
getNodeName
in class NodeImpl
public void setNodeValue(java.lang.String value) throws org.w3c.dom.DOMException
setNodeValue
in interface org.w3c.dom.Node
setNodeValue
in class NodeImpl
org.w3c.dom.Node
org.w3c.dom.DOMException
- NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly and if
it is not defined to be null
.public java.lang.String getTypeName()
org.w3c.dom.TypeInfo
null
if unknown.getTypeName
in interface org.w3c.dom.TypeInfo
TypeInfo.getTypeName()
public java.lang.String getTypeNamespace()
org.w3c.dom.TypeInfo
null
if the element does not have
declaration or if no namespace information is available.getTypeNamespace
in interface org.w3c.dom.TypeInfo
TypeInfo.getTypeNamespace()
public org.w3c.dom.TypeInfo getSchemaTypeInfo()
getSchemaTypeInfo
in interface org.w3c.dom.Attr
public java.lang.String getNodeValue()
getNodeValue
in interface org.w3c.dom.Node
getNodeValue
in class NodeImpl
getValue()
public java.lang.String getName()
getName
in interface org.w3c.dom.Attr
public void setValue(java.lang.String newvalue)
setValue
in interface org.w3c.dom.Attr
org.w3c.dom.Attr
org.w3c.dom.DOMException
- NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.public java.lang.String getValue()
getValue
in interface org.w3c.dom.Attr
public boolean getSpecified()
getSpecified
in interface org.w3c.dom.Attr
public org.w3c.dom.Element getElement()
getOwnerElement()
public org.w3c.dom.Element getOwnerElement()
getOwnerElement
in interface org.w3c.dom.Attr
public void normalize()
org.w3c.dom.Node
Text
nodes in the full depth of the sub-tree
underneath this Node
, including attribute nodes, into a
"normal" form where only structure (e.g., elements, comments,
processing instructions, CDATA sections, and entity references)
separates Text
nodes, i.e., there are neither adjacent
Text
nodes nor empty 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 [XPointer]
lookups) that depend on a particular document tree structure are to
be used. If the parameter "normalize-characters" of the
DOMConfiguration
object attached to the
Node.ownerDocument
is true
, this method
will also fully normalize the characters of the Text
nodes.
Note: 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.
normalize
in interface org.w3c.dom.Node
normalize
in class NodeImpl
public void setSpecified(boolean arg)
public void setType(java.lang.Object type)
type
- public java.lang.String toString()
toString
in class NodeImpl
public boolean hasChildNodes()
hasChildNodes
in interface org.w3c.dom.Node
hasChildNodes
in class NodeImpl
org.w3c.dom.Node
true
if this node has any children,
false
otherwise.public org.w3c.dom.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 org.w3c.dom.Node
getChildNodes
in class NodeImpl
public org.w3c.dom.Node getFirstChild()
getFirstChild
in interface org.w3c.dom.Node
getFirstChild
in class NodeImpl
org.apache.xerces.dom.NodeImpl
ParentNode
public org.w3c.dom.Node getLastChild()
getLastChild
in interface org.w3c.dom.Node
getLastChild
in class NodeImpl
org.apache.xerces.dom.NodeImpl
ParentNode
public org.w3c.dom.Node insertBefore(org.w3c.dom.Node newChild, org.w3c.dom.Node refChild) throws org.w3c.dom.DOMException
insertBefore
in interface org.w3c.dom.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.public org.w3c.dom.Node removeChild(org.w3c.dom.Node oldChild) throws org.w3c.dom.DOMException
removeChild
in interface org.w3c.dom.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.public org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild, org.w3c.dom.Node oldChild) throws org.w3c.dom.DOMException
replaceChild
in interface org.w3c.dom.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.public int getLength()
getLength
in class NodeImpl
public org.w3c.dom.Node item(int index)
item
in class NodeImpl
Index
- intpublic boolean isEqualNode(org.w3c.dom.Node arg)
isEqualNode
in interface org.w3c.dom.Node
isEqualNode
in class NodeImpl
org.w3c.dom.Node
arg
- The node to compare equality with.true
if the nodes are equal,
false
otherwise.public boolean isDerivedFrom(java.lang.String typeNamespaceArg, java.lang.String typeNameArg, int derivationMethod)
Checks if a type is derived from another by restriction. See: http://www.w3.org/TR/DOM-Level-3-Core/core.html#TypeInfo-isDerivedFrom
isDerivedFrom
in interface org.w3c.dom.TypeInfo
ancestorNS
- The namspace of the ancestor type declarationancestorName
- The name of the ancestor type declarationtype
- The reference type definitionpublic void setReadOnly(boolean readOnly, boolean deep)
setReadOnly
in class NodeImpl
Note: this will not change the state of an EntityReference or its
children, which are always read-only.
protected void synchronizeChildren()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |