1 2 18 package com.sun.org.apache.xml.internal.security.utils; 19 20 21 22 import java.util.ArrayList ; 23 24 import org.w3c.dom.Document ; 25 import org.w3c.dom.Node ; 26 import org.w3c.dom.NodeList ; 27 28 29 35 public class HelperNodeList implements NodeList { 36 37 38 static java.util.logging.Logger log = 39 java.util.logging.Logger.getLogger(HelperNodeList.class.getName()); 40 41 42 ArrayList nodes = new ArrayList (20); 43 44 boolean _allNodesMustHaveSameParent = false; 45 46 49 public HelperNodeList() { 50 this(false); 51 } 52 53 54 57 public HelperNodeList(boolean allNodesMustHaveSameParent) { 58 this._allNodesMustHaveSameParent = allNodesMustHaveSameParent; 59 } 60 61 67 public Node item(int index) { 68 69 71 return (Node ) nodes.get(index); 72 } 73 74 79 public int getLength() { 80 return nodes.size(); 81 } 82 83 89 public void appendChild(Node node) throws IllegalArgumentException { 90 if (this._allNodesMustHaveSameParent && this.getLength() > 0) { 91 if (this.item(0).getParentNode() != node.getParentNode()) { 92 throw new IllegalArgumentException ("Nodes have not the same Parent"); 93 } 94 } 95 nodes.add(node); 96 } 97 98 101 public Document getOwnerDocument() { 102 if (this.getLength() == 0) { 103 return null; 104 } 105 return XMLUtils.getOwnerDocument(this.item(0)); 106 } 107 } 108 | Popular Tags |