1 package org.jicengine.operation; 2 3 import java.lang.reflect.InvocationTargetException ; 4 import java.lang.reflect.Method ; 5 import java.lang.reflect.Constructor ; 6 import java.lang.reflect.Field ; 7 8 18 public class BeanUtils extends ReflectionUtils { 19 private static final Object [] EMPTY_ARRAY = new Object [0]; 20 21 28 public static void setProperty(Object instance, String propertyName, Object value) throws java.lang.NoSuchMethodException , IllegalAccessException , IllegalArgumentException , InvocationTargetException 29 { 30 String setterName = toSetterMethodName(propertyName); 31 invokeMethod(instance, setterName, new Object []{value}); 32 } 33 34 38 public static String toGetterMethodName(String property){ 39 return "get" + Character.toUpperCase(property.charAt(0)) + property.substring(1); 40 } 41 42 46 public static String toSetterMethodName(String property){ 47 return "set" + Character.toUpperCase(property.charAt(0)) + property.substring(1); 48 } 49 50 54 public static Object getProperty(Object instance, String propertyName) throws java.lang.NoSuchMethodException , InvocationTargetException , IllegalAccessException { 55 String getterName = toGetterMethodName(propertyName); 56 return invokeMethod(instance, getterName, EMPTY_ARRAY); 57 } 58 } 59 | Popular Tags |