1 16 package com.ibatis.sqlmap.engine.accessplan; 17 18 import com.ibatis.common.beans.ClassInfo; 19 import com.ibatis.common.exception.NestedRuntimeException; 20 21 import java.lang.reflect.Method ; 22 23 26 public class PropertyAccessPlan extends BaseAccessPlan { 27 28 protected static final Object [] NO_ARGUMENTS = new Object [0]; 29 30 protected Method [] setters; 31 protected Method [] getters; 32 33 PropertyAccessPlan(Class clazz, String [] propertyNames) { 34 super(clazz, propertyNames); 35 setters = getSetters(propertyNames); 36 getters = getGetters(propertyNames); 37 } 38 39 public void setProperties(Object object, Object [] values) { 40 try { 41 Object [] arg = new Object [1]; 42 for (int i = 0; i < propertyNames.length; i++) { 43 arg[0] = values[i]; 44 try { 45 setters[i].invoke(object, arg); 46 } catch (Throwable t) { 47 throw ClassInfo.unwrapThrowable(t); 48 } 49 } 50 } catch (Throwable t) { 51 throw new NestedRuntimeException("Error setting properties of '" + object + "'. Cause: " + t, t); 52 } 53 } 54 55 public Object [] getProperties(Object object) { 56 Object [] values = new Object [propertyNames.length]; 57 try { 58 for (int i = 0; i < propertyNames.length; i++) { 60 try { 61 values[i] = getters[i].invoke(object, NO_ARGUMENTS); 62 } catch (Throwable t) { 63 throw ClassInfo.unwrapThrowable(t); 64 } 65 } 66 } catch (Throwable t) { 67 throw new NestedRuntimeException("Error getting properties of '" + object + "'. Cause: " + t, t); 68 } 69 return values; 70 } 71 72 } 73 | Popular Tags |