use of org.eclipse.wst.xml.xpath2.api.XPath2Expression in project webtools.sourceediting by eclipse.
the class FilteringPerformanceTest method evalXPath2.
protected Object evalXPath2(String xpath, Node doc, Class resultClass) {
StaticContext sc = new StaticContextBuilder();
XPath2Expression path = new Engine().parseExpression(xpath, sc);
DynamicContext dynamicContext = new DynamicContextBuilder(sc);
long before = System.nanoTime();
// path.evaluate(dynamicContext, doc != null ? new Object[] { doc } : new Object[0]);
// path.evaluate(dynamicContext, doc != null ? new Object[] { doc } : new Object[0]);
org.eclipse.wst.xml.xpath2.api.ResultSequence rs = path.evaluate(dynamicContext, doc != null ? new Object[] { doc } : new Object[0]);
assertEquals("Expected single result from \'" + xpath + "\'", 1, rs.size());
Object result = rs.value(0);
long after = System.nanoTime();
System.out.println("XPath2 " + xpath + " evaluated to " + result + " in " + (after - before) / 1000 + " μs");
assertTrue("Exected XPath result instanceof class " + resultClass.getSimpleName() + " from \'" + xpath + "\', got " + result.getClass(), resultClass.isInstance(result));
return resultClass.cast(result);
}
use of org.eclipse.wst.xml.xpath2.api.XPath2Expression in project webservices-axiom by apache.
the class PsychoPathTest method evaluate.
private static ResultSequence evaluate(String xpath) throws Exception {
InputStream is = PsychoPathTest.class.getResourceAsStream("test.xml");
try {
OMFactory factory = OMAbstractFactory.getMetaFactory(OMAbstractFactory.FEATURE_DOM).getOMFactory();
Document doc = (Document) OMXMLBuilderFactory.createOMBuilder(factory, is).getDocument();
StaticContextBuilder scb = new StaticContextBuilder();
XPath2Expression expr = new Engine().parseExpression(xpath, scb);
return expr.evaluate(new DynamicContextBuilder(scb), new Object[] { doc });
} finally {
is.close();
}
}
use of org.eclipse.wst.xml.xpath2.api.XPath2Expression in project webtools.sourceediting by eclipse.
the class CompleteNewApiTest method evaluateSimpleXPath.
protected Object evaluateSimpleXPath(String xpath, StaticContext sc, Document doc, Class resultClass) {
XPath2Expression path = new Engine().parseExpression(xpath, sc);
DynamicContext dynamicContext = new DynamicContextBuilder(sc);
org.eclipse.wst.xml.xpath2.api.ResultSequence rs = path.evaluate(dynamicContext, doc != null ? new Object[] { doc } : new Object[0]);
assertEquals("Expected single result from \'" + xpath + "\'", 1, rs.size());
Object result = rs.value(0);
assertTrue("Exected XPath result instanceof class " + resultClass.getSimpleName() + " from \'" + xpath + "\', got " + result.getClass(), resultClass.isInstance(result));
return result;
}
use of org.eclipse.wst.xml.xpath2.api.XPath2Expression in project webtools.sourceediting by eclipse.
the class Engine method parseExpression.
public XPath2Expression parseExpression(String expression, StaticContext context) {
XPath xPath = new JFlexCupParser().parse(expression);
xPath.setStaticContext(context);
StaticNameResolver name_check = new StaticNameResolver(context);
name_check.check(xPath);
xPath.setAxes(name_check.getAxes());
xPath.setFreeVariables(name_check.getFreeVariables());
xPath.setResolvedFunctions(name_check.getResolvedFunctions());
xPath.setRootUsed(name_check.isRootUsed());
return xPath;
}
Aggregations