1 8 13 14 package org.webjmx.tags; 15 16 import java.lang.reflect.*; 17 import java.util.*; 18 import javax.management.*; 19 import javax.servlet.jsp.*; 20 import javax.servlet.jsp.tagext.*; 21 22 26 public class GetFeatureByNameTag extends TagSupport 27 implements JMXTaglibConstants 28 { 29 30 31 private String id; 32 33 34 private String name; 35 36 37 private String property; 38 39 40 private String featureName; 41 42 public int doEndTag() 43 throws JspException 44 { 45 Object o = pageContext.getAttribute(name); 46 if(o == null) 47 throw new JspException("GetFeatureByNameTag requires type MBeanServer, no object found under name: " +name); 48 if(property != null) 49 { 50 String name = "get" +property.substring(0, 1).toUpperCase() +property.substring(1); 51 try 52 { 53 Class clazz = o.getClass(); 54 Method m = clazz.getDeclaredMethod(name, new Class [0]); 55 o = m.invoke(o, new Object [0]); 56 }catch(Exception ex) 57 { 58 throw new JspException("error while accessing property: " +name +"; on object: "+ o +" - " +ex.getMessage()); 59 } 60 } 61 62 if(o == null ||!(o instanceof MBeanFeatureInfo[])) 63 throw new JspException("GetFeatureByNameTag requires type MBeanFeatureInfo[], Illegal name and or property"); 64 65 MBeanFeatureInfo features[] = (MBeanFeatureInfo[])o; 66 for(int i = 0; i < features.length; i++) 67 { 68 if(features[i].getName().equals(featureName)) 71 { 72 pageContext.setAttribute(id, features[i]); 73 if(Boolean.getBoolean(DEBUG_PROP)) 74 pageContext.getServletContext().log("setting attribute: " +id +"; to: " +features[i]); 75 break; 76 } 77 } 78 return (EVAL_PAGE); 79 } 80 81 84 public String getId() { 85 return id; 86 } 87 88 91 public void setId(String id) { 92 this.id = id; 93 } 94 95 98 public String getName() { 99 return name; 100 } 101 102 105 public void setName(String name) { 106 this.name = name; 107 } 108 109 112 public String getProperty() { 113 return property; 114 } 115 116 119 public void setProperty(String property) { 120 this.property = property; 121 } 122 123 126 public String getFeatureName() { 127 return featureName; 128 } 129 130 133 public void setFeatureName(String featureName) { 134 this.featureName = featureName; 135 } 136 137 } 138 | Popular Tags |