1 20 package org.enhydra.barracuda.contrib.sam.models; 21 22 24 25 import java.lang.reflect.*; 26 import org.enhydra.barracuda.core.comp.*; 27 import org.enhydra.barracuda.contrib.sam.data.*; 28 import org.apache.log4j.*; 29 30 public class ReflectionModel extends AbstractTemplateModel { 31 32 protected static Logger logger = Logger.getLogger(ReflectionModel.class); 33 protected String name; 34 protected Object obj; 35 36 public ReflectionModel(String name) { 37 this.name = name; 38 } 39 40 public ReflectionModel(String name, Object obj) { 41 this.name = name; 42 setObject(obj); 43 } 44 45 public void setObject(Object obj) { 46 this.obj = obj; 47 } 48 49 public String getName() { 50 return name; 51 } 52 53 public Object getItem(String key) { 54 try { 55 Method m = obj.getClass().getMethod("get" + key, null); 56 return m.invoke(obj, null); 57 58 } catch (Exception ex) { 59 logger.error(ex.getMessage() ); 60 return ex.getMessage(); 61 } 62 } 63 } 64 | Popular Tags |