Search in sources :

Example 6 with AnyType

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

the class FnDeepEqual method deep_equal.

/**
 * Deep-Equal boolean operation.
 *
 * @param one
 *            input1 xpath expression/variable.
 * @param two
 *            input2 xpath expression/variable.
 * @param context
 *            Current dynamic context
 * @return Result of fn:deep-equal operation.
 */
public static boolean deep_equal(ResultSequence one, ResultSequence two, EvaluationContext context, String collationURI) {
    if (one.empty() && two.empty())
        return true;
    if (one.size() != two.size())
        return false;
    Iterator onei = one.iterator();
    Iterator twoi = two.iterator();
    while (onei.hasNext()) {
        AnyType a = (AnyType) onei.next();
        AnyType b = (AnyType) twoi.next();
        if (!deep_equal(a, b, context, collationURI))
            return false;
    }
    return true;
}
Also used : Iterator(java.util.Iterator) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 7 with AnyType

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

the class FnMin method min.

/**
 * Min operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @param dynamic
 *            Dynamic context
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:min operation.
 */
public static ResultSequence min(Collection args, DynamicContext context) throws DynamicError {
    ResultSequence arg = FnMax.get_arg(args, CmpLt.class);
    if (arg.empty())
        return ResultSequenceFactory.create_new();
    CmpLt max = null;
    TypePromoter tp = new ComparableTypePromoter();
    tp.considerSequence(arg);
    for (Iterator i = arg.iterator(); i.hasNext(); ) {
        AnyAtomicType conv = tp.promote((AnyType) i.next());
        if (conv != null) {
            if (conv instanceof XSDouble && ((XSDouble) conv).nan() || conv instanceof XSFloat && ((XSFloat) conv).nan()) {
                return ResultSequenceFactory.create_new(tp.promote(new XSFloat(Float.NaN)));
            }
            if (max == null || ((CmpLt) conv).lt((AnyType) max, context)) {
                max = (CmpLt) conv;
            }
        }
    }
    return ResultSequenceFactory.create_new((AnyType) max);
}
Also used : XSFloat(org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat) XSDouble(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator) TypePromoter(org.eclipse.wst.xml.xpath2.processor.internal.utils.TypePromoter) ComparableTypePromoter(org.eclipse.wst.xml.xpath2.processor.internal.utils.ComparableTypePromoter) AnyAtomicType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType) ComparableTypePromoter(org.eclipse.wst.xml.xpath2.processor.internal.utils.ComparableTypePromoter) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 8 with AnyType

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

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

the class FnTrace method trace.

/**
 * Trace operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:trace operation.
 */
public static ResultSequence trace(Collection args) throws DynamicError {
    // sanity check args
    if (args.size() != 2)
        DynamicError.throw_type_error();
    Iterator argsi = args.iterator();
    ResultSequence arg1 = (ResultSequence) argsi.next();
    ResultSequence arg2 = (ResultSequence) argsi.next();
    if (arg2.size() != 1)
        DynamicError.throw_type_error();
    Item at = arg2.first();
    if (!(at instanceof XSString))
        DynamicError.throw_type_error();
    XSString label = (XSString) at;
    int index = 1;
    for (Iterator i = arg1.iterator(); i.hasNext(); index++) {
        at = (AnyType) i.next();
        System.out.println(label.value() + " [" + index + "] " + ((AnyType) at).string_type() + ":" + at.getStringValue());
    }
    return arg1;
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 10 with AnyType

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

the class FnRemove method remove.

/**
 * Remove operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:remove operation.
 */
public static ResultSequence remove(Collection args) throws DynamicError {
    assert args.size() == 2;
    ResultBuffer rs = new ResultBuffer();
    // get args
    Iterator citer = args.iterator();
    ResultSequence target = (ResultSequence) citer.next();
    ResultSequence arg2 = (ResultSequence) citer.next();
    // sanity chex
    if (arg2.size() != 1)
        DynamicError.throw_type_error();
    Item at = arg2.first();
    if (!(at instanceof XSInteger))
        DynamicError.throw_type_error();
    int position = ((XSInteger) at).int_value().intValue();
    if (position < 1)
        return target;
    if (position > target.size())
        return target;
    if (target.empty())
        return rs.getSequence();
    int curpos = 1;
    for (Iterator i = target.iterator(); i.hasNext(); ) {
        at = (AnyType) i.next();
        if (curpos != position)
            rs.add(at);
        curpos++;
    }
    return rs.getSequence();
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSInteger(org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger) Iterator(java.util.Iterator)

Aggregations

AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)162 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)127 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)123 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)123 URL (java.net.URL)122 XSModel (org.apache.xerces.xs.XSModel)121 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)40 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)38 Iterator (java.util.Iterator)37 Item (org.eclipse.wst.xml.xpath2.api.Item)26 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)14 NodeType (org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)14 QName (org.eclipse.wst.xml.xpath2.processor.internal.types.QName)11 AnyAtomicType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType)9 XSDouble (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble)9 Collection (java.util.Collection)8 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)8 ListIterator (java.util.ListIterator)7 ArrayList (java.util.ArrayList)6 NumericType (org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType)6