Search in sources :

Example 1 with CalendarType

use of org.eclipse.wst.xml.xpath2.processor.internal.types.CalendarType in project webtools.sourceediting by eclipse.

the class FnAdjustDateTimeToTimeZone method adjustdateTime.

/**
 * 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 adjustdateTime(Collection args, org.eclipse.wst.xml.xpath2.api.DynamicContext dynamicContext) 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 = null;
    if (argiter.hasNext()) {
        arg2 = (ResultSequence) argiter.next();
    }
    XSDateTime dateTime = (XSDateTime) arg1.item(0);
    XSDayTimeDuration timezone = null;
    if (arg2 != null && arg2.empty()) {
        if (dateTime.timezoned()) {
            CalendarType localized = new XSDateTime(dateTime.calendar(), null);
            return localized;
        } else {
            return arg1;
        }
    } else if (arg2 == null) {
        CalendarType localized = new XSDateTime(dateTime.normalizeCalendar(dateTime.calendar(), dateTime.tz()), null);
        return localized;
    }
    timezone = (XSDayTimeDuration) arg2.item(0);
    if (timezone.lt(minDuration, dynamicContext) || timezone.gt(maxDuration, dynamicContext)) {
        throw DynamicError.invalidTimezone();
    }
    if (dateTime.tz() == null) {
        return new XSDateTime(dateTime.calendar(), timezone);
    }
    XMLGregorianCalendar xmlCalendar = _datatypeFactory.newXMLGregorianCalendar((GregorianCalendar) dateTime.normalizeCalendar(dateTime.calendar(), dateTime.tz()));
    Duration duration = _datatypeFactory.newDuration(timezone.getStringValue());
    xmlCalendar.add(duration);
    return new XSDateTime(xmlCalendar.toGregorianCalendar(), timezone);
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) XSDateTime(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDateTime) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator) XSDayTimeDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration) Collection(java.util.Collection) Duration(javax.xml.datatype.Duration) XSDayTimeDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration) CalendarType(org.eclipse.wst.xml.xpath2.processor.internal.types.CalendarType)

Example 2 with CalendarType

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

Example 3 with CalendarType

use of org.eclipse.wst.xml.xpath2.processor.internal.types.CalendarType in project webtools.sourceediting by eclipse.

the class XSBoolean method constructor.

/**
 * Creates a new result sequence consisting of the retrievable boolean value
 * in the supplied result sequence
 *
 * @param arg
 *            The result sequence from which to extract the boolean value.
 * @throws DynamicError
 * @return A new result sequence consisting of the boolean value supplied.
 */
public ResultSequence constructor(ResultSequence arg) throws DynamicError {
    if (arg.empty())
        return ResultBuffer.EMPTY;
    Item anyType = arg.first();
    if (anyType instanceof XSDuration || anyType instanceof CalendarType || anyType instanceof XSBase64Binary || anyType instanceof XSHexBinary || anyType instanceof XSAnyURI) {
        throw DynamicError.invalidType();
    }
    String str_value = anyType.getStringValue();
    if (!(isCastable(anyType, str_value))) {
        throw DynamicError.cant_cast(null);
    }
    return XSBoolean.valueOf(!isFalse(str_value));
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item)

Aggregations

Item (org.eclipse.wst.xml.xpath2.api.Item)2 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 Duration (javax.xml.datatype.Duration)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)1 CalendarType (org.eclipse.wst.xml.xpath2.processor.internal.types.CalendarType)1 XSDateTime (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDateTime)1 XSDayTimeDuration (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration)1