Search in sources :

Example 66 with Item

use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.

the class DefaultEvaluator method do_exists.

private XSBoolean do_exists(ListIterator iter, Expr finalexpr) {
    // we have more vars to bind...
    if (iter.hasNext()) {
        VarExprPair ve = (VarExprPair) iter.next();
        // evaluate binding sequence
        ResultSequence rs = (ResultSequence) ve.expr().accept(this);
        QName varname = ve.varname();
        try {
            for (Iterator i = rs.iterator(); i.hasNext(); ) {
                AnyType item = (AnyType) i.next();
                pushScope(varname, item);
                XSBoolean effbool = do_exists(iter, finalexpr);
                popScope();
                // out what to do with it
                if (effbool.value())
                    return XSBoolean.TRUE;
            }
        } finally {
            iter.previous();
        }
        // since none in this sequence evaluated to true, return false
        return XSBoolean.FALSE;
    } else // we finally got to do the "last expression"
    {
        return effective_boolean_value((ResultSequence) finalexpr.accept(this));
    }
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) XSBoolean(org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType) VarExprPair(org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)

Example 67 with Item

use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.

the class XSNormalizedString method constructor.

/**
 * Creates a new ResultSequence consisting of the extractable String in the
 * supplied ResultSequence
 *
 * @param arg
 *            The ResultSequence from which to extract the String
 * @return New ResultSequence consisting of the supplied String
 * @throws DynamicError
 */
public ResultSequence constructor(ResultSequence arg) throws DynamicError {
    if (arg.empty())
        return ResultBuffer.EMPTY;
    Item aat = arg.first();
    String srcString = aat.getStringValue();
    if (!isSatisfiesConstraints(srcString)) {
        // invalid input
        DynamicError.throw_type_error();
    }
    return new XSNormalizedString(srcString);
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item)

Example 68 with Item

use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.

the class XSPositiveInteger method constructor.

/**
 * Creates a new ResultSequence consisting of the extractable positiveInteger
 * in the supplied ResultSequence
 *
 * @param arg
 *            The ResultSequence from which the positiveInteger is to be extracted
 * @return New ResultSequence consisting of the 'positiveInteger' supplied
 * @throws DynamicError
 */
public ResultSequence constructor(ResultSequence arg) throws DynamicError {
    if (arg.empty())
        return ResultBuffer.EMPTY;
    // the function conversion rules apply here too. Get the argument
    // and convert it's string value to a positiveInteger.
    Item aat = arg.first();
    try {
        BigInteger bigInt = new BigInteger(aat.getStringValue());
        // doing the range checking
        // min value is 1
        // max value is INF
        BigInteger min = BigInteger.valueOf(1);
        if (bigInt.compareTo(min) < 0) {
            // invalid input
            throw DynamicError.cant_cast(null);
        }
        return new XSPositiveInteger(bigInt);
    } catch (NumberFormatException e) {
        throw DynamicError.cant_cast(null);
    }
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) BigInteger(java.math.BigInteger)

Example 69 with Item

use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.

the class XSUnsignedInt method constructor.

/**
 * Creates a new ResultSequence consisting of the extractable unsignedInt
 * in the supplied ResultSequence
 *
 * @param arg
 *            The ResultSequence from which the unsignedInt is to be extracted
 * @return New ResultSequence consisting of the 'unsignedInt' supplied
 * @throws DynamicError
 */
public ResultSequence constructor(ResultSequence arg) throws DynamicError {
    if (arg.empty())
        return ResultBuffer.EMPTY;
    // the function conversion rules apply here too. Get the argument
    // and convert it's string value to a unsignedInt.
    Item aat = arg.first();
    try {
        BigInteger bigInt = new BigInteger(aat.getStringValue());
        // doing the range checking
        // min value is 0
        // max value is 4294967295
        BigInteger min = BigInteger.valueOf(0);
        BigInteger max = BigInteger.valueOf(4294967295L);
        if (bigInt.compareTo(min) < 0 || bigInt.compareTo(max) > 0) {
            // invalid input
            throw DynamicError.cant_cast(null);
        }
        return new XSUnsignedInt(bigInt);
    } catch (NumberFormatException e) {
        throw DynamicError.cant_cast(null);
    }
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) BigInteger(java.math.BigInteger)

Example 70 with Item

use of org.eclipse.wst.xml.xpath2.api.Item in project webtools.sourceediting by eclipse.

the class XSUnsignedShort method constructor.

/**
 * Creates a new ResultSequence consisting of the extractable unsignedShort
 * in the supplied ResultSequence
 *
 * @param arg
 *            The ResultSequence from which the unsignedShort is to be extracted
 * @return New ResultSequence consisting of the 'unsignedShort' supplied
 * @throws DynamicError
 */
public ResultSequence constructor(ResultSequence arg) throws DynamicError {
    if (arg.empty())
        return ResultBuffer.EMPTY;
    // the function conversion rules apply here too. Get the argument
    // and convert it's string value to a unsignedShort.
    Item aat = arg.first();
    try {
        BigInteger bigInt = new BigInteger(aat.getStringValue());
        // doing the range checking
        // min value is 0
        // max value is 65535
        BigInteger min = BigInteger.valueOf(0);
        BigInteger max = BigInteger.valueOf(65535L);
        if (bigInt.compareTo(min) < 0 || bigInt.compareTo(max) > 0) {
            // invalid input
            throw DynamicError.cant_cast(null);
        }
        return new XSUnsignedShort(bigInt);
    } catch (NumberFormatException e) {
        throw DynamicError.cant_cast(null);
    }
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) BigInteger(java.math.BigInteger)

Aggregations

DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)71 Item (org.eclipse.wst.xml.xpath2.api.Item)69 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)66 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)65 URL (java.net.URL)64 XSModel (org.apache.xerces.xs.XSModel)64 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)64 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)46 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)34 Iterator (java.util.Iterator)26 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)14 BigInteger (java.math.BigInteger)13 Collection (java.util.Collection)13 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)11 ListIterator (java.util.ListIterator)8 NodeType (org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)8 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)6 NumericType (org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType)5 ArrayList (java.util.ArrayList)4 GregorianCalendar (java.util.GregorianCalendar)4