1 20 21 25 26 package org.ozoneDB.xml.dom; 27 28 import java.io.*; 29 import java.util.*; 30 import org.w3c.dom.*; 31 32 33 50 final class ElementListImpl implements NodeList, Externalizable { 51 52 final static long serialVersionUID = 1; 53 54 55 public ElementListImpl() { 56 } 57 58 59 public Node item( int index ) { 60 if (index < 0 || index >= _elements.size()) { 61 return null; 62 } else { 63 return (Node)_elements.elementAt( index ); 64 } 65 } 66 67 68 public int getLength() { 69 return _elements.size(); 70 } 71 72 73 78 void addElement( Element newElem ) { 79 _elements.addElement( newElem ); 80 } 81 82 83 92 void addElements( Node element, String tagName ) { 93 Node node; 94 95 if (tagName.equals( "*" )) { 97 tagName = null; 98 } 99 node = element.getFirstChild(); 103 while (node != null) { 104 if (node instanceof ElementProxy) { 105 if (tagName == null || node.getNodeName().equals( tagName )) { 106 addElement( (Element)node ); 107 } 108 addElements( node, tagName ); 109 } 110 node = node.getNextSibling(); 111 } 112 } 113 114 115 123 ElementListImpl( Node element, String tagName ) { 124 init( element, tagName ); 125 } 126 127 128 public void init( Node element, String tagName ) { 129 if (tagName == null) { 130 throw new NullPointerException ( "Argument 'tagName' is null." ); 131 } 132 _elements = new Vector(); 133 addElements( element, tagName ); 134 } 135 136 137 public void init( NodeProxy node ) { 138 throw new NullPointerException ( "Argument 'tagName' is null." ); 139 } 140 141 145 private Vector _elements; 146 147 148 public void writeExternal( ObjectOutput out ) throws IOException { 149 out.writeObject( _elements ); 150 } 151 152 153 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { 154 _elements = (Vector)in.readObject(); 155 } 156 157 } 158 | Popular Tags |