Search in sources :

Example 21 with DynamicError

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

use of org.eclipse.wst.xml.xpath2.processor.DynamicError 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 23 with DynamicError

use of org.eclipse.wst.xml.xpath2.processor.DynamicError 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 24 with DynamicError

use of org.eclipse.wst.xml.xpath2.processor.DynamicError 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)

Example 25 with DynamicError

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

the class FnLocalNameFromQName method local_name.

/**
 * Local-Name-from-QName operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:local-name-from-QName operation.
 */
public static ResultSequence local_name(Collection args) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    // get arg
    ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
    if (arg1.empty())
        return ResultBuffer.EMPTY;
    QName qname = (QName) arg1.first();
    return new XSNCName(qname.local());
}
Also used : XSNCName(org.eclipse.wst.xml.xpath2.processor.internal.types.XSNCName) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) Collection(java.util.Collection)

Aggregations

DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)8211 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)8203 URL (java.net.URL)8194 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)8193 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)8193 XSModel (org.apache.xerces.xs.XSModel)8192 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)144 Schema (javax.xml.validation.Schema)100 Collection (java.util.Collection)81 DefaultEvaluator (org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator)72 Evaluator (org.eclipse.wst.xml.xpath2.processor.Evaluator)72 XPath (org.eclipse.wst.xml.xpath2.processor.ast.XPath)72 DynamicContext (org.eclipse.wst.xml.xpath2.processor.DynamicContext)71 Iterator (java.util.Iterator)70 Item (org.eclipse.wst.xml.xpath2.api.Item)68 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)54 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)47 XSInteger (org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger)25 XSAnyURI (org.eclipse.wst.xml.xpath2.processor.internal.types.XSAnyURI)22 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)20