protected Object parseParameter(ReportParameter parameter, String value)
      throws ProviderException {
    try {
      if (parameter.getClassName().equals("java.lang.String")) {
        return value;
      } else if (parameter.getClassName().equals("java.lang.Double")) {
        return new Double(value);
      } else if (parameter.getClassName().equals("java.lang.Integer")) {
        return new Integer(value);
      } else if (parameter.getClassName().equals("java.lang.Long")) {
        return new Long(value);
      } else if (parameter.getClassName().equals("java.math.BigDecimal")) {
        return new BigDecimal(value);
      } else if (parameter.getClassName().equals("java.util.Date")) {
        return dateProvider.parseDate(value);
      } else if (parameter.getClassName().equals("java.sql.Date")) {
        return dateProvider.parseDate(value);
      } else if (parameter.getClassName().equals("java.sql.Timestamp")) {
        long time = dateProvider.parseDate(value).getTime();
        return new Timestamp(time);
      } else if (parameter.getClassName().equals("java.lang.Boolean")) {
        return new Boolean(value);
      }
    } catch (Exception e) {
      throw new ProviderException(parameter.getName() + " Invalid: " + e.getMessage());
    }

    throw new ProviderException(parameter.getName() + " currently unsupported!");
  }
  private String buildMultipleSelectString(ReportParameter reportParameter, Object[] values) {
    StringBuffer sb = new StringBuffer();

    if (values == null || values.length < 1 || values[0].equals("")) return "";

    for (int j = 0; j < values.length; j++) {
      String value = "";

      if (values[j] instanceof ReportParameterValue) {
        value = ((ReportParameterValue) values[j]).getId().toString();
      } else {
        value = (String) values[j];
      }

      if (j > 0) {
        sb.append(',');
      }

      if (reportParameter.getClassName().equals("java.lang.String")) {
        sb.append("'" + value + "'");
      } else {
        sb.append(value);
      }
    }

    return sb.toString();
  }
  protected ReportParameterValue[] parseListValues(ReportParameter reportParameter)
      throws ProviderException {
    StringTokenizer st = new StringTokenizer(reportParameter.getData(), "|");

    ReportParameterValue[] values = new ReportParameterValue[st.countTokens()];

    int index = 0;
    while (st.hasMoreTokens()) {
      String token = st.nextToken();
      String id = token;
      String description = token;

      StringTokenizer paramValue = new StringTokenizer(token, ":");
      if (paramValue.countTokens() == 2) {
        id = paramValue.nextToken();
        description = paramValue.nextToken();
      }

      try {
        if (reportParameter.getClassName().equals("java.lang.Integer")) {
          values[index] = new ReportParameterValue(Integer.valueOf(id), description);
        } else if (reportParameter.getClassName().equals("java.lang.Double")) {
          values[index] = new ReportParameterValue(Double.valueOf(id), description);
        } else if (reportParameter.getClassName().equals("java.lang.Long")) {
          values[index] = new ReportParameterValue(Long.valueOf(id), description);
        } else if (reportParameter.getClassName().equals("java.math.BigDecimal")) {
          values[index] = new ReportParameterValue(new BigDecimal(id), description);
        } else {
          values[index] = new ReportParameterValue(id, description);
        }
      } catch (Exception e) {
        throw new ProviderException(
            reportParameter.getData() + " contains invalid " + reportParameter.getClassName());
      }

      index++;
    }

    return values;
  }
 protected void validateParameter(ReportParameter parameter, String value)
     throws ProviderException {
   try {
     if (parameter.getClassName().equals("java.lang.Double")) {
       new Double(value);
     } else if (parameter.getClassName().equals("java.lang.Integer")) {
       new Integer(value);
     } else if (parameter.getClassName().equals("java.lang.Long")) {
       new Long(value);
     } else if (parameter.getClassName().equals("java.math.BigDecimal")) {
       new BigDecimal(value);
     } else if (parameter.getClassName().equals("java.util.Date")
         || parameter.getClassName().equals("java.sql.Date")
         || parameter.getClassName().equals("java.sql.Timestamp")) {
       try {
         dateProvider.parseDate(value);
       } catch (Exception e) {
         throw new ProviderException(e.getMessage());
       }
     }
   } catch (Exception e) {
     throw new ProviderException(parameter.getDescription() + " Invalid: " + e.getMessage());
   }
 }
  protected ReportParameterValue[] getParamValuesFromDataSource(
      ReportParameter param, Map<String, Object> parameters) throws ProviderException {
    Connection conn = null;
    PreparedStatement pStmt = null;
    ResultSet rs = null;

    try {
      ReportDataSource dataSource = param.getDataSource();
      conn = dataSourceProvider.getConnection(dataSource.getId());

      if (parameters == null || parameters.isEmpty()) {
        pStmt = conn.prepareStatement(param.getData());
      } else {
      }

      rs = pStmt.executeQuery();

      ResultSetMetaData rsMetaData = rs.getMetaData();

      boolean multipleColumns = false;
      if (rsMetaData.getColumnCount() > 1) multipleColumns = true;

      ArrayList<ReportParameterValue> v = new ArrayList<ReportParameterValue>();

      while (rs.next()) {
        ReportParameterValue value = new ReportParameterValue();

        if (param.getClassName().equals("java.lang.String")) {
          value.setId(rs.getString(1));
        } else if (param.getClassName().equals("java.lang.Double")) {
          value.setId(new Double(rs.getDouble(1)));
        } else if (param.getClassName().equals("java.lang.Integer")) {
          value.setId(new Integer(rs.getInt(1)));
        } else if (param.getClassName().equals("java.lang.Long")) {
          value.setId(new Long(rs.getLong(1)));
        } else if (param.getClassName().equals("java.math.BigDecimal")) {
          value.setId(rs.getBigDecimal(1));
        } else if (param.getClassName().equals("java.util.Date")) {
          value.setId(rs.getDate(1));
        } else if (param.getClassName().equals("java.sql.Date")) {
          value.setId(rs.getDate(1));
        } else if (param.getClassName().equals("java.sql.Timestamp")) {
          value.setId(rs.getTimestamp(1));
        }

        if (multipleColumns) {
          value.setDescription(rs.getString(2));
        }

        v.add(value);
      }

      rs.close();

      ReportParameterValue[] values = new ReportParameterValue[v.size()];
      v.toArray(values);

      return values;
    } catch (Exception e) {
      throw new ProviderException("Error retreiving param values from database: " + e.getMessage());
    } finally {
      try {
        if (pStmt != null) pStmt.close();
        if (conn != null) conn.close();
      } catch (Exception c) {
        log.error("Error closing");
      }
    }
  }