/* * (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; }
/* * (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; }
/** * Get the Class that owns the function * * @param level Number of calling function */ public Class getClass(int level) { try { return ClassUtil.forName(classNames[level]); } catch (ClassNotFoundException ex) { assert false : ex; return null; } }
/* * (non-Javadoc) * * @see * org.crosswire.common.config.AbstractReflectedChoice#convertToObject(java * .lang.String) */ @Override public Object convertToObject(String orig) { try { return ClassUtil.forName(orig); } catch (ClassNotFoundException ex) { log.warn("Class not found: " + orig, ex); return null; } }