Search in sources :

Example 1 with AnyAtomicType

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

the class FnMax method max.

/**
 * Max operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @param context
 *            Relevant dynamic context
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:max operation.
 */
public static ResultSequence max(Collection args, DynamicContext dynamicContext) throws DynamicError {
    ResultSequence arg = get_arg(args, CmpGt.class);
    if (arg.empty())
        return ResultSequenceFactory.create_new();
    CmpGt 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 || ((CmpGt) conv).gt((AnyType) max, dynamicContext)) {
                max = (CmpGt) 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 2 with AnyAtomicType

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

Example 3 with AnyAtomicType

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

the class ConstructorFL method add_abstract_type.

/**
 * Adds a type into the functions library as an abstract type.
 *
 * @param at
 *            input of any atomic type.
 */
public void add_abstract_type(String localName, AnyAtomicType at) {
    QName name = new QName(localName);
    name.set_namespace(namespace());
    _types.put(name, at);
}
Also used : QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName)

Example 4 with AnyAtomicType

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

the class FnDeepEqual method deep_equal_atomic.

/**
 * Deep-Equal boolean operation for inputs of any atomic type.
 *
 * @param one
 *            input1 xpath expression/variable.
 * @param two
 *            input2 xpath expression/variable.
 * @return Result of fn:deep-equal operation.
 */
public static boolean deep_equal_atomic(AnyAtomicType one, AnyAtomicType two, DynamicContext context, String collationURI) {
    if (!(one instanceof CmpEq))
        return false;
    if (!(two instanceof CmpEq))
        return false;
    CmpEq a = (CmpEq) one;
    try {
        if (isNumeric(one, two)) {
            NumericType numeric = (NumericType) one;
            if (numeric.eq(two, context)) {
                return true;
            } else {
                XSString value1 = new XSString(one.getStringValue());
                if (value1.eq(two, context)) {
                    return true;
                }
            }
        }
        if (a.eq(two, context))
            return true;
        if (needsStringComparison(one, two)) {
            XSString xstr1 = new XSString(one.getStringValue());
            XSString xstr2 = new XSString(two.getStringValue());
            if (FnCompare.compare_string(collationURI, xstr1, xstr2, context).equals(BigInteger.ZERO)) {
                return true;
            }
        }
        return false;
    } catch (DynamicError err) {
        // XXX ???
        return false;
    }
}
Also used : NumericType(org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError)

Example 5 with AnyAtomicType

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

the class FnDistinctValues method distinct_values.

/**
 * Distinct-values operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:distinct-values operation.
 */
public static ResultSequence distinct_values(Collection args, DynamicContext context) throws DynamicError {
    ResultBuffer rs = new ResultBuffer();
    // get args
    Iterator citer = args.iterator();
    ResultSequence arg1 = (ResultSequence) citer.next();
    ResultSequence arg2 = ResultBuffer.EMPTY;
    if (citer.hasNext()) {
        arg2 = (ResultSequence) citer.next();
    }
    String collationURI = context.getCollationProvider().getDefaultCollation();
    if (!arg2.empty()) {
        XSString collation = (XSString) arg2.item(0);
        collationURI = collation.getStringValue();
    }
    for (Iterator iter = arg1.iterator(); iter.hasNext(); ) {
        AnyAtomicType atomizedItem = (AnyAtomicType) FnData.atomize((Item) iter.next());
        if (!contains(rs, atomizedItem, context, collationURI))
            rs.add(atomizedItem);
    }
    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) Iterator(java.util.Iterator) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) AnyAtomicType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Aggregations

AnyAtomicType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType)11 Iterator (java.util.Iterator)10 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)10 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)9 XSDouble (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble)6 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)5 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)5 NumericType (org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType)4 QName (org.eclipse.wst.xml.xpath2.processor.internal.types.QName)4 XSFloat (org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat)4 TypePromoter (org.eclipse.wst.xml.xpath2.processor.internal.utils.TypePromoter)4 Item (org.eclipse.wst.xml.xpath2.api.Item)3 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)3 ArrayList (java.util.ArrayList)2 XSSimpleTypeDefinition (org.apache.xerces.xs.XSSimpleTypeDefinition)2 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)2 ConstructorFL (org.eclipse.wst.xml.xpath2.processor.internal.function.ConstructorFL)2 FunctionLibrary (org.eclipse.wst.xml.xpath2.processor.internal.function.FunctionLibrary)2 XSInteger (org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger)2 XSUntypedAtomic (org.eclipse.wst.xml.xpath2.processor.internal.types.XSUntypedAtomic)2