Search in sources :

Example 16 with ResultSequence

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

the class FsGe method fs_ge_value.

/**
 * Greater than or equal to operation on the values of the arguments.
 *
 * @param args
 *            input arguments.
 * @param dc
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of the operation.
 */
public static ResultSequence fs_ge_value(Collection args, DynamicContext dc) throws DynamicError {
    ResultSequence greater = FsGt.fs_gt_value(args, dc);
    if (((XSBoolean) greater.first()).value())
        return greater;
    ResultSequence equal = FsEq.fs_eq_value(args, dc);
    if (((XSBoolean) equal.first()).value())
        return equal;
    return ResultSequenceFactory.create_new(new XSBoolean(false));
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSBoolean(org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean)

Example 17 with ResultSequence

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

the class FsPlus method fs_plus_unary.

/**
 * Unary operation on the arguments.
 *
 * @param args
 *            input arguments.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of the operation.
 */
public static ResultSequence fs_plus_unary(Collection args) throws DynamicError {
    // make sure we got only one arg
    if (args.size() != 1)
        DynamicError.throw_type_error();
    ResultSequence arg = (ResultSequence) args.iterator().next();
    // make sure we got only one numeric atom
    if (arg.size() != 1)
        DynamicError.throw_type_error();
    Item at = arg.first();
    if (!(at instanceof NumericType))
        DynamicError.throw_type_error();
    // no-op
    return arg;
}
Also used : NumericType(org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType) Item(org.eclipse.wst.xml.xpath2.api.Item) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence)

Example 18 with ResultSequence

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

the class FsPlus method do_math_op.

// voodoo
/**
 * Mathematical operation on the arguments.
 *
 * @param args
 *            input arguments.
 * @param type
 *            type of arguments.
 * @param mname
 *            Method name for template simulation.
 * @param sc
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of operation.
 */
public static ResultSequence do_math_op(Collection args, Class type, String mname) throws DynamicError {
    // sanity check args + convert em
    if (args.size() != 2)
        DynamicError.throw_type_error();
    Collection cargs = convert_args(args);
    if (cargs.size() == 0)
        return ResultBuffer.EMPTY;
    // make sure arugments are good [at least the first one]
    Iterator argi = cargs.iterator();
    Item arg = ((org.eclipse.wst.xml.xpath2.api.ResultSequence) argi.next()).item(0);
    org.eclipse.wst.xml.xpath2.api.ResultSequence arg2 = (org.eclipse.wst.xml.xpath2.api.ResultSequence) argi.next();
    if (!(type.isInstance(arg)))
        DynamicError.throw_type_error();
    // here is da ownage
    try {
        Class[] margsdef = { ResultSequence.class };
        Method method = null;
        method = type.getMethod(mname, margsdef);
        Object[] margs = { arg2 };
        return (ResultSequence) method.invoke(arg, margs);
    } catch (NoSuchMethodException err) {
        System.out.println("NoSuchMethodException: " + err.getMessage());
        assert false;
    } catch (IllegalAccessException err) {
        System.out.println("IllegalAccessException: " + err.getMessage());
        assert false;
    } catch (InvocationTargetException err) {
        Throwable ex = err.getTargetException();
        if (ex instanceof DynamicError) {
            throw (DynamicError) ex;
        } else {
            throw new RuntimeException(ex);
        }
    }
    // unreach!
    return null;
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) 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) Iterator(java.util.Iterator) Collection(java.util.Collection)

Example 19 with ResultSequence

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

the class Function method getResultSetForArityZero.

protected static ResultSequence getResultSetForArityZero(EvaluationContext ec) throws DynamicError {
    ResultSequence rs = ResultSequenceFactory.create_new();
    Item contextItem = ec.getContextItem();
    if (contextItem != null) {
        // if context item is defined, then that is the default argument
        // to fn:string function
        rs.add(new XSString(contextItem.getStringValue()));
    } else {
        throw DynamicError.contextUndefined();
    }
    return rs;
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Example 20 with ResultSequence

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

the class Function method convert_argument.

// convert argument according to section 3.1.5 of xpath 2.0 spec
/**
 * Convert the input argument according to section 3.1.5 of specification.
 *
 * @param arg
 *            input argument.
 * @param expected
 *            Expected Sequence type.
 * @throws DynamicError
 *             Dynamic error.
 * @return Converted argument.
 */
public static org.eclipse.wst.xml.xpath2.api.ResultSequence convert_argument(org.eclipse.wst.xml.xpath2.api.ResultSequence arg, SeqType expected) throws DynamicError {
    ResultBuffer result = new ResultBuffer();
    // XXX: Should use type_class instead and use item.getClass().isAssignableTo(expected.type_class())
    AnyType expected_type = expected.type();
    // expected is atomic
    if (expected_type instanceof AnyAtomicType) {
        AnyAtomicType expected_aat = (AnyAtomicType) expected_type;
        // atomize
        org.eclipse.wst.xml.xpath2.api.ResultSequence rs = FnData.atomize(arg);
        // cast untyped to expected type
        for (Iterator i = rs.iterator(); i.hasNext(); ) {
            AnyType item = (AnyType) i.next();
            if (item instanceof XSUntypedAtomic) {
                // create a new item of the expected
                // type initialized with from the string
                // value of the item
                ResultSequence converted = null;
                if (expected_aat instanceof XSString) {
                    XSString strType = new XSString(item.getStringValue());
                    converted = ResultSequenceFactory.create_new(strType);
                } else {
                    converted = ResultSequenceFactory.create_new(item);
                }
                result.concat(converted);
            } else // xs:anyURI promotion to xs:string
            if (item instanceof XSAnyURI && expected_aat instanceof XSString) {
                result.add(new XSString(item.getStringValue()));
            } else // numeric type promotion
            if (item instanceof NumericType) {
                if (expected_aat instanceof XSDouble) {
                    XSDouble doubleType = new XSDouble(item.getStringValue());
                    result.add(doubleType);
                } else {
                    result.add(item);
                }
            } else {
                result.add(item);
            }
        }
        // do sequence type matching on converted arguments
        return expected.match(result.getSequence());
    } else {
        // do sequence type matching on converted arguments
        return expected.match(arg);
    }
}
Also used : NumericType(org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType) ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) XSAnyURI(org.eclipse.wst.xml.xpath2.processor.internal.types.XSAnyURI) XSDouble(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) Iterator(java.util.Iterator) AnyAtomicType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType) XSUntypedAtomic(org.eclipse.wst.xml.xpath2.processor.internal.types.XSUntypedAtomic) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Aggregations

ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)8383 URL (java.net.URL)8366 XSModel (org.apache.xerces.xs.XSModel)8363 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)8279 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)8279 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)8208 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)173 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)156 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)130 Schema (javax.xml.validation.Schema)102 Iterator (java.util.Iterator)92 Collection (java.util.Collection)83 XSBoolean (org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean)83 DefaultEvaluator (org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator)74 Evaluator (org.eclipse.wst.xml.xpath2.processor.Evaluator)74 XPath (org.eclipse.wst.xml.xpath2.processor.ast.XPath)74 DynamicContext (org.eclipse.wst.xml.xpath2.processor.DynamicContext)72 Item (org.eclipse.wst.xml.xpath2.api.Item)56 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)34 XSInteger (org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger)32