1 8 13 14 package org.webjmx.tags; 15 16 import java.io.*; 17 import java.util.*; 18 import javax.management.*; 19 import javax.servlet.jsp.*; 20 import javax.servlet.jsp.tagext.*; 21 22 27 public class QueryNamesTag extends BodyTagSupport 28 implements JMXTaglibConstants 29 { 30 31 private String id; 32 33 34 private String server; 35 36 39 private String name; 40 41 42 private String query; 43 44 45 public QueryNamesTag() 46 { } 47 48 51 public int doEndTag() 52 throws JspException 53 { 54 Object o = pageContext.getAttribute(server); 55 if(o == null ||!(o instanceof MBeanServer)) 56 throw new JspException("QueryNamesTag requires type MBeanServer, Illegal server: " +o.getClass()); 57 MBeanServer s = (MBeanServer)o; 58 if(name == null) 59 { 60 BufferedReader in = new BufferedReader(getBodyContent().getReader()); 62 StringBuffer sb = new StringBuffer (); 63 64 try 65 { 66 String line = in.readLine(); 67 while(line != null) 68 { 69 sb.append(line); 70 line = in.readLine(); 71 } 72 if(Boolean.getBoolean(DEBUG_PROP)) pageContext.getServletContext().log("mbean tag body content: " +sb.toString()); 73 getBodyContent().clear(); 74 }catch(IOException ie) 75 { ie.printStackTrace(); } 76 name = sb.toString(); 77 } 78 if(Boolean.getBoolean(DEBUG_PROP)) pageContext.getServletContext().log("name: " +name); 79 o = pageContext.getAttribute(name); 80 if(Boolean.getBoolean(DEBUG_PROP)) pageContext.getServletContext().log("object name: " +o); 81 if(o == null) 82 { 83 try{ o = new ObjectName(name); } 84 catch(MalformedObjectNameException mfe) { mfe.printStackTrace(); } 85 }if(o != null && !(o instanceof ObjectName)) 86 throw new JspException("QueryNamesTag requires type ObjectName, Illegal name: " +o); 87 ObjectName n = (ObjectName)o; 88 if(Boolean.getBoolean(DEBUG_PROP)) pageContext.getServletContext().log("object name: " +n); 89 if(query != null) 90 { 91 o = pageContext.getAttribute(query); 92 if(o != null && !(o instanceof QueryExp)) 93 throw new JspException("QueryNamesTag requires type QueryExp, Illegal query: " +o); 94 }else 95 o = null; 96 QueryExp q = (QueryExp)o; 97 Set names = s.queryNames(n, q); 98 if(Boolean.getBoolean(DEBUG_PROP)) pageContext.getServletContext().log("queryNames[" +name +"] set size: " +names.size()); 99 pageContext.setAttribute(id, names); 100 return (SKIP_BODY); 101 } 102 103 106 public String getId() 107 { 108 return id; 109 } 110 111 114 public void setId(String id) 115 { 116 this.id = id; 117 } 118 119 122 public String getServer() 123 { 124 return server; 125 } 126 127 130 public void setServer(String server) 131 { 132 this.server = server; 133 } 134 135 138 public String getName() 139 { 140 return name; 141 } 142 143 146 public void setName(String name) 147 { 148 this.name = name; 149 } 150 151 154 public String getQuery() 155 { 156 return query; 157 } 158 159 162 public void setQuery(String query) 163 { 164 this.query = query; 165 } 166 167 170 public void release() 171 { 172 name = id = server = query = null; 173 } 174 175 } 176 | Popular Tags |