コード例 #1
0
 @Override
 public <T> T getProperty(E bean, String name, Class<T> clazz) {
   String methodName =
       (!clazz.equals(Boolean.class))
           ? JavaBeanNamingUtils.getGetMethod(name)
           : JavaBeanNamingUtils.getIsMethod(name);
   Method method = getMethods.get(methodName);
   if (method != null)
     try {
       return clazz.cast(method.invoke(bean));
     } catch (IllegalArgumentException e) {
       throw new JavaBeanOperateException(
           JavaBeanOperateException.JAVA_BEAN_GETTER_HAS_PARAMETERS + name, e);
     } catch (IllegalAccessException e) {
       throw new JavaBeanOperateException(
           JavaBeanOperateException.JAVA_BEAN_METHODS_NOT_PUBLIC + name, e);
     } catch (InvocationTargetException e) {
       throw new JavaBeanOperateException(e);
     } catch (ClassCastException ex) {
       throw new JavaBeanOperateException(
           "The return value of the java bean is not the class : " + clazz, ex);
     }
   else
     throw new JavaBeanOperateException(JavaBeanOperateException.JAVA_BEAN_NO_SUCH_GETTER + name);
 }
コード例 #2
0
 @Override
 public void setProperty(E bean, String name, Object value) {
   String methodName = JavaBeanNamingUtils.getSetMethod(name);
   Method method = setMethods.get(methodName);
   if (method != null)
     try {
       method.invoke(bean, value);
     } catch (IllegalArgumentException e) {
       throw new JavaBeanOperateException(
           JavaBeanOperateException.JAVA_BEAN_SETTER_HAS_ILLEGAL_PARAMETERS + name, e);
     } catch (IllegalAccessException e) {
       throw new JavaBeanOperateException(
           JavaBeanOperateException.JAVA_BEAN_METHODS_NOT_PUBLIC + name, e);
     } catch (InvocationTargetException e) {
       throw new JavaBeanOperateException(e);
     }
   else
     throw new JavaBeanOperateException(JavaBeanOperateException.JAVA_BEAN_NO_SUCH_SETTER + name);
 }
コード例 #3
0
 private void handleMethod(Method method) {
   String methodName = method.getName();
   if (JavaBeanNamingUtils.isGetter(methodName)) getMethods.put(methodName, method);
   else if (JavaBeanNamingUtils.isSetter(methodName)) setMethods.put(methodName, method);
 }