Search in sources :

Example 1 with XSUntypedAtomic

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

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

the class FsPlus method convert_args.

/**
 * Convert and promote arguments for operation.
 *
 * @param args
 *            input arguments.
 * @param sc
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of conversion.
 */
private static Collection convert_args(Collection args) throws DynamicError {
    Collection result = new ArrayList();
    // Keep track of numeric types for promotion
    boolean has_float = false;
    boolean has_double = false;
    // atomize arguments
    for (Iterator i = args.iterator(); i.hasNext(); ) {
        org.eclipse.wst.xml.xpath2.api.ResultSequence rs = FnData.atomize((org.eclipse.wst.xml.xpath2.api.ResultSequence) i.next());
        if (rs.empty())
            return new ArrayList();
        if (rs.size() > 1)
            throw new DynamicError(TypeError.invalid_type(null));
        AnyType arg = (AnyType) rs.item(0);
        if (arg instanceof XSUntypedAtomic) {
            arg = new XSDouble(arg.getStringValue());
        }
        if (arg instanceof XSDouble)
            has_double = true;
        if (arg instanceof XSFloat)
            has_float = true;
        result.add(ResultBuffer.wrap(arg));
    }
    if (has_double)
        has_float = false;
    if (has_double || has_float) {
        Collection result2 = new ArrayList();
        // promote arguments
        for (Iterator i = result.iterator(); i.hasNext(); ) {
            org.eclipse.wst.xml.xpath2.api.ResultSequence rs = (org.eclipse.wst.xml.xpath2.api.ResultSequence) i.next();
            Item arg = rs.item(0);
            if (has_double && (arg instanceof XSFloat)) {
                arg = new XSDouble(((XSFloat) arg).float_value());
            } else if (has_double && (arg instanceof XSDecimal)) {
                arg = new XSDouble(((XSDecimal) arg).getValue().doubleValue());
            } else if (has_float && (arg instanceof XSDecimal)) {
                arg = new XSFloat(((XSDecimal) arg).getValue().floatValue());
            }
            result2.add(arg);
        }
        return result2;
    }
    return result;
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSDouble(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) ArrayList(java.util.ArrayList) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError) Item(org.eclipse.wst.xml.xpath2.api.Item) XSFloat(org.eclipse.wst.xml.xpath2.processor.internal.types.XSFloat) Iterator(java.util.Iterator) Collection(java.util.Collection) XSUntypedAtomic(org.eclipse.wst.xml.xpath2.processor.internal.types.XSUntypedAtomic) XSDecimal(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 3 with XSUntypedAtomic

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

the class NodeType method getXDMTypedValue.

// getTypedValueForPrimitiveType
/*
	 * Construct the "typed value" from a "string value", given the simpleType of the node.
     */
protected ResultSequence getXDMTypedValue(TypeDefinition typeDef, List itemValTypes) {
    if ("anySimpleType".equals(typeDef.getName()) || "anyAtomicType".equals(typeDef.getName())) {
        return new XSUntypedAtomic(getStringValue());
    } else {
        SimpleTypeDefinition simpType = null;
        if (typeDef instanceof ComplexTypeDefinition) {
            ComplexTypeDefinition complexTypeDefinition = (ComplexTypeDefinition) typeDef;
            simpType = complexTypeDefinition.getSimpleType();
            if (simpType != null) {
                // element has a complexType with a simple content
                return getTypedValueForSimpleContent(simpType, itemValTypes);
            } else {
                // element has a complexType with complex content
                return new XSUntypedAtomic(getStringValue());
            }
        } else {
            // element has a simpleType
            simpType = (SimpleTypeDefinition) typeDef;
            return getTypedValueForSimpleContent(simpType, itemValTypes);
        }
    }
}
Also used : ComplexTypeDefinition(org.eclipse.wst.xml.xpath2.api.typesystem.ComplexTypeDefinition) SimpleTypeDefinition(org.eclipse.wst.xml.xpath2.api.typesystem.SimpleTypeDefinition)

Example 4 with XSUntypedAtomic

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

the class FsConvertOperand method convert_operand.

/**
 * Convert-Operand operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fs: operation.
 */
public static ResultSequence convert_operand(Collection args) throws DynamicError {
    assert args.size() == 2;
    Iterator iter = args.iterator();
    ResultSequence actual = (ResultSequence) iter.next();
    ResultSequence expected = (ResultSequence) iter.next();
    if (expected.size() != 1)
        DynamicError.throw_type_error();
    Item at = expected.first();
    if (!(at instanceof AnyAtomicType))
        DynamicError.throw_type_error();
    AnyAtomicType exp_aat = (AnyAtomicType) at;
    ResultBuffer result = new ResultBuffer();
    // 1
    if (actual.empty())
        return result.getSequence();
    // convert sequence
    for (Iterator i = actual.iterator(); i.hasNext(); ) {
        AnyType item = (AnyType) i.next();
        // 2
        if (item instanceof XSUntypedAtomic) {
            // a
            if (exp_aat instanceof XSUntypedAtomic)
                result.add(new XSString(item.getStringValue()));
            else // b
            if (exp_aat instanceof NumericType)
                result.add(new XSDouble(item.getStringValue()));
            else // c
            {
                assert exp_aat instanceof CtrType;
                CtrType cons = (CtrType) exp_aat;
                result.concat(cons.constructor(new XSString(item.getStringValue())));
            }
        } else
            // 4
            result.add(item);
    }
    return result.getSequence();
}
Also used : NumericType(org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType) Item(org.eclipse.wst.xml.xpath2.api.Item) ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) XSDouble(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator) CtrType(org.eclipse.wst.xml.xpath2.processor.internal.types.CtrType) AnyAtomicType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSUntypedAtomic(org.eclipse.wst.xml.xpath2.processor.internal.types.XSUntypedAtomic) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 5 with XSUntypedAtomic

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

the class FsEq method value_convert_args.

/**
 * Converts arguments to values.
 *
 * @param args
 *            Result from expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of conversion.
 */
private static Collection value_convert_args(Collection args) throws DynamicError {
    Collection result = new ArrayList(args.size());
    // atomize arguments
    for (Iterator i = args.iterator(); i.hasNext(); ) {
        ResultSequence rs = (ResultSequence) i.next();
        // FnData.fast_atomize(rs);
        rs = FnData.atomize(rs);
        if (rs.empty())
            return new ArrayList();
        if (rs.size() > 1)
            throw new DynamicError(TypeError.invalid_type(null));
        Item arg = rs.first();
        if (arg instanceof XSUntypedAtomic)
            arg = new XSString(arg.getStringValue());
        result.add(arg);
    }
    return result;
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Collection(java.util.Collection) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSUntypedAtomic(org.eclipse.wst.xml.xpath2.processor.internal.types.XSUntypedAtomic) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError)

Aggregations

XSUntypedAtomic (org.eclipse.wst.xml.xpath2.processor.internal.types.XSUntypedAtomic)5 Iterator (java.util.Iterator)4 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)4 XSDouble (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble)4 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 Item (org.eclipse.wst.xml.xpath2.api.Item)3 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)3 NumericType (org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType)3 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)2 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)2 AnyAtomicType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ComplexTypeDefinition (org.eclipse.wst.xml.xpath2.api.typesystem.ComplexTypeDefinition)1 SimpleTypeDefinition (org.eclipse.wst.xml.xpath2.api.typesystem.SimpleTypeDefinition)1 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)1 CtrType (org.eclipse.wst.xml.xpath2.processor.internal.types.CtrType)1 XSAnyURI (org.eclipse.wst.xml.xpath2.processor.internal.types.XSAnyURI)1 XSBoolean (org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean)1