/** * <p>Retrieve getter from given class by field name.</p> * @param pClazz - class * @param pFieldName - field name * @return Method getter. * @throws Exception if method not exist **/ @Override public final Method retrieveGetterForField(final Class<?> pClazz, final String pFieldName) throws Exception { String getterName = "get" + pFieldName.substring(0, 1).toUpperCase() + pFieldName.substring(1); return retrieveMethod(pClazz, getterName); }
/** * <p>Retrieve setter from given class by field name.</p> * @param pClazz - class * @param pFieldName - field name * @return Method setter. * @throws Exception if method not exist **/ @Override public final Method retrieveSetterForField(final Class<?> pClazz, final String pFieldName) throws Exception { String setterName = "set" + pFieldName.substring(0, 1).toUpperCase() + pFieldName.substring(1); return retrieveMethod(pClazz, setterName); } }
/** * <p>Retrieve method from given class by name.</p> * @param pClazz - class * @param pMethodName - method name * @return Method method. * @throws Exception if method not exist **/ @Override public final Method retrieveMethod(final Class<?> pClazz, final String pMethodName) throws Exception { for (Method mfd : pClazz.getDeclaredMethods()) { if (mfd.getName().equals(pMethodName)) { return mfd; } } final Class<?> superClazz = pClazz.getSuperclass(); Method method = null; if (superClazz != null && superClazz != java.lang.Object.class) { method = retrieveMethod(superClazz, pMethodName); } if (method == null) { throw new Exception("There is no method " + pMethodName + " in class " + pClazz); //TO-DO class must be original } return method; }