use of org.eclipse.wst.xml.xpath2.processor.util.StaticContextBuilder 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.processor.util.StaticContextBuilder in project webtools.sourceediting by eclipse.
the class AbstractPsychoPathTest method setupDynamicContext.
protected DefaultDynamicContext setupDynamicContext(XSModel schema) {
XercesTypeModel typeModel = schema != null ? new XercesTypeModel(schema) : null;
if (useNewApi) {
staticContextBuilder.withTypeModel(typeModel);
staticContextBuilder.withNamespace("xs", "http://www.w3.org/2001/XMLSchema");
staticContextBuilder.withNamespace("xsd", "http://www.w3.org/2001/XMLSchema");
staticContextBuilder.withNamespace("fn", "http://www.w3.org/2005/xpath-functions");
staticContextBuilder.withNamespace("xml", "http://www.w3.org/XML/1998/namespace");
dynamicContextBuilder = new DynamicContextBuilder(staticContextBuilder);
setupVariables(dynamicContext);
try {
dynamicContextBuilder.withTimezoneOffset(DatatypeFactory.newInstance().newDuration(false, /*i.e. negative*/
0, 0, 0, 5, 0, 0));
} catch (DatatypeConfigurationException e) {
throw new RuntimeException("Shouldn't fail here", e);
}
return null;
}
DefaultDynamicContext dc = new DefaultDynamicContext(typeModel);
dynamicContext = dc;
dc.add_namespace("xs", "http://www.w3.org/2001/XMLSchema");
dc.add_namespace("xsd", "http://www.w3.org/2001/XMLSchema");
dc.add_namespace("fn", "http://www.w3.org/2005/xpath-functions");
dc.add_namespace("xml", "http://www.w3.org/XML/1998/namespace");
dc.add_function_library(new FnFunctionLibrary());
dc.add_function_library(new XSCtrLibrary());
setupVariables(dc);
return dc;
}
use of org.eclipse.wst.xml.xpath2.processor.util.StaticContextBuilder in project webtools.sourceediting by eclipse.
the class AbstractPsychoPathTest method compileXPath.
protected XPath compileXPath(String xpath) throws XPathParserException, StaticError {
if (useNewApi) {
newXPath = new Engine().parseExpression(xpath, staticContextBuilder);
return null;
} else {
XPathParser xpp = new JFlexCupParser();
XPath path = oldXPath = xpp.parse(xpath);
StaticChecker name_check = new StaticNameResolver(dynamicContext);
name_check.check(path);
return path;
}
}
use of org.eclipse.wst.xml.xpath2.processor.util.StaticContextBuilder in project webtools.sourceediting by eclipse.
the class ContextBuilderTest method testReasonableDefaults.
public void testReasonableDefaults() {
StaticContextBuilder scb = new StaticContextBuilder();
assertFalse(scb.isXPath1Compatible());
assertEquals("", scb.getDefaultNamespace());
assertEquals(null, scb.getBaseUri());
}
use of org.eclipse.wst.xml.xpath2.processor.util.StaticContextBuilder 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();
}
}
Aggregations