예제 #1
0
  @Override
  public XpathForClause visitOrExpr(OrExprContext ctx) {
    if (isSimpleXpath) {
      return super.visitOrExpr(ctx);
    }

    if (ctx.andExpr().size() > 1) {

      Where<Coverage> orWhere = query.expressionFactory();
      stack.pushWhereStack(orWhere);

      int i = 0;
      for (AndExprContext andExprContext : ctx.andExpr()) {

        visit(andExprContext);

        if (i + 1 < ctx.andExpr().size()) {
          stack.popWhereStack();
          stack.pushWhereStack(stack.popWhereBuilderStack().or());
        }

        ++i;
      }

      stack.popWhereStack();
      stack.pushWhereBuilderStack(stack.peekWhereStack().expression(stack.popWhereBuilderStack()));

      return null;
    } else {
      return super.visitOrExpr(ctx);
    }
  }
예제 #2
0
  XpathForClause executeQuery() {
    if (!stack.isEmptyWhereBuilderStack()) {
      this.query = stack.popWhereBuilderStack().build();
    }

    List<Coverage> coverages = this.query.find();

    return new XpathForClause().setCoverages(coverages);
  }
예제 #3
0
  @Override
  public XpathForClause visitStep(StepContext ctx) {

    if (isSimpleXpath) {
      return super.visitStep(ctx);
    }

    boolean foundCoverage = false;

    String axisSpecifier = ctx.axisSpecifier().getText();
    String nodeName = ctx.nodeTest().getText();

    if (axisSpecifier.isEmpty()) {
      // is node

      switch (nodeName) {
        case XWCPSReservedWords.COVERAGE:
          foundCoverage = true;

          for (PredicateContext predicate : ctx.predicate()) {
            visit(predicate);
          }

          break;
        case XWCPSReservedWords.SERVER:
          Where<Coverage> serverWhere = query.expressionFactory();
          stack.pushWhereStack(serverWhere);

          for (PredicateContext predicate : ctx.predicate()) {
            visit(predicate);
          }

          stack.popWhereStack();
          WhereBuilder<Coverage> serverWhereBuilder =
              stack.peekWhereStack().isChildOf(stack.popWhereBuilderStack());
          stack.popWhereStack();

          stack.pushWhereStack(serverWhereBuilder.and());

          break;
        default:
          throw new ParseCancellationException(
              "Expecting an xpath with '" + XWCPSReservedWords.COVERAGE + "' element");
      }
    }

    if (foundCoverage) {
      isSimpleXpath = true;
    }

    // FIXME
    return null;
  }