Esempio n. 1
0
  /*
   * (non-Javadoc)
   *
   * @see java.text.DateFormat#getDateInstance(int)
   */
  public static DateFormatter getSimpleDateInstance(String format) {
    DateFormatter fmt = new DateFormatter();
    boolean oops = false;
    try {
      fmt.formatterClass = ClassUtil.forName("com.ibm.icu.text.SimpleDateFormat");
      fmt.formatter = ReflectionUtil.construct("com.ibm.icu.text.SimpleDateFormat", format);
    } catch (NoSuchMethodException e) {
      oops = true;
    } catch (IllegalAccessException e) {
      oops = true;
    } catch (InvocationTargetException e) {
      oops = true;
    } catch (ClassNotFoundException e) {
      oops = true;
    } catch (InstantiationException e) {
      oops = true;
    }

    if (oops) {
      fmt.formatterClass = SimpleDateFormat.class;
      fmt.formatter = new SimpleDateFormat(format);
    }

    return fmt;
  }
Esempio n. 2
0
  /*
   * (non-Javadoc)
   *
   * @see java.text.DateFormat#getDateInstance(int)
   */
  public static DateFormatter getDateInstance(int format) {
    DateFormatter fmt = new DateFormatter();
    boolean oops = false;
    try {
      fmt.formatterClass = ClassUtil.forName("com.ibm.icu.text.DateFormat");
      // To call a method taking a type of int, the type has to match but
      // the object has to be wrapped
      Class<?>[] instanceTypes = {int.class};
      Object[] instanceParams = {Integer.valueOf(format)};
      fmt.formatter =
          ReflectionUtil.invoke(
              fmt.formatterClass,
              fmt.formatterClass,
              "getDateInstance",
              instanceParams,
              instanceTypes);
    } catch (NoSuchMethodException e) {
      oops = true;
    } catch (IllegalAccessException e) {
      oops = true;
    } catch (InvocationTargetException e) {
      oops = true;
    } catch (ClassNotFoundException e) {
      oops = true;
    }

    if (oops) {
      fmt.formatterClass = DateFormat.class;
      fmt.formatter = DateFormat.getDateInstance(format);
    }

    return fmt;
  }