1 16 package org.apache.commons.jexl.util; 17 18 import java.lang.reflect.InvocationTargetException ; 19 20 import org.apache.commons.jexl.util.introspection.Introspector; 21 import org.apache.commons.logging.Log; 22 23 27 public class PropertyExecutor extends AbstractExecutor { 28 29 30 private static final int PROPERTY_START_INDEX = 3; 31 32 protected Introspector introspector = null; 33 34 35 protected String methodUsed = null; 36 37 45 public PropertyExecutor(Log r, Introspector ispctr, 46 Class clazz, String property) { 47 rlog = r; 48 introspector = ispctr; 49 50 discover(clazz, property); 51 } 52 53 59 protected void discover(Class clazz, String property) { 60 63 64 try { 65 char c; 66 StringBuffer sb; 67 68 Object [] params = {}; 69 70 75 sb = new StringBuffer ("get"); 76 sb.append(property); 77 78 methodUsed = sb.toString(); 79 80 method = introspector.getMethod(clazz, methodUsed, params); 81 82 if (method != null) { 83 return; 84 } 85 86 89 90 sb = new StringBuffer ("get"); 91 sb.append(property); 92 93 c = sb.charAt(PROPERTY_START_INDEX); 94 95 if (Character.isLowerCase(c)) { 96 sb.setCharAt(PROPERTY_START_INDEX, Character.toUpperCase(c)); 97 } else { 98 sb.setCharAt(PROPERTY_START_INDEX, Character.toLowerCase(c)); 99 } 100 101 methodUsed = sb.toString(); 102 method = introspector.getMethod(clazz, methodUsed, params); 103 104 if (method != null) { 105 return; 106 } 107 108 } catch (Exception e) { 109 rlog.error("PROGRAMMER ERROR : PropertyExector() : " + e); 110 } 111 } 112 113 114 117 public Object execute(Object o) 118 throws IllegalAccessException , InvocationTargetException { 119 if (method == null) { 120 return null; 121 } 122 123 return method.invoke(o, null); 124 } 125 } 126 127 | Popular Tags |