Search in sources :

Example 1 with XSBoolean

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean in project webtools.sourceediting by eclipse.

the class FnLang method lang.

/**
 * Language operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:lang operation.
 */
public static ResultSequence lang(Collection args, EvaluationContext ec) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    // get arg
    Iterator citer = cargs.iterator();
    ResultSequence arg1 = (ResultSequence) citer.next();
    ResultSequence arg2 = null;
    if (cargs.size() == 1) {
        if (ec.getContextItem() == null) {
            throw DynamicError.contextUndefined();
        }
        arg2 = (AnyType) ec.getContextItem();
    } else {
        arg2 = (ResultSequence) citer.next();
    }
    String lang = "";
    if (!arg1.empty()) {
        lang = ((XSString) arg1.first()).value();
    }
    if (!(arg2.first() instanceof NodeType)) {
        throw DynamicError.invalidType();
    }
    NodeType an = (NodeType) arg2.first();
    return new XSBoolean(test_lang(an.node_value(), lang));
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSBoolean(org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) Iterator(java.util.Iterator) Collection(java.util.Collection) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Example 2 with XSBoolean

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean 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 3 with XSBoolean

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean in project webtools.sourceediting by eclipse.

the class FnIndexOf method index_of.

/**
 * Index-Of operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @param dynamicContext
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:index-of operation.
 */
public static ResultSequence index_of(Collection args, DynamicContext dc) {
    Function.convert_arguments(args, expected_args());
    // get args
    Iterator citer = args.iterator();
    ResultSequence arg1 = (ResultSequence) citer.next();
    ResultSequence arg2 = (ResultSequence) citer.next();
    if (arg1.empty()) {
        return ResultBuffer.EMPTY;
    }
    // sanity chex
    if (arg2.size() != 1)
        DynamicError.throw_type_error();
    String collationUri = dc.getCollationProvider().getDefaultCollation();
    if (citer.hasNext()) {
        ResultSequence arg3 = (ResultSequence) citer.next();
        if (!arg3.empty()) {
            XSString collation = (XSString) arg3.first();
            collationUri = collation.getStringValue();
        }
    }
    ResultBuffer rb = new ResultBuffer();
    AnyAtomicType at = (AnyAtomicType) arg2.first();
    get_comparable(at);
    int index = 1;
    for (Iterator i = arg1.iterator(); i.hasNext(); ) {
        AnyType cmptype = (AnyType) i.next();
        get_comparable(cmptype);
        if (!(at instanceof CmpEq))
            continue;
        if (isBoolean(cmptype, at)) {
            XSBoolean boolat = (XSBoolean) cmptype;
            if (boolat.eq(at, dc)) {
                rb.add(new XSInteger(BigInteger.valueOf(index)));
            }
        } else if (isNumeric(cmptype, at)) {
            NumericType numericat = (NumericType) at;
            if (numericat.eq(cmptype, dc)) {
                rb.add(new XSInteger(BigInteger.valueOf(index)));
            }
        } else if (isDuration(cmptype, at)) {
            XSDuration durat = (XSDuration) at;
            if (durat.eq(cmptype, dc)) {
                rb.add(new XSInteger(BigInteger.valueOf(index)));
            }
        } else if (at instanceof QName && cmptype instanceof QName) {
            QName qname = (QName) at;
            if (qname.eq(cmptype, dc)) {
                rb.add(new XSInteger(BigInteger.valueOf(index)));
            }
        } else if (needsStringComparison(cmptype, at)) {
            XSString xstr1 = new XSString(cmptype.getStringValue());
            XSString itemStr = new XSString(at.getStringValue());
            if (FnCompare.compare_string(collationUri, xstr1, itemStr, dc).equals(BigInteger.ZERO)) {
                rb.add(new XSInteger(BigInteger.valueOf(index)));
            }
        }
        index++;
    }
    return rb.getSequence();
}
Also used : NumericType(org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType) XSDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration) ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSBoolean(org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean) XSInteger(org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger) Iterator(java.util.Iterator) AnyAtomicType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 4 with XSBoolean

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean in project webtools.sourceediting by eclipse.

the class FsEq method do_cmp_general_op.

// voodoo 3
/**
 * Actual equality operation for fs_eq_general.
 *
 * @param args
 *            input arguments.
 * @param type
 *            type of the arguments.
 * @param mname
 *            Method name for template simulation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of the operation.
 */
public static ResultSequence do_cmp_general_op(Collection args, Class type, String mname, DynamicContext dc) throws DynamicError {
    // do the voodoo
    Method comparator = null;
    try {
        Class[] margsdef = { Collection.class, DynamicContext.class };
        comparator = type.getMethod(mname, margsdef);
    } catch (NoSuchMethodException err) {
        throw new RuntimeException("Can�'t find method : " + mname, err);
    }
    // sanity check args and get them
    if (args.size() != 2)
        DynamicError.throw_type_error();
    Iterator argiter = args.iterator();
    org.eclipse.wst.xml.xpath2.api.ResultSequence one = (org.eclipse.wst.xml.xpath2.api.ResultSequence) argiter.next();
    org.eclipse.wst.xml.xpath2.api.ResultSequence two = (org.eclipse.wst.xml.xpath2.api.ResultSequence) argiter.next();
    // XXX ?
    if (one.empty() || two.empty())
        return ResultSequenceFactory.create_new(new XSBoolean(false));
    // atomize
    one = FnData.atomize(one);
    two = FnData.atomize(two);
    // we gotta find a pair that satisfied the condition
    for (Iterator i = one.iterator(); i.hasNext(); ) {
        AnyType a = (AnyType) i.next();
        for (Iterator j = two.iterator(); j.hasNext(); ) {
            AnyType b = (AnyType) j.next();
            if (do_general_pair(a, b, comparator, dc))
                return ResultSequenceFactory.create_new(new XSBoolean(true));
        }
    }
    return ResultSequenceFactory.create_new(new XSBoolean(false));
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Method(java.lang.reflect.Method) XSBoolean(org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean) Iterator(java.util.Iterator) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 5 with XSBoolean

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean 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

XSBoolean (org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean)87 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)69 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)65 URL (java.net.URL)62 XSModel (org.apache.xerces.xs.XSModel)61 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)15 Iterator (java.util.Iterator)10 QName (org.eclipse.wst.xml.xpath2.processor.internal.types.QName)5 Collection (java.util.Collection)4 ListIterator (java.util.ListIterator)4 VarExprPair (org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)4 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)4 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)3 NodeType (org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)3 XSInteger (org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 Schema (javax.xml.validation.Schema)2 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)2 ElementType (org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType)2