示例#1
0
  /**
   * Generate MDX Expression
   *
   * @return
   */
  public Exp generate() {
    Exp exp = null;

    List<TreeNode<Exp>> nodes = rootNode.getChildren();

    // single members (nDimension = 1) are enclosed in set brackets
    // collect single members
    List<Exp> openSet = new ArrayList<Exp>();

    // loop over top level nodes
    for (TreeNode<Exp> node : nodes) {
      Exp expForNode = genExpForNode(node, nDimension);

      boolean closeOpenSet = false;
      if (nDimension == 1) {
        if (quaxUtil.isMember(expForNode)) {
          openSet.add(expForNode);
          continue;
        } else {
          closeOpenSet = true;
        }
      } else {
        if (quaxUtil.isFunCallTo(expForNode, "()")) {
          openSet.add(expForNode);
          continue;
        } else {
          closeOpenSet = true;
        }
      }

      if (closeOpenSet && !openSet.isEmpty()) {
        // close open set
        Exp set = new FunCall("{}", Syntax.Braces, openSet);

        if (exp == null) {
          exp = set;
        } else {
          // generate Union
          FunCall call = new FunCall("Union", Syntax.Function);
          call.getArgs().add(exp);
          call.getArgs().add(set);

          exp = call;
        }

        openSet.clear();
      }

      if (exp == null) {
        exp = expForNode;
      } else {
        // generate Union of Exp and expForNode
        FunCall call = new FunCall("Union", Syntax.Function);
        call.getArgs().add(exp);
        call.getArgs().add(expForNode);

        exp = call;
      }
    }

    if (!openSet.isEmpty()) {
      // close open set
      Exp set = new FunCall("{}", Syntax.Braces, openSet);

      if (exp == null) {
        exp = set;
      } else {
        // generate Union
        FunCall call = new FunCall("Union", Syntax.Function);
        call.getArgs().add(exp);
        call.getArgs().add(set);

        exp = call;
      }

      openSet.clear();
    }

    return exp;
  }