Search in sources :

Example 16 with XSDuration

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;
}
Also used : XSDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration) SeqType(org.eclipse.wst.xml.xpath2.processor.internal.SeqType) ArrayList(java.util.ArrayList)

Example 17 with XSDuration

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));
}
Also used : XSDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSInteger(org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger) Collection(java.util.Collection)

Example 18 with XSDuration

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;
    }
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Duration(javax.xml.datatype.Duration)

Example 19 with XSDuration

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));
}
Also used : XSDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSInteger(org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger) Collection(java.util.Collection)

Example 20 with XSDuration

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;
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item)

Aggregations

XSDuration (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration)18 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)8 Collection (java.util.Collection)7 ArrayList (java.util.ArrayList)6 SeqType (org.eclipse.wst.xml.xpath2.processor.internal.SeqType)6 XSInteger (org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger)6 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)5 URL (java.net.URL)4 XSModel (org.apache.xerces.xs.XSModel)4 Item (org.eclipse.wst.xml.xpath2.api.Item)4 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)4 BigDecimal (java.math.BigDecimal)2 Iterator (java.util.Iterator)2 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 Duration (javax.xml.datatype.Duration)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)1 AnyAtomicType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType)1 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)1