Search in sources :

Example 31 with Item

use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.

the class FsMinus method fs_minus_unary.

/**
 * Unary operation on the values of the arguments.
 *
 * @param args
 *            input arguments.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of the operation.
 */
public static ResultSequence fs_minus_unary(Collection args) throws DynamicError {
    // make sure we got only one arg
    if (args.size() != 1)
        DynamicError.throw_type_error();
    ResultSequence arg = (org.eclipse.wst.xml.xpath2.api.ResultSequence) args.iterator().next();
    // make sure we got only one numeric atom
    if (arg.size() != 1)
        DynamicError.throw_type_error();
    Item at = arg.first();
    if (!(at instanceof NumericType))
        DynamicError.throw_type_error();
    NumericType nt = (NumericType) at;
    return nt.unary_minus();
}
Also used : NumericType(org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType) Item(org.eclipse.wst.xml.xpath2.api.Item) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence)

Example 32 with Item

use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.

the class XSDate method plus.

/**
 * Mathematical addition operator between this XSDate 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 XSDate 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;
            XSDate res = (XSDate) clone();
            res.calendar().add(Calendar.MONTH, val.monthValue());
            return ResultSequenceFactory.create_new(res);
        } else if (at instanceof XSDayTimeDuration) {
            XSDayTimeDuration val = (XSDayTimeDuration) at;
            XSDate res = (XSDate) clone();
            // We only need to add the Number of days dropping the rest.
            int days = val.days();
            if (val.negative()) {
                days *= -1;
            }
            res.calendar().add(Calendar.DAY_OF_MONTH, days);
            res.calendar().add(Calendar.MILLISECOND, (int) (val.time_value() * 1000.0));
            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)

Example 33 with Item

use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.

the class XSDate method gt.

/**
 * Comparison on this and the supplied dates (taking timezones into account)
 *
 * @param arg
 *            XSDate representation of the date to compare to
 * @throws DynamicError
 * @return True if in time, this date lies after the date supplied. False
 *         otherwise.
 */
public boolean gt(AnyType arg, DynamicContext context) throws DynamicError {
    XSDate val = (XSDate) NumericType.get_single_type((Item) arg, XSDate.class);
    Calendar thiscal = normalizeCalendar(calendar(), tz());
    Calendar thatcal = normalizeCalendar(val.calendar(), val.tz());
    return thiscal.after(thatcal);
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Calendar(java.util.Calendar)

Example 34 with Item

use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.

the class XSDate method eq.

// comparisons
/**
 * Equality comparison on this and the supplied dates (taking timezones into
 * account)
 *
 * @param arg
 *            XSDate representation of the date to compare to
 * @throws DynamicError
 * @return True if the two dates are represent the same exact point in time.
 *         False otherwise.
 */
public boolean eq(AnyType arg, DynamicContext dynamicContext) throws DynamicError {
    XSDate val = (XSDate) NumericType.get_single_type((Item) arg, XSDate.class);
    Calendar thiscal = normalizeCalendar(calendar(), tz());
    Calendar thatcal = normalizeCalendar(val.calendar(), val.tz());
    return thiscal.equals(thatcal);
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Calendar(java.util.Calendar)

Example 35 with Item

use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.

the class XSInteger method convertArg.

protected Item convertArg(AnyType arg) throws DynamicError {
    ResultSequence rs = ResultSequenceFactory.create_new(arg);
    rs = constructor(rs);
    Item carg = rs.first();
    return carg;
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence)

Aggregations

DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)71 Item (org.eclipse.wst.xml.xpath2.api.Item)69 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)66 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)65 URL (java.net.URL)64 XSModel (org.apache.xerces.xs.XSModel)64 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)64 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)46 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)34 Iterator (java.util.Iterator)26 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)14 BigInteger (java.math.BigInteger)13 Collection (java.util.Collection)13 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)11 ListIterator (java.util.ListIterator)8 NodeType (org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)8 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)6 NumericType (org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType)5 ArrayList (java.util.ArrayList)4 GregorianCalendar (java.util.GregorianCalendar)4