use of org.eclipse.wst.xml.xpath2.processor.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;
}
use of org.eclipse.wst.xml.xpath2.processor.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();
}
use of org.eclipse.wst.xml.xpath2.processor.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);
}
use of org.eclipse.wst.xml.xpath2.processor.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;
}
use of org.eclipse.wst.xml.xpath2.processor.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));
}
Aggregations