use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration in project webtools.sourceediting by eclipse.
the class FnHoursFromDuration method expected_args.
/**
* Obtain a list of expected arguments.
*
* @return Result of operation.
*/
public static synchronized Collection expected_args() {
if (_expected_args == null) {
_expected_args = new ArrayList();
_expected_args.add(new SeqType(new XSDuration(), SeqType.OCC_QMARK));
}
return _expected_args;
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration in project webtools.sourceediting by eclipse.
the class FnHoursFromDuration method hours_from_duration.
/**
* Hours-from-Duration operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:hours-from-duration operation.
*/
public static ResultSequence hours_from_duration(Collection args) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expected_args());
ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
if (arg1.empty()) {
return ResultBuffer.EMPTY;
}
XSDuration dtd = (XSDuration) arg1.first();
int res = dtd.hours();
if (dtd.negative())
res *= -1;
return new XSInteger(BigInteger.valueOf(res));
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration in project webtools.sourceediting by eclipse.
the class XSDateTime method plus.
/**
* Mathematical addition operator between this XSDateTime and a supplied
* result sequence (XDTYearMonthDuration and XDTDayTimeDuration are only
* valid ones).
*
* @param arg
* The supplied ResultSequence that is on the right of the minus
* operator. If arg is an XDTYearMonthDuration or an
* XDTDayTimeDuration the result will be a XSDateTime of the
* result of the current date minus the duration of time
* supplied.
* @return New ResultSequence consisting of the result of the mathematical
* minus operation.
*/
public ResultSequence plus(ResultSequence arg) throws DynamicError {
if (arg.size() != 1)
DynamicError.throw_type_error();
Item at = arg.first();
try {
if (at instanceof XSYearMonthDuration) {
XSYearMonthDuration val = (XSYearMonthDuration) at;
XSDateTime res = (XSDateTime) clone();
res.calendar().add(Calendar.MONTH, val.monthValue());
return ResultSequenceFactory.create_new(res);
} else if (at instanceof XSDayTimeDuration) {
XSDuration val = (XSDuration) at;
XSDateTime res = (XSDateTime) clone();
XMLGregorianCalendar xmlCal = _datatypeFactory.newXMLGregorianCalendar((GregorianCalendar) calendar());
Duration dtduration = _datatypeFactory.newDuration(val.getStringValue());
xmlCal.add(dtduration);
res = new XSDateTime(xmlCal.toGregorianCalendar(), res.tz());
return ResultSequenceFactory.create_new(res);
} else {
DynamicError.throw_type_error();
// unreach
return null;
}
} catch (CloneNotSupportedException err) {
assert false;
return null;
}
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration in project webtools.sourceediting by eclipse.
the class FnYearsFromDuration method years_from_duration.
/**
* Years-from-Duration operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:years-from-duration operation.
*/
public static ResultSequence years_from_duration(Collection args) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expected_args());
ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
if (arg1.empty()) {
return ResultBuffer.EMPTY;
}
XSDuration ymd = (XSDuration) arg1.first();
int res = ymd.year();
if (ymd.negative())
res *= -1;
return new XSInteger(BigInteger.valueOf(res));
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration in project webtools.sourceediting by eclipse.
the class XSDouble method constructor.
/**
* Creates a new result sequence consisting of the retrievable double number
* in the supplied result sequence
*
* @param arg
* The result sequence from which to extract the double number.
* @throws DynamicError
* @return A new result sequence consisting of the double number supplied.
*/
public ResultSequence constructor(ResultSequence arg) throws DynamicError {
if (arg.empty())
return ResultBuffer.EMPTY;
Item aat = arg.first();
if (aat instanceof XSDuration || aat instanceof CalendarType || aat instanceof XSBase64Binary || aat instanceof XSHexBinary || aat instanceof XSAnyURI) {
throw DynamicError.invalidType();
}
if (!isCastable(aat)) {
throw DynamicError.cant_cast(null);
}
XSDouble d = castDouble(aat);
if (d == null)
throw DynamicError.cant_cast(null);
return d;
}
Aggregations