Methods Summary |
---|
public void | add(ElementNode element)Appends an element at the end of the list
if (element == null) {
throw new NullPointerException();
}
element.preValidate();
if (firstChild == null) {
firstChild = element;
lastChild = element;
element.nextSibling = null;
element.prevSibling = null;
} else {
lastChild.nextSibling = element;
element.nextSibling = null;
element.prevSibling = lastChild;
lastChild = element;
}
// An insertion event is triggered from the setParent call.
element.setParent(this);
|
public org.w3c.dom.Node | appendChild(org.w3c.dom.Node newChild)
return insertBefore(newChild, null);
|
protected void | clearLayouts()Clears the text layouts, if any exist. This is typically
called when the font selection has changed and nodes such
as Text should recompute their layouts.
This should recursively call clearLayouts on children
node or expanded content, if any.
clearLayouts(firstChild);
|
public ModelNode | getFirstChildNode()
return firstChild;
|
public ModelNode | getLastChildNode()
return lastChild;
|
public abstract java.lang.String | getLocalName()
|
public abstract java.lang.String | getNamespaceURI()
|
public abstract org.w3c.dom.Node | getParentNode()Returns the parent Node of this Node .
|
public org.w3c.dom.Node | insertBefore(org.w3c.dom.Node newChild, org.w3c.dom.Node refChild)
if (newChild == null) {
throw new NullPointerException();
}
if (newChild == ownerDocument) {
throw new DOMException
(DOMException.HIERARCHY_REQUEST_ERR,
Messages.formatMessage
(Messages.ERROR_CANNOT_INSERT_DOCUMENT_NODE,
null));
}
// The DocumentNode class can only create ElementNode instances. If we
// are dealing with an object which is not an ElementNode instance, we
// know we are dealing with something in the wrong document.
if (!(newChild instanceof ElementNode)) {
throw new DOMException
(DOMException.WRONG_DOCUMENT_ERR,
Messages.formatMessage
(Messages.ERROR_CANNOT_INSERT_FROM_OTHER_DOCUMENT,
null));
}
ElementNode newNode = (ElementNode) newChild;
// Check if newNode belongs to the same document.
if (newNode.ownerDocument != ownerDocument) {
throw new DOMException
(DOMException.WRONG_DOCUMENT_ERR,
Messages.formatMessage
(Messages.ERROR_CANNOT_INSERT_FROM_OTHER_DOCUMENT,
null));
}
// Check if the newNode is of a type allowed by this Node
// implementation.
if (!isAllowedChild(newNode)) {
throw new DOMException
(DOMException.HIERARCHY_REQUEST_ERR,
Messages.formatMessage
(Messages.ERROR_CHILD_NOT_ALLOWED,
new String[] {newNode.getLocalName(),
newNode.getNamespaceURI(),
getLocalName(),
getNamespaceURI()}));
}
// Check if the newNode is one of this node's ancestor, or the
// node itself.
if (isAncestor(newNode)) {
throw new DOMException
(DOMException.HIERARCHY_REQUEST_ERR,
Messages.formatMessage
(Messages.ERROR_INSERTING_ANCESTOR,
null));
}
// Check if this node is of type document and already has a child.
if (this == ownerDocument) {
if (firstChild != null) {
throw new DOMException
(DOMException.HIERARCHY_REQUEST_ERR,
Messages.formatMessage
(Messages.ERROR_INSERTING_UNDER_DOCUMENT, null));
}
}
// Check refChild if refChild is not null
if (refChild != null) {
if (!isChild(refChild)) {
throw new DOMException
(DOMException.NOT_FOUND_ERR,
Messages.formatMessage
(Messages.ERROR_REF_NODE_NOT_A_CHILD, null));
}
}
// Check that newChild is _not_ a child of the DocumentNode
if (newNode.parent == ownerDocument) {
throw new DOMException
(DOMException.NOT_SUPPORTED_ERR,
Messages.formatMessage
(Messages.ERROR_INSERTING_DOCUMENT_ELEMENT,
null));
}
// If the inserted node already has a parent, remove the node
// from its current parent.
if (newNode.parent != null) {
((CompositeNode) newNode.parent).removeChild(newNode);
}
if (refChild == null) {
// Performs the Use xlink:href attribute validation
add(newNode);
} else {
// Because refChild's parent is this node, we know it has to
// be an ElementNode. So the following cast is safe. See
// isChild call above.
ElementNode refNode = (ElementNode) refChild;
newNode.prevSibling = refNode.prevSibling;
newNode.nextSibling = refNode;
if (refNode.prevSibling != null) {
// refNode is _not_ the first node
refNode.prevSibling.nextSibling = newNode;
} else {
// refNode _is_ the first node
firstChild = newNode;
}
refNode.prevSibling = newNode;
newNode.nextSibling = refNode;
// An insertion event is triggered from the setParent call
newNode.setParent(this);
}
return newChild;
|
protected boolean | isAllowedChild(ElementNode node)Implementation helper. By default, we only disallow SVG nodes under
all nodes except DocumentNode.
if (node instanceof SVG) {
return false;
}
return true;
|
final boolean | isAncestor(ElementNode node)Implementation helper.
if (node == this) {
return true;
} else if (parent != null) {
return ((CompositeNode) parent).isAncestor(node);
} else {
return false;
}
|
final boolean | isChild(org.w3c.dom.Node node)Implementation helper.
ElementNode c = firstChild;
while (c != null) {
if (c == node) {
return true;
}
c = (ElementNode) c.nextSibling;
}
return false;
|
protected static boolean | isIdBranch(ElementNode node)
if (node.id != null) {
return true;
}
ElementNode c = node.firstChild;
while (c != null) {
if (isIdBranch(c)) {
return true;
} else {
c = (ElementNode) c.nextSibling;
}
}
return false;
|
protected boolean | isRemoveChildSupported()
return true;
|
void | nodeHookedInDocumentTree()To be overriddent by derived classes, such as TimedElementNode,
if they need to do special operations when hooked into the
document tree.
|
void | nodeUnhookedFromDocumentTree()To be overriddent by derived classes, such as TimedElementNode,
if they need to do special operations when unhooked from the
document tree.
|
final void | onHookedInDocumentTree()When a CompositeNode is hooked into the document tree, by default,
it notifies its children and calls its own nodeHookedInDocumentTree
method.
super.onHookedInDocumentTree();
nodeHookedInDocumentTree();
ModelNode c = getFirstExpandedChild();
while (c != null) {
c.onHookedInDocumentTree();
c = c.nextSibling;
}
c = getFirstChildNode();
while (c != null) {
c.onHookedInDocumentTree();
c = c.nextSibling;
}
|
final void | onUnhookedFromDocumentTree()When a CompositeNode is hooked into the document tree, by default,
it notifies its children and calls its own nodeUnhookedFromDocumentTree
method.
super.onUnhookedFromDocumentTree();
nodeUnhookedFromDocumentTree();
ModelNode c = getFirstExpandedChild();
while (c != null) {
c.onUnhookedFromDocumentTree();
c = c.nextSibling;
}
c = getFirstChildNode();
while (c != null) {
c.onUnhookedFromDocumentTree();
c = c.nextSibling;
}
|
public org.w3c.dom.Node | removeChild(org.w3c.dom.Node oldChild)
// First, check if this is indeed a child of this node.
if (!isChild(oldChild)) {
if (oldChild == null) {
throw new NullPointerException();
}
throw new DOMException(
DOMException.NOT_FOUND_ERR,
Messages.formatMessage(Messages.ERROR_NOT_A_CHILD, null));
}
// Now, check if this is a supported operation
if (!isRemoveChildSupported()) {
throw new DOMException
(DOMException.NOT_SUPPORTED_ERR,
Messages.formatMessage(
Messages.ERROR_REMOVE_CHILD_NOT_SUPPORTED,
new String[] {
getLocalName(),
getNamespaceURI()
}));
}
// Check if the removed child, or one of its descendants, has
// an identifier.
ElementNode oldNode = (ElementNode) oldChild;
if (isIdBranch(oldNode)) {
throw new DOMException(
DOMException.INVALID_ACCESS_ERR,
Messages.formatMessage(
Messages.ERROR_CANNOT_REMOVE_NODE_WITH_ID,
null));
}
if (oldNode.nextSibling != null) {
oldNode.nextSibling.prevSibling = oldNode.prevSibling;
} else {
lastChild = (ElementNode) oldNode.prevSibling;
}
if (oldNode.prevSibling != null) {
oldNode.prevSibling.nextSibling = oldNode.nextSibling;
} else {
firstChild = (ElementNode) oldNode.nextSibling;
}
oldNode.nextSibling = null;
oldNode.prevSibling = null;
oldNode.setParent(null);
return oldChild;
|
protected void | unhookChildrenQuiet()Utility method. Unhooks the children.
unhookQuiet(firstChild);
firstChild = null;
lastChild = null;
|