1 8 13 14 package org.webjmx.tags; 15 16 import java.io.*; 17 import javax.management.*; 18 import javax.servlet.jsp.*; 19 import javax.servlet.jsp.tagext.*; 20 21 26 public class GetAttributeTag extends TagSupport 27 implements JMXTaglibConstants 28 { 29 30 private String id; 31 32 33 private String server; 34 35 36 private String name; 37 38 39 private String attribute; 40 41 42 private String attributeInfo; 43 44 45 public GetAttributeTag() { 46 } 47 48 public int doStartTag() 49 throws JspException 50 { 51 Object o = pageContext.getAttribute(server); 52 if(o == null ||!(o instanceof MBeanServer)) 53 throw new JspException("GetAttributeTag requires type MBeanServer, Illegal server: " +o); 54 MBeanServer s = (MBeanServer)o; 55 o = pageContext.getAttribute(name); 56 if(o == null ||!(o instanceof ObjectName)) 57 throw new JspException("GetAttributeTag requires type ObjectName, Illegal name: " +o); 58 ObjectName n = (ObjectName)o; 59 if(attributeInfo != null) 60 { 61 o = pageContext.getAttribute(attributeInfo); 62 if(o == null ||!(o instanceof MBeanAttributeInfo)) 63 throw new JspException("GetAttributeTag requires type MBeanAttributeInfo, Illegal attributeInfo: " +o); 64 MBeanAttributeInfo attrInfo = (MBeanAttributeInfo)o; 65 attribute = attrInfo.getName(); 66 } 67 68 if(attribute == null) 69 throw new JspException("GetAttributeTag requires a value"); 70 71 try 72 { 73 o = s.getAttribute(n, attribute); 74 75 if(id == null) 76 pageContext.getOut().write(o != null ? o.toString() : "null"); 77 else if(o != null) 78 pageContext.setAttribute(id, o); 79 80 }catch(Exception ex) { ex.printStackTrace(); } 82 return (SKIP_BODY); 83 } 84 85 88 public String getId() 89 { 90 return id; 91 } 92 93 96 public void setId(String id) 97 { 98 this.id = id; 99 } 100 101 104 public String getServer() 105 { 106 return server; 107 } 108 109 112 public void setServer(String server) 113 { 114 this.server = server; 115 } 116 117 120 public String getName() 121 { 122 return name; 123 } 124 125 128 public void setName(String name) 129 { 130 this.name = name; 131 } 132 133 136 public String getAttribute() 137 { 138 return attribute; 139 } 140 141 144 public void setAttribute(String attribute) 145 { 146 this.attribute = attribute; 147 } 148 149 152 public String getAttributeInfo() 153 { 154 return attributeInfo; 155 } 156 157 160 public void setAttributeInfo(String attributeInfo) 161 { 162 this.attributeInfo = attributeInfo; 163 } 164 165 } 166 | Popular Tags |