/**
  * Method "getDataFilter".
  *
  * @param analysis
  * @return the list of domains or null
  */
 public static EList<Domain> getDataFilter(Analysis analysis) {
   AnalysisParameters parameters = analysis.getParameters();
   if (parameters == null) {
     return null;
   }
   return parameters.getDataFilter();
 }
 /**
  * Method "setAnalysisType".
  *
  * @param analysis an analysis
  * @param analysisType the type to set to the analysis
  */
 public static void setAnalysisType(Analysis analysis, AnalysisType analysisType) {
   AnalysisParameters parameters = analysis.getParameters();
   if (parameters == null) {
     parameters = AnalysisFactory.eINSTANCE.createAnalysisParameters();
     analysis.setParameters(parameters);
   }
   parameters.setAnalysisType(analysisType);
 }
 /**
  * Method "getExecutionEngine".
  *
  * @param analysis the analysis
  * @return the execution language (SQL by default)
  */
 public static ExecutionLanguage getExecutionEngine(Analysis analysis) {
   AnalysisParameters parameters = analysis.getParameters();
   if (parameters == null) {
     return ExecutionLanguage.SQL;
   }
   // else
   return parameters.getExecutionLanguage();
 }
 /**
  * Method "getAnalysisType".
  *
  * @param analysis
  * @return the analysis type or null if not set
  */
 public static AnalysisType getAnalysisType(Analysis analysis) {
   AnalysisParameters parameters = analysis.getParameters();
   if (parameters == null) {
     return null;
   }
   // else
   return parameters.getAnalysisType();
 }
  /**
   * Current analysis whether is java engin
   *
   * @param analysis the analysis
   * @return true if is java engin else false
   */
  public static boolean isJavaExecutionEngine(Analysis analysis) {
    AnalysisParameters parameters = analysis.getParameters();

    if (parameters == null) {
      return false;
    }
    ExecutionLanguage executionLanguage = parameters.getExecutionLanguage();
    return ExecutionLanguage.JAVA == executionLanguage;
  }
  /**
   * DOC xqliu Comment method "getStringDataFilter".
   *
   * @param analysis
   * @param index 0 for DataFilterA, 1 for DataFilterB
   * @return
   */
  public static String getStringDataFilter(Analysis analysis, int index) {
    AnalysisParameters parameters = analysis.getParameters();
    if (parameters == null) {
      return null;
    }
    EList<Domain> dataFilters = parameters.getDataFilter();
    // remove existing filters
    if (dataFilters == null || dataFilters.isEmpty()) {
      return null;
    }

    int i = 0;
    for (Domain domain : dataFilters) {
      if (domain == null) {
        continue;
      }
      EList<RangeRestriction> ranges = domain.getRanges();
      for (RangeRestriction rangeRestriction : ranges) {
        BooleanExpressionNode expressions = rangeRestriction.getExpressions();
        if (expressions == null) {
          continue;
        }
        Expression expression = expressions.getExpression();
        if (expression == null) {
          continue;
        }
        if (i == index) {
          // MOD klliu 2011-07-14 bug 23150 solve an NPE
          String body = expression.getBody();
          if (body == null) {
            continue;
          }
          // ~
          return body.trim();
        } else if (i > index) {
          return null;
        }
      }
      i++;
    }
    return null;
  }