From jbosscache-commits at lists.jboss.org Tue Nov 27 14:04:35 2007 Content-Type: multipart/mixed; boundary="===============4707102258375974578==" MIME-Version: 1.0 From: jbosscache-commits at lists.jboss.org To: jbosscache-commits at lists.jboss.org Subject: [jbosscache-commits] JBoss Cache SVN: r4788 - core/trunk/src/main/java/org/jboss/cache/util. Date: Tue, 27 Nov 2007 14:04:35 -0500 Message-ID: --===============4707102258375974578== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: manik.surtani(a)jboss.com Date: 2007-11-27 14:04:35 -0500 (Tue, 27 Nov 2007) New Revision: 4788 Added: core/trunk/src/main/java/org/jboss/cache/util/BeanUtils.java Log: JavaBean utility class Added: core/trunk/src/main/java/org/jboss/cache/util/BeanUtils.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- core/trunk/src/main/java/org/jboss/cache/util/BeanUtils.java = (rev 0) +++ core/trunk/src/main/java/org/jboss/cache/util/BeanUtils.java 2007-11-27= 19:04:35 UTC (rev 4788) @@ -0,0 +1,67 @@ +package org.jboss.cache.util; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.lang.reflect.Method; +import java.util.Locale; + +/** + * Simple JavaBean manipulation helper methods + * + * @author Manik Surtani (manik(a)jbo= ss.org) + * @since 2.1.0 + */ +public class BeanUtils +{ + private static Log log =3D LogFactory.getLog(BeanUtils.class); + /** + * Retrieves a setter name based on a field name passed in + * @param fieldName field name to find setter for + * @return name of setter method + */ + public static String setterName(String fieldName) + { + StringBuilder sb =3D new StringBuilder("set"); + if (fieldName !=3D null && fieldName.length() > 0) + { + sb.append(fieldName.substring(0, 1).toUpperCase(Locale.ENGLISH)); + if (fieldName.length() > 1) + { + sb.append(fieldName.substring(1)); + } + } + return sb.toString(); + } + + /** + * Returns a getter for a given class + * @param componentClass class to find getter for + * @return name of getter method + */ + public static String getterName(Class componentClass) + { + StringBuilder sb =3D new StringBuilder("get"); + sb.append(componentClass.getSimpleName()); + return sb.toString(); + } + + /** + * Returns a Method object corresponding to a getter that retrieves an = instance of componentClass from target. + * @param target class that the getter should exist on + * @param componentClass component to get + * @return Method object, or null of one does not exist + */ + public static Method getterMethod(Class target, Class componentClass) + { + try + { + return target.getMethod(getterName(componentClass)); + } + catch (NoSuchMethodException e) + { + log.trace("Unable to find method " + getterName(componentClass) += " in class " + target); + return null; + } + } +} --===============4707102258375974578==--