Search in sources :

Example 86 with XSBoolean

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

the class FnCodepointEqual method codepoint_equals.

/**
 * Compare the arguments as codepoints
 *
 * @param args
 *            are compared.
 * @param dynamicContext
 *            The current dynamic context
 * @throws DynamicError
 *             Dynamic error.
 * @return The result of the comparison of the arguments.
 */
public static ResultSequence codepoint_equals(Collection args, DynamicContext dynamicContext) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultBuffer rs = new ResultBuffer();
    Iterator argiter = cargs.iterator();
    ResultSequence arg1 = (ResultSequence) argiter.next();
    XSString xstr1 = arg1.empty() ? null : (XSString) arg1.first();
    ResultSequence arg2 = (ResultSequence) argiter.next();
    XSString xstr2 = arg2.empty() ? null : (XSString) arg2.first();
    // This delegates to FnCompare
    BigInteger result = FnCompare.compare_string(CollationProvider.CODEPOINT_COLLATION, xstr1, xstr2, dynamicContext);
    if (result != null)
        rs.add(new XSBoolean(BigInteger.ZERO.equals(result)));
    return rs.getSequence();
}
Also used : ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSBoolean(org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean) Iterator(java.util.Iterator) Collection(java.util.Collection) BigInteger(java.math.BigInteger) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Example 87 with XSBoolean

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

the class FsEq method do_general_pair.

/**
 * Making sure that the types are the same before comparing the inputs.
 *
 * @param a
 *            input1 of any type.
 * @param b
 *            input2 of any type.
 * @param dc
 *              Dynamic Context
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of Equality operation.
 */
private static boolean do_general_pair(AnyType a, AnyType b, Method comparator, DynamicContext ec) throws DynamicError {
    // double
    if ((a instanceof XSUntypedAtomic && b instanceof NumericType) || (b instanceof XSUntypedAtomic && a instanceof NumericType)) {
        if (a instanceof XSUntypedAtomic)
            a = new XSDouble(a.getStringValue());
        else
            b = new XSDouble(b.getStringValue());
    } else // untyped to string
    if ((a instanceof XSUntypedAtomic && (b instanceof XSString || b instanceof XSUntypedAtomic) || (b instanceof XSUntypedAtomic && (a instanceof XSString || a instanceof XSUntypedAtomic)))) {
        if (a instanceof XSUntypedAtomic)
            a = new XSString(a.getStringValue());
        if (b instanceof XSUntypedAtomic)
            b = new XSString(b.getStringValue());
    } else // TODO: This makes no sense as implemented before
    if (a instanceof XSUntypedAtomic) {
    // ResultSequence converted = ResultSequenceFactory.create_new(a);
    // assert converted.size() == 1;
    // a = converted.first();
    } else if (b instanceof XSUntypedAtomic) {
    // ResultSequence converted = ResultSequenceFactory.create_new(b);
    // assert converted.size() == 1;
    // b = converted.first();
    }
    // rule d
    // if value comparison is true, return true.
    ResultSequence one = ResultSequenceFactory.create_new(a);
    ResultSequence two = ResultSequenceFactory.create_new(b);
    Collection args = new ArrayList();
    args.add(one);
    args.add(two);
    Object[] margs = { args, ec };
    ResultSequence result = null;
    try {
        result = (ResultSequence) comparator.invoke(null, margs);
    } catch (IllegalAccessException err) {
        assert false;
    } catch (InvocationTargetException err) {
        Throwable ex = err.getTargetException();
        if (ex instanceof RuntimeException)
            throw (RuntimeException) ex;
        throw new RuntimeException(ex);
    }
    if (((XSBoolean) result.first()).value())
        return true;
    return false;
}
Also used : NumericType(org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType) XSDouble(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) ArrayList(java.util.ArrayList) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) InvocationTargetException(java.lang.reflect.InvocationTargetException) XSBoolean(org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean) Collection(java.util.Collection) XSUntypedAtomic(org.eclipse.wst.xml.xpath2.processor.internal.types.XSUntypedAtomic)

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