Search in sources :

Example 16 with AnyAtomicType

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

the class XercesIntegerUserDefined method constructor.

public ResultSequence constructor(ResultSequence arg) throws DynamicError {
    ResultSequence rs = ResultSequenceFactory.create_new();
    if (arg.empty())
        return rs;
    // AnyAtomicType aat = (AnyAtomicType) arg.first();
    Item aat = arg.first();
    XSSimpleTypeDefinition simpletype = (XSSimpleTypeDefinition) typeInfo;
    if (simpletype != null) {
        if (simpletype.isDefinedFacet(XSSimpleTypeDefinition.FACET_MININCLUSIVE)) {
            String minValue = simpletype.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MININCLUSIVE);
            int iminValue = Integer.parseInt(minValue);
            int actualValue = Integer.parseInt(aat.getStringValue());
            if (actualValue < iminValue) {
                throw DynamicError.invalidForCastConstructor();
            }
        }
        if (simpletype.isDefinedFacet(XSSimpleTypeDefinition.FACET_MAXINCLUSIVE)) {
            String maxValue = simpletype.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MAXINCLUSIVE);
            int imaxValue = Integer.parseInt(maxValue);
            int actualValue = Integer.parseInt(aat.getStringValue());
            if (actualValue > imaxValue) {
                throw DynamicError.invalidForCastConstructor();
            }
        }
    }
    return new XercesIntegerUserDefined(new BigInteger(aat.getStringValue()));
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) BigInteger(java.math.BigInteger) XSSimpleTypeDefinition(org.apache.xerces.xs.XSSimpleTypeDefinition)

Example 17 with AnyAtomicType

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

the class FnSum method evaluate.

/**
 * Evaluate arguments.
 *
 * @param args
 *            argument expressions.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of evaluation.
 */
public ResultSequence evaluate(Collection args, org.eclipse.wst.xml.xpath2.api.EvaluationContext ec) throws DynamicError {
    Iterator argIterator = args.iterator();
    ResultSequence argSequence = (ResultSequence) argIterator.next();
    AnyAtomicType zero = ZERO;
    if (argIterator.hasNext()) {
        ResultSequence zeroSequence = (ResultSequence) argIterator.next();
        if (zeroSequence.size() != 1)
            throw new DynamicError(TypeError.invalid_type(null));
        if (!(zeroSequence.first() instanceof AnyAtomicType))
            throw new DynamicError(TypeError.invalid_type(zeroSequence.first().getStringValue()));
        zero = (AnyAtomicType) zeroSequence.first();
    }
    return sum(argSequence, zero);
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator) AnyAtomicType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError)

Example 18 with AnyAtomicType

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

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

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