1 17 package org.apache.ws.jaxme.generator.util; 18 19 20 21 25 public class Reflect { 26 40 public static void assignBeanValue(Object pBean, 41 String pPropertyName, 42 String pValue) 43 throws IllegalAccessException , java.lang.reflect.InvocationTargetException { 44 assignBeanValue(pBean, pPropertyName, pValue, null); 45 } 46 47 61 public static void assignBeanValue(Object pBean, 62 String pPropertyName, 63 String pValue, 64 ReflectResolver pResolver) 65 throws IllegalAccessException , java.lang.reflect.InvocationTargetException { 66 Class c = pBean.getClass(); 67 java.lang.reflect.Method [] methods = c.getMethods(); 68 String methodName = "set" + Character.toUpperCase(pPropertyName.charAt(0)) + 69 pPropertyName.substring(1); 70 for (int i = 0; i < methods.length; i++) { 71 java.lang.reflect.Method m = methods[i]; 72 if (methodName.equals(m.getName())) { 73 Class [] parameterTypes = m.getParameterTypes(); 74 if (parameterTypes.length == 1) { 75 Class parameterClass = parameterTypes[0]; 76 Object [] parameters = null; 77 if (pResolver != null) { 78 parameters = pResolver.resolve(parameterClass, pValue); 79 } 80 if (parameters == null) { 81 if (parameterClass == String .class) { 82 parameters = new Object []{pValue}; 83 } else if (parameterClass == Long .class || 84 parameterClass == long.class) { 85 parameters = new Object []{new Long (pValue)}; 86 } else if (parameterClass == Integer .class || 87 parameterClass == int.class) { 88 parameters = new Object []{new Integer (pValue)}; 89 } else if (parameterClass == Short .class || 90 parameterClass == short.class) { 91 parameters = new Object []{new Short (pValue)}; 92 } else if (parameterClass == Byte .class || 93 parameterClass == byte.class) { 94 parameters = new Object []{new Byte (pValue)}; 95 } else if (parameterClass == Double .class || 96 parameterClass == double.class) { 97 parameters = new Object []{new Double (pValue)}; 98 } else if (parameterClass == Float .class || 99 parameterClass == float.class) { 100 parameters = new Object []{new Float (pValue)}; 101 } else if (parameterClass == Boolean .class || 102 parameterClass == boolean.class) { 103 parameters = new Object []{new Boolean (pValue)}; 104 } 105 } 106 if (parameters != null) { 107 m.invoke(pBean, parameters); 108 return; 109 } 110 } 111 } 112 } 113 } 114 } 115 | Popular Tags |