use of org.exist.xquery.util.Error in project exist by eXist-db.
the class NamespaceConstructor method setContentExpr.
public void setContentExpr(final PathExpr path) {
path.setUseStaticContext(true);
final Expression expr = new DynamicCardinalityCheck(context, Cardinality.EXACTLY_ONE, path, new Error(Error.FUNC_PARAM_CARDINALITY));
this.content = expr;
}
use of org.exist.xquery.util.Error 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);
}
}
use of org.exist.xquery.util.Error in project exist by eXist-db.
the class Function method looseCheckArgumentType.
protected Tuple2<Expression, Integer> looseCheckArgumentType(Expression argument, @Nullable final SequenceType argType, final AnalyzeContextInfo argContextInfo, final int argPosition, int returnType) {
if (Type.subTypeOf(argType.getPrimaryType(), Type.STRING)) {
if (!Type.subTypeOf(returnType, Type.ATOMIC)) {
argument = new Atomize(context, argument);
}
argument = new AtomicToString(context, argument);
returnType = Type.STRING;
} else if (Type.subTypeOfUnion(argType.getPrimaryType(), Type.NUMBER)) {
if (!Type.subTypeOf(returnType, Type.ATOMIC)) {
argument = new Atomize(context, argument);
}
argument = new UntypedValueCheck(context, argType.getPrimaryType(), argument, new Error(Error.FUNC_PARAM_TYPE, String.valueOf(argPosition), mySignature));
returnType = argType.getPrimaryType();
}
// If the required type is an atomic type, convert the argument to an atomic
if (Type.subTypeOf(argType.getPrimaryType(), Type.ATOMIC)) {
if (!Type.subTypeOf(returnType, Type.ATOMIC)) {
argument = new Atomize(context, argument);
}
if (argType.getPrimaryType() != Type.ATOMIC) {
argument = new UntypedValueCheck(context, argType.getPrimaryType(), argument, new Error(Error.FUNC_PARAM_TYPE, String.valueOf(argPosition), mySignature));
}
returnType = argument.returnsType();
}
return Tuple(argument, returnType);
}
use of org.exist.xquery.util.Error in project exist by eXist-db.
the class ConcatExpr method add.
@Override
public void add(PathExpr pathExpr) {
Expression expr = new DynamicCardinalityCheck(context, Cardinality.ZERO_OR_ONE, pathExpr, new Error(Error.FUNC_PARAM_CARDINALITY));
if (!Type.subTypeOf(expr.returnsType(), Type.ATOMIC)) {
expr = new Atomize(context, expr);
}
super.add(expr);
}
use of org.exist.xquery.util.Error in project exist by eXist-db.
the class FunMatches method setArguments.
@Override
public void setArguments(final List<Expression> arguments) throws XPathException {
steps.clear();
final Expression path = arguments.get(0);
steps.add(path);
if (arguments.size() >= 2) {
Expression 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);
}
if (arguments.size() >= 3) {
Expression 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);
}
final List<LocationStep> steps = BasicExpressionVisitor.findLocationSteps(path);
if (!steps.isEmpty()) {
final LocationStep firstStep = steps.get(0);
LocationStep lastStep = steps.get(steps.size() - 1);
if (firstStep != null && lastStep != null) {
final NodeTest test = lastStep.getTest();
if (!test.isWildcardTest() && test.getName() != null) {
if (lastStep.getAxis() == Constants.ATTRIBUTE_AXIS || lastStep.getAxis() == Constants.DESCENDANT_ATTRIBUTE_AXIS) {
contextQName = new QName(test.getName(), ElementValue.ATTRIBUTE);
} else {
contextQName = new QName(test.getName());
}
contextStep = lastStep;
axis = firstStep.getAxis();
if (axis == Constants.SELF_AXIS && steps.size() > 1) {
if (steps.get(1) != null) {
axis = steps.get(1).getAxis();
} else {
contextQName = null;
contextStep = null;
axis = Constants.UNKNOWN_AXIS;
}
}
}
}
}
}
Aggregations