Search in sources :

Example 21 with ResultSequence

use of org.eclipse.wst.xml.xpath2.api.ResultSequence 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 22 with ResultSequence

use of org.eclipse.wst.xml.xpath2.api.ResultSequence in project webtools.sourceediting by eclipse.

the class FnDistinctValues method distinct_values.

/**
 * Distinct-values operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:distinct-values operation.
 */
public static ResultSequence distinct_values(Collection args, DynamicContext context) throws DynamicError {
    ResultBuffer rs = new ResultBuffer();
    // get args
    Iterator citer = args.iterator();
    ResultSequence arg1 = (ResultSequence) citer.next();
    ResultSequence arg2 = ResultBuffer.EMPTY;
    if (citer.hasNext()) {
        arg2 = (ResultSequence) citer.next();
    }
    String collationURI = context.getCollationProvider().getDefaultCollation();
    if (!arg2.empty()) {
        XSString collation = (XSString) arg2.item(0);
        collationURI = collation.getStringValue();
    }
    for (Iterator iter = arg1.iterator(); iter.hasNext(); ) {
        AnyAtomicType atomizedItem = (AnyAtomicType) FnData.atomize((Item) iter.next());
        if (!contains(rs, atomizedItem, context, collationURI))
            rs.add(atomizedItem);
    }
    return rs.getSequence();
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) AnyAtomicType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Example 23 with ResultSequence

use of org.eclipse.wst.xml.xpath2.api.ResultSequence in project webtools.sourceediting by eclipse.

the class FnError method evaluate.

/**
 * Evaluate arguments.
 *
 * @param args
 *            argument expressions.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of evaluation.
 */
public ResultSequence evaluate(Collection args, org.eclipse.wst.xml.xpath2.api.EvaluationContext ec) throws DynamicError {
    // Differentiate depending on whether there is one (required) argument or whatever.
    Collection cargs = Function.convert_arguments(args, args.size() == 1 ? expected_args1() : expected_args());
    QName code = null;
    ResultSequence items = null;
    String description = null;
    // Iterate over the args
    Iterator it = cargs.iterator();
    if (it.hasNext()) {
        ResultSequence rsQName = (ResultSequence) it.next();
        // for arity 2 and 3, the code is not mandatory, as in fn:code((), "description). Handle this:
        if (!rsQName.empty())
            code = (QName) rsQName.first();
    }
    // Next arg (if present) is the description
    if (it.hasNext()) {
        ResultSequence rsDescription = (ResultSequence) it.next();
        description = ((XSString) rsDescription.first()).value();
    }
    // Final arg (if present) is the list of items
    if (it.hasNext()) {
        items = (ResultSequence) it.next();
    }
    // Handle the code if missing
    if (code == null)
        code = new QName("err", "FOER0000", "http://www.w3.org/2005/xqt-errors");
    return error(code, description, items);
}
Also used : QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) 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)

Example 24 with ResultSequence

use of org.eclipse.wst.xml.xpath2.api.ResultSequence in project webtools.sourceediting by eclipse.

the class FnExactlyOne method exactly_one.

/**
 * Exactly-one operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:exactly-one operation.
 */
public static ResultSequence exactly_one(Collection args) throws DynamicError {
    assert args.size() == 1;
    // get args
    Iterator citer = args.iterator();
    ResultSequence arg = (ResultSequence) citer.next();
    if (arg.size() != 1)
        throw DynamicError.not_one(null);
    return arg;
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator)

Example 25 with ResultSequence

use of org.eclipse.wst.xml.xpath2.api.ResultSequence in project webtools.sourceediting by eclipse.

the class FnHoursFromDateTime method hours_from_date_time.

/**
 * Hours-from-DateTime operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:hours-from-dateTime operation.
 */
public static ResultSequence hours_from_date_time(Collection args) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
    if (arg1.empty()) {
        return ResultBuffer.EMPTY;
    }
    XSDateTime dt = (XSDateTime) arg1.first();
    int res = dt.hour();
    return new XSInteger(BigInteger.valueOf(res));
}
Also used : XSDateTime(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDateTime) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSInteger(org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger) Collection(java.util.Collection)

Aggregations

ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)8383 URL (java.net.URL)8366 XSModel (org.apache.xerces.xs.XSModel)8363 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)8279 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)8279 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)8208 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)173 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)156 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)130 Schema (javax.xml.validation.Schema)102 Iterator (java.util.Iterator)92 Collection (java.util.Collection)83 XSBoolean (org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean)83 DefaultEvaluator (org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator)74 Evaluator (org.eclipse.wst.xml.xpath2.processor.Evaluator)74 XPath (org.eclipse.wst.xml.xpath2.processor.ast.XPath)74 DynamicContext (org.eclipse.wst.xml.xpath2.processor.DynamicContext)72 Item (org.eclipse.wst.xml.xpath2.api.Item)56 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)34 XSInteger (org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger)32