KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mx4j > tools > adaptor > http > DeleteMBeanCommandProcessor


1 /*
2  * Copyright (C) The MX4J Contributors.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the MX4J License version 1.0.
6  * See the terms of the MX4J License in the documentation provided with this software.
7  */

8 package mx4j.tools.adaptor.http;
9
10 import java.io.IOException JavaDoc;
11 import javax.management.JMException JavaDoc;
12 import javax.management.MalformedObjectNameException JavaDoc;
13 import javax.management.ObjectName JavaDoc;
14
15 import org.w3c.dom.Document JavaDoc;
16 import org.w3c.dom.Element JavaDoc;
17
18 /**
19  * DeleteMBeanCommandProcessor, processes a request for unregistering an MBean
20  *
21  * @version $Revision: 1.3 $
22  */

23 public class DeleteMBeanCommandProcessor extends HttpCommandProcessorAdaptor
24 {
25
26    public DeleteMBeanCommandProcessor()
27    {
28    }
29
30
31    public Document JavaDoc executeRequest(HttpInputStream in)
32            throws IOException JavaDoc, JMException JavaDoc
33    {
34       Document JavaDoc document = builder.newDocument();
35
36       Element JavaDoc root = document.createElement("MBeanOperation");
37       document.appendChild(root);
38       Element JavaDoc operationElement = document.createElement("Operation");
39       operationElement.setAttribute("operation", "delete");
40       root.appendChild(operationElement);
41
42       String JavaDoc 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 JavaDoc name = null;
51       try
52       {
53          name = new ObjectName JavaDoc(objectVariable);
54       }
55       catch (MalformedObjectNameException JavaDoc 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 JavaDoc 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