예제 #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;
  }
예제 #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;
  }
예제 #3
0
 /*
  * (non-Javadoc)
  *
  * @see java.text.DateFormat#format(java.util.Date)
  */
 public String format(Date date) {
   try {
     return (String) ReflectionUtil.invoke(formatterClass, formatter, "format", date);
   } catch (Exception e) {
     assert false : e;
     return "";
   }
 }
예제 #4
0
  /*
   * (non-Javadoc)
   *
   * @see java.text.DateFormat#parse(java.lang.String)
   */
  public Date parse(String text) throws ParseException {
    try {
      return (Date) ReflectionUtil.invoke(formatterClass, formatter, "parse", text);
    } catch (Exception e) {
      if (e instanceof ParseException) {
        throw (ParseException) e;
      }

      assert false : e;
      return new Date();
    }
  }
예제 #5
0
 /*
  * (non-Javadoc)
  *
  * @see java.text.DateFormat#setLenient(boolean)
  */
 public void setLenient(boolean lenient) {
   try {
     Class<?>[] lenientTypes = {boolean.class};
     Object[] lenientParams = {Boolean.valueOf(lenient)};
     ReflectionUtil.invoke(formatterClass, formatter, "setLenient", lenientParams, lenientTypes);
   } catch (NoSuchMethodException e) {
     assert false : e;
   } catch (IllegalAccessException e) {
     assert false : e;
   } catch (InvocationTargetException e) {
     assert false : e;
   }
 }