use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.
the class XSDouble method gt.
/**
* Comparison between this number and the supplied representation.
*
* @param arg
* Representation to be compared with (must currently be of type
* XSDouble)
* @return True if the supplied type represents a number smaller than this
* one stored. False otherwise
*/
public boolean gt(AnyType arg, DynamicContext context) throws DynamicError {
Item carg = convertArg(arg);
XSDouble val = (XSDouble) get_single_type(carg, XSDouble.class);
return double_value() > val.double_value();
}
use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.
the class XSDouble method plus.
// math
/**
* Mathematical addition operator between this XSDouble and the supplied
* ResultSequence.
*
* @param arg
* The ResultSequence to perform an addition with
* @return A XSDouble consisting of the result of the mathematical addition.
*/
public ResultSequence plus(ResultSequence arg) throws DynamicError {
ResultSequence carg = convertResultSequence(arg);
Item at = get_single_arg(carg);
if (!(at instanceof XSDouble))
DynamicError.throw_type_error();
XSDouble val = (XSDouble) at;
return ResultSequenceFactory.create_new(new XSDouble(double_value() + val.double_value()));
}
use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.
the class XSInt method constructor.
/**
* Creates a new ResultSequence consisting of the extractable 'int' in the
* supplied ResultSequence
*
* @param arg
* The ResultSequence from which the int is to be extracted
* @return New ResultSequence consisting of the 'int' 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 an int.
Item aat = arg.first();
try {
BigInteger bigInt = new BigInteger(aat.getStringValue());
// doing the range checking
BigInteger min = BigInteger.valueOf(-2147483648L);
BigInteger max = BigInteger.valueOf(2147483647L);
if (bigInt.compareTo(min) < 0 || bigInt.compareTo(max) > 0) {
// invalid input
DynamicError.throw_type_error();
}
return new XSInt(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 XSLong method constructor.
/**
* Creates a new ResultSequence consisting of the extractable long in the
* supplied ResultSequence
*
* @param arg
* The ResultSequence from which the long is to be extracted
* @return New ResultSequence consisting of the 'long' 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 long.
Item aat = arg.first();
try {
BigInteger bigInt = new BigInteger(aat.getStringValue());
// doing the range checking
BigInteger min = BigInteger.valueOf(-9223372036854775808L);
BigInteger max = BigInteger.valueOf(9223372036854775807L);
if (bigInt.compareTo(min) < 0 || bigInt.compareTo(max) > 0) {
// invalid input
DynamicError.throw_type_error();
}
return new XSLong(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 FsEq method do_cmp_value_op.
// voodoo 2
/**
* Actual equality operation for fs_eq_value.
*
* @param args
* input arguments.
* @param type
* type of the arguments.
* @param mname
* Method name for template simulation.
* @param dynamicContext
* Dynamic error.
* @throws DynamicError
* Dynamic error.
* @return Result of the operation.
*/
public static ResultSequence do_cmp_value_op(Collection args, Class type, String mname, DynamicContext context) throws DynamicError {
// sanity check args + convert em
if (args.size() != 2)
DynamicError.throw_type_error();
Collection cargs = value_convert_args(args);
if (cargs.size() == 0)
return ResultBuffer.EMPTY;
// make sure arugments are comparable by equality
Iterator argi = cargs.iterator();
Item arg = ((ResultSequence) argi.next()).first();
ResultSequence arg2 = (ResultSequence) argi.next();
if (arg2.size() != 1)
DynamicError.throw_type_error();
if (!(type.isInstance(arg)))
DynamicError.throw_type_error();
try {
Class[] margsdef = { AnyType.class, DynamicContext.class };
Method method = null;
method = type.getMethod(mname, margsdef);
Object[] margs = { arg2.first(), context };
Boolean cmpres = (Boolean) method.invoke(arg, margs);
return ResultSequenceFactory.create_new(new XSBoolean(cmpres.booleanValue()));
} catch (NoSuchMethodException err) {
assert false;
throw new RuntimeException("cannot compare using method " + mname, err);
} catch (IllegalAccessException err) {
assert false;
throw new RuntimeException("cannot compare using method " + mname, err);
} catch (InvocationTargetException err) {
Throwable ex = err.getTargetException();
if (ex instanceof DynamicError)
throw (DynamicError) ex;
throw new RuntimeException("cannot compare using method " + mname, ex);
}
}
Aggregations