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;
}
}
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));
}
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);
}
}
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);
}
}
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);
}
Aggregations