KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > jmx > browser > web > action > UnregisterAction


1 /*
2
3  * EJTools, the Enterprise Java Tools
4
5  *
6
7  * Distributable under LGPL license.
8
9  * See terms of license at www.gnu.org.
10
11  */

12
13 package org.ejtools.jmx.browser.web.action;
14
15
16
17 import java.io.IOException JavaDoc;
18
19 import java.io.PrintWriter JavaDoc;
20
21 import java.io.StringWriter JavaDoc;
22
23 import java.util.Locale JavaDoc;
24
25
26
27 import javax.servlet.ServletContext JavaDoc;
28
29 import javax.servlet.ServletException JavaDoc;
30
31 import javax.servlet.http.HttpServletRequest JavaDoc;
32
33 import javax.servlet.http.HttpServletResponse JavaDoc;
34
35
36
37 import org.apache.log4j.Logger;
38
39 import org.apache.struts.action.Action;
40
41 import org.apache.struts.action.ActionError;
42
43 import org.apache.struts.action.ActionErrors;
44
45 import org.apache.struts.action.ActionForm;
46
47 import org.apache.struts.action.ActionForward;
48
49 import org.apache.struts.action.ActionMapping;
50
51 import org.apache.struts.util.MessageResources;
52
53 import org.ejtools.jmx.browser.model.Resource;
54
55 import org.ejtools.jmx.browser.web.Constants;
56
57 import org.ejtools.jmx.browser.web.JMXContainer;
58
59
60
61 /**
62
63  * Description of the Class
64
65  *
66
67  * @author letiemble
68
69  * @created 12 novembre 2001
70
71  * @version $Revision: 1.6 $
72
73  * @todo Javadoc to complete
74
75  */

76
77 public class UnregisterAction extends Action
78
79 {
80
81    /** Description of the Field */
82
83    private static Logger logger = Logger.getLogger(UnregisterAction.class);
84
85
86
87
88
89    /** Constructor for the SearchLoginAction object */
90
91    public UnregisterAction() { }
92
93
94
95
96
97    /**
98
99     * Description of the Method
100
101     *
102
103     * @param mapping Description of the Parameter
104
105     * @param form Description of the Parameter
106
107     * @param request Description of the Parameter
108
109     * @param response Description of the Parameter
110
111     * @return Description of the Return Value
112
113     * @exception IOException Description of the Exception
114
115     * @exception ServletException Description of the Exception
116
117     */

118
119    public ActionForward perform(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
120
121       throws IOException JavaDoc, ServletException JavaDoc
122
123    {
124
125       String JavaDoc reference = null;
126
127
128
129       // Extract attributes we will need
130

131       Locale JavaDoc locale = getLocale(request);
132
133       MessageResources messages = getResources();
134
135
136
137       // Validate the request parameters specified by the user
138

139       ActionErrors errors = new ActionErrors();
140
141
142
143       reference = request.getParameter("reference");
144
145       logger.debug("ObjectName requested " + reference);
146
147
148
149       ServletContext JavaDoc context = this.getServlet().getServletContext();
150
151       JMXContainer tree = (JMXContainer) context.getAttribute(Constants.TREE);
152
153
154
155       if (tree != null)
156
157       {
158
159          logger.debug("Tree root found => " + tree);
160
161          Resource res = (Resource) tree.searchObjectName(reference);
162
163
164
165          if (res != null)
166
167          {
168
169             try
170
171             {
172
173                res.unregisterMBean();
174
175             }
176
177             catch (Exception JavaDoc e)
178
179             {
180
181                logger.error("Exception occured " + e.getMessage());
182
183
184
185                errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("web.error.mbean.unregister", reference));
186
187                errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("web.error.exception.message", e.getMessage()));
188
189
190
191                StringWriter JavaDoc w = new StringWriter JavaDoc();
192
193                PrintWriter JavaDoc pw = new PrintWriter JavaDoc(w);
194
195                e.printStackTrace(pw);
196
197                pw.close();
198
199
200
201                errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("web.error.exception.stack", w.toString()));
202
203             }
204
205          }
206
207          else
208
209          {
210
211             errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("web.error.no.mbean"));
212
213          }
214
215       }
216
217       else
218
219       {
220
221          errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("web.error.cannot.connect"));
222
223       }
224
225
226
227       // Report any errors we have discovered back to the original form
228

229       if (!errors.empty())
230
231       {
232
233          saveErrors(request, errors);
234
235          return (mapping.findForward("error"));
236
237       }
238
239
240
241       return (mapping.findForward("view"));
242
243    }
244
245 }
246
247
248
249
Popular Tags