Search in sources :

Example 1 with XSDuration

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

the class FnDateTime method dateTime.

/**
 * 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 dateTime(Collection args, StaticContext sc) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    // get args
    Iterator argiter = cargs.iterator();
    ResultSequence arg1 = (ResultSequence) argiter.next();
    ResultSequence arg2 = (ResultSequence) argiter.next();
    // is an empty sequence
    if (arg1.empty() || arg2.empty()) {
        return ResultBuffer.EMPTY;
    }
    XSDate param1 = (XSDate) arg1.first();
    XSTime param2 = (XSTime) arg2.first();
    Calendar cal = Calendar.getInstance();
    cal.set(param1.year(), param1.month() - 1, param1.day());
    cal.set(Calendar.HOUR_OF_DAY, param2.hour());
    cal.set(Calendar.MINUTE, param2.minute());
    cal.set(Calendar.SECOND, (new Double(Math.floor(param2.second())).intValue()));
    cal.set(Calendar.MILLISECOND, 0);
    XSDuration dateTimeZone = param1.tz();
    XSDuration timeTimeZone = param2.tz();
    if ((dateTimeZone != null && timeTimeZone != null) && !dateTimeZone.getStringValue().equals(timeTimeZone.getStringValue())) {
        // it's an error, if the arguments have different timezones
        throw DynamicError.inconsistentTimeZone();
    } else if (dateTimeZone == null && timeTimeZone != null) {
        return new XSDateTime(cal, timeTimeZone);
    } else if (dateTimeZone != null && timeTimeZone == null) {
        return new XSDateTime(cal, dateTimeZone);
    } else if ((dateTimeZone != null && timeTimeZone != null) && dateTimeZone.getStringValue().equals(timeTimeZone.getStringValue())) {
        return new XSDateTime(cal, dateTimeZone);
    } else {
        return new XSDateTime(cal, null);
    }
}
Also used : XSDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration) XSDateTime(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDateTime) XSDate(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDate) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Calendar(java.util.Calendar) Iterator(java.util.Iterator) Collection(java.util.Collection) XSTime(org.eclipse.wst.xml.xpath2.processor.internal.types.XSTime)

Example 2 with XSDuration

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

the class FnMinutesFromDuration 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 3 with XSDuration

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

the class FnMonthsFromDuration 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 4 with XSDuration

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

the class FnIndexOf method index_of.

/**
 * Index-Of operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @param dynamicContext
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:index-of operation.
 */
public static ResultSequence index_of(Collection args, DynamicContext dc) {
    Function.convert_arguments(args, expected_args());
    // get args
    Iterator citer = args.iterator();
    ResultSequence arg1 = (ResultSequence) citer.next();
    ResultSequence arg2 = (ResultSequence) citer.next();
    if (arg1.empty()) {
        return ResultBuffer.EMPTY;
    }
    // sanity chex
    if (arg2.size() != 1)
        DynamicError.throw_type_error();
    String collationUri = dc.getCollationProvider().getDefaultCollation();
    if (citer.hasNext()) {
        ResultSequence arg3 = (ResultSequence) citer.next();
        if (!arg3.empty()) {
            XSString collation = (XSString) arg3.first();
            collationUri = collation.getStringValue();
        }
    }
    ResultBuffer rb = new ResultBuffer();
    AnyAtomicType at = (AnyAtomicType) arg2.first();
    get_comparable(at);
    int index = 1;
    for (Iterator i = arg1.iterator(); i.hasNext(); ) {
        AnyType cmptype = (AnyType) i.next();
        get_comparable(cmptype);
        if (!(at instanceof CmpEq))
            continue;
        if (isBoolean(cmptype, at)) {
            XSBoolean boolat = (XSBoolean) cmptype;
            if (boolat.eq(at, dc)) {
                rb.add(new XSInteger(BigInteger.valueOf(index)));
            }
        } else if (isNumeric(cmptype, at)) {
            NumericType numericat = (NumericType) at;
            if (numericat.eq(cmptype, dc)) {
                rb.add(new XSInteger(BigInteger.valueOf(index)));
            }
        } else if (isDuration(cmptype, at)) {
            XSDuration durat = (XSDuration) at;
            if (durat.eq(cmptype, dc)) {
                rb.add(new XSInteger(BigInteger.valueOf(index)));
            }
        } else if (at instanceof QName && cmptype instanceof QName) {
            QName qname = (QName) at;
            if (qname.eq(cmptype, dc)) {
                rb.add(new XSInteger(BigInteger.valueOf(index)));
            }
        } else if (needsStringComparison(cmptype, at)) {
            XSString xstr1 = new XSString(cmptype.getStringValue());
            XSString itemStr = new XSString(at.getStringValue());
            if (FnCompare.compare_string(collationUri, xstr1, itemStr, dc).equals(BigInteger.ZERO)) {
                rb.add(new XSInteger(BigInteger.valueOf(index)));
            }
        }
        index++;
    }
    return rb.getSequence();
}
Also used : NumericType(org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType) XSDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration) ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSBoolean(org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean) XSInteger(org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger) Iterator(java.util.Iterator) AnyAtomicType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 5 with XSDuration

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

the class FnDaysFromDuration 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)

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