On Mon, 16 Apr 2001, Geir Magnusson Jr. wrote:
> What I was thinking about was a method that would return a Map
> containing the appropos name/value pairs...
>
> Is that what you were thinking of?
yep.
but if you want to do round-trip, swap out display name for getName()
---
Date: Fri, 6 Apr 2001 17:14:10 -0400 (EDT)
To: [EMAIL PROTECTED]
Subject: [beanutils] Add describe method
Could a describe method, the inverse of the populate method, be added to
the BeanUtils class, as attached
michael
< [EMAIL PROTECTED] >
Index: src/share/org/apache/commons/beanutils/BeanUtils.java
===================================================================
RCS file:
/home/cvspublic/jakarta-commons/beanutils/src/share/org/apache/commons/beanutils/BeanUtils.java,v
retrieving revision 1.1
diff -r1.1 BeanUtils.java
75a76
> import java.util.Collections;
77a79
> import java.util.HashMap;
485a488,505
> /**
> * Describe the specified JavaBean, returning a Map of
> * property display name, (String or String[]) value(s).
> *
> * @param bean JavaBean whose properties are being described
> *
> * @return a Map keyed by property display name, with the
> * corresponding (String or String[]) value(s) from <code>bean</code>
> *
> * @exception IllegalAccessException if the caller does not have
> * access to the property accessor method
> * @exception InvocationTargetException if the property accessor method
> * throws an exception
> * @exception NoSuchMethodException if a method name returned by
> * getPropertyDescriptors doesn't exist upon invocation
> */
> public static Map describe(Object bean)
> throws IllegalAccessException, InvocationTargetException,
>NoSuchMethodException {
486a507,508
> if (bean == null)
> return Collections.EMPTY_MAP;
487a510,519
> PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(bean);
> Map description = new HashMap(descriptors.length);
>
> for (int i = 0; i < descriptors.length; i++) {
> description.put(descriptors[i].getDisplayName(),
> BeanUtils.getProperty(bean, descriptors[i].getName()));
> }
>
> return description;
> }
488a521,526
>
>
>
>
>
>