Search in sources :

Example 26 with Item

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();
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item)

Example 27 with Item

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()));
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence)

Example 28 with Item

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);
    }
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) BigInteger(java.math.BigInteger)

Example 29 with Item

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);
    }
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) BigInteger(java.math.BigInteger)

Example 30 with Item

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);
    }
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Method(java.lang.reflect.Method) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError) InvocationTargetException(java.lang.reflect.InvocationTargetException) Item(org.eclipse.wst.xml.xpath2.api.Item) XSBoolean(org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean) Iterator(java.util.Iterator) Collection(java.util.Collection) XSBoolean(org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean)

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