public Dictionary<String, ?> getProperties () { try { final Dictionary<String, Object> result = new Hashtable<String, Object> (); final Map<?, ?> properties = new BeanUtilsBean2 ().describe ( this.targetBean ); for ( final Map.Entry<?, ?> entry : properties.entrySet () ) { if ( entry.getValue () != null ) { result.put ( entry.getKey ().toString (), entry.getValue () ); } } return result; } catch ( final Exception e ) { logger.warn ( "Failed to get dictionary", e ); return new Hashtable<String, Object> ( 1 ); } }
/** * Copy properties. * * @param desc 不允许为空 * @param src 不允许为空 */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static void copyProperties(Object desc, Object src) { BeanUtilsBean2 beanUtilsBean2 = new BeanUtilsBean2(); try { if (desc instanceof Map) { Map<String, Object> map = beanToMap(src); ((Map) desc).putAll(map); } else { beanUtilsBean2.copyProperties(desc, src); } } catch (Exception e) { log.error(e.getMessage(), e); } }
public static void main(String[] args) throws InvocationTargetException, IllegalAccessException { BeanUtilsBean utilsBean = BeanUtilsBean2.getInstance(); utilsBean.getConvertUtils().register(false, false, 0); BeanOne one = new BeanOne(); one.setPropertyOne("One"); one.setPropertyTwo("Two"); one.setPropertyThree(3L); one.setPropertyFour(4); //this is a string in BeanTwo BeanTwo two = new BeanTwo(); utilsBean.copyProperties(two, one); BeanUtilsBean.getInstance().getConvertUtils().register(false, false, 0); System.out.println(two); }
@SuppressWarnings({"unchecked"}) @Override public void init(ServletConfig config) throws ServletException { this.config = config; BlockingQueue<Filter> waiters = (BlockingQueue<Filter>) config.getServletContext() .getAttribute(APPLICATION_CONTEXT_LOCK_KEY); if (waiters != null) { waiters.add(this); } else { //Servlet 2.5 lazy filter initing delayedInit(); } // register the bean utils converter to fail if encounters a type mismatch between the destination // and the original, see RTFACT-3610 BeanUtilsBean instance = BeanUtilsBean2.getInstance(); instance.getConvertUtils().register(true, false, 0); }
@Inject protected GitRiver(RiverName riverName, RiverSettings settings, @RiverIndexName String riverIndexName, Client client) throws InvocationTargetException, IllegalAccessException { super(riverName, settings); this.client = client; logger.info("Creating Git river"); if (settings.settings().containsKey("git")) { Map<String, Object> gitSettings = (Map<String, Object>) settings.settings().get("git"); BeanUtilsBean2.getInstance().populate(context, transformKeys(gitSettings, new Function<String, String>() { @Override public String apply(String input) { return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, input); } })); } context.setRiverName(riverName.name()); context.setRiverIndexName(riverIndexName); context.setClient(client); context.setIssuePattern(compilePattern(context.getIssueRegex())); }
private GluuInumMap getMarkInumMapEntryAsRemoved(GluuInumMap currentInumMap, String date) { GluuInumMap clonedInumMap; try { clonedInumMap = (GluuInumMap) BeanUtilsBean2.getInstance().cloneBean(currentInumMap); } catch (Exception ex) { log.error("Failed to prepare GluuInumMap for removal", ex); return null; } String suffix = "-" + date; String[] primaryKeyValues = ArrayHelper.arrayClone(clonedInumMap.getPrimaryKeyValues()); String[] secondaryKeyValues = ArrayHelper.arrayClone(clonedInumMap.getSecondaryKeyValues()); String[] tertiaryKeyValues = ArrayHelper.arrayClone(clonedInumMap.getTertiaryKeyValues()); if (ArrayHelper.isNotEmpty(primaryKeyValues)) { markInumMapEntryKeyValuesAsRemoved(primaryKeyValues, suffix); } if (ArrayHelper.isNotEmpty(secondaryKeyValues)) { markInumMapEntryKeyValuesAsRemoved(secondaryKeyValues, suffix); } if (ArrayHelper.isNotEmpty(tertiaryKeyValues)) { markInumMapEntryKeyValuesAsRemoved(tertiaryKeyValues, suffix); } clonedInumMap.setPrimaryKeyValues(primaryKeyValues); clonedInumMap.setSecondaryKeyValues(secondaryKeyValues); clonedInumMap.setTertiaryKeyValues(tertiaryKeyValues); clonedInumMap.setStatus(GluuStatus.INACTIVE); return clonedInumMap; }
@PrePersist public void onCreate(Object object) { final String ID = "id"; final String CREATED_AT = "createdAt"; final String LAST_MODIFIED_AT = "lastModifiedAt"; BeanUtilsBean beanUtilsBean = BeanUtilsBean2.getInstance(); try { if (Objects.equals(beanUtilsBean.getProperty(object, ID), CommonsConstant.ZERO)) { beanUtilsBean.setProperty(object, CREATED_AT, System.currentTimeMillis()); beanUtilsBean.setProperty(object, LAST_MODIFIED_AT, System.currentTimeMillis()); } } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ignore) {} }
@PrePersist public void onCreate(Object object) { final String ID = "id"; final String VALID_FLAG = "validFlag"; BeanUtilsBean beanUtilsBean = BeanUtilsBean2.getInstance(); try { if (Objects.equals(beanUtilsBean.getProperty(object, ID), CommonsConstant.ZERO)) { beanUtilsBean.setProperty(object, VALID_FLAG, ValidFlag.VALID); } } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ignore) {} }
@Override protected ConvertUtilsBean initialValue() { ConvertUtilsBean ret = BeanUtilsBean2.getInstance().getConvertUtils(); ret.deregister(); ret.register(false, true, 1); return ret; }
public void update ( final Map<String, String> parameters ) throws Exception { new BeanUtilsBean2 ().populate ( this.targetBean, parameters ); }