Search in sources :

Example 21 with AnyType

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

the class SequenceTypeSyntaxTest method test_sequence_type_14.

// Simple evaluation of sequence type matching involving castable as and a sequence of two decimals. (Uses decimal?).
public void test_sequence_type_14() throws Exception {
    String inputFile = "/TestSources/emptydoc.xml";
    String xqFile = "/Queries/XQuery/Basics/Types/SequenceTypeSyntax/sequence-type-14.xq";
    String resultFile = "/ExpectedTestResults/Basics/Types/SequenceTypeSyntax/falsevalue.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)

Example 22 with AnyType

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

the class AbstractURIFunction method escape_uri.

/**
 * Apply the URI escaping rules to the arguments.
 *
 * @param args
 *            have the URI escaping rules applied to them.
 * @param escape_space TODO
 * @throws DynamicError
 *             Dynamic error.
 * @return The result of applying the URI escaping rules to the arguments.
 */
public static ResultSequence escape_uri(Collection args, boolean escape_delimiters, boolean escape_space) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    Iterator argi = cargs.iterator();
    ResultSequence arg1 = (ResultSequence) argi.next();
    if (arg1.empty()) {
        return new XSString("");
    }
    AnyType aat = (AnyType) arg1.item(0);
    String str = aat.getStringValue();
    ByteBuffer buffer = UTF_8.encode(str);
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < buffer.limit(); i++) {
        byte x = buffer.get(i);
        if (needs_escape(x, escape_delimiters, escape_space)) {
            sb.append("%");
            sb.append(Integer.toHexString(x & 0xFF).toUpperCase());
        } else
            sb.append((char) x);
    }
    return new XSString(sb.toString());
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator) Collection(java.util.Collection) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType) ByteBuffer(java.nio.ByteBuffer)

Example 23 with AnyType

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

the class FnAbs method get_single_numeric_arg.

/**
 * Obtain numeric value from expression.
 *
 * @param arg
 *            input expression.
 * @throws DynamicError
 *             Dynamic error.
 * @return Resulting numeric type from the operation.
 */
public static NumericType get_single_numeric_arg(ResultSequence arg) throws DynamicError {
    int size = arg.size();
    if (size > 1)
        DynamicError.throw_type_error();
    if (size == 0)
        return null;
    arg = FnData.atomize(arg);
    AnyType at = (AnyType) arg.item(0);
    if (!(at instanceof NumericType))
        throw DynamicError.invalidType();
    return (NumericType) at;
}
Also used : NumericType(org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 24 with AnyType

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

the class FnAvg method avg.

/**
 * Average value operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:avg operation.
 */
public static ResultSequence avg(Collection args) throws DynamicError {
    ResultSequence arg = (ResultSequence) args.iterator().next();
    if (arg.empty())
        return ResultSequenceFactory.create_new();
    int elems = 0;
    MathPlus total = null;
    TypePromoter tp = new ScalarTypePromoter();
    tp.considerSequence(arg);
    for (Iterator i = arg.iterator(); i.hasNext(); ) {
        ++elems;
        AnyAtomicType conv = tp.promote((AnyType) i.next());
        if (conv != null) {
            if (conv instanceof XSDouble && ((XSDouble) conv).nan() || conv instanceof XSFloat && ((XSFloat) conv).nan()) {
                return ResultSequenceFactory.create_new(tp.promote(new XSFloat(Float.NaN)));
            }
            if (total == null) {
                total = (MathPlus) conv;
            } else {
                total = (MathPlus) total.plus(ResultSequenceFactory.create_new(conv)).first();
            }
        }
    }
    if (!(total instanceof MathDiv))
        DynamicError.throw_type_error();
    return ((MathDiv) total).div(ResultSequenceFactory.create_new(new XSInteger(BigInteger.valueOf(elems))));
}
Also used : XSFloat(org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat) ScalarTypePromoter(org.eclipse.wst.xml.xpath2.processor.internal.utils.ScalarTypePromoter) XSDouble(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSInteger(org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger) Iterator(java.util.Iterator) TypePromoter(org.eclipse.wst.xml.xpath2.processor.internal.utils.TypePromoter) ScalarTypePromoter(org.eclipse.wst.xml.xpath2.processor.internal.utils.ScalarTypePromoter) AnyAtomicType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType)

Example 25 with AnyType

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

the class DefaultStaticContext method debug_print_vars.

/**
 * Debug function which will print current variable scopes and info.
 */
// debug functions
public void debug_print_vars() {
    int level = 0;
    for (Iterator i = _scopes.iterator(); i.hasNext(); ) {
        Map scope = (Map) i.next();
        System.out.println("Scope level " + level);
        // scope.entrySet().iterator();
        for (Iterator j = scope.entrySet().iterator(); j.hasNext(); ) {
            QName varname = (QName) j.next();
            AnyType val = (AnyType) scope.get(varname);
            String string_val = "null";
            if (val != null)
                string_val = val.getStringValue();
            System.out.println("Varname: " + varname.string() + " expanded=" + varname.expanded() + " Value: " + string_val);
        }
        level++;
    }
}
Also used : QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

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