1 4 package org.oddjob.monitor.model; 5 6 import java.lang.reflect.InvocationTargetException ; 7 import java.lang.reflect.Method ; 8 import java.util.HashMap ; 9 import java.util.Map ; 10 11 import org.apache.commons.beanutils.BeanUtils; 12 import org.apache.log4j.Logger; 13 import org.oddjob.Reserved; 14 15 21 public class Describer { 22 private static final Logger logger = Logger.getLogger(Describer.class); 23 24 34 public static Map describe(Object component) { 35 if (component == null) { 36 throw new NullPointerException ("Component must not be null."); 37 } 38 Map description = null; 39 try { 40 Method m = component.getClass().getMethod(Reserved.DESCRIBE_METHOD, new Class [0]); 41 description = (Map ) m.invoke(component, new Object [0]); 42 } catch (Exception exception) { 43 } 45 if (description != null) { 46 return description; 47 } 48 49 try { 50 return BeanUtils.describe(component); 51 } catch (InvocationTargetException e) { 52 logger.debug("Failed to describe:", e); 53 Throwable t = e.getTargetException(); 54 Map map = new HashMap (); 55 map.put("Error", t.getMessage()); 56 return map; 57 } catch (Exception e) { 58 logger.debug("Failed to describe:", e); 59 Map map = new HashMap (); 60 map.put("Failed to describe:", e.getMessage()); 61 return map; 62 } 63 } 64 } 65 | Popular Tags |