Example #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;
 }
Example #2
0
  public void checkArguments(ExpressionVisitor visitor) throws XPathException {
    StaticContext env = visitor.getStaticContext();
    if (checked) return;
    checked = true;
    super.checkArguments(visitor);
    if (argument[1] instanceof StringLiteral) {
      // picture is known statically - optimize for this common case
      picture = ((StringLiteral) argument[1]).getStringValue();
    }
    if (argument.length == 3) {
      if (argument[2] instanceof StringLiteral) {
        // common case, decimal format name is supplied as a string literal

        String lexicalName = ((StringLiteral) argument[2]).getStringValue();

        StructuredQName qName;
        try {
          qName =
              StructuredQName.fromLexicalQName(
                  lexicalName,
                  false,
                  visitor.getConfiguration().getNameChecker(),
                  env.getNamespaceResolver());
        } catch (XPathException e) {
          XPathException se = new XPathException("Invalid decimal format name. " + e.getMessage());
          se.setErrorCode("XTDE1280");
          throw se;
        }

        DecimalFormatManager dfm =
            ((ExpressionContext) env).getXSLStylesheet().getDecimalFormatManager();
        requireFixup = true;
        dfm.registerUsage(qName, this);
        // this causes a callback to the fixup() method, either now, or later if it's a forwards
        // reference
      } else {
        // we need to save the namespace context
        nsContext = env.getNamespaceResolver();
      }
    } else {
      // two arguments only: it uses the default decimal format
      if (env instanceof ExpressionContext) {
        // this is XSLT
        DecimalFormatManager dfm =
            ((ExpressionContext) env).getXSLStylesheet().getDecimalFormatManager();
        dfm.registerUsage(DecimalFormatManager.DEFAULT_NAME, this);
        // Note: if using the "default default", there will be no fixup call.
      } else {
        // using saxon:decimal-format in some other environment
      }
    }
  }
 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();
   }
 }
Example #4
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;
 }
Example #5
0
 public void checkArguments(/*@NotNull*/ ExpressionVisitor visitor) throws XPathException {
   if (expressionBaseURI == null) {
     super.checkArguments(visitor);
     expressionBaseURI = visitor.getStaticContext().getBaseURI();
   }
 }