1 8 package mx4j.tools.adaptor.http; 9 10 import java.io.IOException ; 11 import javax.management.JMException ; 12 import javax.management.MalformedObjectNameException ; 13 import javax.management.ObjectName ; 14 15 import org.w3c.dom.Document ; 16 import org.w3c.dom.Element ; 17 18 23 public class DeleteMBeanCommandProcessor extends HttpCommandProcessorAdaptor 24 { 25 26 public DeleteMBeanCommandProcessor() 27 { 28 } 29 30 31 public Document executeRequest(HttpInputStream in) 32 throws IOException , JMException 33 { 34 Document document = builder.newDocument(); 35 36 Element root = document.createElement("MBeanOperation"); 37 document.appendChild(root); 38 Element operationElement = document.createElement("Operation"); 39 operationElement.setAttribute("operation", "delete"); 40 root.appendChild(operationElement); 41 42 String objectVariable = in.getVariable("objectname"); 43 operationElement.setAttribute("objectname", objectVariable); 44 if (objectVariable == null || objectVariable.equals("")) 45 { 46 operationElement.setAttribute("result", "error"); 47 operationElement.setAttribute("errorMsg", "Incorrect parameters in the request"); 48 return document; 49 } 50 ObjectName name = null; 51 try 52 { 53 name = new ObjectName (objectVariable); 54 } 55 catch (MalformedObjectNameException e) 56 { 57 operationElement.setAttribute("result", "error"); 58 operationElement.setAttribute("errorMsg", "Malformed object name"); 59 return document; 60 } 61 62 if (server.isRegistered(name)) 63 { 64 try 65 { 66 server.unregisterMBean(name); 67 operationElement.setAttribute("result", "success"); 68 } 69 catch (Exception e) 70 { 71 operationElement.setAttribute("result", "error"); 72 operationElement.setAttribute("errorMsg", e.getMessage()); 73 } 74 } 75 else 76 { 77 if (name != null) 78 { 79 operationElement.setAttribute("result", "error"); 80 operationElement.setAttribute("errorMsg", "MBean " + name + " not registered"); 81 } 82 } 83 return document; 84 } 85 86 } 87 88 | Popular Tags |