You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by kn...@apache.org on 2009/11/23 21:28:30 UTC
svn commit: r883487 -
/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/
Author: knoaman
Date: Mon Nov 23 20:28:10 2009
New Revision: 883487
URL: http://svn.apache.org/viewvc?rev=883487&view=rev
Log:
Various DOM changes - Keep 1.1 branch up to date with Xerces-J trunk
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/AttributeMap.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DOMImplementationListImpl.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DOMImplementationSourceImpl.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DOMNormalizer.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DOMXSImplementationSourceImpl.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DeepNodeListImpl.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DeferredDocumentImpl.java
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/NamedNodeMapImpl.java
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/AttributeMap.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/AttributeMap.java?rev=883487&r1=883486&r2=883487&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/AttributeMap.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/AttributeMap.java Mon Nov 23 20:28:10 2009
@@ -17,7 +17,8 @@
package org.apache.xerces.dom;
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.List;
import org.w3c.dom.DOMException;
import org.w3c.dom.Node;
@@ -105,8 +106,8 @@
int i = findNamePoint(argn.getNodeName(),0);
AttrImpl previous = null;
if (i >= 0) {
- previous = (AttrImpl) nodes.elementAt(i);
- nodes.setElementAt(arg,i);
+ previous = (AttrImpl) nodes.get(i);
+ nodes.set(i, arg);
previous.ownerNode = ownerNode.ownerDocument();
previous.isOwned(false);
// make sure it won't be mistaken with defaults in case it's reused
@@ -114,9 +115,9 @@
} else {
i = -1 - i; // Insert point (may be end of list)
if (null == nodes) {
- nodes = new Vector(5, 10);
+ nodes = new ArrayList(5);
}
- nodes.insertElementAt(arg, i);
+ nodes.add(i, arg);
}
// notify document
@@ -174,8 +175,8 @@
int i = findNamePoint(argn.getNamespaceURI(), argn.getLocalName());
AttrImpl previous = null;
if (i >= 0) {
- previous = (AttrImpl) nodes.elementAt(i);
- nodes.setElementAt(arg,i);
+ previous = (AttrImpl) nodes.get(i);
+ nodes.set(i, arg);
previous.ownerNode = ownerNode.ownerDocument();
previous.isOwned(false);
// make sure it won't be mistaken with defaults in case it's reused
@@ -185,14 +186,14 @@
// nodeName so we know where to insert.
i = findNamePoint(arg.getNodeName(),0);
if (i >=0) {
- previous = (AttrImpl) nodes.elementAt(i);
- nodes.insertElementAt(arg,i);
+ previous = (AttrImpl) nodes.get(i);
+ nodes.add(i, arg);
} else {
i = -1 - i; // Insert point (may be end of list)
if (null == nodes) {
- nodes = new Vector(5, 10);
+ nodes = new ArrayList(5);
}
- nodes.insertElementAt(arg, i);
+ nodes.add(i, arg);
}
}
// changed(true);
@@ -253,8 +254,9 @@
int index = -1;
if (nodes != null) {
- for (int i = 0; i < nodes.size(); i++) {
- if (nodes.elementAt(i) == item) {
+ final int size = nodes.size();
+ for (int i = 0; i < size; ++i) {
+ if (nodes.get(i) == item) {
index = i;
break;
}
@@ -287,7 +289,7 @@
}
}
- return remove((AttrImpl)nodes.elementAt(i), i, true);
+ return remove((AttrImpl)nodes.get(i), i, true);
} // internalRemoveNamedItem(String,boolean):Node
@@ -321,16 +323,16 @@
clone.isOwned(true);
clone.isSpecified(false);
- nodes.setElementAt(clone, index);
+ nodes.set(index, clone);
if (attr.isIdAttribute()) {
ownerDocument.putIdentifier(clone.getNodeValue(),
(ElementImpl)ownerNode);
}
} else {
- nodes.removeElementAt(index);
+ nodes.remove(index);
}
} else {
- nodes.removeElementAt(index);
+ nodes.remove(index);
}
// changed(true);
@@ -403,7 +405,7 @@
}
}
- AttrImpl n = (AttrImpl)nodes.elementAt(i);
+ AttrImpl n = (AttrImpl)nodes.get(i);
if (n.isIdAttribute()) {
ownerDocument.removeIdentifier(n.getValue());
@@ -429,19 +431,19 @@
}
clone.isOwned(true);
clone.isSpecified(false);
- nodes.setElementAt(clone, i);
+ nodes.set(i, clone);
if (clone.isIdAttribute()) {
ownerDocument.putIdentifier(clone.getNodeValue(),
(ElementImpl)ownerNode);
}
} else {
- nodes.removeElementAt(i);
+ nodes.remove(i);
}
} else {
- nodes.removeElementAt(i);
+ nodes.remove(i);
}
} else {
- nodes.removeElementAt(i);
+ nodes.remove(i);
}
// changed(true);
@@ -483,19 +485,21 @@
* Override parent's method to set the ownerNode correctly
*/
protected void cloneContent(NamedNodeMapImpl srcmap) {
- Vector srcnodes = srcmap.nodes;
+ List srcnodes = srcmap.nodes;
if (srcnodes != null) {
int size = srcnodes.size();
if (size != 0) {
if (nodes == null) {
- nodes = new Vector(size);
+ nodes = new ArrayList(size);
+ }
+ else {
+ nodes.clear();
}
- nodes.setSize(size);
for (int i = 0; i < size; ++i) {
- NodeImpl n = (NodeImpl) srcnodes.elementAt(i);
+ NodeImpl n = (NodeImpl) srcnodes.get(i);
NodeImpl clone = (NodeImpl) n.cloneNode(true);
clone.isSpecified(n.isSpecified());
- nodes.setElementAt(clone, i);
+ nodes.add(clone);
clone.ownerNode = ownerNode;
clone.isOwned(true);
}
@@ -510,7 +514,7 @@
void moveSpecifiedAttributes(AttributeMap srcmap) {
int nsize = (srcmap.nodes != null) ? srcmap.nodes.size() : 0;
for (int i = nsize - 1; i >= 0; i--) {
- AttrImpl attr = (AttrImpl) srcmap.nodes.elementAt(i);
+ AttrImpl attr = (AttrImpl) srcmap.nodes.get(i);
if (attr.isSpecified()) {
srcmap.remove(attr, i, false);
if (attr.getLocalName() != null) {
@@ -532,8 +536,8 @@
// remove any existing default
int nsize = (nodes != null) ? nodes.size() : 0;
- for (int i = nsize - 1; i >= 0; i--) {
- AttrImpl attr = (AttrImpl) nodes.elementAt(i);
+ for (int i = nsize - 1; i >= 0; --i) {
+ AttrImpl attr = (AttrImpl) nodes.get(i);
if (!attr.isSpecified()) {
remove(attr, i, false);
}
@@ -547,8 +551,8 @@
}
else {
int dsize = defaults.nodes.size();
- for (int n = 0; n < dsize; n++) {
- AttrImpl d = (AttrImpl) defaults.nodes.elementAt(n);
+ for (int n = 0; n < dsize; ++n) {
+ AttrImpl d = (AttrImpl) defaults.nodes.get(n);
int i = findNamePoint(d.getNodeName(), 0);
if (i < 0) {
i = -1 - i;
@@ -556,7 +560,7 @@
clone.ownerNode = ownerNode;
clone.isOwned(true);
clone.isSpecified(false);
- nodes.insertElementAt(clone, i);
+ nodes.add(i, clone);
}
}
}
@@ -573,21 +577,21 @@
int i = findNamePoint(argn.getNamespaceURI(), argn.getLocalName());
if (i >= 0) {
- nodes.setElementAt(arg,i);
+ nodes.set(i, arg);
}
else {
// If we can't find by namespaceURI, localName, then we find by
// nodeName so we know where to insert.
i = findNamePoint(argn.getNodeName(),0);
if (i >= 0) {
- nodes.insertElementAt(arg,i);
+ nodes.add(i, arg);
}
else {
i = -1 - i; // Insert point (may be end of list)
if (null == nodes) {
- nodes = new Vector(5, 10);
+ nodes = new ArrayList(5);
}
- nodes.insertElementAt(arg, i);
+ nodes.add(i, arg);
}
}
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DOMImplementationListImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DOMImplementationListImpl.java?rev=883487&r1=883486&r2=883487&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DOMImplementationListImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DOMImplementationListImpl.java Mon Nov 23 20:28:10 2009
@@ -17,6 +17,7 @@
package org.apache.xerces.dom;
+import java.util.ArrayList;
import java.util.Vector;
import org.w3c.dom.DOMImplementation;
@@ -32,21 +33,28 @@
*/
public class DOMImplementationListImpl implements DOMImplementationList {
- //A collection of DOMImplementations
- private Vector fImplementations;
+ // A collection of DOMImplementations
+ private final ArrayList fImplementations;
/**
* Construct an empty list of DOMImplementations
*/
public DOMImplementationListImpl() {
- fImplementations = new Vector();
+ fImplementations = new ArrayList();
+ }
+
+ /**
+ * Construct a list of DOMImplementations from an ArrayList
+ */
+ public DOMImplementationListImpl(ArrayList params) {
+ fImplementations = params;
}
- /**
- * Construct an empty list of DOMImplementations
- */
+ /**
+ * Construct a list of DOMImplementations from a Vector
+ */
public DOMImplementationListImpl(Vector params) {
- fImplementations = params;
+ fImplementations = new ArrayList(params);
}
/**
@@ -55,11 +63,11 @@
* @param index The index of the DOMImplemetation from the list to return.
*/
public DOMImplementation item(int index) {
- try {
- return (DOMImplementation) fImplementations.elementAt(index);
- } catch (ArrayIndexOutOfBoundsException e) {
- return null;
+ final int length = getLength();
+ if (index >= 0 && index < length) {
+ return (DOMImplementation) fImplementations.get(index);
}
+ return null;
}
/**
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DOMImplementationSourceImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DOMImplementationSourceImpl.java?rev=883487&r1=883486&r2=883487&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DOMImplementationSourceImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DOMImplementationSourceImpl.java Mon Nov 23 20:28:10 2009
@@ -17,8 +17,8 @@
package org.apache.xerces.dom;
+import java.util.ArrayList;
import java.util.StringTokenizer;
-import java.util.Vector;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.DOMImplementationList;
@@ -78,13 +78,13 @@
public DOMImplementationList getDOMImplementationList(String features) {
// first check whether the CoreDOMImplementation would do
DOMImplementation impl = CoreDOMImplementationImpl.getDOMImplementation();
- final Vector implementations = new Vector();
+ final ArrayList implementations = new ArrayList();
if (testImpl(impl, features)) {
- implementations.addElement(impl);
+ implementations.add(impl);
}
impl = DOMImplementationImpl.getDOMImplementation();
if (testImpl(impl, features)) {
- implementations.addElement(impl);
+ implementations.add(impl);
}
return new DOMImplementationListImpl(implementations);
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DOMNormalizer.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DOMNormalizer.java?rev=883487&r1=883486&r2=883487&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DOMNormalizer.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DOMNormalizer.java Mon Nov 23 20:28:10 2009
@@ -18,6 +18,7 @@
package org.apache.xerces.dom;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Vector;
import org.apache.xerces.impl.Constants;
@@ -136,8 +137,7 @@
protected final NamespaceContext fLocalNSBinder = new NamespaceSupport();
/** list of attributes */
- protected final Vector fAttributeList = new Vector(5,10);
-
+ protected final ArrayList fAttributeList = new ArrayList(5);
/** DOM Locator - for namespace fixup algorithm */
protected final DOMLocatorImpl fLocator = new DOMLocatorImpl();
@@ -877,7 +877,7 @@
// clone content of the attributes
attributes.cloneMap(fAttributeList);
for (int i = 0; i < fAttributeList.size(); i++) {
- Attr attr = (Attr) fAttributeList.elementAt(i);
+ Attr attr = (Attr) fAttributeList.get(i);
fLocator.fRelatedNode = attr;
if (DEBUG) {
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DOMXSImplementationSourceImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DOMXSImplementationSourceImpl.java?rev=883487&r1=883486&r2=883487&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DOMXSImplementationSourceImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DOMXSImplementationSourceImpl.java Mon Nov 23 20:28:10 2009
@@ -17,7 +17,7 @@
package org.apache.xerces.dom;
-import java.util.Vector;
+import java.util.ArrayList;
import org.apache.xerces.impl.xs.XSImplementationImpl;
import org.w3c.dom.DOMImplementation;
@@ -76,23 +76,23 @@
* features.
*/
public DOMImplementationList getDOMImplementationList(String features) {
- final Vector implementations = new Vector();
-
+ final ArrayList implementations = new ArrayList();
+
// first check whether the CoreDOMImplementation would do
DOMImplementationList list = super.getDOMImplementationList(features);
- //Add core DOMImplementations
- for (int i=0; i < list.getLength(); i++ ) {
- implementations.addElement(list.item(i));
+ // Add core DOMImplementations
+ for (int i = 0; i < list.getLength(); ++i) {
+ implementations.add(list.item(i));
}
-
+
DOMImplementation impl = PSVIDOMImplementationImpl.getDOMImplementation();
if (testImpl(impl, features)) {
- implementations.addElement(impl);
+ implementations.add(impl);
}
-
+
impl = XSImplementationImpl.getDOMImplementation();
if (testImpl(impl, features)) {
- implementations.addElement(impl);
+ implementations.add(impl);
}
return new DOMImplementationListImpl(implementations);
}
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DeepNodeListImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DeepNodeListImpl.java?rev=883487&r1=883486&r2=883487&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DeepNodeListImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DeepNodeListImpl.java Mon Nov 23 20:28:10 2009
@@ -17,7 +17,7 @@
package org.apache.xerces.dom;
-import java.util.Vector;
+import java.util.ArrayList;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -58,7 +58,7 @@
* it is being extended. That requires knowing which subtrees have
* changed, which can become an arbitrarily complex problem.
* <P>
- * We save some work by filling the vector only as we access the
+ * We save some work by filling the ArrayList only as we access the
* item()s... but I suspect the same users who demanded index-based
* access will also start by doing a getLength() to control their loop,
* blowing this optimization out of the water.
@@ -81,7 +81,7 @@
protected NodeImpl rootNode; // Where the search started
protected String tagName; // Or "*" to mean all-tags-acceptable
protected int changes=0;
- protected Vector nodes;
+ protected ArrayList nodes;
protected String nsName;
protected boolean enableNS = false;
@@ -94,7 +94,7 @@
public DeepNodeListImpl(NodeImpl rootNode, String tagName) {
this.rootNode = rootNode;
this.tagName = tagName;
- nodes = new Vector();
+ nodes = new ArrayList();
}
/** Constructor for Namespace support. */
@@ -121,30 +121,34 @@
Node thisNode;
// Tree changed. Do it all from scratch!
- if(rootNode.changes() != changes) {
- nodes = new Vector();
+ if (rootNode.changes() != changes) {
+ nodes = new ArrayList();
changes = rootNode.changes();
}
// In the cache
- if (index < nodes.size())
- return (Node)nodes.elementAt(index);
-
+ final int currentSize = nodes.size();
+ if (index < currentSize) {
+ return (Node)nodes.get(index);
+ }
// Not yet seen
else {
// Pick up where we left off (Which may be the beginning)
- if (nodes.size() == 0)
+ if (currentSize == 0) {
thisNode = rootNode;
- else
- thisNode=(NodeImpl)(nodes.lastElement());
+ }
+ else {
+ thisNode = (NodeImpl)(nodes.get(currentSize - 1));
+ }
// Add nodes up to the one we're looking for
- while(thisNode != null && index >= nodes.size()) {
- thisNode=nextMatchingElementAfter(thisNode);
- if (thisNode != null)
- nodes.addElement(thisNode);
+ while (thisNode != null && index >= nodes.size()) {
+ thisNode = nextMatchingElementAfter(thisNode);
+ if (thisNode != null) {
+ nodes.add(thisNode);
}
+ }
// Either what we want, or null (not avail.)
return thisNode;
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DeferredDocumentImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DeferredDocumentImpl.java?rev=883487&r1=883486&r2=883487&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DeferredDocumentImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/DeferredDocumentImpl.java Mon Nov 23 20:28:10 2009
@@ -17,7 +17,7 @@
package org.apache.xerces.dom;
-import java.util.Vector;
+import java.util.ArrayList;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Element;
@@ -130,7 +130,7 @@
// private data
//
private transient final StringBuffer fBufferStr = new StringBuffer();
- private transient final Vector fStrChunks = new Vector();
+ private transient final ArrayList fStrChunks = new ArrayList();
//
// Constructors
@@ -1157,14 +1157,14 @@
// append data that is stored in fNodeValue
// REVISIT: for text nodes it works differently than for CDATA
// nodes.
- fStrChunks.addElement(value);
+ fStrChunks.add(value);
do {
// go in reverse order: find last child, then
// its previous sibling, etc
chunk = prevSib >> CHUNK_SHIFT;
index = prevSib & CHUNK_MASK;
value = getChunkValue(fNodeValue, chunk, index);
- fStrChunks.addElement(value);
+ fStrChunks.add(value);
prevSib = getChunkIndex(fNodePrevSib, chunk, index);
if (prevSib == -1) {
break;
@@ -1175,11 +1175,11 @@
// add to the buffer in the correct order.
for (int i = chunkCount - 1; i >= 0; i--) {
- fBufferStr.append((String)fStrChunks.elementAt(i));
+ fBufferStr.append((String)fStrChunks.get(i));
}
value = fBufferStr.toString();
- fStrChunks.removeAllElements();
+ fStrChunks.clear();
fBufferStr.setLength(0);
return value;
}
@@ -1196,16 +1196,16 @@
chunk = child >> CHUNK_SHIFT;
index = child & CHUNK_MASK;
value = getChunkValue(fNodeValue, chunk, index);
- fStrChunks.addElement(value);
+ fStrChunks.add(value);
child = getChunkIndex(fNodePrevSib, chunk, index);
}
// add to the buffer in the correct order.
for (int i=fStrChunks.size()-1; i>=0; i--) {
- fBufferStr.append((String)fStrChunks.elementAt(i));
+ fBufferStr.append((String)fStrChunks.get(i));
}
value = fBufferStr.toString();
- fStrChunks.setSize(0);
+ fStrChunks.clear();
fBufferStr.setLength(0);
return value;
}
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/NamedNodeMapImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/NamedNodeMapImpl.java?rev=883487&r1=883486&r2=883487&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/NamedNodeMapImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/NamedNodeMapImpl.java Mon Nov 23 20:28:10 2009
@@ -17,7 +17,12 @@
package org.apache.xerces.dom;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Vector;
import org.w3c.dom.DOMException;
@@ -38,7 +43,7 @@
* NOTE: The "primary" storage key is taken from the NodeName attribute of the
* node. The "secondary" storage key is the namespaceURI and localName, when
* accessed by DOM level 2 nodes. All nodes, even DOM Level 2 nodes are stored
- * in a single Vector sorted by the primary "nodename" key.
+ * in a single ArrayList sorted by the primary "nodename" key.
* <P>
* NOTE: item()'s integer index does _not_ imply that the named nodes
* must be stored in an array; that's only an access method. Note too
@@ -72,7 +77,7 @@
protected final static short HASDEFAULTS = 0x1<<2;
/** Nodes. */
- protected Vector nodes;
+ protected List nodes;
protected NodeImpl ownerNode; // the node this map belongs to
@@ -115,7 +120,7 @@
*/
public Node item(int index) {
return (nodes != null && index < nodes.size()) ?
- (Node)(nodes.elementAt(index)) : null;
+ (Node)(nodes.get(index)) : null;
}
/**
@@ -128,7 +133,7 @@
public Node getNamedItem(String name) {
int i = findNamePoint(name,0);
- return (i < 0) ? null : (Node)(nodes.elementAt(i));
+ return (i < 0) ? null : (Node)(nodes.get(i));
} // getNamedItem(String):Node
@@ -146,7 +151,7 @@
public Node getNamedItemNS(String namespaceURI, String localName) {
int i = findNamePoint(namespaceURI, localName);
- return (i < 0) ? null : (Node)(nodes.elementAt(i));
+ return (i < 0) ? null : (Node)(nodes.get(i));
} // getNamedItemNS(String,String):Node
@@ -185,14 +190,14 @@
int i = findNamePoint(arg.getNodeName(),0);
NodeImpl previous = null;
if (i >= 0) {
- previous = (NodeImpl) nodes.elementAt(i);
- nodes.setElementAt(arg,i);
+ previous = (NodeImpl) nodes.get(i);
+ nodes.set(i, arg);
} else {
i = -1 - i; // Insert point (may be end of list)
if (null == nodes) {
- nodes = new Vector(5, 10);
+ nodes = new ArrayList(5);
}
- nodes.insertElementAt(arg, i);
+ nodes.add(i, arg);
}
return previous;
@@ -228,21 +233,21 @@
int i = findNamePoint(arg.getNamespaceURI(), arg.getLocalName());
NodeImpl previous = null;
if (i >= 0) {
- previous = (NodeImpl) nodes.elementAt(i);
- nodes.setElementAt(arg,i);
+ previous = (NodeImpl) nodes.get(i);
+ nodes.set(i, arg);
} else {
// If we can't find by namespaceURI, localName, then we find by
// nodeName so we know where to insert.
i = findNamePoint(arg.getNodeName(),0);
if (i >= 0) {
- previous = (NodeImpl) nodes.elementAt(i);
- nodes.insertElementAt(arg,i);
+ previous = (NodeImpl) nodes.get(i);
+ nodes.add(i, arg);
} else {
i = -1 - i; // Insert point (may be end of list)
if (null == nodes) {
- nodes = new Vector(5, 10);
+ nodes = new ArrayList(5);
}
- nodes.insertElementAt(arg, i);
+ nodes.add(i, arg);
}
}
return previous;
@@ -270,8 +275,8 @@
throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
}
- NodeImpl n = (NodeImpl)nodes.elementAt(i);
- nodes.removeElementAt(i);
+ NodeImpl n = (NodeImpl)nodes.get(i);
+ nodes.remove(i);
return n;
@@ -306,8 +311,8 @@
throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
}
- NodeImpl n = (NodeImpl)nodes.elementAt(i);
- nodes.removeElementAt(i);
+ NodeImpl n = (NodeImpl)nodes.get(i);
+ nodes.remove(i);
return n;
@@ -329,19 +334,21 @@
}
protected void cloneContent(NamedNodeMapImpl srcmap) {
- Vector srcnodes = srcmap.nodes;
+ List srcnodes = srcmap.nodes;
if (srcnodes != null) {
int size = srcnodes.size();
if (size != 0) {
if (nodes == null) {
- nodes = new Vector(size);
+ nodes = new ArrayList(size);
+ }
+ else {
+ nodes.clear();
}
- nodes.setSize(size);
for (int i = 0; i < size; ++i) {
- NodeImpl n = (NodeImpl) srcmap.nodes.elementAt(i);
+ NodeImpl n = (NodeImpl) srcmap.nodes.get(i);
NodeImpl clone = (NodeImpl) n.cloneNode(true);
clone.isSpecified(n.isSpecified());
- nodes.setElementAt(clone, i);
+ nodes.add(clone);
}
}
}
@@ -366,7 +373,7 @@
isReadOnly(readOnly);
if (deep && nodes != null) {
for (int i = nodes.size() - 1; i >= 0; i--) {
- ((NodeImpl) nodes.elementAt(i)).setReadOnly(readOnly,deep);
+ ((NodeImpl) nodes.get(i)).setReadOnly(readOnly,deep);
}
}
} // setReadOnly(boolean,boolean)
@@ -390,7 +397,8 @@
*/
protected void setOwnerDocument(CoreDocumentImpl doc) {
if (nodes != null) {
- for (int i = 0; i < nodes.size(); i++) {
+ final int size = nodes.size();
+ for (int i = 0; i < size; ++i) {
((NodeImpl)item(i)).setOwnerDocument(doc);
}
}
@@ -446,7 +454,7 @@
while (first <= last) {
i = (first + last) / 2;
- int test = name.compareTo(((Node)(nodes.elementAt(i))).getNodeName());
+ int test = name.compareTo(((Node)(nodes.get(i))).getNodeName());
if (test == 0) {
return i; // Name found
}
@@ -475,15 +483,16 @@
if (nodes == null) return -1;
if (name == null) return -1;
- // This is a linear search through the same nodes Vector.
- // The Vector is sorted on the DOM Level 1 nodename.
+ // This is a linear search through the same nodes ArrayList.
+ // The ArrayList is sorted on the DOM Level 1 nodename.
// The DOM Level 2 NS keys are namespaceURI and Localname,
// so we must linear search thru it.
// In addition, to get this to work with nodes without any namespace
// (namespaceURI and localNames are both null) we then use the nodeName
- // as a seconday key.
- for (int i = 0; i < nodes.size(); i++) {
- NodeImpl a = (NodeImpl)nodes.elementAt(i);
+ // as a secondary key.
+ final int size = nodes.size();
+ for (int i = 0; i < size; ++i) {
+ NodeImpl a = (NodeImpl)nodes.get(i);
String aNamespaceURI = a.getNamespaceURI();
String aLocalName = a.getLocalName();
if (namespaceURI == null) {
@@ -507,15 +516,15 @@
// return false
protected boolean precedes(Node a, Node b) {
- if (nodes != null) {
- for (int i = 0; i < nodes.size(); i++) {
- Node n = (Node)nodes.elementAt(i);
- if (n==a) return true;
- if (n==b) return false;
- }
- }
-
- return false;
+ if (nodes != null) {
+ final int size = nodes.size();
+ for (int i = 0; i < size; ++i) {
+ Node n = (Node)nodes.get(i);
+ if (n==a) return true;
+ if (n==b) return false;
+ }
+ }
+ return false;
}
@@ -524,14 +533,14 @@
*/
protected void removeItem(int index) {
if (nodes != null && index < nodes.size()){
- nodes.removeElementAt(index);
+ nodes.remove(index);
}
}
protected Object getItem (int index){
- if (nodes !=null) {
- return nodes.elementAt(index);
+ if (nodes != null) {
+ return nodes.get(index);
}
return null;
}
@@ -539,43 +548,43 @@
protected int addItem (Node arg) {
int i = findNamePoint(arg.getNamespaceURI(), arg.getLocalName());
if (i >= 0) {
- nodes.setElementAt(arg,i);
+ nodes.set(i, arg);
}
else {
// If we can't find by namespaceURI, localName, then we find by
// nodeName so we know where to insert.
i = findNamePoint(arg.getNodeName(),0);
if (i >= 0) {
- nodes.insertElementAt(arg,i);
+ nodes.add(i, arg);
}
else {
i = -1 - i; // Insert point (may be end of list)
if (null == nodes) {
- nodes = new Vector(5, 10);
+ nodes = new ArrayList(5);
}
- nodes.insertElementAt(arg, i);
+ nodes.add(i, arg);
}
}
return i;
}
/**
- * NON-DOM: copy content of this map into the specified vector
+ * NON-DOM: copy content of this map into the specified ArrayList
*
- * @param list Vector to copy information into.
+ * @param list ArrayList to copy information into.
* @return A copy of this node named map
*/
- protected Vector cloneMap(Vector list){
+ protected ArrayList cloneMap(ArrayList list) {
if (list == null) {
- list = new Vector(5, 10);
+ list = new ArrayList(5);
}
- list.setSize(0);
+ list.clear();
if (nodes != null) {
- for (int i=0; i<nodes.size(); i++) {
- list.insertElementAt(nodes.elementAt(i), i);
+ final int size = nodes.size();
+ for (int i = 0; i < size; ++i) {
+ list.add(nodes.get(i));
}
}
-
return list;
}
@@ -588,9 +597,31 @@
*/
public void removeAll (){
if (nodes != null) {
- nodes.removeAllElements();
+ nodes.clear();
}
}
+ private void readObject(ObjectInputStream in)
+ throws IOException, ClassNotFoundException {
+ in.defaultReadObject();
+ if (nodes != null) {
+ nodes = new ArrayList(nodes);
+ }
+ }
+ private void writeObject(ObjectOutputStream out) throws IOException {
+ List oldNodes = this.nodes;
+ try {
+ if (oldNodes != null) {
+ this.nodes = new Vector(oldNodes);
+ }
+ out.defaultWriteObject();
+ }
+ // If the write fails for some reason ensure
+ // that we restore the original object.
+ finally {
+ this.nodes = oldNodes;
+ }
+ }
+
} // class NamedNodeMapImpl
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org