Package org.exist.xquery.util

Examples of org.exist.xquery.util.Error


                        Messages.getMessage(Error.FUNC_EMPTY_SEQ_DISALLOWED,
                        Integer.valueOf(argPosition), ExpressionDumper.dump(expr)));}
            }
        }
        expr = new DynamicCardinalityCheck(context, type.getCardinality(), expr,
            new Error(Error.FUNC_PARAM_CARDINALITY, argPosition, mySignature));
        // check return type if both types are not Type.ITEM
        int returnType = expr.returnsType();
        if (returnType == Type.ANY_TYPE || returnType == Type.EMPTY)
            {returnType = Type.ITEM;}
        boolean typeMatches = type.getPrimaryType() == Type.ITEM;
        typeMatches = Type.subTypeOf(returnType, type.getPrimaryType());
        if (typeMatches && cardinalityMatches) {
            if (type.getNodeName() != null)
                {expr = new DynamicNameCheck(context,
                    new NameTest(type.getPrimaryType(), type.getNodeName()), expr);}
            return expr;
        }
        //Loose argument check : we may move this, or a part hereof, to UntypedValueCheck
        if (context.isBackwardsCompatible()) {
            if (Type.subTypeOf(type.getPrimaryType(), Type.STRING)) {
                if (!Type.subTypeOf(returnType, Type.ATOMIC)) {
                    expr = new Atomize(context, expr);
                    returnType = Type.ATOMIC;
                }
                expr = new AtomicToString(context, expr);
                returnType = Type.STRING;
            } else if (type.getPrimaryType() == Type.NUMBER
                    || Type.subTypeOf(type.getPrimaryType(), Type.DOUBLE)) {
                if (!Type.subTypeOf(returnType, Type.ATOMIC)) {
                    expr = new Atomize(context, expr);
                    returnType = Type.ATOMIC;
                }
                expr = new UntypedValueCheck(context, type.getPrimaryType(), expr,
                    new Error(Error.FUNC_PARAM_TYPE, String.valueOf(argPosition), mySignature));
                returnType = type.getPrimaryType();
            }
            //If the required type is an atomic type, convert the argument to an atomic
            if (Type.subTypeOf(type.getPrimaryType(), Type.ATOMIC)) {
                if(!Type.subTypeOf(returnType, Type.ATOMIC))
                    {expr = new Atomize(context, expr);}
                if (!(type.getPrimaryType() == Type.ATOMIC))
                    {expr = new UntypedValueCheck(context, type.getPrimaryType(),
                        expr, new Error(Error.FUNC_PARAM_TYPE, String.valueOf(argPosition), mySignature));}
                returnType = expr.returnsType();
            }
        //Strict argument check : we may move this, or a part hereof, to UntypedValueCheck
        } else {
            //If the required type is an atomic type, convert the argument to an atomic
            if (Type.subTypeOf(type.getPrimaryType(), Type.ATOMIC)) {
                if(!Type.subTypeOf(returnType, Type.ATOMIC))
                    {expr = new Atomize(context, expr);}
                expr = new UntypedValueCheck(context, type.getPrimaryType(),
                    expr, new Error(Error.FUNC_PARAM_TYPE, String.valueOf(argPosition), mySignature));
                returnType = expr.returnsType();
            }
        }
        if (returnType != Type.ITEM && !Type.subTypeOf(returnType, type.getPrimaryType())) {
            if (!(Type.subTypeOf(type.getPrimaryType(), returnType) ||
View Full Code Here


   * @see org.exist.xquery.Function#setArguments(java.util.List)
   */
  public void setArguments(List<Expression> arguments) throws XPathException {
        Expression arg = arguments.get(0);
        arg = new DynamicCardinalityCheck(context, Cardinality.ZERO_OR_ONE, arg,
                new Error(Error.FUNC_PARAM_CARDINALITY, "1", mySignature));   
        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", mySignature));
        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", mySignature));
        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", mySignature));
            if(!Type.subTypeOf(arg.returnsType(), Type.ATOMIC))
                {arg = new Atomize(context, arg);}
            steps.add(arg);           
        }
  }
View Full Code Here

      steps.clear();
        for (Expression argument : arguments) {
          if (!(argument instanceof Placeholder)) {
              argument = new DynamicCardinalityCheck(context,
                  Cardinality.ZERO_OR_ONE, argument,
                  new Error(Error.FUNC_PARAM_CARDINALITY, "1", mySignature));
              if (!Type.subTypeOf(argument.returnsType(), Type.ATOMIC))
                  {argument = new Atomize(context, argument);}
          }
            steps.add(argument);
        }
View Full Code Here

    public void setArguments(List<Expression> arguments) throws XPathException {
        steps.clear();
        Expression path = arguments.get(0);
        path = new DynamicCardinalityCheck(context, Cardinality.ONE_OR_MORE, path,
                new Error(Error.FUNC_PARAM_CARDINALITY, "1", mySignature));
        steps.add(path);

        int j = 1;
        if (isCalledAs("field")) {
            Expression fields = arguments.get(1);
            fields = new DynamicCardinalityCheck(context, Cardinality.ONE_OR_MORE, fields,
                    new Error(Error.FUNC_PARAM_CARDINALITY, "2", mySignature));
            steps.add(fields);
            j++;
        }
        for (int i = j; i < arguments.size(); i++) {
            Expression arg = arguments.get(i).simplify();
View Full Code Here

     */
    public NodeComparison(XQueryContext context, Expression left, Expression right, int relation) {
        super(context);
        this.relation = relation;
        add(new DynamicCardinalityCheck(context, Cardinality.ZERO_OR_ONE, left,
                new Error(Error.NODE_COMP_TYPE_MISMATCH)));
        add(right);
        //add(new DynamicCardinalityCheck(context, Cardinality.ZERO_OR_ONE, right,
        //        new Error(Error.NODE_COMP_TYPE_MISMATCH)));
        //add(left);
    }
View Full Code Here

    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", mySignature));
        steps.add(arg);
       
        arg = arguments.get(1);
        arg = new DynamicCardinalityCheck(context, Cardinality.ONE_OR_MORE, arg,
                new Error(Error.FUNC_PARAM_CARDINALITY, "2", mySignature));
        steps.add(arg);
    }
View Full Code Here

        final Expression path = arguments.get(0);
        steps.add(path);
       
        Expression arg = arguments.get(1);
        arg = new DynamicCardinalityCheck(context, Cardinality.EXACTLY_ONE, arg,
                new Error(Error.FUNC_PARAM_CARDINALITY, "2", mySignature));
        if(!Type.subTypeOf(arg.returnsType(), Type.ATOMIC))
            {arg = new Atomize(context, arg);}
        steps.add(arg);
       
        if (arguments.size() == 3) {
            arg = arguments.get(2);
            arg = new DynamicCardinalityCheck(context, Cardinality.EXACTLY_ONE, arg,
                    new Error(Error.FUNC_PARAM_CARDINALITY, "3", mySignature));
            if(!Type.subTypeOf(arg.returnsType(), Type.ATOMIC))
                {arg = new Atomize(context, arg);}
            steps.add(arg);
        }
View Full Code Here

    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.ZERO_OR_MORE, arg,
                new Error(Error.FUNC_PARAM_CARDINALITY, "1", mySignature));
        steps.add(arg);
       
        arg = arguments.get(1);
        arg = new DynamicCardinalityCheck(context, Cardinality.ZERO_OR_MORE, arg,
                new Error(Error.FUNC_PARAM_CARDINALITY, "2", mySignature));
        steps.add(arg);
    }
View Full Code Here

  private final int requiredType;
  private final Error error;
    private final boolean atomize;
   
    public UntypedValueCheck(XQueryContext context, int requiredType, Expression expression) {
        this(context, requiredType, expression, new Error(Error.TYPE_MISMATCH));
    }
View Full Code Here

        this.functionDef.setCaller(this);
        final SequenceType returnType = this.functionDef.getSignature().getReturnType();
       
        // add return type checks
        if(returnType.getCardinality() != Cardinality.ZERO_OR_MORE) {
                expression = new DynamicCardinalityCheck(context, returnType.getCardinality(), expression, new Error(Error.FUNC_RETURN_CARDINALITY));
        }
       
        if(Type.subTypeOf(returnType.getPrimaryType(), Type.ATOMIC)) {
                expression = new Atomize(context, expression);
        }
       
        if(Type.subTypeOf(returnType.getPrimaryType(), Type.NUMBER)) {
                expression = new UntypedValueCheck(context, returnType.getPrimaryType(), expression, new Error(Error.FUNC_RETURN_TYPE));
        } else if(returnType.getPrimaryType() != Type.ITEM) {
                expression = new DynamicTypeCheck(context, returnType.getPrimaryType(), expression);
        }
    }
View Full Code Here

TOP

Related Classes of org.exist.xquery.util.Error

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.