Methods Summary |
---|
public org.w3c.dom.Node | appendChild(org.w3c.dom.Node newChild)Adds the node newChild to the end of the list of children
of this node. If the newChild is already in the tree, it
is first removed.
if (newChild == null) {
throw new DOMException
(DOMException.HIERARCHY_REQUEST_ERR,
"Can't append a null node.");
}
initializeChildren();
// per DOM spec - must remove from tree. If newChild.parent == null,
// detachNode() does nothing. So this shouldn't hurt performace of
// serializers.
((NodeImpl) newChild).detachNode();
children.add(newChild);
((NodeImpl) newChild).parent = this;
setDirty();
return newChild;
|
public org.w3c.dom.Node | cloneNode(boolean deep)Returns a duplicate of this node, i.e., serves as a generic copy
constructor for nodes. The duplicate node has no parent; (
parentNode is null .).
Cloning an 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 text it
contains unless it is a deep clone, since the text is contained in a
child Text node. Cloning an Attribute
directly, as opposed to be cloned as part of an Element
cloning operation, returns a specified attribute (
specified is true ). Cloning any other type
of node simply returns a copy of this node.
Note that cloning an immutable subtree results in a mutable copy,
but the children of an EntityReference clone are readonly
. In addition, clones of unspecified Attr nodes are
specified. And, cloning Document ,
DocumentType , Entity , and
Notation nodes is implementation dependent.
return new NodeImpl(textRep);
|
protected org.w3c.dom.NamedNodeMap | convertAttrSAXtoDOM(org.xml.sax.Attributes saxAttr)The internal representation of Attributes cannot help being changed
It is because Attribute is not immutible Type, so if we keep out value and
just return it in another form, the application may chnae it, which we cannot
detect without some kind back track method (call back notifying the chnage.)
I am not sure which approach is better.
try {
org.w3c.dom.Document doc = org.apache.axis.utils.XMLUtils.newDocument();
AttributesImpl saxAttrs = (AttributesImpl) saxAttr;
NamedNodeMap domAttributes = new NamedNodeMapImpl();
for (int i = 0; i < saxAttrs.getLength(); i++) {
String uri = saxAttrs.getURI(i);
String qname = saxAttrs.getQName(i);
String value = saxAttrs.getValue(i);
if (uri != null && uri.trim().length() > 0) {
// filterring out the tricky method to differentiate the null namespace
// -ware case
if (NULL_URI_NAME.equals(uri)) {
uri = null;
}
Attr attr = doc.createAttributeNS(uri, qname);
attr.setValue(value);
domAttributes.setNamedItemNS(attr);
} else {
Attr attr = doc.createAttribute(qname);
attr.setValue(value);
domAttributes.setNamedItem(attr);
}
}
return domAttributes;
} catch (Exception ex) {
log.error(Messages.getMessage("saxToDomFailed00"),ex);
return null;
}
|
public void | detachNode()Removes this Node object from the tree. Once
removed, this node can be garbage collected if there are no
application references to it.
setDirty();
if (parent != null) {
parent.removeChild(this);
parent = null;
}
|
public org.w3c.dom.NamedNodeMap | getAttributes()A NamedNodeMap containing the attributes of this node (if
it is an Element ) or null otherwise.
// make first it is editable.
makeAttributesEditable();
return convertAttrSAXtoDOM(attributes);
|
public org.w3c.dom.NodeList | getChildNodes()A NodeList that contains all children of this node. If
there are no children, this is a NodeList containing no
nodes.
if (children == null) {
return NodeListImpl.EMPTY_NODELIST;
} else {
return new NodeListImpl(children);
}
|
public org.w3c.dom.Node | getFirstChild()The first child of this node. If there is no such node, this returns
null .
if (children != null && !children.isEmpty()) {
return (Node) children.get(0);
} else {
return null;
}
|
public org.w3c.dom.Node | getLastChild()The last child of this node. If there is no such node, this returns
null .
if (children != null && !children.isEmpty()) {
return (Node) children.get(children.size() - 1);
} else {
return null;
}
|
public java.lang.String | getLocalName()Returns the local part of the qualified name of this node.
For nodes of any type other than ELEMENT_NODE and
ATTRIBUTE_NODE and nodes created with a DOM Level 1
method, such as createElement from the
Document interface, this is always null .
return name;
|
public java.lang.String | getNamespaceURI()The namespace URI of this node, or null if it is
unspecified.
This is not a computed value that is the result of a namespace
lookup based on an examination of the namespace declarations in
scope. It is merely the namespace URI given at creation time.
For nodes of any type other than ELEMENT_NODE and
ATTRIBUTE_NODE and nodes created with a DOM Level 1
method, such as createElement from the
Document interface, this is always null .Per
the Namespaces in XML Specification an attribute does not inherit
its namespace from the element it is attached to. If an attribute is
not explicitly given a namespace, it simply has no namespace.
return (namespaceURI);
|
public org.w3c.dom.Node | getNextSibling()The node immediately following this node. If there is no such node,
this returns null .
SOAPElement parent = getParentElement();
if (parent == null) {
return null;
}
Iterator iter = parent.getChildElements();
Node nextSibling = null;
while (iter.hasNext()) {
if (iter.next() == this) {
if (iter.hasNext()) {
return (Node) iter.next();
} else {
return null;
}
}
}
return nextSibling; // should be null.
|
public java.lang.String | getNodeName()The name of this node, depending on its type; see the table above.
return (prefix != null && prefix.length() > 0) ?
prefix + ":" + name : name;
|
public short | getNodeType()A code representing the type of the underlying object, as defined above.
if (this.textRep != null) {
if (textRep instanceof Comment) {
return COMMENT_NODE;
} else if (textRep instanceof CDATASection) {
return CDATA_SECTION_NODE;
} else {
return TEXT_NODE;
}
} else if (false) {
return DOCUMENT_FRAGMENT_NODE;
} else if (false) {
return Node.ELEMENT_NODE;
} else { // most often but we cannot give prioeity now
return Node.ELEMENT_NODE;
}
|
public java.lang.String | getNodeValue()The value of this node, depending on its type; see the table above.
When it is defined to be null , setting it has no effect.
if (textRep == null) {
return null;
} else {
return textRep.getData();
}
|
public org.w3c.dom.Document | getOwnerDocument()The Document object associated with this node. This is
also the Document object used to create new nodes. When
this node is a Document or a DocumentType
which is not used with any Document yet, this is
null .
if(document == null) {
NodeImpl node = getParent();
if (node != null) {
return node.getOwnerDocument();
}
}
return document;
|
protected org.apache.axis.message.NodeImpl | getParent()get the parent node
return parent;
|
public javax.xml.soap.SOAPElement | getParentElement()Returns the parent element of this Node object.
This method can throw an UnsupportedOperationException
if the tree is not kept in memory.
return (SOAPElement) getParent();
|
public org.w3c.dom.Node | getParentNode()The parent of this node. All nodes, except Attr ,
Document , DocumentFragment ,
Entity , and Notation may have a parent.
However, if a node has just been created and not yet added to the
tree, or if it has been removed from the tree, this is
null .
return (Node) getParent();
|
public java.lang.String | getPrefix()The namespace prefix of this node, or null if it is
unspecified.
Note that setting this attribute, when permitted, changes the
nodeName attribute, which holds the qualified name, as
well as the tagName and name attributes of
the Element and Attr interfaces, when
applicable.
Note also that changing the prefix of an attribute that is known to
have a default value, does not make a new attribute with the default
value and the original prefix appear, since the
namespaceURI and localName do not change.
For nodes of any type other than ELEMENT_NODE and
ATTRIBUTE_NODE and nodes created with a DOM Level 1
method, such as createElement from the
Document interface, this is always null .
return (prefix);
|
public org.w3c.dom.Node | getPreviousSibling()The node immediately preceding this node. If there is no such node,
this returns null .
SOAPElement parent = getParentElement();
if (parent == null) {
return null;
}
NodeList nl = parent.getChildNodes();
int len = nl.getLength();
int i = 0;
Node previousSibling = null;
while (i < len) {
if (nl.item(i) == this) {
return previousSibling;
}
previousSibling = nl.item(i);
i++;
}
return previousSibling; // should be null.
|
public java.lang.String | getValue()Returns the the value of the immediate child of this Node
object if a child exists and its value is text.
return textRep.getNodeValue();
|
public boolean | hasAttributes()Returns whether this node (if it is an element) has any attributes.
return attributes.getLength() > 0;
|
public boolean | hasChildNodes()Returns whether this node has any children.
return (children != null && !children.isEmpty());
|
protected void | initializeChildren()Initialize the children array
if (children == null) {
children = new ArrayList();
}
|
public org.w3c.dom.Node | insertBefore(org.w3c.dom.Node newChild, org.w3c.dom.Node refChild)Inserts the node newChild before the existing child node
refChild . If refChild is null ,
insert newChild at the end of the list of children.
If newChild is a DocumentFragment object,
all of its children are inserted, in the same order, before
refChild . If the newChild is already in the
tree, it is first removed.
initializeChildren();
int position = children.indexOf(refChild);
if (position < 0) {
position = 0;
}
children.add(position, newChild);
setDirty();
return newChild;
|
public boolean | isDirty()get the dirty bit
return _isDirty;
|
public boolean | isSupported(java.lang.String feature, java.lang.String version)Tests whether the DOM implementation implements a specific feature and
that feature is supported by this node.
return false; //TODO: Fix this for SAAJ 1.2 Implementation
|
protected org.xml.sax.helpers.AttributesImpl | makeAttributesEditable()make the attributes editable
if (attributes == null || attributes instanceof NullAttributes) {
attributes = new AttributesImpl();
} else if (!(attributes instanceof AttributesImpl)) {
attributes = new AttributesImpl(attributes);
}
return (AttributesImpl) attributes;
|
public 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. 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.
//TODO: Fix this for SAAJ 1.2 Implementation
|
public void | output(org.apache.axis.encoding.SerializationContext context)print the contents of this node
if (textRep == null)
return;
boolean oldPretty = context.getPretty();
context.setPretty(false);
if (textRep instanceof CDATASection) {
context.writeString("<![CDATA[");
context.writeString(((org.w3c.dom.Text) textRep).getData());
context.writeString("]]>");
} else if (textRep instanceof Comment) {
context.writeString("<!--");
context.writeString(((CharacterData) textRep).getData());
context.writeString("-->");
} else if (textRep instanceof Text) {
context.writeSafeString(((Text) textRep).getData());
}
context.setPretty(oldPretty);
|
public void | recycleNode()Notifies the implementation that this Node
object is no longer being used by the application and that the
implementation is free to reuse this object for nodes that may
be created later.
Calling the method recycleNode implies that the method
detachNode has been called previously.
//TODO: Fix this for SAAJ 1.2 Implementation
|
public org.w3c.dom.Node | removeChild(org.w3c.dom.Node oldChild)Removes the child node indicated by oldChild from the list
of children, and returns it.
if (removeNodeFromChildList((NodeImpl) oldChild)) {
setDirty();
return oldChild;
}
throw new DOMException(DOMException.NOT_FOUND_ERR,
"NodeImpl Not found");
|
private boolean | removeNodeFromChildList(org.apache.axis.message.NodeImpl n)
boolean removed = false;
initializeChildren();
final Iterator itr = children.iterator();
while (itr.hasNext()) {
final NodeImpl node = (NodeImpl) itr.next();
if (node == n) {
removed = true;
itr.remove();
}
}
return removed;
|
public org.w3c.dom.Node | replaceChild(org.w3c.dom.Node newChild, org.w3c.dom.Node oldChild)Replaces the child node oldChild with newChild
in the list of children, and returns the oldChild node.
If newChild is a DocumentFragment object,
oldChild is replaced by all of the
DocumentFragment children, which are inserted in the
same order. If the newChild is already in the tree, it
is first removed.
initializeChildren();
int position = children.indexOf(oldChild);
if (position < 0) {
throw new DOMException(DOMException.NOT_FOUND_ERR,
"NodeImpl Not found");
}
children.remove(position);
children.add(position, newChild);
setDirty();
return oldChild;
|
public void | reset()
if (children != null) {
for (int i=0; i<children.size(); i++) {
((NodeImpl) children.get(i)).reset();
}
}
this._isDirty = false;
|
public void | setDirty(boolean dirty)set the dirty bit. will also set our parent as dirty, if there is one.
Note that clearing the dirty bit does not propagate upwards.
_isDirty = dirty;
if (_isDirty && parent != null) {
((NodeImpl) parent).setDirty();
}
|
public void | setDirty()
_isDirty = true;
if (parent != null) {
((NodeImpl) parent).setDirty();
}
|
public void | setNodeValue(java.lang.String nodeValue)The value of this node, depending on its type; see the table above.
When it is defined to be null , setting it has no effect.
throw new DOMException(DOMException.NO_DATA_ALLOWED_ERR,
"Cannot use TextNode.set in " + this);
|
public void | setOwnerDocument(org.w3c.dom.Document doc)Set the owner document
document = doc;
|
protected void | setParent(org.apache.axis.message.NodeImpl parent)Set the parent node and invoke appendChild(this) to
add this node to the parent's list of children.
if (this.parent == parent) {
return;
}
if (this.parent != null) {
this.parent.removeChild(this);
}
if (parent != null) {
parent.appendChild(this);
}
this.setDirty();
this.parent = parent;
|
public void | setParentElement(javax.xml.soap.SOAPElement parent)Sets the parent of this Node object to the given
SOAPElement object.
if (parent == null)
throw new IllegalArgumentException(
Messages.getMessage("nullParent00"));
try {
setParent((NodeImpl) parent);
} catch (Throwable t) {
throw new SOAPException(t);
}
|
public void | setPrefix(java.lang.String prefix)The namespace prefix of this node, or null if it is
unspecified.
Note that setting this attribute, when permitted, changes the
nodeName attribute, which holds the qualified name, as
well as the tagName and name attributes of
the Element and Attr interfaces, when
applicable.
Note also that changing the prefix of an attribute that is known to
have a default value, does not make a new attribute with the default
value and the original prefix appear, since the
namespaceURI and localName do not change.
For nodes of any type other than ELEMENT_NODE and
ATTRIBUTE_NODE and nodes created with a DOM Level 1
method, such as createElement from the
Document interface, this is always null .
this.prefix = prefix;
|
public void | setValue(java.lang.String value)If this is a Text node then this method will set its value, otherwise it
sets the value of the immediate (Text) child of this node. The value of
the immediate child of this node can be set only if, there is one child
node and that node is a Text node, or if there are no children in which
case a child Text node will be created.
if (this instanceof org.apache.axis.message.Text) {
setNodeValue(value);
} else if (children != null) {
if (children.size() != 1) {
throw new IllegalStateException( "setValue() may not be called on a non-Text node with more than one child." );
}
javax.xml.soap.Node child = (javax.xml.soap.Node) children.get(0);
if (!(child instanceof org.apache.axis.message.Text)) {
throw new IllegalStateException( "setValue() may not be called on a non-Text node with a non-Text child." );
}
((javax.xml.soap.Text)child).setNodeValue(value);
} else {
appendChild(new org.apache.axis.message.Text(value));
}
|