Custom NodeList Implementation
I want my own org.w3c.dom.NodeList backed by an ArrayList, so I implemented:
public class SimNodeList extends ArrayList<Node> implements NodeList {
private static final long serialVersionUID = 1L;
public SimNodeList() {
super();
}
public SimNodeList(NodeList nodeList) {
super();
this.add(nodeList);
}
public Node item(int index) {
if (index>=size())
return null;
return get(index);
}
public int getLength() {
return size();
}
public void add(NodeList nodeList) {
if (nodeList==null)
return;
for (int i = 0; i < nodeList.getLength(); i++)
super.add(nodeList.item(i));
}
}
This seems to work ok until I try and use my custom NodeList as the context for another xpath.evaluate:
SimNodeList result1 = new SimNodeList();
result1.add( ..some NodeList... )
SimNodeList result2 = new SimNodeList((NodeList)xpath.evaluate("*", result 1, XPathConstants.NODESET));
If I use anything but "." as the xpath expression I get the following:
javax.xml.transform.TransformerException: Unknown error in XPath.
at com.sun.org.apache.xpath.internal.XPath.execute(Unknown Source)
at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.eval(Unknown Source)
at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.evaluate(Unknown Source)
at org.rje.sim.core.ConfigHelper.getFullOrderedMessageExchangeProcess(ConfigHelper.java:74)
at org.rje.sim.test.ConfigHelperTest.main(ConfigHelperTest.java:41)
Caused by: java.lang.NullPointerException
at com.sun.org.apache.xpath.internal.axes.ChildTestIterator.setRoot(Unknown Source)
at com.sun.org.apache.xpath.internal.axes.NodeSequence.setRoot(Unknown Source)
at com.sun.org.apache.xpath.internal.axes.LocPathIterator.execute(Unknown Source)
... 5 more
java.lang.NullPointerException
at com.sun.org.apache.xpath.internal.axes.ChildTestIterator.setRoot(Unknown Source)
at com.sun.org.apache.xpath.internal.axes.NodeSequence.setRoot(Unknown Source)
at com.sun.org.apache.xpath.internal.axes.LocPathIterator.execute(Unknown Source)
at com.sun.org.apache.xpath.internal.XPath.execute(Unknown Source)
at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.eval(Unknown Source)
at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.evaluate(Unknown Source)
at org.rje.sim.core.ConfigHelper.getFullOrderedMessageExchangeProcess(ConfigHelper.java:74)
at org.rje.sim.test.ConfigHelperTest.main(ConfigHelperTest.java:41)
Process Node List:
linked to
javax.xml.xpath.XPathExpressionException
at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.evaluate(Unknown Source)
at org.rje.sim.core.ConfigHelper.getFullOrderedMessageExchangeProcess(ConfigHelper.java:74)
at org.rje.sim.test.ConfigHelperTest.main(ConfigHelperTest.java:41)
Caused by: javax.xml.transform.TransformerException: Unknown error in XPath.
at com.sun.org.apache.xpath.internal.XPath.execute(Unknown Source)
at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.eval(Unknown Source)
... 3 more
Caused by: java.lang.NullPointerException
at com.sun.org.apache.xpath.internal.axes.ChildTestIterator.setRoot(Unknown Source)
at com.sun.org.apache.xpath.internal.axes.NodeSequence.setRoot(Unknown Source)
at com.sun.org.apache.xpath.internal.axes.LocPathIterator.execute(Unknown Source)
... 5 more

