1 23 24 29 30 package com.sun.enterprise.tools.common; 31 32 import java.lang.reflect.Method ; 33 import java.beans.PropertyDescriptor ; 34 35 import com.sun.enterprise.tools.common.util.diagnostics.Reporter; 36 import com.sun.enterprise.tools.common.util.diagnostics.StackTrace; 37 38 43 public class PropertyUtils { 44 45 46 private PropertyUtils() { 47 } 48 49 public static Method getWriter(Object target, String destFieldName) throws java.beans.IntrospectionException { 50 try { 51 PropertyDescriptor destPd = new PropertyDescriptor (destFieldName, target.getClass()); 52 return destPd.getWriteMethod(); 53 } 54 catch (java.beans.IntrospectionException t) { 55 Reporter.critical(new StackTrace(t)); throw t; 57 } 58 } 59 60 public static Method getReader(Object target, String destFieldName) throws java.beans.IntrospectionException { 61 try { 62 PropertyDescriptor destPd = new PropertyDescriptor (destFieldName, target.getClass()); 63 return destPd.getReadMethod(); 64 } 65 catch (java.beans.IntrospectionException t) { 66 return getReader2(target,destFieldName); 69 } 70 } 71 72 public static Method getReader2(Object target, String destFieldName) throws java.beans.IntrospectionException { 73 String getterName = createGetterName(destFieldName); 74 Class targetClass = null; 75 try { 76 targetClass = target.getClass(); 77 Method reader = targetClass.getMethod(getterName,null); 78 return reader; 79 } 82 catch (Throwable t) { 83 Method [] allmethods = targetClass.getMethods(); 84 for (int i = 0; null != allmethods && i < allmethods.length; i++) 85 Reporter.info(allmethods[i].getReturnType() + " " +allmethods[i].getName()); Reporter.critical(new StackTrace(t)); throw new java.beans.IntrospectionException (getterName); 88 } 90 } 91 92 static private String createGetterName(String propName) { 93 String retVal = "get"; String capitalizedProp = propName.toUpperCase(); 95 return retVal + capitalizedProp.substring(0,1) + propName.substring(1); 96 } 97 } 98 99 | Popular Tags |