1 8 package mx4j.tools.adaptor.http; 9 10 import java.io.IOException ; 11 import java.util.Iterator ; 12 import java.util.Set ; 13 import java.util.TreeSet ; 14 import javax.management.JMException ; 15 import javax.management.MBeanInfo ; 16 import javax.management.MalformedObjectNameException ; 17 import javax.management.ObjectInstance ; 18 import javax.management.ObjectName ; 19 20 import org.w3c.dom.Document ; 21 import org.w3c.dom.Element ; 22 23 29 public class ServerCommandProcessor extends HttpCommandProcessorAdaptor 30 { 31 public ServerCommandProcessor() 32 { 33 } 34 35 public Document executeRequest(HttpInputStream in) throws IOException , JMException 36 { 37 Document document = builder.newDocument(); 38 39 Element root = document.createElement("Server"); 40 document.appendChild(root); 41 42 String classVariable = in.getVariable("instanceof"); 43 String queryNames = in.getVariable("querynames"); 44 Set mbeans = null; 45 ObjectName query = null; 46 if (queryNames != null) 47 { 48 try 49 { 50 query = new ObjectName (queryNames); 51 mbeans = new TreeSet (CommandProcessorUtil.createObjectInstanceComparator()); 52 mbeans.addAll(server.queryMBeans(query, null)); 53 } 54 catch (MalformedObjectNameException e) 55 { 56 Element exceptionElement = document.createElement("Exception"); 57 exceptionElement.setAttribute("errorMsg", e.getMessage()); 58 root.appendChild(exceptionElement); 59 return document; 60 } 61 } 62 else 63 { 64 mbeans = new TreeSet (CommandProcessorUtil.createObjectInstanceComparator()); 65 mbeans.addAll(server.queryMBeans(null, null)); 66 } 67 Iterator i = mbeans.iterator(); 68 while (i.hasNext()) 69 { 70 ObjectInstance instance = (ObjectInstance )i.next(); 71 if (classVariable != null && !classVariable.equals(instance.getClassName())) 72 { 73 continue; 74 } 75 Element mBeanElement = document.createElement("MBean"); 76 mBeanElement.setAttribute("objectname", instance.getObjectName().toString()); 77 mBeanElement.setAttribute("classname", instance.getClassName()); 78 MBeanInfo info = server.getMBeanInfo(instance.getObjectName()); 79 mBeanElement.setAttribute("description", info.getDescription()); 80 root.appendChild(mBeanElement); 81 } 82 return document; 83 } 84 85 } 86 | Popular Tags |