List of usage examples for org.apache.commons.beanutils Converter Converter
Converter
From source file:hermes.browser.HermesBrowser.java
public static void main(String[] args) { log.debug("Hermes Browser " + Hermes.VERSION + " starting..."); log.debug("working directory: " + new File(".").getAbsolutePath()); Hermes.events.addConnectionListener(new ConnectionListener() { public void onConnectionOpen(Hermes hermes) { log.debug("Connection " + hermes.getId() + " opened"); }/*w w w .ja v a 2s.co m*/ public void onConnectionClosed(Hermes hermes) { log.debug("Connection " + hermes.getId() + " closed"); } }); // // Need to bootstrap objects into the singleton manager... hack for now. JVMUtils.forceInit(SingletonManager.class); JVMUtils.forceInit(ThreadPool.class); JVMUtils.forceInit(SimpleClassLoaderManager.class); // // Commented out as this is for debug use only. // RepaintManager.setCurrentManager(new ThreadCheckingRepaintManager()); // // Note this is the license for the JIDE Framework, it is licenced // to Colin Crist and the Hermes project and should not be used for any // other purpose // Lm.verifyLicense("Colin Crist", "Hermes", "9vkNAfxF1lvVyW7uZXYjpxFskycSGLw1"); // // See http://www.jidesoft.com for licensing terms. // // Register a converter from a String to a File with PropertyUtils. ConvertUtils.register(new Converter() { public Object convert(Class arg0, Object filename) { return new File((String) filename); } }, File.class); SplashScreen.create(IconCache.getIcon("hermes.splash")); SplashScreen.show(); SwingUtilities.invokeLater(new Runnable() { public void run() { try { ui = new HermesBrowser(HERMES_TITLE); ui.initJIDE(); try { ui.loadConfig(); } catch (NamingException ex) { log.fatal("cannot initialise hermes: " + ex.getMessage(), ex); System.exit(1); } catch (HeadlessException ex) { log.fatal("cannot initialise hermes browser, no head: " + ex.getMessage(), ex); System.exit(1); } ui.initUI(); ui.init(); ui.getLayoutPersistence().setProfileKey(ui.getUserProfileName()); ui.getLayoutPersistence().loadLayoutData(); // This must be done after the layout has been set otherwise // the // frames are hidden. final ArrayList<WatchConfig> tmpList = new ArrayList<WatchConfig>(ui.getConfig().getWatch()); ui.getLoader().getConfig().getWatch().clear(); for (WatchConfig wConfig : tmpList) { ui.createWatch(wConfig); } ui.firstLoad = false; } catch (Exception ex) { log.fatal("cannot initialise hermes browser: " + ex.getMessage(), ex); } } }); }
From source file:common.ClassUtils.java
public static void copyBean(Object src, Object dest) { try {/* ww w . ja va 2 s .c o m*/ // ? frombean-->birthday="" user-birhday=null ConvertUtils.register(new Converter() { public Object convert(Class type, Object value) { //198a if (value == null) { return null; } String s = (String) value; if (s.trim().equals("")) { return null; } SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); try { return sdf.parse(s); } catch (ParseException e) { throw new RuntimeException(e); } } }, Date.class); //bean BeanUtils.copyProperties(dest, src); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.yunmel.syncretic.utils.biz.TreeUtils.java
/** * ??List? (listcopy)// w w w . j a v a 2 s.co m * * @param list * @return */ public static <T extends BaseEntity> List<T> toTreeNodeList(List<T> source, Class<T> bean) { final Map<String, T> nodes = Maps.newHashMap(); ConvertUtils.register(new Converter() { @SuppressWarnings("hiding") @Override public <T> T convert(Class<T> arg0, Object arg1) { // TODO Auto-generated method stub return null; } }, java.util.Date.class); // copy?list? List<T> list = CollectionsUtils.copyTo(source, bean); // ? for (T node : list) { node.put("level", -1); node.put("hasChild", false); node.put("children", new ArrayList<T>()); nodes.put(node.getString("id"), node); } final BaseEntity root = new BaseEntity(); root.put("level", 0); root.put("children", new ArrayList<T>()); root.put("hasChild", false); nodes.put("0", (T) root); for (T node : list) { final T parent = nodes.get(node.getString("parentId")); if (parent == null) { ((ArrayList<T>) root.get("children")).add(node); continue; // throw new RuntimeException("?id?"); } else { // ? ((List<T>) parent.get("children")).add(node); } } int max = 0; for (T node : list) { max = Math.max(resolveLevel(node, nodes), max); } return (List<T>) root.get("children"); }
From source file:com.yahoo.elide.utils.coerce.BidirectionalConvertUtilBeanTest.java
@BeforeClass public void init() { convertUtilBean = new BidirectionalConvertUtilBean(); convertUtilBean.register(String.class, Currency.class, new Converter() { @Override// w ww . j a v a2 s . co m public <T> T convert(Class<T> aClass, Object o) { return null; } }); }
From source file:common.ClassUtils.java
public static void copyProperty(Object dest, String name, Object value) { try {/*from ww w . java2s . com*/ // ?Date ConvertUtils.register(new Converter() { public Object convert(Class type, Object value) { //198a if (value == null) { return null; } String s = (String) value; if (s.trim().equals("")) { return null; } SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); try { return sdf.parse(s); } catch (ParseException e) { throw new RuntimeException(e); } } }, Date.class); BeanUtils.copyProperty(dest, name, value); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.datatorrent.stram.StringCodecs.java
public static void loadDefaultConverters() { LOG.debug("Loading default converters for BeanUtils"); ConvertUtils.register(new Converter() { @Override//from w w w . java 2s . co m @SuppressWarnings("unchecked") public Object convert(Class type, Object value) { if (value == null) { return null; } for (Class<?> clazz = value.getClass(); clazz != null; clazz = clazz.getSuperclass()) { Class<? extends StringCodec> codec = codecs.get(clazz); if (codec == null) { continue; } StringCodec instance; try { instance = codec.newInstance(); } catch (IllegalAccessException ex) { throw new RuntimeException( "Internal Error - it's impossible for this exception to be thrown!", ex); } catch (InstantiationException ex) { throw new RuntimeException( "Internal Error - it's impossible for this exception to be thrown!", ex); } return instance.toString(value); } return value.toString(); } }, String.class); ConvertUtils.register(new Converter() { @Override public Object convert(Class type, Object value) { return value == null ? null : URI.create(value.toString()); } }, URI.class); }
From source file:com.xpfriend.fixture.cast.temp.TypeConverter.java
private static Converter getTextConverter() { return new Converter() { @Override// w ww .j a va 2s . c o m public Object convert(@SuppressWarnings("rawtypes") Class type, Object value) { if (value == null) { return null; } if (value instanceof BigDecimal) { return ((BigDecimal) value).toPlainString(); } if (value instanceof Date) { return Formi.format((Date) value, JDBC_FORMAT_TIMESTAMP); } return value.toString(); } }; }
From source file:com.datatorrent.stram.StringCodecs.java
public static void check() { if (classLoaders.putIfAbsent(Thread.currentThread().getContextClassLoader(), Boolean.TRUE) == null) { loadDefaultConverters();/*w w w . ja v a 2 s .c o m*/ for (Map.Entry<Class<?>, Class<? extends StringCodec<?>>> entry : codecs.entrySet()) { try { final StringCodec<?> codecInstance = entry.getValue().newInstance(); ConvertUtils.register(new Converter() { @Override public Object convert(Class type, Object value) { return value == null ? null : codecInstance.fromString(value.toString()); } }, entry.getKey()); } catch (Exception ex) { throw new RuntimeException(ex); } } } }
From source file:com.datatorrent.stram.StringCodecs.java
public static <T> void register(final Class<? extends StringCodec<?>> codec, final Class<T> clazz) throws InstantiationException, IllegalAccessException { check();/*from www .j a va 2 s . c o m*/ final StringCodec<?> codecInstance = codec.newInstance(); ConvertUtils.register(new Converter() { @Override public Object convert(Class type, Object value) { return value == null ? null : codecInstance.fromString(value.toString()); } }, clazz); codecs.put(clazz, codec); }
From source file:net.servicefixture.converter.ObjectConverter.java
public static void register(final net.servicefixture.converter.Converter converter, Class clazz) { ConvertUtils.register(new Converter() { public Object convert(Class type, Object obj) { return converter.fromObject(obj); }/*from w w w . ja v a 2 s .c o m*/ }, clazz); converters.put(clazz, converter); }