use of org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType in project webtools.sourceediting by eclipse.
the class ExternalContextExprTest method test_externalcontextitem_16.
// Evaluation of external context item expression where context item used as part of a boolean expression (and operator).
public void test_externalcontextitem_16() throws Exception {
String inputFile = "/TestSources/works-mod.xml";
String xqFile = "/Queries/XQuery/Expressions/ContextExpr/ExternalContextExpr/externalcontextitem-16.xq";
String resultFile = "/ExpectedTestResults/Expressions/ContextExpr/ExternalContextExpr/externalcontextitem-16.txt";
String expectedResult = getExpectedResult(resultFile);
URL fileURL = bundle.getEntry(inputFile);
loadDOMDocument(fileURL);
// Get XML Schema Information for the Document
XSModel schema = getGrammar();
setupDynamicContext(schema);
String xpath = extractXPathExpression(xqFile, inputFile);
String actual = null;
try {
compileXPath(xpath);
ResultSequence rs = evaluate(domDoc);
AnyType result = rs.first();
actual = result.getStringValue();
} catch (XPathParserException ex) {
actual = ex.code();
} catch (StaticError ex) {
actual = ex.code();
} catch (DynamicError ex) {
actual = ex.code();
}
assertEquals("XPath Result Error " + xqFile + ":", expectedResult, actual);
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType in project webtools.sourceediting by eclipse.
the class ExternalContextExprTest method test_externalcontextitem_19.
// Evaluation of external context item expression where context item used as argument to "avg" function.
public void test_externalcontextitem_19() throws Exception {
String inputFile = "/TestSources/works-mod.xml";
String xqFile = "/Queries/XQuery/Expressions/ContextExpr/ExternalContextExpr/externalcontextitem-19.xq";
String resultFile = "/ExpectedTestResults/Expressions/ContextExpr/ExternalContextExpr/externalcontextitem-19.txt";
String expectedResult = getExpectedResult(resultFile);
URL fileURL = bundle.getEntry(inputFile);
loadDOMDocument(fileURL);
// Get XML Schema Information for the Document
XSModel schema = getGrammar();
setupDynamicContext(schema);
String xpath = extractXPathExpression(xqFile, inputFile);
String actual = null;
try {
compileXPath(xpath);
ResultSequence rs = evaluate(domDoc);
AnyType result = rs.first();
actual = result.getStringValue();
} catch (XPathParserException ex) {
actual = ex.code();
} catch (StaticError ex) {
actual = ex.code();
} catch (DynamicError ex) {
actual = ex.code();
}
assertEquals("XPath Result Error " + xqFile + ":", expectedResult, actual);
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method do_exists.
private XSBoolean do_exists(ListIterator iter, Expr finalexpr) {
// we have more vars to bind...
if (iter.hasNext()) {
VarExprPair ve = (VarExprPair) iter.next();
// evaluate binding sequence
ResultSequence rs = (ResultSequence) ve.expr().accept(this);
QName varname = ve.varname();
try {
for (Iterator i = rs.iterator(); i.hasNext(); ) {
AnyType item = (AnyType) i.next();
pushScope(varname, item);
XSBoolean effbool = do_exists(iter, finalexpr);
popScope();
// out what to do with it
if (effbool.value())
return XSBoolean.TRUE;
}
} finally {
iter.previous();
}
// since none in this sequence evaluated to true, return false
return XSBoolean.FALSE;
} else // we finally got to do the "last expression"
{
return effective_boolean_value((ResultSequence) finalexpr.accept(this));
}
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method visit.
/**
* visit cast expression
*
* @param cexp
* is the cast expression.
* @return a new function
*/
public Object visit(CastExpr cexp) {
ResultSequence rs = (ResultSequence) cexp.left().accept(this);
SingleType st = (SingleType) cexp.right();
rs = FnData.atomize(rs);
if (rs.size() > 1)
report_error(TypeError.invalid_type(null));
if (rs.empty()) {
if (st.qmark())
return rs;
else
report_error(TypeError.invalid_type(null));
}
AnyType at = (AnyType) rs.item(0);
if (!(at instanceof AnyAtomicType))
report_error(TypeError.invalid_type(null));
AnyAtomicType aat = (AnyAtomicType) at;
QName type = st.type();
// prepare args from function
Collection args = new ArrayList();
args.add(ResultSequenceFactory.create_new(aat));
try {
Function function = cexp.function();
if (function == null) {
function = _sc.resolveFunction(type.asQName(), args.size());
cexp.set_function(function);
}
if (function == null)
report_error(TypeError.invalid_type(null));
return function.evaluate(args, _ec);
} catch (DynamicError err) {
report_error(err);
// unreach
return null;
}
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType in project webtools.sourceediting by eclipse.
the class AbstractPsychoPathWTPTest method setupVariables.
protected DynamicContext setupVariables(DynamicContext dc) {
dc.add_variable(new QName("x"));
dc.add_variable(new QName("var"));
if (domDoc != null) {
AnyType docType = new DocType(domDoc, dc.getTypeModel(domDoc));
dc.set_variable(new QName("input-context1"), docType);
dc.set_variable(new QName("input-context"), docType);
if (domDoc2 == null) {
dc.set_variable(new QName("input-context2"), docType);
} else {
dc.set_variable(new QName("input-context2"), (AnyType) new DocType(domDoc2, dc.getTypeModel(domDoc2)));
}
}
return dc;
}
Aggregations