Java Code Examples for org.w3c.dom.DOMException#HIERARCHY_REQUEST_ERR

The following examples show how to use org.w3c.dom.DOMException#HIERARCHY_REQUEST_ERR . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InnerNodeImpl.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public Node insertBefore(Node newChild, Node refChild) throws DOMException {
    LeafNodeImpl refChildImpl = (LeafNodeImpl) refChild;

    if (refChildImpl == null) {
        return appendChild(newChild);
    }

    if (refChildImpl.document != document) {
        throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, null);
    }

    if (refChildImpl.parent != this) {
        throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, null);
    }

    return insertChildAt(newChild, refChildImpl.index);
}
 
Example 2
Source File: DomNode.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * Check for insertion errors for a new child node. This is overridden by derived
 * classes to enforce which types of children are allowed.
 *
 * @param newChild the new child node that is being inserted below this node
 * @throws DOMException HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does
 * not allow children of the type of the newChild node, or if the node to insert is one of
 * this node's ancestors or this node itself, or if this node is of type Document and the
 * DOM application attempts to insert a second DocumentType or Element node.
 * WRONG_DOCUMENT_ERR: Raised if newChild was created from a different document than the
 * one that created this node.
 */
protected void checkChildHierarchy(final Node newChild) throws DOMException {
    Node parentNode = this;
    while (parentNode != null) {
        if (parentNode == newChild) {
            throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "Child node is already a parent.");
        }
        parentNode = parentNode.getParentNode();
    }
    final Document thisDocument = getOwnerDocument();
    final Document childDocument = newChild.getOwnerDocument();
    if (childDocument != thisDocument && childDocument != null) {
        throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, "Child node " + newChild.getNodeName()
            + " is not in the same Document as this " + getNodeName() + ".");
    }
}
 
Example 3
Source File: HtmlPage.java    From HtmlUnit-Android with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void checkChildHierarchy(final org.w3c.dom.Node newChild) throws DOMException {
    if (newChild instanceof Element) {
        if (getDocumentElement() != null) {
            throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
                "The Document may only have a single child Element.");
        }
    }
    else if (newChild instanceof DocumentType) {
        if (getDoctype() != null) {
            throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
                "The Document may only have a single child DocumentType.");
        }
    }
    else if (!(newChild instanceof Comment || newChild instanceof ProcessingInstruction)) {
        throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
            "The Document may not have a child of this type: " + newChild.getNodeType());
    }
    super.checkChildHierarchy(newChild);
}
 
Example 4
Source File: CoreDocumentImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Since we cache the docElement (and, currently, docType),
 * replaceChild has to update the cache
 *
 * REVISIT: According to the spec it is not allowed to alter neither the
 * document element nor the document type in any way
 */
public Node replaceChild(Node newChild, Node oldChild)
throws DOMException {

    // Adopt orphan doctypes
    if (newChild.getOwnerDocument() == null &&
    newChild instanceof DocumentTypeImpl) {
        ((DocumentTypeImpl) newChild).ownerDocument = this;
    }

    if (errorChecking &&((docType != null &&
        oldChild.getNodeType() != Node.DOCUMENT_TYPE_NODE &&
        newChild.getNodeType() == Node.DOCUMENT_TYPE_NODE)
        || (docElement != null &&
        oldChild.getNodeType() != Node.ELEMENT_NODE &&
        newChild.getNodeType() == Node.ELEMENT_NODE))) {

        throw new DOMException(
            DOMException.HIERARCHY_REQUEST_ERR,
            DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "HIERARCHY_REQUEST_ERR", null));
    }
    super.replaceChild(newChild, oldChild);

    int type = oldChild.getNodeType();
    if(type == Node.ELEMENT_NODE) {
        docElement = (ElementImpl)newChild;
    }
    else if (type == Node.DOCUMENT_TYPE_NODE) {
        docType = (DocumentTypeImpl)newChild;
    }
    return oldChild;
}
 
Example 5
Source File: DocumentImpl.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Document elements may have at most one root element and at most one DTD
 * element.
 */
@Override public Node insertChildAt(Node toInsert, int index) {
    if (toInsert instanceof Element && getDocumentElement() != null) {
        throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
                "Only one root element allowed");
    }
    if (toInsert instanceof DocumentType && getDoctype() != null) {
        throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
                "Only one DOCTYPE element allowed");
    }
    return super.insertChildAt(toInsert, index);
}
 
Example 6
Source File: CoreDocumentImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Since a Document may contain at most one top-level Element child,
 * and at most one DocumentType declaraction, we need to subclass our
 * add-children methods to implement this constraint.
 * Since appendChild() is implemented as insertBefore(,null),
 * altering the latter fixes both.
 * <p>
 * While I'm doing so, I've taken advantage of the opportunity to
 * cache documentElement and docType so we don't have to
 * search for them.
 *
 * REVISIT: According to the spec it is not allowed to alter neither the
 * document element nor the document type in any way
 */
public Node insertBefore(Node newChild, Node refChild)
        throws DOMException {

    // Only one such child permitted
    int type = newChild.getNodeType();
    if (errorChecking) {
        if((type == Node.ELEMENT_NODE && docElement != null) ||
        (type == Node.DOCUMENT_TYPE_NODE && docType != null)) {
            String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "HIERARCHY_REQUEST_ERR", null);
            throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, msg);
        }
    }
    // Adopt orphan doctypes
    if (newChild.getOwnerDocument() == null &&
    newChild instanceof DocumentTypeImpl) {
        ((DocumentTypeImpl) newChild).ownerDocument = this;
    }
    super.insertBefore(newChild,refChild);

    // If insert succeeded, cache the kid appropriately
    if (type == Node.ELEMENT_NODE) {
        docElement = (ElementImpl)newChild;
    }
    else if (type == Node.DOCUMENT_TYPE_NODE) {
        docType = (DocumentTypeImpl)newChild;
    }

    return newChild;

}
 
Example 7
Source File: CoreDocumentImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Since we cache the docElement (and, currently, docType),
 * replaceChild has to update the cache
 *
 * REVISIT: According to the spec it is not allowed to alter neither the
 * document element nor the document type in any way
 */
public Node replaceChild(Node newChild, Node oldChild)
        throws DOMException {

    // Adopt orphan doctypes
    if (newChild.getOwnerDocument() == null &&
    newChild instanceof DocumentTypeImpl) {
        ((DocumentTypeImpl) newChild).ownerDocument = this;
    }

    if (errorChecking &&((docType != null &&
        oldChild.getNodeType() != Node.DOCUMENT_TYPE_NODE &&
        newChild.getNodeType() == Node.DOCUMENT_TYPE_NODE)
        || (docElement != null &&
        oldChild.getNodeType() != Node.ELEMENT_NODE &&
        newChild.getNodeType() == Node.ELEMENT_NODE))) {

        throw new DOMException(
                DOMException.HIERARCHY_REQUEST_ERR,
                DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "HIERARCHY_REQUEST_ERR", null));
    }
    super.replaceChild(newChild, oldChild);

    int type = oldChild.getNodeType();
    if(type == Node.ELEMENT_NODE) {
        docElement = (ElementImpl)newChild;
    }
    else if (type == Node.DOCUMENT_TYPE_NODE) {
        docType = (DocumentTypeImpl)newChild;
    }
    return oldChild;
}
 
Example 8
Source File: RangeImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Utility method for traversing a single node when
 * we know a-priori that the node if fully
 * selected.
 *
 * @param n      The node to be traversed.
 *
 * @param how    Specifies what type of traversal is being
 *               requested (extract, clone, or delete).
 *               Legal values for this argument are:
 *
 *               <ol>
 *               <li><code>EXTRACT_CONTENTS</code> - will simply
 *               return the original node.
 *
 *               <li><code>CLONE_CONTENTS</code> - will leave the
 *               context tree of the range undisturbed, but will
 *               return a cloned node.
 *
 *               <li><code>DELETE_CONTENTS</code> - will delete the
 *               node from it's parent, but will return null.
 *               </ol>
 *
 * @return Returns a node that is the result of visiting the node.
 *         If the traversal operation is
 *         <code>DELETE_CONTENTS</code> the return value is null.
 */
private Node traverseFullySelected( Node n, int how )
{
    switch( how )
    {
    case CLONE_CONTENTS:
        return n.cloneNode( true );
    case EXTRACT_CONTENTS:
        if ( n.getNodeType()==Node.DOCUMENT_TYPE_NODE )
        {
            // TBD: This should be a HIERARCHY_REQUEST_ERR
            throw new DOMException(
                    DOMException.HIERARCHY_REQUEST_ERR,
            DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "HIERARCHY_REQUEST_ERR", null));
        }
        return n;
    case DELETE_CONTENTS:
        n.getParentNode().removeChild(n);
        return null;
    }
    return null;
}
 
Example 9
Source File: TransformXPath.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Method enginePerformTransform
 * @inheritDoc
 * @param input
 *
 * @throws TransformationException
 */
protected XMLSignatureInput enginePerformTransform(
    XMLSignatureInput input, OutputStream os, Transform transformObject
) throws TransformationException {
    try {
        /**
         * If the actual input is an octet stream, then the application MUST
         * convert the octet stream to an XPath node-set suitable for use by
         * Canonical XML with Comments. (A subsequent application of the
         * REQUIRED Canonical XML algorithm would strip away these comments.)
         *
         * ...
         *
         * The evaluation of this expression includes all of the document's nodes
         * (including comments) in the node-set representing the octet stream.
         */
        Element xpathElement =
            XMLUtils.selectDsNode(
                transformObject.getElement().getFirstChild(), Constants._TAG_XPATH, 0);

        if (xpathElement == null) {
            Object exArgs[] = { "ds:XPath", "Transform" };

            throw new TransformationException("xml.WrongContent", exArgs);
        }
        Node xpathnode = xpathElement.getChildNodes().item(0);
        String str = XMLUtils.getStrFromNode(xpathnode);
        input.setNeedsToBeExpanded(needsCircumvent(str));
        if (xpathnode == null) {
            throw new DOMException(
                DOMException.HIERARCHY_REQUEST_ERR, "Text must be in ds:Xpath"
            );
        }

        XPathFactory xpathFactory = XPathFactory.newInstance();
        XPathAPI xpathAPIInstance = xpathFactory.newXPathAPI();
        input.addNodeFilter(new XPathNodeFilter(xpathElement, xpathnode, str, xpathAPIInstance));
        input.setNodeSet(true);
        return input;
    } catch (DOMException ex) {
        throw new TransformationException("empty", ex);
    }
}
 
Example 10
Source File: TransformXPath.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Method enginePerformTransform
 * @inheritDoc
 * @param input
 *
 * @throws TransformationException
 */
protected XMLSignatureInput enginePerformTransform(
    XMLSignatureInput input, OutputStream os, Transform transformObject
) throws TransformationException {
    try {
        /**
         * If the actual input is an octet stream, then the application MUST
         * convert the octet stream to an XPath node-set suitable for use by
         * Canonical XML with Comments. (A subsequent application of the
         * REQUIRED Canonical XML algorithm would strip away these comments.)
         *
         * ...
         *
         * The evaluation of this expression includes all of the document's nodes
         * (including comments) in the node-set representing the octet stream.
         */
        Element xpathElement =
            XMLUtils.selectDsNode(
                transformObject.getElement().getFirstChild(), Constants._TAG_XPATH, 0);

        if (xpathElement == null) {
            Object exArgs[] = { "ds:XPath", "Transform" };

            throw new TransformationException("xml.WrongContent", exArgs);
        }
        Node xpathnode = xpathElement.getChildNodes().item(0);
        String str = XMLUtils.getStrFromNode(xpathnode);
        input.setNeedsToBeExpanded(needsCircumvent(str));
        if (xpathnode == null) {
            throw new DOMException(
                DOMException.HIERARCHY_REQUEST_ERR, "Text must be in ds:Xpath"
            );
        }

        XPathFactory xpathFactory = XPathFactory.newInstance();
        XPathAPI xpathAPIInstance = xpathFactory.newXPathAPI();
        input.addNodeFilter(new XPathNodeFilter(xpathElement, xpathnode, str, xpathAPIInstance));
        input.setNodeSet(true);
        return input;
    } catch (DOMException ex) {
        throw new TransformationException("empty", ex);
    }
}
 
Example 11
Source File: RangeImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Utility method for traversing a single node when
 * we know a-priori that the node if fully
 * selected.
 *
 * @param n      The node to be traversed.
 *
 * @param how    Specifies what type of traversal is being
 *               requested (extract, clone, or delete).
 *               Legal values for this argument are:
 *
 *               <ol>
 *               <li><code>EXTRACT_CONTENTS</code> - will simply
 *               return the original node.
 *
 *               <li><code>CLONE_CONTENTS</code> - will leave the
 *               context tree of the range undisturbed, but will
 *               return a cloned node.
 *
 *               <li><code>DELETE_CONTENTS</code> - will delete the
 *               node from it's parent, but will return null.
 *               </ol>
 *
 * @return Returns a node that is the result of visiting the node.
 *         If the traversal operation is
 *         <code>DELETE_CONTENTS</code> the return value is null.
 */
private Node traverseFullySelected( Node n, int how )
{
    switch( how )
    {
    case CLONE_CONTENTS:
        return n.cloneNode( true );
    case EXTRACT_CONTENTS:
        if ( n.getNodeType()==Node.DOCUMENT_TYPE_NODE )
        {
            // TBD: This should be a HIERARCHY_REQUEST_ERR
            throw new DOMException(
                    DOMException.HIERARCHY_REQUEST_ERR,
            DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "HIERARCHY_REQUEST_ERR", null));
        }
        return n;
    case DELETE_CONTENTS:
        n.getParentNode().removeChild(n);
        return null;
    }
    return null;
}
 
Example 12
Source File: CommentImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected NodeImpl getChildIfPermitted( Node proposedChild ) {
    throw new DOMException( DOMException.HIERARCHY_REQUEST_ERR, "Comment nodes may not have children" );
}
 
Example 13
Source File: NodeImpl.java    From j2objc with Apache License 2.0 4 votes vote down vote up
public Node removeChild(Node oldChild) throws DOMException {
    throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, null);
}
 
Example 14
Source File: TransformXPath.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Method enginePerformTransform
 * @inheritDoc
 * @param input
 *
 * @throws TransformationException
 */
protected XMLSignatureInput enginePerformTransform(
    XMLSignatureInput input, OutputStream os, Transform transformObject
) throws TransformationException {
    try {
        /**
         * If the actual input is an octet stream, then the application MUST
         * convert the octet stream to an XPath node-set suitable for use by
         * Canonical XML with Comments. (A subsequent application of the
         * REQUIRED Canonical XML algorithm would strip away these comments.)
         *
         * ...
         *
         * The evaluation of this expression includes all of the document's nodes
         * (including comments) in the node-set representing the octet stream.
         */
        Element xpathElement =
            XMLUtils.selectDsNode(
                transformObject.getElement().getFirstChild(), Constants._TAG_XPATH, 0);

        if (xpathElement == null) {
            Object exArgs[] = { "ds:XPath", "Transform" };

            throw new TransformationException("xml.WrongContent", exArgs);
        }
        Node xpathnode = xpathElement.getChildNodes().item(0);
        String str = XMLUtils.getStrFromNode(xpathnode);
        input.setNeedsToBeExpanded(needsCircumvent(str));
        if (xpathnode == null) {
            throw new DOMException(
                DOMException.HIERARCHY_REQUEST_ERR, "Text must be in ds:Xpath"
            );
        }

        XPathFactory xpathFactory = XPathFactory.newInstance();
        XPathAPI xpathAPIInstance = xpathFactory.newXPathAPI();
        input.addNodeFilter(new XPathNodeFilter(xpathElement, xpathnode, str, xpathAPIInstance));
        input.setNodeSet(true);
        return input;
    } catch (DOMException ex) {
        throw new TransformationException("empty", ex);
    }
}
 
Example 15
Source File: RangeImpl.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Utility method for traversing a single node when
 * we know a-priori that the node if fully
 * selected.
 *
 * @param n      The node to be traversed.
 *
 * @param how    Specifies what type of traversal is being
 *               requested (extract, clone, or delete).
 *               Legal values for this argument are:
 *
 *               <ol>
 *               <li><code>EXTRACT_CONTENTS</code> - will simply
 *               return the original node.
 *
 *               <li><code>CLONE_CONTENTS</code> - will leave the
 *               context tree of the range undisturbed, but will
 *               return a cloned node.
 *
 *               <li><code>DELETE_CONTENTS</code> - will delete the
 *               node from it's parent, but will return null.
 *               </ol>
 *
 * @return Returns a node that is the result of visiting the node.
 *         If the traversal operation is
 *         <code>DELETE_CONTENTS</code> the return value is null.
 */
private Node traverseFullySelected( Node n, int how )
{
    switch( how )
    {
    case CLONE_CONTENTS:
        return n.cloneNode( true );
    case EXTRACT_CONTENTS:
        if ( n.getNodeType()==Node.DOCUMENT_TYPE_NODE )
        {
            // TBD: This should be a HIERARCHY_REQUEST_ERR
            throw new DOMException(
                    DOMException.HIERARCHY_REQUEST_ERR,
            DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "HIERARCHY_REQUEST_ERR", null));
        }
        return n;
    case DELETE_CONTENTS:
        n.getParentNode().removeChild(n);
        return null;
    }
    return null;
}
 
Example 16
Source File: TransformXPath.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Method enginePerformTransform
 * @inheritDoc
 * @param input
 *
 * @throws TransformationException
 */
protected XMLSignatureInput enginePerformTransform(
    XMLSignatureInput input, OutputStream os, Transform transformObject
) throws TransformationException {
    try {
        /**
         * If the actual input is an octet stream, then the application MUST
         * convert the octet stream to an XPath node-set suitable for use by
         * Canonical XML with Comments. (A subsequent application of the
         * REQUIRED Canonical XML algorithm would strip away these comments.)
         *
         * ...
         *
         * The evaluation of this expression includes all of the document's nodes
         * (including comments) in the node-set representing the octet stream.
         */
        Element xpathElement =
            XMLUtils.selectDsNode(
                transformObject.getElement().getFirstChild(), Constants._TAG_XPATH, 0);

        if (xpathElement == null) {
            Object exArgs[] = { "ds:XPath", "Transform" };

            throw new TransformationException("xml.WrongContent", exArgs);
        }
        Node xpathnode = xpathElement.getChildNodes().item(0);
        String str = XMLUtils.getStrFromNode(xpathnode);
        input.setNeedsToBeExpanded(needsCircumvent(str));
        if (xpathnode == null) {
            throw new DOMException(
                DOMException.HIERARCHY_REQUEST_ERR, "Text must be in ds:Xpath"
            );
        }

        XPathFactory xpathFactory = XPathFactory.newInstance();
        XPathAPI xpathAPIInstance = xpathFactory.newXPathAPI();
        input.addNodeFilter(new XPathNodeFilter(xpathElement, xpathnode, str, xpathAPIInstance));
        input.setNodeSet(true);
        return input;
    } catch (DOMException ex) {
        throw new TransformationException("empty", ex);
    }
}
 
Example 17
Source File: NodeImpl.java    From openjdk-8-source with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Make newChild occupy the location that oldChild used to
 * have. Note that newChild will first be removed from its previous
 * parent, if any. Equivalent to inserting newChild before oldChild,
 * then removing oldChild.
 * <P>
 * By default we do not have any children, ParentNode overrides this.
 * @see ParentNode
 *
 * @return oldChild, in its new state (removed).
 *
 * @throws 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.
 *
 * @throws DOMException(WRONG_DOCUMENT_ERR) if newChild has a
 * different owner document than we do.
 *
 * @throws DOMException(NOT_FOUND_ERR) if oldChild is not a child of
 * this node.
 *
 * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if this node is
 * read-only.
 */
public Node replaceChild(Node newChild, Node oldChild)
    throws DOMException {
    throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
          DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN,
             "HIERARCHY_REQUEST_ERR", null));
}
 
Example 18
Source File: NodeImpl.java    From JDKSourceCode1.8 with MIT License 3 votes vote down vote up
/**
 * Move one or more node(s) to our list of children. Note that this
 * implicitly removes them from their previous parent.
 * <P>
 * By default we do not accept any children, ParentNode overrides this.
 * @see ParentNode
 *
 * @param newChild The Node to be moved to our subtree. As a
 * convenience feature, inserting a DocumentNode will instead insert
 * all its children.
 *
 * @param refChild Current child which newChild should be placed
 * immediately before. If refChild is null, the insertion occurs
 * after all existing Nodes, like appendChild().
 *
 * @return newChild, in its new state (relocated, or emptied in the case of
 * DocumentNode.)
 *
 * @throws 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.
 *
 * @throws DOMException(WRONG_DOCUMENT_ERR) if newChild has a
 * different owner document than we do.
 *
 * @throws DOMException(NOT_FOUND_ERR) if refChild is not a child of
 * this node.
 *
 * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if this node is
 * read-only.
 */
public Node insertBefore(Node newChild, Node refChild)
    throws DOMException {
    throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
          DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN,
             "HIERARCHY_REQUEST_ERR", null));
}
 
Example 19
Source File: NodeImpl.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Make newChild occupy the location that oldChild used to
 * have. Note that newChild will first be removed from its previous
 * parent, if any. Equivalent to inserting newChild before oldChild,
 * then removing oldChild.
 * <P>
 * By default we do not have any children, ParentNode overrides this.
 * @see ParentNode
 *
 * @return oldChild, in its new state (removed).
 *
 * @throws 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.
 *
 * @throws DOMException(WRONG_DOCUMENT_ERR) if newChild has a
 * different owner document than we do.
 *
 * @throws DOMException(NOT_FOUND_ERR) if oldChild is not a child of
 * this node.
 *
 * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if this node is
 * read-only.
 */
public Node replaceChild(Node newChild, Node oldChild)
    throws DOMException {
    throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
          DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN,
             "HIERARCHY_REQUEST_ERR", null));
}
 
Example 20
Source File: NodeImpl.java    From jdk1.8-source-analysis with Apache License 2.0 3 votes vote down vote up
/**
 * Make newChild occupy the location that oldChild used to
 * have. Note that newChild will first be removed from its previous
 * parent, if any. Equivalent to inserting newChild before oldChild,
 * then removing oldChild.
 * <P>
 * By default we do not have any children, ParentNode overrides this.
 * @see ParentNode
 *
 * @return oldChild, in its new state (removed).
 *
 * @throws 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.
 *
 * @throws DOMException(WRONG_DOCUMENT_ERR) if newChild has a
 * different owner document than we do.
 *
 * @throws DOMException(NOT_FOUND_ERR) if oldChild is not a child of
 * this node.
 *
 * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if this node is
 * read-only.
 */
public Node replaceChild(Node newChild, Node oldChild)
    throws DOMException {
    throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
          DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN,
             "HIERARCHY_REQUEST_ERR", null));
}