Search in sources :

Example 81 with AnyType

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);
}
Also used : XPathParserException(org.eclipse.wst.xml.xpath2.processor.XPathParserException) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) XSModel(org.apache.xerces.xs.XSModel) StaticError(org.eclipse.wst.xml.xpath2.processor.StaticError) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType) URL(java.net.URL)

Example 82 with AnyType

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);
}
Also used : XPathParserException(org.eclipse.wst.xml.xpath2.processor.XPathParserException) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) XSModel(org.apache.xerces.xs.XSModel) StaticError(org.eclipse.wst.xml.xpath2.processor.StaticError) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType) URL(java.net.URL)

Example 83 with AnyType

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));
    }
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) XSBoolean(org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType) VarExprPair(org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)

Example 84 with AnyType

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;
    }
}
Also used : Function(org.eclipse.wst.xml.xpath2.api.Function) SingleType(org.eclipse.wst.xml.xpath2.processor.internal.ast.SingleType) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) ArrayList(java.util.ArrayList) Collection(java.util.Collection) AnyAtomicType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 85 with AnyType

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;
}
Also used : QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType) DocType(org.eclipse.wst.xml.xpath2.processor.internal.types.DocType)

Aggregations

AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)162 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)127 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)123 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)123 URL (java.net.URL)122 XSModel (org.apache.xerces.xs.XSModel)121 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)40 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)38 Iterator (java.util.Iterator)37 Item (org.eclipse.wst.xml.xpath2.api.Item)26 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)14 NodeType (org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)14 QName (org.eclipse.wst.xml.xpath2.processor.internal.types.QName)11 AnyAtomicType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType)9 XSDouble (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble)9 Collection (java.util.Collection)8 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)8 ListIterator (java.util.ListIterator)7 ArrayList (java.util.ArrayList)6 NumericType (org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType)6