Пример #1
0
 /*@NotNull*/
 public Expression optimize(
     /*@NotNull*/ ExpressionVisitor visitor, ExpressionVisitor.ContextItemType contextItemType)
     throws XPathException {
   Expression e2 = super.optimize(visitor, contextItemType);
   if (e2 != this) {
     return e2;
   }
   // See if we can deduce the answer from the cardinality
   int c = argument[0].getCardinality();
   if (c == StaticProperty.ALLOWS_ONE_OR_MORE) {
     return new Literal(BooleanValue.FALSE);
   } else if (c == StaticProperty.ALLOWS_ZERO) {
     return new Literal(BooleanValue.TRUE);
   }
   // Rewrite
   //    empty(A|B) => empty(A) and empty(B)
   if (argument[0] instanceof VennExpression) {
     VennExpression v = (VennExpression) argument[0];
     if (v.getOperator() == Token.UNION && !visitor.isOptimizeForStreaming()) {
       FunctionCall e0 =
           SystemFunction.makeSystemFunction("empty", new Expression[] {v.getOperands()[0]});
       FunctionCall e1 =
           SystemFunction.makeSystemFunction("empty", new Expression[] {v.getOperands()[1]});
       return new AndExpression(e0, e1).optimize(visitor, contextItemType);
     }
   }
   return this;
 }
 public void checkArguments(StaticContext env) throws XPathException {
   if (checked) return;
   checked = true;
   super.checkArguments(env);
   Optimizer opt = env.getConfiguration().getOptimizer();
   argument[1] = ExpressionTool.unsorted(opt, argument[1], false);
   if (argument[0] instanceof StringValue) {
     // common case, key name is supplied as a constant
     try {
       keyFingerprint =
           ((ExpressionContext) env)
               .getFingerprint(((StringValue) argument[0]).getStringValue(), false);
     } catch (XPathException e) {
       StaticError err =
           new StaticError(
               "Error in key name "
                   + ((StringValue) argument[0]).getStringValue()
                   + ": "
                   + e.getMessage());
       err.setLocator(this);
       err.setErrorCode("XTDE1260");
       throw err;
     }
     if (keyFingerprint == -1) {
       StaticError err =
           new StaticError(
               "Key " + ((StringValue) argument[0]).getStringValue() + " has not been defined");
       err.setLocator(this);
       err.setErrorCode("XTDE1260");
       throw err;
     }
   } else {
     // we need to save the namespace context
     nsContext = env.getNamespaceResolver();
   }
 }
Пример #3
0
 /**
  * Return the negation of the expression
  *
  * @return the negation of the expression
  */
 public Expression negate() {
   FunctionCall fc = SystemFunction.makeSystemFunction("exists", getArguments());
   fc.setLocationId(getLocationId());
   return fc;
 }