src/share/classes/javax/imageio/metadata/IIOMetadataNode.java

Print this page
rev 9344 : 8034998: Fix raw and unchecked lint warnings in javax.imageio
Reviewed-by: darcy, prr


  33 import org.w3c.dom.Document;
  34 import org.w3c.dom.Element;
  35 import org.w3c.dom.DOMException;
  36 import org.w3c.dom.NamedNodeMap;
  37 import org.w3c.dom.Node;
  38 import org.w3c.dom.NodeList;
  39 import org.w3c.dom.TypeInfo;
  40 import org.w3c.dom.UserDataHandler;
  41 
  42 
  43 class IIODOMException extends DOMException {
  44     private static final long serialVersionUID = -4369510142067447468L;
  45 
  46     public IIODOMException(short code, String message) {
  47         super(code, message);
  48     }
  49 }
  50 
  51 class IIONamedNodeMap implements NamedNodeMap {
  52 
  53     List nodes;
  54 
  55     public IIONamedNodeMap(List nodes) {
  56         this.nodes = nodes;
  57     }
  58 
  59     public int getLength() {
  60         return nodes.size();
  61     }
  62 
  63     public Node getNamedItem(String name) {
  64         Iterator iter = nodes.iterator();
  65         while (iter.hasNext()) {
  66             Node node = (Node)iter.next();
  67             if (name.equals(node.getNodeName())) {
  68                 return node;
  69             }
  70         }
  71 
  72         return null;
  73     }
  74 
  75     public Node item(int index) {
  76         Node node = (Node)nodes.get(index);
  77         return node;
  78     }
  79 
  80     public Node removeNamedItem(java.lang.String name) {
  81         throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
  82                                "This NamedNodeMap is read-only!");
  83     }
  84 
  85     public Node setNamedItem(Node arg) {
  86         throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
  87                                "This NamedNodeMap is read-only!");
  88     }
  89 
  90     /**
  91      * Equivalent to <code>getNamedItem(localName)</code>.
  92      */
  93     public Node getNamedItemNS(String namespaceURI, String localName) {
  94         return getNamedItem(localName);
  95     }
  96 
  97     /**
  98      * Equivalent to <code>setNamedItem(arg)</code>.
  99      */
 100     public Node setNamedItemNS(Node arg) {
 101         return setNamedItem(arg);
 102     }
 103 
 104     /**
 105      * Equivalent to <code>removeNamedItem(localName)</code>.
 106      */
 107     public Node removeNamedItemNS(String namespaceURI, String localName) {
 108         return removeNamedItem(localName);
 109     }
 110 }
 111 
 112 class IIONodeList implements NodeList {
 113 
 114     List nodes;
 115 
 116     public IIONodeList(List nodes) {
 117         this.nodes = nodes;
 118     }
 119 
 120     public int getLength() {
 121         return nodes.size();
 122     }
 123 
 124     public Node item(int index) {
 125         if (index < 0 || index > nodes.size()) {
 126             return null;
 127         }
 128         return (Node)nodes.get(index);
 129     }
 130 }
 131 
 132 class IIOAttr extends IIOMetadataNode implements Attr {
 133 
 134     Element owner;
 135     String name;
 136     String value;
 137 
 138     public IIOAttr(Element owner, String name, String value) {
 139         this.owner = owner;
 140         this.name = name;
 141         this.value = value;
 142     }
 143 
 144     public String getName() {
 145         return name;
 146     }
 147 
 148     public String getNodeName() {


 268      * <code>null</code> if this node is a leaf node.
 269      */
 270     private IIOMetadataNode lastChild = null;
 271 
 272     /**
 273      * The next (right) sibling node of this node, or
 274      * <code>null</code> if this node is its parent's last child node.
 275      */
 276     private IIOMetadataNode nextSibling = null;
 277 
 278     /**
 279      * The previous (left) sibling node of this node, or
 280      * <code>null</code> if this node is its parent's first child node.
 281      */
 282     private IIOMetadataNode previousSibling = null;
 283 
 284     /**
 285      * A <code>List</code> of <code>IIOAttr</code> nodes representing
 286      * attributes.
 287      */
 288     private List attributes = new ArrayList();
 289 
 290     /**
 291      * Constructs an empty <code>IIOMetadataNode</code>.
 292      */
 293     public IIOMetadataNode() {}
 294 
 295     /**
 296      * Constructs an <code>IIOMetadataNode</code> with a given node
 297      * name.
 298      *
 299      * @param nodeName the name of the node, as a <code>String</code>.
 300      */
 301     public IIOMetadataNode(String nodeName) {
 302         this.nodeName = nodeName;
 303     }
 304 
 305     /**
 306      * Check that the node is either <code>null</code> or an
 307      * <code>IIOMetadataNode</code>.
 308      */


 772         attributes.add(new IIOAttr(this, name, value));
 773     }
 774 
 775     /**
 776      * Equivalent to <code>setAttribute(qualifiedName, value)</code>.
 777      *
 778      * @see #getAttributeNS
 779      */
 780     public void setAttributeNS(String namespaceURI,
 781                                String qualifiedName, String value) {
 782         setAttribute(qualifiedName, value);
 783     }
 784 
 785     public void removeAttribute(String name) {
 786         removeAttribute(name, true);
 787     }
 788 
 789     private void removeAttribute(String name, boolean checkPresent) {
 790         int numAttributes = attributes.size();
 791         for (int i = 0; i < numAttributes; i++) {
 792             IIOAttr attr = (IIOAttr)attributes.get(i);
 793             if (name.equals(attr.getName())) {
 794                 attr.setOwnerElement(null);
 795                 attributes.remove(i);
 796                 return;
 797             }
 798         }
 799 
 800         // If we get here, the attribute doesn't exist
 801         if (checkPresent) {
 802             throw new IIODOMException(DOMException.NOT_FOUND_ERR,
 803                                       "No such attribute!");
 804         }
 805     }
 806 
 807     /**
 808      * Equivalent to <code>removeAttribute(localName)</code>.
 809      */
 810     public void removeAttributeNS(String namespaceURI,
 811                                   String localName) {
 812         removeAttribute(localName);


 856         attributes.add(attr);
 857 
 858         return oldAttr;
 859     }
 860 
 861     /**
 862      * Equivalent to <code>setAttributeNode(newAttr)</code>.
 863      *
 864      * @see #getAttributeNodeNS
 865      */
 866     public Attr setAttributeNodeNS(Attr newAttr) {
 867         return setAttributeNode(newAttr);
 868     }
 869 
 870     public Attr removeAttributeNode(Attr oldAttr) {
 871         removeAttribute(oldAttr.getName());
 872         return oldAttr;
 873     }
 874 
 875     public NodeList getElementsByTagName(String name) {
 876         List l = new ArrayList();
 877         getElementsByTagName(name, l);
 878         return new IIONodeList(l);
 879     }
 880 
 881     private void getElementsByTagName(String name, List l) {
 882         if (nodeName.equals(name)) {
 883             l.add(this);
 884         }
 885 
 886         Node child = getFirstChild();
 887         while (child != null) {
 888             ((IIOMetadataNode)child).getElementsByTagName(name, l);
 889             child = child.getNextSibling();
 890         }
 891     }
 892 
 893     /**
 894      * Equivalent to <code>getElementsByTagName(localName)</code>.
 895      */
 896     public NodeList getElementsByTagNameNS(String namespaceURI,
 897                                            String localName) {
 898         return getElementsByTagName(localName);
 899     }
 900 
 901     public boolean hasAttributes() {




  33 import org.w3c.dom.Document;
  34 import org.w3c.dom.Element;
  35 import org.w3c.dom.DOMException;
  36 import org.w3c.dom.NamedNodeMap;
  37 import org.w3c.dom.Node;
  38 import org.w3c.dom.NodeList;
  39 import org.w3c.dom.TypeInfo;
  40 import org.w3c.dom.UserDataHandler;
  41 
  42 
  43 class IIODOMException extends DOMException {
  44     private static final long serialVersionUID = -4369510142067447468L;
  45 
  46     public IIODOMException(short code, String message) {
  47         super(code, message);
  48     }
  49 }
  50 
  51 class IIONamedNodeMap implements NamedNodeMap {
  52 
  53     List<? extends Node> nodes;
  54 
  55     public IIONamedNodeMap(List<? extends Node> nodes) {
  56         this.nodes = nodes;
  57     }
  58 
  59     public int getLength() {
  60         return nodes.size();
  61     }
  62 
  63     public Node getNamedItem(String name) {
  64         Iterator<? extends Node> iter = nodes.iterator();
  65         while (iter.hasNext()) {
  66             Node node = iter.next();
  67             if (name.equals(node.getNodeName())) {
  68                 return node;
  69             }
  70         }
  71 
  72         return null;
  73     }
  74 
  75     public Node item(int index) {
  76         Node node = nodes.get(index);
  77         return node;
  78     }
  79 
  80     public Node removeNamedItem(java.lang.String name) {
  81         throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
  82                                "This NamedNodeMap is read-only!");
  83     }
  84 
  85     public Node setNamedItem(Node arg) {
  86         throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
  87                                "This NamedNodeMap is read-only!");
  88     }
  89 
  90     /**
  91      * Equivalent to <code>getNamedItem(localName)</code>.
  92      */
  93     public Node getNamedItemNS(String namespaceURI, String localName) {
  94         return getNamedItem(localName);
  95     }
  96 
  97     /**
  98      * Equivalent to <code>setNamedItem(arg)</code>.
  99      */
 100     public Node setNamedItemNS(Node arg) {
 101         return setNamedItem(arg);
 102     }
 103 
 104     /**
 105      * Equivalent to <code>removeNamedItem(localName)</code>.
 106      */
 107     public Node removeNamedItemNS(String namespaceURI, String localName) {
 108         return removeNamedItem(localName);
 109     }
 110 }
 111 
 112 class IIONodeList implements NodeList {
 113 
 114     List<? extends Node> nodes;
 115 
 116     public IIONodeList(List<? extends Node> nodes) {
 117         this.nodes = nodes;
 118     }
 119 
 120     public int getLength() {
 121         return nodes.size();
 122     }
 123 
 124     public Node item(int index) {
 125         if (index < 0 || index > nodes.size()) {
 126             return null;
 127         }
 128         return nodes.get(index);
 129     }
 130 }
 131 
 132 class IIOAttr extends IIOMetadataNode implements Attr {
 133 
 134     Element owner;
 135     String name;
 136     String value;
 137 
 138     public IIOAttr(Element owner, String name, String value) {
 139         this.owner = owner;
 140         this.name = name;
 141         this.value = value;
 142     }
 143 
 144     public String getName() {
 145         return name;
 146     }
 147 
 148     public String getNodeName() {


 268      * <code>null</code> if this node is a leaf node.
 269      */
 270     private IIOMetadataNode lastChild = null;
 271 
 272     /**
 273      * The next (right) sibling node of this node, or
 274      * <code>null</code> if this node is its parent's last child node.
 275      */
 276     private IIOMetadataNode nextSibling = null;
 277 
 278     /**
 279      * The previous (left) sibling node of this node, or
 280      * <code>null</code> if this node is its parent's first child node.
 281      */
 282     private IIOMetadataNode previousSibling = null;
 283 
 284     /**
 285      * A <code>List</code> of <code>IIOAttr</code> nodes representing
 286      * attributes.
 287      */
 288     private List<IIOAttr> attributes = new ArrayList<>();
 289 
 290     /**
 291      * Constructs an empty <code>IIOMetadataNode</code>.
 292      */
 293     public IIOMetadataNode() {}
 294 
 295     /**
 296      * Constructs an <code>IIOMetadataNode</code> with a given node
 297      * name.
 298      *
 299      * @param nodeName the name of the node, as a <code>String</code>.
 300      */
 301     public IIOMetadataNode(String nodeName) {
 302         this.nodeName = nodeName;
 303     }
 304 
 305     /**
 306      * Check that the node is either <code>null</code> or an
 307      * <code>IIOMetadataNode</code>.
 308      */


 772         attributes.add(new IIOAttr(this, name, value));
 773     }
 774 
 775     /**
 776      * Equivalent to <code>setAttribute(qualifiedName, value)</code>.
 777      *
 778      * @see #getAttributeNS
 779      */
 780     public void setAttributeNS(String namespaceURI,
 781                                String qualifiedName, String value) {
 782         setAttribute(qualifiedName, value);
 783     }
 784 
 785     public void removeAttribute(String name) {
 786         removeAttribute(name, true);
 787     }
 788 
 789     private void removeAttribute(String name, boolean checkPresent) {
 790         int numAttributes = attributes.size();
 791         for (int i = 0; i < numAttributes; i++) {
 792             IIOAttr attr = attributes.get(i);
 793             if (name.equals(attr.getName())) {
 794                 attr.setOwnerElement(null);
 795                 attributes.remove(i);
 796                 return;
 797             }
 798         }
 799 
 800         // If we get here, the attribute doesn't exist
 801         if (checkPresent) {
 802             throw new IIODOMException(DOMException.NOT_FOUND_ERR,
 803                                       "No such attribute!");
 804         }
 805     }
 806 
 807     /**
 808      * Equivalent to <code>removeAttribute(localName)</code>.
 809      */
 810     public void removeAttributeNS(String namespaceURI,
 811                                   String localName) {
 812         removeAttribute(localName);


 856         attributes.add(attr);
 857 
 858         return oldAttr;
 859     }
 860 
 861     /**
 862      * Equivalent to <code>setAttributeNode(newAttr)</code>.
 863      *
 864      * @see #getAttributeNodeNS
 865      */
 866     public Attr setAttributeNodeNS(Attr newAttr) {
 867         return setAttributeNode(newAttr);
 868     }
 869 
 870     public Attr removeAttributeNode(Attr oldAttr) {
 871         removeAttribute(oldAttr.getName());
 872         return oldAttr;
 873     }
 874 
 875     public NodeList getElementsByTagName(String name) {
 876         List<Node> l = new ArrayList<>();
 877         getElementsByTagName(name, l);
 878         return new IIONodeList(l);
 879     }
 880 
 881     private void getElementsByTagName(String name, List<Node> l) {
 882         if (nodeName.equals(name)) {
 883             l.add(this);
 884         }
 885 
 886         Node child = getFirstChild();
 887         while (child != null) {
 888             ((IIOMetadataNode)child).getElementsByTagName(name, l);
 889             child = child.getNextSibling();
 890         }
 891     }
 892 
 893     /**
 894      * Equivalent to <code>getElementsByTagName(localName)</code>.
 895      */
 896     public NodeList getElementsByTagNameNS(String namespaceURI,
 897                                            String localName) {
 898         return getElementsByTagName(localName);
 899     }
 900 
 901     public boolean hasAttributes() {