Search in sources :

Example 71 with Item

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

the class XSYearMonthDuration method div.

/**
 * Mathematical division between this duration stored and the supplied
 * duration of time (of type XSYearMonthDuration)
 *
 * @param arg
 *            The duration of time to divide by
 * @return New XSYearMonthDuration representing the resulting duration
 *         after the division
 * @throws DynamicError
 */
public ResultSequence div(ResultSequence arg) throws DynamicError {
    if (arg.size() != 1)
        DynamicError.throw_type_error();
    Item at = arg.first();
    if (at instanceof XSDouble) {
        XSDouble dt = (XSDouble) at;
        int ret = 0;
        if (!dt.zero())
            ret = (int) Math.round(monthValue() / dt.double_value());
        return ResultSequenceFactory.create_new(new XSYearMonthDuration(ret));
    } else if (at instanceof XSDecimal) {
        XSDecimal dt = (XSDecimal) at;
        int ret = 0;
        if (!dt.zero())
            ret = (int) Math.round(monthValue() / dt.getValue().doubleValue());
        return ResultSequenceFactory.create_new(new XSYearMonthDuration(ret));
    } else if (at instanceof XSYearMonthDuration) {
        XSYearMonthDuration md = (XSYearMonthDuration) at;
        double res = (double) monthValue() / md.monthValue();
        return ResultSequenceFactory.create_new(new XSDecimal(new BigDecimal(res)));
    } else {
        DynamicError.throw_type_error();
        // unreach
        return null;
    }
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) BigDecimal(java.math.BigDecimal)

Example 72 with Item

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

the class XSYearMonthDuration method times.

/**
 * Mathematical multiplication between this duration stored and the supplied
 * duration of time (of type XSYearMonthDuration)
 *
 * @param arg
 *            The duration of time to multiply by
 * @return New XSYearMonthDuration representing the resulting duration
 *         after the multiplication
 * @throws DynamicError
 */
public ResultSequence times(ResultSequence arg) throws DynamicError {
    ResultSequence convertedRS = arg;
    if (arg.size() == 1) {
        Item argValue = arg.first();
        if (argValue instanceof XSDecimal) {
            convertedRS = ResultSequenceFactory.create_new(new XSDouble(argValue.getStringValue()));
        }
    }
    XSDouble val = (XSDouble) NumericType.get_single_type(convertedRS, XSDouble.class);
    if (val.nan()) {
        throw DynamicError.nan();
    }
    if (val.infinite()) {
        throw DynamicError.overflowDateTime();
    }
    int res = (int) Math.round(monthValue() * val.double_value());
    return ResultSequenceFactory.create_new(new XSYearMonthDuration(res));
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence)

Example 73 with Item

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

the class XSUnsignedLong method constructor.

/**
 * Creates a new ResultSequence consisting of the extractable unsignedLong
 * in the supplied ResultSequence
 *
 * @param arg
 *            The ResultSequence from which the unsignedLong is to be extracted
 * @return New ResultSequence consisting of the 'unsignedLong' supplied
 * @throws DynamicError
 */
public ResultSequence constructor(ResultSequence arg) throws DynamicError {
    if (arg.empty())
        return ResultBuffer.EMPTY;
    // the function conversion rules apply here too. Get the argument
    // and convert it's string value to a unsignedLong.
    Item aat = arg.first();
    try {
        BigInteger bigInt = new BigInteger(aat.getStringValue());
        // doing the range checking
        // min value is 0
        // max value is 18446744073709551615
        BigInteger min = BigInteger.valueOf(0);
        BigInteger max = new BigInteger("18446744073709551615");
        if (bigInt.compareTo(min) < 0 || bigInt.compareTo(max) > 0) {
            // invalid input
            throw DynamicError.cant_cast(null);
        }
        return new XSUnsignedLong(bigInt);
    } catch (NumberFormatException e) {
        throw DynamicError.cant_cast(null);
    }
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) BigInteger(java.math.BigInteger)

Example 74 with Item

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

the class TypePromoter method considerSequence.

public void considerSequence(ResultSequence sequenceToConsider) throws DynamicError {
    for (int i = 0; i < sequenceToConsider.size(); ++i) {
        Item item = sequenceToConsider.item(i);
        considerValue(item);
    }
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item)

Example 75 with Item

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

the class SeqIDREFFuncTest method test_fn_idref_22.

// Evaluation of fn:idref with second argument set to "." and no context item.
public void test_fn_idref_22() throws Exception {
    String inputFile = "/TestSources/emptydoc.xml";
    String xqFile = "/Queries/XQuery/Functions/NodeSeqFunc/SeqIDREFFunc/fn-idref-22.xq";
    String expectedResult = "XPDY0002";
    URL fileURL = bundle.getEntry(inputFile);
    loadDOMDocument(fileURL);
    // Get XML Schema Information for the Document
    XSModel schema = getGrammar();
    setupDynamicContext(schema);
    String xpath = "fn:idref(\"argument1\", .)";
    String actual = null;
    try {
        compileXPath(xpath);
        // no context
        ResultSequence rs = evaluate(null);
        actual = buildResultString(rs);
    } catch (XPathParserException ex) {
        actual = ex.code();
    } catch (StaticError ex) {
        actual = ex.code();
    } catch (DynamicError ex) {
        actual = ex.code();
    }
    assertEquals("XPath Result Error " + xqFile + ":", expectedResult, actual);
}
Also used : XPathParserException(org.eclipse.wst.xml.xpath2.processor.XPathParserException) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) XSModel(org.apache.xerces.xs.XSModel) StaticError(org.eclipse.wst.xml.xpath2.processor.StaticError) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError) URL(java.net.URL)

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