/**
   * Convert report parameter value object into string.
   *
   * @param reportParameterObj report parameter value object.
   * @return parameter value in string.
   */
  public String format(Object reportParameterObj) {
    String reportParameterValue = null;

    if (reportParameterObj != null && uLocale != null) {
      if (reportParameterObj instanceof String) {
        StringFormatter sf = getStringFormatter();
        if (sf != null) {
          reportParameterValue = sf.format((String) reportParameterObj);
        } else {
          reportParameterValue = reportParameterObj.toString();
        }
      } else if (reportParameterObj instanceof Date) {
        DateFormatter df = getDateFormatter();
        if (df != null) {
          reportParameterValue = df.format((Date) reportParameterObj);
        } else {
          reportParameterValue = reportParameterObj.toString();
        }
      } else if (reportParameterObj instanceof Double) {
        NumberFormatter nf = getNumberFormatter();
        if (nf != null) {
          reportParameterValue = nf.format(((Double) reportParameterObj).doubleValue());
        } else {
          reportParameterValue = reportParameterObj.toString();
        }
      } else if (reportParameterObj instanceof BigDecimal) {
        NumberFormatter nf = getNumberFormatter();
        if (nf != null) {
          reportParameterValue = nf.format((BigDecimal) reportParameterObj);
        } else {
          reportParameterValue = reportParameterObj.toString();
        }
      } else if (reportParameterObj instanceof Boolean) {
        reportParameterValue = ((Boolean) reportParameterObj).toString();
      } else if (reportParameterObj instanceof Number) {
        NumberFormatter nf = getNumberFormatter();
        if (nf != null) {
          reportParameterValue = nf.format(((Number) reportParameterObj));
        } else {
          reportParameterValue = reportParameterObj.toString();
        }
      } else {
        reportParameterValue = (reportParameterObj.toString());
      }
    }

    return reportParameterValue;
  }
 /**
  * Get string formatter.
  *
  * @return StringFormatter object
  */
 private StringFormatter getStringFormatter() {
   if (sf == null && uLocale != null) {
     sf = new StringFormatter(uLocale);
     if (format != null) {
       sf.applyPattern(format);
     }
   }
   return sf;
 }
 /**
  * localize the value to a string.
  *
  * @param value
  * @param style
  * @param locale
  * @return
  */
 protected String localizeValue(Object value, IScriptStyle style) {
   if (value == null) {
     return null;
   }
   if (value instanceof Number) {
     String format = getNumberFormat(style);
     NumberFormatter fmt = getNumberFormatter(format);
     ;
     return fmt.format((Number) value);
   }
   if (value instanceof java.util.Date) {
     String format = getDateFormat(style, (java.util.Date) value);
     DateFormatter fmt = getDateFormatter(format);
     return fmt.format((Date) value);
   } else if (value instanceof String) {
     String format = getStringFormat(style);
     StringFormatter fmt = getStringFormatter(format);
     return fmt.format((String) value);
   }
   return value.toString();
 }
  /**
   * Convert report parameter from string into object. Need to be pointed out is it return a Double
   * object when the value type is Float.
   *
   * @param reportParameterValue report parameter value in string.
   * @param parameterValueType report parameter type.
   * @return parameter value object.
   */
  public Object parse(String reportParameterValue, int parameterValueType) {
    Object parameterValueObj = null;

    if (reportParameterValue != null && uLocale != null) {
      switch (parameterValueType) {
        case IScalarParameterDefn.TYPE_STRING:
          {
            StringFormatter sf = getStringFormatter();
            if (sf == null) {
              parameterValueObj = null;
              break;
            }

            try {
              parameterValueObj = sf.parser(reportParameterValue);
            } catch (ParseException e) {
              parameterValueObj = reportParameterValue;
            }
            break;
          }

        case IScalarParameterDefn.TYPE_DATE_TIME:
          {
            parameterValueObj = parseDateTime(reportParameterValue);
            break;
          }

        case IScalarParameterDefn.TYPE_FLOAT:
          {
            NumberFormatter nf = getNumberFormatter();
            if (nf == null) {
              parameterValueObj = null;
              break;
            }

            try {
              Number num = nf.parse(reportParameterValue);

              if (num != null) {
                parameterValueObj = new Double(num.toString());
              }
            } catch (ParseException e) {
              nf.applyPattern("General Number");

              try {
                Number num = nf.parse(reportParameterValue);

                if (num != null) {
                  parameterValueObj = new Double(num.toString());
                }
              } catch (ParseException ex) {
                parameterValueObj = null;
              }
            }

            break;
          }

        case IScalarParameterDefn.TYPE_DECIMAL:
          {
            NumberFormatter nf = getNumberFormatter();
            if (nf == null) {
              parameterValueObj = null;
              break;
            }

            try {
              Number num = nf.parse(reportParameterValue);

              if (num != null) {
                parameterValueObj = new BigDecimal(num.toString());
              }
            } catch (ParseException e) {
              nf.applyPattern("General Number");

              try {
                Number num = nf.parse(reportParameterValue);

                if (num != null) {
                  parameterValueObj = new BigDecimal(num.toString());
                }
              } catch (ParseException ex) {
                parameterValueObj = null;
              }
            }

            break;
          }

        case IScalarParameterDefn.TYPE_BOOLEAN:
          {
            parameterValueObj = Boolean.valueOf(reportParameterValue);
            break;
          }

        case IScalarParameterDefn.TYPE_DATE:
          {
            try {
              parameterValueObj = java.sql.Date.valueOf(reportParameterValue);
            } catch (IllegalArgumentException ie) {
              parameterValueObj = parseDateTime(reportParameterValue);
              if (parameterValueObj != null) {
                parameterValueObj = new java.sql.Date(((Date) parameterValueObj).getTime());
              }
            }
            break;
          }

        case IScalarParameterDefn.TYPE_TIME:
          {
            try {
              parameterValueObj = java.sql.Time.valueOf(reportParameterValue);
            } catch (IllegalArgumentException ie) {
              parameterValueObj = parseDateTime(reportParameterValue);
              if (parameterValueObj != null) {
                parameterValueObj = new java.sql.Time(((Date) parameterValueObj).getTime());
              }
            }
            break;
          }

          // can use class DataTypeUtil to convert
        case IScalarParameterDefn.TYPE_INTEGER:
          {
            NumberFormatter nf = getNumberFormatter();
            if (nf == null) {
              parameterValueObj = null;
              break;
            }

            try {
              Number num = nf.parse(reportParameterValue);

              if (num != null) {
                parameterValueObj = Integer.valueOf(num.intValue());
              }
            } catch (ParseException ex) {
              nf.applyPattern("General Number");

              try {
                Number num = nf.parse(reportParameterValue);

                if (num != null) {
                  parameterValueObj = Integer.valueOf(num.intValue());
                }
              } catch (ParseException pex) {
                try {
                  parameterValueObj = Integer.valueOf(reportParameterValue);
                } catch (NumberFormatException nfe) {
                  parameterValueObj = null;
                }
              }
            }
          }
      }
    }

    return parameterValueObj;
  }