Search in sources :

Example 11 with XSDuration

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

the class TestBugs method testXSYearMonthDurationDivide1.

public void testXSYearMonthDurationDivide1() throws Exception {
    // Bug 279376
    bundle = Platform.getBundle("org.w3c.xqts.testsuite");
    URL fileURL = bundle.getEntry("/TestSources/emptydoc.xml");
    loadDOMDocument(fileURL);
    // Get XML Schema Information for the Document
    XSModel schema = getGrammar();
    setupDynamicContext(schema);
    String xpath = "xs:yearMonthDuration('P2Y11M') div 1.5";
    compileXPath(xpath);
    ResultSequence rs = evaluate(domDoc);
    XSDuration result = (XSDuration) rs.first();
    String actual = result.getStringValue();
    assertEquals("P1Y11M", actual);
}
Also used : XSDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) XSModel(org.apache.xerces.xs.XSModel) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) URL(java.net.URL)

Example 12 with XSDuration

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

the class FnSecondsFromDuration method seconds_from_duration.

/**
 * Seconds-from-Duration operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:seconds-from-duration operation.
 */
public static ResultSequence seconds_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();
    double res = dtd.seconds();
    if (dtd.negative())
        res *= -1;
    return new XSDecimal(new BigDecimal(res));
}
Also used : XSDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Collection(java.util.Collection) XSDecimal(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal) BigDecimal(java.math.BigDecimal)

Example 13 with XSDuration

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

the class FnMinutesFromDuration method minutes_from_duration.

/**
 * Minutes-from-Duration operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:minutes-from-duration operation.
 */
public static ResultSequence minutes_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.minutes();
    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 14 with XSDuration

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

the class FnMonthsFromDuration method months_from_duration.

/**
 * Months-from-Duration operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:months-from-duration operation.
 */
public static ResultSequence months_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.month();
    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 15 with XSDuration

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

the class FnDaysFromDuration method days_from_duration.

/**
 * Days-From-Duration operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:days-from-duration operation.
 */
public static ResultSequence days_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.days();
    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)

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