protected String generateScript() {
    StringBuffer sb = new StringBuffer();

    generateScriptStart(sb);

    generateDeclarations(sb);
    generateInitMethod(sb);

    sb.append("\n");
    sb.append("\n");

    List expressions = sourceTask.getExpressions();
    sb.append(generateMethod(JRExpression.EVALUATION_DEFAULT, expressions));
    if (sourceTask.isOnlyDefaultEvaluation()) {
      List empty = new ArrayList();
      sb.append(generateMethod(JRExpression.EVALUATION_OLD, empty));
      sb.append(generateMethod(JRExpression.EVALUATION_ESTIMATED, empty));
    } else {
      sb.append(generateMethod(JRExpression.EVALUATION_OLD, expressions));
      sb.append(generateMethod(JRExpression.EVALUATION_ESTIMATED, expressions));
    }

    generateScriptEnd(sb);

    return sb.toString();
  }
  protected JRBshGenerator(JRSourceCompileTask sourceTask) {
    this.sourceTask = sourceTask;

    this.parametersMap = sourceTask.getParametersMap();
    this.fieldsMap = sourceTask.getFieldsMap();
    this.variablesMap = sourceTask.getVariablesMap();
    this.variables = sourceTask.getVariables();
  }
  protected final String generateMethod(byte evaluationType, List expressionsList) {
    StringBuffer sb = new StringBuffer();

    /*   */
    sb.append("    Object evaluate");
    sb.append((String) methodSuffixMap.get(new Byte(evaluationType)));
    sb.append("(int id)\n");
    sb.append("    {\n");
    sb.append("        Object value = null;\n");
    sb.append("\n");
    sb.append("        switch (id)\n");
    sb.append("        {\n");

    if (expressionsList != null && !expressionsList.isEmpty()) {
      JRExpression expression = null;
      for (Iterator it = expressionsList.iterator(); it.hasNext(); ) {
        expression = (JRExpression) it.next();

        sb.append("            case ");
        sb.append(sourceTask.getExpressionId(expression));
        sb.append(" :\n");
        sb.append("            {\n");
        sb.append("                value = (");
        sb.append(expression.getValueClassName());
        sb.append(")(");
        sb.append(this.generateExpression(expression, evaluationType));
        sb.append(");\n");
        sb.append("                break;\n");
        sb.append("            }\n");
      }
    }

    /*   */
    sb.append("           default :\n");
    sb.append("           {\n");
    sb.append("           }\n");
    sb.append("        }\n");
    sb.append("        \n");
    sb.append("        return value;\n");
    sb.append("    }\n");
    sb.append("\n");
    sb.append("\n");

    return sb.toString();
  }
  protected final void generateScriptStart(StringBuffer sb) {
    /*   */
    sb.append("//\n");
    sb.append("// Generated by JasperReports - ");
    sb.append((new SimpleDateFormat()).format(new java.util.Date()));
    sb.append("\n");
    sb.append("//\n");
    sb.append("import net.sf.jasperreports.engine.*;\n");
    sb.append("import net.sf.jasperreports.engine.fill.*;\n");
    sb.append("\n");
    sb.append("import java.util.*;\n");
    sb.append("import java.math.*;\n");
    sb.append("import java.text.*;\n");
    sb.append("import java.io.*;\n");
    sb.append("import java.net.*;\n");
    sb.append("\n");

    /*   */
    String[] imports = sourceTask.getImports();
    if (imports != null && imports.length > 0) {
      for (int i = 0; i < imports.length; i++) {
        sb.append("import ");
        sb.append(imports[i]);
        sb.append(";\n");
      }
    }

    /*   */
    sb.append("\n");
    sb.append("\n");
    sb.append("createBshEvaluator()\n");
    sb.append("{\n");
    sb.append("\n");
    sb.append("\n");
    sb.append("    JREvaluator evaluator = null;\n");
    sb.append("\n");
  }