1132 lines · 32.3 KB · Java
RawDownload
        }         ++numChildren;        return newChildNode;    }     /**     * Replaces the child node <code>oldChild</code> with     * <code>newChild</code> in the list of children, and returns the     * <code>oldChild</code> node.     *     * @param newChild the <code>Node</code> to insert.     * @param oldChild the <code>Node</code> to be replaced.     *     * @return the node replaced.     *     * @exception IllegalArgumentException if <code>newChild</code> is     * <code>null</code>.     */    public Node replaceChild(Node newChild,                             Node oldChild) {        if (newChild == null) {            throw new IllegalArgumentException("newChild == null!");        }         checkNode(newChild);        checkNode(oldChild);         IIOMetadataNode newChildNode = (IIOMetadataNode)newChild;        IIOMetadataNode oldChildNode = (IIOMetadataNode)oldChild;         IIOMetadataNode previous = oldChildNode.previousSibling;        IIOMetadataNode next = oldChildNode.nextSibling;         if (previous != null) {            previous.nextSibling = newChildNode;        }        if (next != null) {            next.previousSibling = newChildNode;        }         newChildNode.parent = this;        newChildNode.previousSibling = previous;        newChildNode.nextSibling = next;         if (firstChild == oldChildNode) {            firstChild = newChildNode;        }        if (lastChild == oldChildNode) {            lastChild = newChildNode;        }         oldChildNode.parent = null;        oldChildNode.previousSibling = null;        oldChildNode.nextSibling = null;         return oldChildNode;    }     /**     * Removes the child node indicated by <code>oldChild</code> from     * the list of children, and returns it.     *     * @param oldChild the <code>Node</code> to be removed.     *     * @return the node removed.     *     * @exception IllegalArgumentException if <code>oldChild</code> is     * <code>null</code>.     */    public Node removeChild(Node oldChild) {        if (oldChild == null) {            throw new IllegalArgumentException("oldChild == null!");        }        checkNode(oldChild);         IIOMetadataNode oldChildNode = (IIOMetadataNode)oldChild;         IIOMetadataNode previous = oldChildNode.previousSibling;        IIOMetadataNode next = oldChildNode.nextSibling;         if (previous != null) {            previous.nextSibling = next;        }        if (next != null) {            next.previousSibling = previous;        }         if (this.firstChild == oldChildNode) {            this.firstChild = next;        }        if (this.lastChild == oldChildNode) {            this.lastChild = previous;        }         oldChildNode.parent = null;        oldChildNode.previousSibling = null;        oldChildNode.nextSibling = null;         --numChildren;        return oldChildNode;    }     /**     * Adds the node <code>newChild</code> to the end of the list of     * children of this node.     *     * @param newChild the <code>Node</code> to insert.     *     * @return the node added.     *     * @exception IllegalArgumentException if <code>newChild</code> is     * <code>null</code>.     */    public Node appendChild(Node newChild) {        if (newChild == null) {            throw new IllegalArgumentException("newChild == null!");        }        checkNode(newChild);         // insertBefore will increment numChildren        return insertBefore(newChild, null);    }     /**     * Returns <code>true</code> if this node has child nodes.     *     * @return <code>true</code> if this node has children.     */    public boolean hasChildNodes() {        return numChildren > 0;    }     /**     * Returns a duplicate of this node.  The duplicate node has no     * parent (<code>getParentNode</code> returns <code>null</code>).     * If a shallow clone is being performed (<code>deep</code> is     * <code>false</code>), the new node will not have any children or     * siblings.  If a deep clone is being performed, the new node     * will form the root of a complete cloned subtree.     *     * @param deep if <code>true</code>, recursively clone the subtree     * under the specified node; if <code>false</code>, clone only the     * node itself.     *     * @return the duplicate node.     */    public Node cloneNode(boolean deep) {        IIOMetadataNode newNode = new IIOMetadataNode(this.nodeName);        newNode.setUserObject(getUserObject());        // Attributes         if (deep) {            for (IIOMetadataNode child = firstChild;                 child != null;                 child = child.nextSibling) {                newNode.appendChild(child.cloneNode(true));            }        }         return newNode;    }     /**     * Does nothing, since <code>IIOMetadataNode</code>s do not     * contain <code>Text</code> children.     */    public void normalize() {    }     /**     * Returns <code>false</code> since DOM features are not     * supported.     *     * @return <code>false</code>.     *     * @param feature a <code>String</code>, which is ignored.     * @param version a <code>String</code>, which is ignored.     */    public boolean isSupported(String feature, String version) {        return false;    }     /**     * Returns <code>null</code>, since namespaces are not supported.     */    public String getNamespaceURI() throws DOMException {        return null;    }     /**     * Returns <code>null</code>, since namespaces are not supported.     *     * @return <code>null</code>.     *     * @see #setPrefix     */    public String getPrefix() {        return null;    }     /**     * Does nothing, since namespaces are not supported.     *     * @param prefix a <code>String</code>, which is ignored.     *     * @see #getPrefix     */    public void setPrefix(String prefix) {    }     /**     * Equivalent to <code>getNodeName</code>.     *     * @return the node name, as a <code>String</code>.     */    public String getLocalName() {        return nodeName;    }     // Methods from Element      /**     * Equivalent to <code>getNodeName</code>.     *     * @return the node name, as a <code>String</code>     */    public String getTagName() {        return nodeName;    }     /**     * Retrieves an attribute value by name.     * @param name The name of the attribute to retrieve.     * @return The <code>Attr</code> value as a string, or the empty string     * if that attribute does not have a specified or default value.     */    public String getAttribute(String name) {        Attr attr = getAttributeNode(name);        if (attr == null) {            return "";        }        return attr.getValue();    }     /**     * Equivalent to <code>getAttribute(localName)</code>.     *     * @see #setAttributeNS     */    public String getAttributeNS(String namespaceURI, String localName) {        return getAttribute(localName);    }     public void setAttribute(String name, String value) {        // Name must be valid unicode chars        boolean valid = true;        char[] chs = name.toCharArray();        for (int i=0;i<chs.length;i++) {            if (chs[i] >= 0xfffe) {                valid = false;                break;            }        }        if (!valid) {            throw new IIODOMException(DOMException.INVALID_CHARACTER_ERR,                                      "Attribute name is illegal!");        }        removeAttribute(name, false);        attributes.add(new IIOAttr(this, name, value));    }     /**     * Equivalent to <code>setAttribute(qualifiedName, value)</code>.     *     * @see #getAttributeNS     */    public void setAttributeNS(String namespaceURI,                               String qualifiedName, String value) {        setAttribute(qualifiedName, value);    }     public void removeAttribute(String name) {        removeAttribute(name, true);    }     private void removeAttribute(String name, boolean checkPresent) {        int numAttributes = attributes.size();        for (int i = 0; i < numAttributes; i++) {            IIOAttr attr = (IIOAttr)attributes.get(i);            if (name.equals(attr.getName())) {                attr.setOwnerElement(null);                attributes.remove(i);                return;            }        }         // If we get here, the attribute doesn't exist        if (checkPresent) {            throw new IIODOMException(DOMException.NOT_FOUND_ERR,                                      "No such attribute!");        }    }     /**     * Equivalent to <code>removeAttribute(localName)</code>.     */    public void removeAttributeNS(String namespaceURI,                                  String localName) {        removeAttribute(localName);    }     public Attr getAttributeNode(String name) {        Node node = getAttributes().getNamedItem(name);        return (Attr)node;    }     /**     * Equivalent to <code>getAttributeNode(localName)</code>.     *     * @see #setAttributeNodeNS     */   public Attr getAttributeNodeNS(String namespaceURI,                                   String localName) {        return getAttributeNode(localName);    }     public Attr setAttributeNode(Attr newAttr) throws DOMException {        Element owner = newAttr.getOwnerElement();        if (owner != null) {            if (owner == this) {                return null;            } else {                throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR,                                       "Attribute is already in use");            }        }         IIOAttr attr;        if (newAttr instanceof IIOAttr) {            attr = (IIOAttr)newAttr;            attr.setOwnerElement(this);        } else {            attr = new IIOAttr(this,                               newAttr.getName(),                               newAttr.getValue());        }         Attr oldAttr = getAttributeNode(attr.getName());        if (oldAttr != null) {            removeAttributeNode(oldAttr);        }         attributes.add(attr);         return oldAttr;    }     /**     * Equivalent to <code>setAttributeNode(newAttr)</code>.     *     * @see #getAttributeNodeNS     */    public Attr setAttributeNodeNS(Attr newAttr) {        return setAttributeNode(newAttr);    }     public Attr removeAttributeNode(Attr oldAttr) {        removeAttribute(oldAttr.getName());        return oldAttr;    }     public NodeList getElementsByTagName(String name) {        List l = new ArrayList();        getElementsByTagName(name, l);        return new IIONodeList(l);    }     private void getElementsByTagName(String name, List l) {        if (nodeName.equals(name)) {            l.add(this);        }         Node child = getFirstChild();        while (child != null) {            ((IIOMetadataNode)child).getElementsByTagName(name, l);            child = child.getNextSibling();        }    }     /**     * Equivalent to <code>getElementsByTagName(localName)</code>.     */    public NodeList getElementsByTagNameNS(String namespaceURI,                                           String localName) {        return getElementsByTagName(localName);    }     public boolean hasAttributes() {        return attributes.size() > 0;    }     public boolean hasAttribute(String name) {        return getAttributeNode(name) != null;    }     /**     * Equivalent to <code>hasAttribute(localName)</code>.     */    public boolean hasAttributeNS(String namespaceURI,                                  String localName) {        return hasAttribute(localName);    }     // Methods from NodeList     public int getLength() {        return numChildren;    }     public Node item(int index) {        if (index < 0) {            return null;        }         Node child = getFirstChild();        while (child != null && index-- > 0) {            child = child.getNextSibling();        }        return child;    }     /**     * Returns the <code>Object</code> value associated with this node.     *     * @return the user <code>Object</code>.     *     * @see #setUserObject     */    public Object getUserObject() {        return userObject;    }     /**     * Sets the value associated with this node.     *     * @param userObject the user <code>Object</code>.     *     * @see #getUserObject     */    public void setUserObject(Object userObject) {        this.userObject = userObject;    }     // Start of dummy methods for DOM L3.     /**     * This DOM Level 3 method is not supported for {@code IIOMetadataNode}     * and will throw a {@code DOMException}.     * @throws DOMException - always.     */    public void setIdAttribute(String name,                               boolean isId)                               throws DOMException {        throw new DOMException(DOMException.NOT_SUPPORTED_ERR,                               "Method not supported");    }     /**     * This DOM Level 3 method is not supported for {@code IIOMetadataNode}     * and will throw a {@code DOMException}.     * @throws DOMException - always.     */    public void setIdAttributeNS(String namespaceURI,                                 String localName,                                 boolean isId)                                 throws DOMException {        throw new DOMException(DOMException.NOT_SUPPORTED_ERR,                               "Method not supported");    }     /**     * This DOM Level 3 method is not supported for {@code IIOMetadataNode}     * and will throw a {@code DOMException}.     * @throws DOMException - always.     */    public void setIdAttributeNode(Attr idAttr,                                   boolean isId)                                   throws DOMException {        throw new DOMException(DOMException.NOT_SUPPORTED_ERR,                               "Method not supported");    }     /**     * This DOM Level 3 method is not supported for {@code IIOMetadataNode}     * and will throw a {@code DOMException}.     * @throws DOMException - always.     */    public TypeInfo getSchemaTypeInfo() throws DOMException {

Lines 501–1000 of 1132. Previous lines

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t