1 package org.apache.velocity.runtime.parser.node; 2 17 18 import java.lang.reflect.InvocationTargetException ; 19 20 import org.apache.velocity.util.introspection.Introspector; 21 22 import org.apache.velocity.runtime.RuntimeLogger; 23 24 27 public class PropertyExecutor extends AbstractExecutor 28 { 29 protected Introspector introspector = null; 30 31 protected String methodUsed = null; 32 33 public PropertyExecutor(RuntimeLogger r, Introspector ispctr, 34 Class clazz, String property) 35 { 36 rlog = r; 37 introspector = ispctr; 38 39 discover(clazz, property); 40 } 41 42 protected void discover(Class clazz, String property) 43 { 44 47 48 try 49 { 50 char c; 51 StringBuffer sb; 52 53 Object [] params = { }; 54 55 60 sb = new StringBuffer ("get"); 61 sb.append(property); 62 63 methodUsed = sb.toString(); 64 65 method = introspector.getMethod(clazz, methodUsed, params); 66 67 if (method != null) 68 return; 69 70 73 74 sb = new StringBuffer ("get"); 75 sb.append(property); 76 77 c = sb.charAt(3); 78 79 if (Character.isLowerCase(c)) 80 { 81 sb.setCharAt(3, Character.toUpperCase(c)); 82 } 83 else 84 { 85 sb.setCharAt(3, Character.toLowerCase(c)); 86 } 87 88 methodUsed = sb.toString(); 89 method = introspector.getMethod(clazz, methodUsed, params); 90 91 if (method != null) 92 return; 93 94 } 95 catch(Exception e) 96 { 97 rlog.error("PROGRAMMER ERROR : PropertyExector() : " + e ); 98 } 99 } 100 101 102 105 public Object execute(Object o) 106 throws IllegalAccessException , InvocationTargetException 107 { 108 if (method == null) 109 return null; 110 111 return method.invoke(o, null); 112 } 113 } 114 115 116 | Popular Tags |