}
public XResult evaluateXPath(NodeList nodeList, Object xpath, NamespaceContext nsContext) throws XPathException {
try {
if(nodeList.getLength()>0) {
XResult result = null;
NodeListImpl nodes = null;
PrefixResolver pr = nsContext!=null ? new NSResolver(nsContext) : null;
for( int i=0; i<nodeList.getLength(); i++ ) {
XObject res = XPathAPI.eval(nodeList.item(i),(String)xpath,pr);
switch(res.getType()) {
case XObject.CLASS_BOOLEAN: {
if(nodes!=null) {
throw new XPathException(null,"XPath result cannot contain both values and nodes"); // $NLS-AbstractXercesDriver.AnXPathresultcannotcontainbothval-1$
}
if(result!=null) {
throw new XPathException(null,"XPath exception cannot return multiple values"); // $NLS-AbstractXercesDriver.AnXPathExceptioncannotreturnmulti-1$
}
result = new XResultUtils.BooleanValue(res.bool());
} break;
case XObject.CLASS_NUMBER: {
if(nodes!=null) {
throw new XPathException(null,"XPath result cannot contain both values and nodes"); // $NLS-AbstractXercesDriver.AnXPathresultcannotcontainbothval.1-1$
}
if(result!=null) {
throw new XPathException(null,"XPath exception cannot return multiple values"); // $NLS-AbstractXercesDriver.AnXPathExceptioncannotreturnmulti.1-1$
}
result = new XResultUtils.NumberValue(res.num());
} break;
case XObject.CLASS_STRING: {
if(nodes!=null) {
throw new XPathException(null,"XPath result cannot contain both values and nodes"); // $NLS-AbstractXercesDriver.AnXPathresultcannotcontainbothval.2-1$
}
if(result!=null) {
throw new XPathException(null,"XPath exception cannot return multiple values"); // $NLS-AbstractXercesDriver.AnXPathExceptioncannotreturnmulti.2-1$
}
result = new XResultUtils.StringValue(res.str());
} break;
case XObject.CLASS_NODESET: {
if(result!=null) {
throw new XPathException(null,"XPath result cannot contain both values and nodes"); // $NLS-AbstractXercesDriver.AnXPathresultcannotcontainbothval.3-1$
}
NodeList nl = res.nodelist();
int len = nl.getLength();
if(len>0) {
if(nodes==null) {
nodes = new NodeListImpl();
}
for( int j=0; j<nl.getLength(); j++ ) {
nodes.add(nl.item(j));
}
}
}
}
}
if(result!=null) {
return result;
}
if(nodes!=null) {
int len = nodes.getLength();
if(len==0) {
return XResultUtils.emptyResult;
} else if(len==1) {
return new XResultUtils.XMLNode(nodes.item(0));
} else {
return new XResultUtils.XMLNodeList(nodes);
}
}
}