Search in sources :

Example 96 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 context item expression.
 *
 * @param e
 *            is the context item expression.
 * @return a result sequence
 */
public Object visit(CntxItemExpr e) {
    ResultBuffer rs = new ResultBuffer();
    AnyType contextItem = focus().context_item();
    if (contextItem == null) {
        report_error(DynamicError.contextUndefined());
    }
    rs.add(contextItem);
    return rs.getSequence();
}
Also used : ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 97 with AnyType

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

the class DefaultEvaluator method do_for_all.

// XXX ugly
// type: 0 = for [return == "correct"]
// 1 = for all [return false, return empty on true]
// 2 = there exists [return true, return empty on false]
private XSBoolean do_for_all(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_for_all(iter, finalexpr);
                popScope();
                // out what to do with it
                if (!effbool.value())
                    return XSBoolean.FALSE;
            }
        } finally {
            iter.previous();
        }
        return XSBoolean.TRUE;
    } 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 98 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 variable reference
 *
 * @param e
 *            is the variable reference.
 * @return a result sequence
 */
public Object visit(VarRef e) {
    ResultBuffer rs = new ResultBuffer();
    Object var = getVariable(e.name());
    assert var != null;
    if (var instanceof AnyType) {
        rs.add((AnyType) var);
    } else if (var instanceof ResultSequence) {
        rs.concat((ResultSequence) var);
    }
    return rs.getSequence();
}
Also used : ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 99 with AnyType

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

the class LiteralsTest method test_Literals068.

// Test the escaping of the ' (apostrophe) and " (quotation) characters as part of an XML text node constructor.
public void test_Literals068() throws Exception {
    String inputFile = "/TestSources/emptydoc.xml";
    // String xqFile = "/Queries/XQuery/Expressions/PrimaryExpr/Literals/Literals068.xq";
    String resultFile = "/ExpectedTestResults/Expressions/PrimaryExpr/Literals/Literals068-1.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 = "'He said, \"I don''t like it.\"'";
    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();
    }
    assertEquals("XPath Result Error:", 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) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType) URL(java.net.URL)

Example 100 with AnyType

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

the class LiteralsTest method test_Literals056.

// Test for string literal containing the predefined entity reference '&'.
public void test_Literals056() throws Exception {
    String inputFile = "/TestSources/emptydoc.xml";
    String xqFile = "/Queries/XQuery/Expressions/PrimaryExpr/Literals/Literals056.xq";
    String resultFile = "/ExpectedTestResults/Expressions/PrimaryExpr/Literals/Literals056.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();
    }
    assertEquals("XPath Result Error:", 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) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType) URL(java.net.URL)

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