use of org.eclipse.wst.xml.xpath2.processor.DynamicContext in project webtools.sourceediting by eclipse.
the class FnAdjustTimeToTimeZone method adjustTime.
/**
* Evaluate the function using the arguments passed.
*
* @param args
* Result from the expressions evaluation.
* @param sc
* Result of static context operation.
* @throws DynamicError
* Dynamic error.
* @return Result of the fn:dateTime operation.
*/
public static ResultSequence adjustTime(Collection args, DynamicContext dc) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expectedArgs());
// get args
Iterator argiter = cargs.iterator();
ResultSequence arg1 = (ResultSequence) argiter.next();
if (arg1.empty()) {
return ResultBuffer.EMPTY;
}
ResultSequence arg2 = ResultBuffer.EMPTY;
if (argiter.hasNext()) {
arg2 = (ResultSequence) argiter.next();
}
XSTime time = (XSTime) arg1.first();
XSDayTimeDuration timezone = null;
if (arg2.empty()) {
if (time.timezoned()) {
XSTime localized = new XSTime(time.calendar(), null);
return localized;
} else {
return arg1;
}
}
XMLGregorianCalendar xmlCalendar = null;
if (time.tz() != null) {
xmlCalendar = _datatypeFactory.newXMLGregorianCalendar((GregorianCalendar) time.normalizeCalendar(time.calendar(), time.tz()));
} else {
xmlCalendar = _datatypeFactory.newXMLGregorianCalendarTime(time.hour(), time.minute(), (int) time.second(), 0);
}
timezone = (XSDayTimeDuration) arg2.first();
if (timezone.lt(minDuration, dc) || timezone.gt(maxDuration, dc)) {
throw DynamicError.invalidTimezone();
}
if (time.tz() == null) {
return new XSTime(time.calendar(), timezone);
}
Duration duration = _datatypeFactory.newDuration(timezone.getStringValue());
xmlCalendar.add(duration);
return new XSTime(xmlCalendar.toGregorianCalendar(), timezone);
}
use of org.eclipse.wst.xml.xpath2.processor.DynamicContext in project webtools.sourceediting by eclipse.
the class FnCompare method compare.
/**
* Compare the arguments.
*
* @param args
* are compared (optional 3rd argument is the collation)
* @param dynamicContext
* Current dynamic context
* @throws DynamicError
* Dynamic error.
* @return The result of the comparison of the arguments.
*/
public static ResultSequence compare(Collection args, DynamicContext context) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expected_args());
Iterator argiter = cargs.iterator();
ResultSequence arg1 = (ResultSequence) argiter.next();
ResultSequence arg2 = (ResultSequence) argiter.next();
String collationUri = context.getCollationProvider().getDefaultCollation();
if (argiter.hasNext()) {
ResultSequence collArg = (ResultSequence) argiter.next();
collationUri = collArg.first().getStringValue();
}
XSString xstr1 = arg1.empty() ? null : (XSString) arg1.first();
XSString xstr2 = arg2.empty() ? null : (XSString) arg2.first();
BigInteger result = compare_string(collationUri, xstr1, xstr2, context);
if (result != null) {
return ResultSequenceFactory.create_new(new XSInteger(result));
} else {
return ResultSequenceFactory.create_new();
}
}
use of org.eclipse.wst.xml.xpath2.processor.DynamicContext in project webtools.sourceediting by eclipse.
the class FnInScopePrefixes method inScopePrefixes.
/**
* Prefix-from-QName operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:prefix-from-QName operation.
*/
public static ResultSequence inScopePrefixes(Collection args, DynamicContext dc) throws DynamicError {
// Collection cargs = Function.convert_arguments(args, expected_args());
Collection cargs = args;
ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
if (arg1.empty())
return ResultBuffer.EMPTY;
ResultBuffer rs = new ResultBuffer();
Item anytype = arg1.item(0);
if (!(anytype instanceof ElementType)) {
throw new DynamicError(TypeError.invalid_type(null));
}
ElementType element = (ElementType) anytype;
List prefixList = lookupPrefixes(element);
createPrefixResultSet(rs, prefixList);
return rs.getSequence();
}
use of org.eclipse.wst.xml.xpath2.processor.DynamicContext in project webtools.sourceediting by eclipse.
the class FnMax method max.
/**
* Max operation.
*
* @param args
* Result from the expressions evaluation.
* @param context
* Relevant dynamic context
* @throws DynamicError
* Dynamic error.
* @return Result of fn:max operation.
*/
public static ResultSequence max(Collection args, DynamicContext dynamicContext) throws DynamicError {
ResultSequence arg = get_arg(args, CmpGt.class);
if (arg.empty())
return ResultSequenceFactory.create_new();
CmpGt max = null;
TypePromoter tp = new ComparableTypePromoter();
tp.considerSequence(arg);
for (Iterator i = arg.iterator(); i.hasNext(); ) {
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 (max == null || ((CmpGt) conv).gt((AnyType) max, dynamicContext)) {
max = (CmpGt) conv;
}
}
}
return ResultSequenceFactory.create_new((AnyType) max);
}
use of org.eclipse.wst.xml.xpath2.processor.DynamicContext in project webtools.sourceediting by eclipse.
the class FsGe method fs_ge_value.
/**
* Greater than or equal to operation on the values of the arguments.
*
* @param args
* input arguments.
* @param dc
* @throws DynamicError
* Dynamic error.
* @return Result of the operation.
*/
public static ResultSequence fs_ge_value(Collection args, DynamicContext dc) throws DynamicError {
ResultSequence greater = FsGt.fs_gt_value(args, dc);
if (((XSBoolean) greater.first()).value())
return greater;
ResultSequence equal = FsEq.fs_eq_value(args, dc);
if (((XSBoolean) equal.first()).value())
return equal;
return ResultSequenceFactory.create_new(new XSBoolean(false));
}
Aggregations