Search in sources :

Example 1 with DynamicCardinalityCheck

use of org.exist.xquery.DynamicCardinalityCheck in project exist by eXist-db.

the class FunReplace method setArguments.

@Override
public void setArguments(List<Expression> arguments) {
    steps.clear();
    Expression arg = arguments.get(0);
    arg = new DynamicCardinalityCheck(context, Cardinality.ZERO_OR_ONE, arg, new Error(Error.FUNC_PARAM_CARDINALITY, "1", getSignature()));
    if (!Type.subTypeOf(arg.returnsType(), Type.ATOMIC)) {
        arg = new Atomize(context, arg);
    }
    steps.add(arg);
    arg = arguments.get(1);
    arg = new DynamicCardinalityCheck(context, Cardinality.EXACTLY_ONE, arg, new Error(Error.FUNC_PARAM_CARDINALITY, "2", getSignature()));
    if (!Type.subTypeOf(arg.returnsType(), Type.ATOMIC)) {
        arg = new Atomize(context, arg);
    }
    steps.add(arg);
    arg = arguments.get(2);
    arg = new DynamicCardinalityCheck(context, Cardinality.EXACTLY_ONE, arg, new Error(Error.FUNC_PARAM_CARDINALITY, "3", getSignature()));
    if (!Type.subTypeOf(arg.returnsType(), Type.ATOMIC)) {
        arg = new Atomize(context, arg);
    }
    steps.add(arg);
    if (arguments.size() == 4) {
        arg = arguments.get(3);
        arg = new DynamicCardinalityCheck(context, Cardinality.EXACTLY_ONE, arg, new Error(Error.FUNC_PARAM_CARDINALITY, "4", getSignature()));
        if (!Type.subTypeOf(arg.returnsType(), Type.ATOMIC)) {
            arg = new Atomize(context, arg);
        }
        steps.add(arg);
    }
}
Also used : Expression(org.exist.xquery.Expression) RegularExpression(net.sf.saxon.regex.RegularExpression) Atomize(org.exist.xquery.Atomize) DynamicCardinalityCheck(org.exist.xquery.DynamicCardinalityCheck) Error(org.exist.xquery.util.Error)

Example 2 with DynamicCardinalityCheck

use of org.exist.xquery.DynamicCardinalityCheck in project exist by eXist-db.

the class QNameIndexLookup method setArguments.

/**
 * Overwritten to disable automatic type checks. We check manually.
 *
 * @see org.exist.xquery.Function#setArguments(java.util.List)
 */
public void setArguments(List<Expression> arguments) throws XPathException {
    // wrap arguments into a cardinality check, so an error will be generated if
    // one of the arguments returns an empty sequence
    Expression arg = arguments.get(0);
    arg = new DynamicCardinalityCheck(context, Cardinality.ONE_OR_MORE, arg, new Error(Error.FUNC_PARAM_CARDINALITY, "1", getSignature()));
    steps.add(arg);
    arg = arguments.get(1);
    arg = new DynamicCardinalityCheck(context, Cardinality.ONE_OR_MORE, arg, new Error(Error.FUNC_PARAM_CARDINALITY, "2", getSignature()));
    steps.add(arg);
    if (arguments.size() == 3) {
        arg = arguments.get(2);
        arg = new DynamicCardinalityCheck(context, Cardinality.ONE_OR_MORE, arg, new Error(Error.FUNC_PARAM_CARDINALITY, "3", getSignature()));
        steps.add(arg);
    }
}
Also used : Expression(org.exist.xquery.Expression) DynamicCardinalityCheck(org.exist.xquery.DynamicCardinalityCheck) Error(org.exist.xquery.util.Error)

Aggregations

DynamicCardinalityCheck (org.exist.xquery.DynamicCardinalityCheck)2 Expression (org.exist.xquery.Expression)2 Error (org.exist.xquery.util.Error)2 RegularExpression (net.sf.saxon.regex.RegularExpression)1 Atomize (org.exist.xquery.Atomize)1