Search in sources :

Example 1 with DefaultStaticContext

use of org.eclipse.wst.xml.xpath2.processor.internal.DefaultStaticContext in project webtools.sourceediting by eclipse.

the class StaticContextAdapterTest method testFunctionCall.

public void testFunctionCall() {
    XPathParser xpp = new JFlexCupParser();
    XPath xpath = xpp.parse("fn:sum((1,2,3))");
    DefaultStaticContext sc = new DefaultStaticContext(null);
    sc.add_namespace("fn", "http://www.w3.org/2005/xpath-functions");
    sc.add_function_library(new FnFunctionLibrary());
    StaticChecker namecheck = new StaticNameResolver(sc);
    namecheck.check(xpath);
    DefaultDynamicContext dc = new DefaultDynamicContext(null, null);
    dc.add_namespace("fn", "http://www.w3.org/2005/xpath-functions");
    dc.add_function_library(new FnFunctionLibrary());
    Evaluator eval = new DefaultEvaluator(dc, null);
    ResultSequence rs = eval.evaluate(xpath);
    assertEquals(1, rs.size());
    XSDecimal result = (XSDecimal) rs.first();
    String actual = result.getStringValue();
    assertEquals("6", actual);
}
Also used : XPath(org.eclipse.wst.xml.xpath2.processor.ast.XPath) StaticChecker(org.eclipse.wst.xml.xpath2.processor.StaticChecker) XPathParser(org.eclipse.wst.xml.xpath2.processor.XPathParser) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) DefaultEvaluator(org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator) DefaultStaticContext(org.eclipse.wst.xml.xpath2.processor.internal.DefaultStaticContext) Evaluator(org.eclipse.wst.xml.xpath2.processor.Evaluator) DefaultEvaluator(org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator) FnFunctionLibrary(org.eclipse.wst.xml.xpath2.processor.function.FnFunctionLibrary) StaticNameResolver(org.eclipse.wst.xml.xpath2.processor.StaticNameResolver) DefaultDynamicContext(org.eclipse.wst.xml.xpath2.processor.DefaultDynamicContext) XSDecimal(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal) JFlexCupParser(org.eclipse.wst.xml.xpath2.processor.JFlexCupParser)

Aggregations

DefaultDynamicContext (org.eclipse.wst.xml.xpath2.processor.DefaultDynamicContext)1 DefaultEvaluator (org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator)1 Evaluator (org.eclipse.wst.xml.xpath2.processor.Evaluator)1 JFlexCupParser (org.eclipse.wst.xml.xpath2.processor.JFlexCupParser)1 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)1 StaticChecker (org.eclipse.wst.xml.xpath2.processor.StaticChecker)1 StaticNameResolver (org.eclipse.wst.xml.xpath2.processor.StaticNameResolver)1 XPathParser (org.eclipse.wst.xml.xpath2.processor.XPathParser)1 XPath (org.eclipse.wst.xml.xpath2.processor.ast.XPath)1 FnFunctionLibrary (org.eclipse.wst.xml.xpath2.processor.function.FnFunctionLibrary)1 DefaultStaticContext (org.eclipse.wst.xml.xpath2.processor.internal.DefaultStaticContext)1 XSDecimal (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal)1