Search in sources :

Example 1 with XPath

use of org.eclipse.wst.xml.xpath2.processor.ast.XPath in project webtools.sourceediting by eclipse.

the class Function method convert_argument.

// convert argument according to section 3.1.5 of xpath 2.0 spec
/**
 * Convert the input argument according to section 3.1.5 of specification.
 *
 * @param arg
 *            input argument.
 * @param expected
 *            Expected Sequence type.
 * @throws DynamicError
 *             Dynamic error.
 * @return Converted argument.
 */
public static org.eclipse.wst.xml.xpath2.api.ResultSequence convert_argument(org.eclipse.wst.xml.xpath2.api.ResultSequence arg, SeqType expected) throws DynamicError {
    ResultBuffer result = new ResultBuffer();
    // XXX: Should use type_class instead and use item.getClass().isAssignableTo(expected.type_class())
    AnyType expected_type = expected.type();
    // expected is atomic
    if (expected_type instanceof AnyAtomicType) {
        AnyAtomicType expected_aat = (AnyAtomicType) expected_type;
        // atomize
        org.eclipse.wst.xml.xpath2.api.ResultSequence rs = FnData.atomize(arg);
        // cast untyped to expected type
        for (Iterator i = rs.iterator(); i.hasNext(); ) {
            AnyType item = (AnyType) i.next();
            if (item instanceof XSUntypedAtomic) {
                // create a new item of the expected
                // type initialized with from the string
                // value of the item
                ResultSequence converted = null;
                if (expected_aat instanceof XSString) {
                    XSString strType = new XSString(item.getStringValue());
                    converted = ResultSequenceFactory.create_new(strType);
                } else {
                    converted = ResultSequenceFactory.create_new(item);
                }
                result.concat(converted);
            } else // xs:anyURI promotion to xs:string
            if (item instanceof XSAnyURI && expected_aat instanceof XSString) {
                result.add(new XSString(item.getStringValue()));
            } else // numeric type promotion
            if (item instanceof NumericType) {
                if (expected_aat instanceof XSDouble) {
                    XSDouble doubleType = new XSDouble(item.getStringValue());
                    result.add(doubleType);
                } else {
                    result.add(item);
                }
            } else {
                result.add(item);
            }
        }
        // do sequence type matching on converted arguments
        return expected.match(result.getSequence());
    } else {
        // do sequence type matching on converted arguments
        return expected.match(arg);
    }
}
Also used : NumericType(org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType) ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) XSAnyURI(org.eclipse.wst.xml.xpath2.processor.internal.types.XSAnyURI) XSDouble(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) Iterator(java.util.Iterator) AnyAtomicType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType) XSUntypedAtomic(org.eclipse.wst.xml.xpath2.processor.internal.types.XSUntypedAtomic) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 2 with XPath

use of org.eclipse.wst.xml.xpath2.processor.ast.XPath in project webtools.sourceediting by eclipse.

the class FnDeepEqual method deep_equal.

/**
 * Deep-Equal boolean operation.
 *
 * @param one
 *            input1 xpath expression/variable.
 * @param two
 *            input2 xpath expression/variable.
 * @param context
 *            Current dynamic context
 * @return Result of fn:deep-equal operation.
 */
public static boolean deep_equal(ResultSequence one, ResultSequence two, EvaluationContext context, String collationURI) {
    if (one.empty() && two.empty())
        return true;
    if (one.size() != two.size())
        return false;
    Iterator onei = one.iterator();
    Iterator twoi = two.iterator();
    while (onei.hasNext()) {
        AnyType a = (AnyType) onei.next();
        AnyType b = (AnyType) twoi.next();
        if (!deep_equal(a, b, context, collationURI))
            return false;
    }
    return true;
}
Also used : Iterator(java.util.Iterator) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 3 with XPath

use of org.eclipse.wst.xml.xpath2.processor.ast.XPath in project webtools.sourceediting by eclipse.

the class FnDeepEqual method deep_equal_atomic.

/**
 * Deep-Equal boolean operation for inputs of any atomic type.
 *
 * @param one
 *            input1 xpath expression/variable.
 * @param two
 *            input2 xpath expression/variable.
 * @return Result of fn:deep-equal operation.
 */
public static boolean deep_equal_atomic(AnyAtomicType one, AnyAtomicType two, DynamicContext context, String collationURI) {
    if (!(one instanceof CmpEq))
        return false;
    if (!(two instanceof CmpEq))
        return false;
    CmpEq a = (CmpEq) one;
    try {
        if (isNumeric(one, two)) {
            NumericType numeric = (NumericType) one;
            if (numeric.eq(two, context)) {
                return true;
            } else {
                XSString value1 = new XSString(one.getStringValue());
                if (value1.eq(two, context)) {
                    return true;
                }
            }
        }
        if (a.eq(two, context))
            return true;
        if (needsStringComparison(one, two)) {
            XSString xstr1 = new XSString(one.getStringValue());
            XSString xstr2 = new XSString(two.getStringValue());
            if (FnCompare.compare_string(collationURI, xstr1, xstr2, context).equals(BigInteger.ZERO)) {
                return true;
            }
        }
        return false;
    } catch (DynamicError err) {
        // XXX ???
        return false;
    }
}
Also used : NumericType(org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError)

Example 4 with XPath

use of org.eclipse.wst.xml.xpath2.processor.ast.XPath in project webtools.sourceediting by eclipse.

the class SeqExprCastableTest method test_CastableAs080.

// Try xs:untypedAtomic(http://www.example.com/~b%C3%A9b%C3%A9) castable as xs:anyURI.
public void test_CastableAs080() throws Exception {
    String inputFile = "/TestSources/emptydoc.xml";
    String xqFile = "/Queries/XQuery/Expressions/exprSeqTypes/SeqExprCastable/CastableAs080.xq";
    String resultFile = "/ExpectedTestResults/Expressions/exprSeqTypes/SeqExprCastable/CastableAs080.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);
        actual = buildResultString(rs);
    } 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) URL(java.net.URL)

Example 5 with XPath

use of org.eclipse.wst.xml.xpath2.processor.ast.XPath in project webtools.sourceediting by eclipse.

the class SeqExprCastableTest method test_CastableAs342.

// Try xs:dayTimeDuration(P3DT10H30M) castable as xs:date.
public void test_CastableAs342() throws Exception {
    String inputFile = "/TestSources/emptydoc.xml";
    String xqFile = "/Queries/XQuery/Expressions/exprSeqTypes/SeqExprCastable/CastableAs342.xq";
    String resultFile = "/ExpectedTestResults/Expressions/exprSeqTypes/SeqExprCastable/CastableAs342.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);
        actual = buildResultString(rs);
    } 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) URL(java.net.URL)

Aggregations

ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)8378 URL (java.net.URL)8369 XSModel (org.apache.xerces.xs.XSModel)8366 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)8282 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)8281 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)8197 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)126 Schema (javax.xml.validation.Schema)102 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)96 XPath (org.eclipse.wst.xml.xpath2.processor.ast.XPath)81 DefaultEvaluator (org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator)74 Evaluator (org.eclipse.wst.xml.xpath2.processor.Evaluator)74 DynamicContext (org.eclipse.wst.xml.xpath2.processor.DynamicContext)73 XSBoolean (org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean)69 XSAnyURI (org.eclipse.wst.xml.xpath2.processor.internal.types.XSAnyURI)17 XPathExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr)8 Iterator (java.util.Iterator)7 JFlexCupParser (org.eclipse.wst.xml.xpath2.processor.JFlexCupParser)7 XPathParser (org.eclipse.wst.xml.xpath2.processor.XPathParser)7 XSInteger (org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger)7