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:org.kuali.maven.plugins.graph.dot.html.HtmlUtils.java
@SuppressWarnings("unchecked") public Map<String, ?> describe(HtmlTag element) { try {//w w w . java 2s. co m return new TreeMap<String, Object>(PropertyUtils.describe(element)); } catch (Exception e) { throw new IllegalStateException(e); } }
From source file:org.kuali.maven.plugins.graph.util.Helper.java
/** * Copy properties from "orig" to "dest" where the property from "orig" is not null, and the property from "dest" is * null/*from w ww .ja v a 2 s. c o m*/ */ public static final <T> void copyPropertiesIfNull(T dest, T orig) { try { @SuppressWarnings("unchecked") Map<String, ?> description = PropertyUtils.describe(orig); for (String name : description.keySet()) { copyPropertyIfNull(dest, name, orig); } } catch (Exception e) { throw new IllegalArgumentException(e); } }
From source file:org.kuali.ole.coa.service.ObjectCodeServiceTest.java
License:asdf
@Test public void testPropertyUtilsDescribe() throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { ObjectCode objectCode = new ObjectCode(); Map boProps = PropertyUtils.describe(objectCode); }
From source file:org.kuali.rice.core.web.format.Formatter.java
/** * If an element of the Collection isn't a supported type, assume it's a JavaBean, and format each of its properties. Returns a * Map containing the formatted properties keyed by property name. *//*ww w . ja v a 2 s .c om*/ protected Object formatBean(Object bean) { Map properties = null; try { // begin Kuali Foundation modification properties = PropertyUtils.describe(bean); // end Kuali Foundation modification } catch (Exception e) { throw new FormatException("Unable to format values for bean " + bean, e); } Map formattedVals = new HashMap(); // begin Kuali Foundation modification Iterator propIter = properties.entrySet().iterator(); while (propIter.hasNext()) { Map.Entry entry = (Map.Entry) propIter.next(); Object value = entry.getValue(); if (value != null && isSupportedType(value.getClass())) { Formatter formatter = getFormatter(value.getClass()); formattedVals.put(entry.getKey(), formatter.formatForPresentation(value)); } } // end Kuali Foundation modification return formattedVals; }
From source file:org.molasdin.wbase.ReflectionHelper.java
/** * Extracts all properties from the bean * @param bean/*from www . j a v a 2 s . c om*/ * @return */ @SuppressWarnings("unchecked") private static Map<String, Object> extractAll(Object bean) { Map<String, Object> description = Collections.emptyMap(); try { description = PropertyUtils.describe(bean); description.remove("class"); } catch (Exception ex) { throw new RuntimeException(ex); } return description; }
From source file:org.openlaszlo.remote.json.LZReturnObject.java
/** * Create JSON for an object that conforms to JavaBean spec. *///from w w w . j a va 2 s.c o m void pushObjectJavaBean(Object object) throws Exception { //------------------------------------------------------------ // Just get the fields from the objects and add it to this object Map<?, ?> beanProps = null; try { //Use jakarta-commons beanutils to inspect the object beanProps = PropertyUtils.describe(object); if (beanProps != null) { Set<?> keys = beanProps.keySet(); Iterator<?> iter = keys.iterator(); while (iter.hasNext()) { Object obj = iter.next(); mLogger.warn("serialize " + obj); String fieldName = (String) obj; //Don't add the class property as it is already set by the method //mLogger.debug("fieldName equals Class ??"); if (!fieldName.equals("class")) { //mLogger.debug("fieldName equals Class !!"); Object value = beanProps.get(fieldName); //if (mLogger.isDebugEnabled()) { mLogger.debug( "add field name " + fieldName + ", " + ((value != null) ? value.getClass() : null)); //} if (value != null) { mLogger.debug("VC NAME: " + value.getClass().getName()); } if (Timestamp.class.isInstance(value)) { mLogger.warn("Found Timestamp"); value = value.toString(); body.append(", "); body.append(ScriptCompiler.JSONquote(fieldName) + ": "); createReturnValue(value); } else { body.append(", "); body.append(ScriptCompiler.JSONquote(fieldName) + ": "); createReturnValue(value); } } } } } catch (IllegalAccessException e) { mLogger.error("IllegalAccessException", e); } catch (InvocationTargetException e) { mLogger.error("InvocationTargetException", e); } catch (NoSuchMethodException e) { mLogger.error("NoSuchMethodException", e); } catch (Exception err) { if (object != null) { mLogger.error("[pushObjectJavaBean]" + object.getClass().getName()); mLogger.error("[pushObjectJavaBean]" + object.toString()); } mLogger.error("[pushObjectJavaBean]", err); } }
From source file:org.posterita.struts.core.BaseForm.java
/** * @param target//w w w . ja va2 s. c om * @param mode * @return */ public Map mapRepresentation(Object vo, int mode) { String errorMsg = "Unable to format values from bean: " + vo; Map valueMap = null; try { valueMap = PropertyUtils.describe(vo); } catch (IllegalAccessException iae) { throw new FormattingException(errorMsg, iae); } catch (InvocationTargetException ite) { throw new FormattingException(errorMsg, ite); } catch (NoSuchMethodException nsme) { throw new FormattingException(errorMsg, nsme); } Iterator keyIter = keysToSkip().iterator(); while (keyIter.hasNext()) { String key = (String) keyIter.next(); valueMap.remove(key); } return valueMap; }
From source file:org.posterita.struts.core.BaseForm.java
protected Map mapRepresentation(Object bean) { String errorMsg = "Unable to format values from bean: " + bean; Map valueMap = null;/* ww w . ja v a 2 s. c o m*/ try { valueMap = PropertyUtils.describe(bean); } catch (IllegalAccessException iae) { throw new FormattingException(errorMsg, iae); } catch (InvocationTargetException ite) { throw new FormattingException(errorMsg, ite); } catch (NoSuchMethodException nsme) { throw new FormattingException(errorMsg, nsme); } Iterator keyIter = keysToSkip().iterator(); while (keyIter.hasNext()) { String key = (String) keyIter.next(); valueMap.remove(key); } return valueMap; }
From source file:org.rhq.test.PropertyMatcher.java
public MatchResult execute() { try {/* ww w . j a va 2s.c om*/ Map<String, ?> expectedProps = PropertyUtils.describe(expected); Map<String, ?> actualProps = PropertyUtils.describe(actual); boolean isMatch = true; StringBuilder details = new StringBuilder( expected.getClass().getSimpleName() + " objects do not match:\n"); for (String name : expectedProps.keySet()) { Object expectedValue = expectedProps.get(name); Object actualValue = actualProps.get(name); if (ignoredProperties.contains(name)) { continue; } if (!propertyEquals(expectedValue, actualValue)) { isMatch = false; details.append("expected." + name + " = " + expectedValue + "\n"); details.append("actual." + name + " = " + actualValue + "\n\n"); } } return new MatchResult(isMatch, details.toString()); } catch (IllegalAccessException e) { throw new PropertyMatchException(e); } catch (InvocationTargetException e) { throw new PropertyMatchException(e); } catch (NoSuchMethodException e) { throw new PropertyMatchException(e); } }
From source file:org.sipfoundry.sipxbridge.symmitron.PortRange.java
@SuppressWarnings("unchecked") public Map toMap() { try {//from ww w. ja va 2s . c om Map retval = PropertyUtils.describe(this); retval.remove("class"); return retval; } catch (Exception ex) { throw new SymmitronException("Error generating map", ex); } }