List of usage examples for org.apache.commons.beanutils PropertyUtils describe
public static Map describe(Object bean) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
Return the entire set of properties for which the specified bean provides a read method.
For more details see PropertyUtilsBean
.
From source file:hermes.renderers.RendererHelper.java
/** * Create a default renderer for a Config that just contains simple * properties (i.e. not 1:m relationships), the dialog will be a normal * property pane./*from ww w.j a v a2 s . c o m*/ * * @param dialogProxy * @return @throws * IllegalAccessException * @throws InvocationTargetException * @throws NoSuchMethodException */ public static JComponent createDefaultConfigPanel(final ConfigDialogProxy dialogProxy) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { final Config theConfig = dialogProxy.getConfig(); final List<Property> list = new ArrayList<Property>(); final Map properties = PropertyUtils.describe(theConfig); for (Iterator iter = properties.entrySet().iterator(); iter.hasNext();) { final Map.Entry entry = (Map.Entry) iter.next(); final String propertyName = (String) entry.getKey(); final Object propertyValue = entry.getValue(); if (!propertyName.equals("class") && !propertyName.equals("name")) { Property displayProperty = new Property(propertyName, theConfig.getPropertyDescription(propertyName), propertyValue.getClass()) { /** * */ private static final long serialVersionUID = -4650355524853942976L; public void setValue(Object value) { try { dialogProxy.setDirty(); PropertyUtils.setProperty(theConfig, propertyName, value); } catch (Exception e) { cat.error(e.getMessage(), e); } } public Object getValue() { try { return PropertyUtils.getProperty(theConfig, propertyName); } catch (Exception e) { cat.error(e.getMessage(), e); } return null; } public boolean hasValue() { return true; } }; list.add(displayProperty); } } PropertyTableModel model = new PropertyTableModel(list); PropertyTable table = new PropertyTable(model); table.setAutoResizeMode(PropertyTable.AUTO_RESIZE_ALL_COLUMNS); PropertyPane pane = new PropertyPane(table); pane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { dialogProxy.setDirty(); } }); model.expandAll(); return pane; }
From source file:com.conversantmedia.mapreduce.tool.FileInputOutputHandlerTest.java
@Test public void testParseContext() { MyBeanA a = new MyBeanA(); a.stringA = "IN A"; a.p = new Path("/a/path"); MyBeanB b = new MyBeanB(); b.stringB = "IN B"; b.p = new Path("/b/path"); try {/* w ww .jav a2s . co m*/ @SuppressWarnings("unchecked") Map<String, Object> ctx = PropertyUtils.describe(a); ctx.put("context", PropertyUtils.describe(b)); String value = BeanUtils.getProperty(ctx, "context.stringB"); System.out.println("VALUE = " + value); Object val = PropertyUtils.getNestedProperty(ctx, "stringA"); System.out.println("Value object is: " + val); Object path = PropertyUtils.getNestedProperty(ctx, "path"); if (path instanceof Path) { System.out.println("Got a path: " + path); } path = PropertyUtils.getNestedProperty(ctx, "context.path"); if (path instanceof Path) { System.out.println("Got a path: " + path); } } catch (Exception e) { fail(e.getMessage()); } }
From source file:jp.co.opentone.bsol.framework.core.util.PropertyGetUtil.java
/** * Dto???. ?Dto????KEY????.?????????.//from w w w .j av a 2 s . c o m * ??) * @param object * Dto. * @param key * ??. * @return key????. * @throws IllegalAccessException ??? * @throws InvocationTargetException ? * @throws NoSuchMethodException ???? */ public static Object getValue(Object object, String key) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { Map<?, ?> map = PropertyUtils.describe(object); if (key.indexOf(".") > -1) { Object bean = map.get(key.substring(0, key.indexOf("."))); if (bean != null) { return getValue(bean, key.substring(key.indexOf(".") + 1)); } else { return null; } } else { return map.get(key); } }
From source file:com.wwinsoft.modules.utils.PropertiesUtils.java
public static Map toParameterMap(Object parameter) { if (parameter instanceof Map) { return (Map) parameter; } else {//from www.j a v a 2s .c o m try { return PropertyUtils.describe(parameter); } catch (Exception e) { ReflectionUtils.handleReflectionException(e); return new HashMap(); } } }
From source file:au.com.jwatmuff.eventmanager.util.JexlBeanMapper.java
@Override public Map<String, Object> mapBean(T bean) { Map<String, Object> map = new HashMap<String, Object>(); JexlContext jc = new HashMapContext(); try {/*from w w w .j a v a2s.com*/ jc.setVars(PropertyUtils.describe(bean)); } catch (Exception e) { log.error("Exception while reading bean properties", e); return map; } for (String prop : mappings.keySet()) { try { Expression e = ExpressionFactory.createExpression(mappings.get(prop)); map.put(prop, e.evaluate(jc)); } catch (Exception e) { log.error("Exception while mapping bean", e); } } return map; }
From source file:hermes.browser.dialog.BeanPropertyPanel.java
public BeanPropertyPanel(Object bean, boolean editable, boolean setProperty) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { super(PropertyUtils.describe(bean), editable); this.bean = bean; this.setProperty = setProperty; }
From source file:com.ms.commons.lang.BeanUtils.java
@SuppressWarnings({ "rawtypes" }) public static <T extends Object> void copyProperties(T target, Object raw, ValueEditable... defaultValues) { try {//from w w w. j a v a 2 s . com Map values = raw == null ? new HashMap() : PropertyUtils.describe(raw); if (Argument.isNotEmptyArray(defaultValues)) { for (ValueEditable edit : defaultValues) { edit.edit(raw, values); } } PropertyUtils.copyProperties(target, values); // ? // TODO } catch (Exception e) { logger.error(e.getMessage(), e); } }
From source file:edu.umn.msi.tropix.common.test.BeanTest.java
public static void testBeanProperties(final Object testBean, final HashMultimap<Class<?>, Object> typeObjects) { try {/*from w w w . j av a 2 s .com*/ @SuppressWarnings("unchecked") final Map<String, ?> propertyMap = PropertyUtils.describe(testBean); for (final String propertyName : propertyMap.keySet()) { if (propertyName.equals("class") || !PropertyUtils.isWriteable(testBean, propertyName)) { continue; } final Class<?> type = PropertyUtils.getPropertyType(testBean, propertyName); Collection<?> objects = null; for (final Class<?> typeQuery : typeObjects.keySet()) { if (typeQuery.isAssignableFrom(type)) { objects = typeObjects.get(typeQuery); } } boolean useEquals = true; if (objects == null) { useEquals = false; try { objects = Lists.<Object>newArrayList(EasyMock.createMock(type)); } catch (final Exception e) { // Cannot instantiate mock of this type continue; } } for (final Object expectedObject : objects) { PropertyUtils.setProperty(testBean, propertyName, expectedObject); final Object object = PropertyUtils.getProperty(testBean, propertyName); if (useEquals) { assert object.equals(expectedObject) : "Expected " + expectedObject + " obtained " + object; } else { assert object == expectedObject : "Expected " + expectedObject + " obtained " + object; } } } } catch (final Exception e) { throw new IllegalStateException(e); } }
From source file:hermes.browser.model.BeanTableModel.java
public BeanTableModel(Object bean, Map filter) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { Map properties = PropertyUtils.describe(bean); Set iterSet = null;//from w w w .ja v a 2s.c o m this.bean = bean; if (filter == null) { iterSet = properties.keySet(); } else { iterSet = filter.keySet(); } for (Iterator iter = iterSet.iterator(); iter.hasNext();) { String propertyName = (String) iter.next(); if (properties.containsKey(propertyName) && !ignore.contains(propertyName)) { Object propertyValue = properties.get(propertyName); if (propertyValue == null) { propertyValue = "null"; } Vector row = new Vector(); row.add(propertyName); row.add(propertyValue); rows.add(row); } } }
From source file:com.discovery.darchrow.bean.PropertyUtil.java
/** * <code>bean</code>???/Map. * /*from ww w .j av a 2s . c o m*/ * <p> * ???classObject??classjava.lang.Object * </p> * * @param bean * Bean whose properties are to be extracted * @return The set of properties for the bean * @see org.apache.commons.beanutils.BeanUtils#describe(Object) * @see org.apache.commons.beanutils.PropertyUtils#describe(Object) * @see com.baozun.nebulaplus.bean.BeanUtil#describe(Object) */ public static Map<String, Object> describe(Object bean) { try { //Return the entire set of properties for which the specified bean provides a read method. Map<String, Object> propertyMap = PropertyUtils.describe(bean); return propertyMap; } catch (Exception e) { LOGGER.error(e.getClass().getName(), e); throw new BeanUtilException(e); } }