01: /* JFox, the OpenSource J2EE Application Server
02: *
03: * Copyright (C) 2002 huihoo.com
04: * Distributable under GNU LGPL license
05: * See the GNU Lesser General Public License for more details.
06: */
07:
08: package org.huihoo.jfox.jmx.adaptor.http;
09:
10: import java.util.Map;
11: import java.util.HashMap;
12: import java.util.StringTokenizer;
13:
14: import javax.management.MBeanServer;
15: import javax.management.ObjectName;
16:
17: /**
18: *
19: * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
20: */
21:
22: public class CreateMBeanCommand extends AbstractCommand {
23: public void doGet(HttpRequest request, HttpResponse response)
24: throws Exception {
25: String domain = "";
26: if (request.getParameter("domain") != null) {
27: domain = request.getParameter("domain");
28: }
29:
30: ctx.put("domain", domain);
31: ctx.put("status", "fill the blanks for creating a MBean");
32: }
33:
34: public void doPost(HttpRequest request, HttpResponse response)
35: throws Exception {
36: String domain = request.getParameter("domain");
37: String keys = request.getParameter("keys");
38: String mbeanClass = request.getParameter("mbeanClass");
39: String _objectName = domain + ":" + keys;
40: ObjectName objectName = new ObjectName(_objectName);
41: String _loaderName = request.getParameter("loaderName");
42: ObjectName loaderName = null;
43: if (_loaderName != null && _loaderName.trim().length() != 0) {
44: loaderName = new ObjectName(_loaderName);
45: }
46: String[] signatures = null;
47: String[] values = null;
48: String _signatures = request.getParameter("signatures");
49: if (_signatures != null && _signatures.trim().length() != 0) {
50: signatures = split(_signatures, ",");
51: }
52: String _values = request.getParameter("values");
53: if (_values != null && _values.trim().length() != 0) {
54: values = split(_values, ",");
55: }
56:
57: if ((signatures == null && values != null)
58: || (signatures != null && values == null)) {
59: throw new InvalidInputException("Signatures with Values");
60: }
61:
62: if (signatures != null && values != null
63: && signatures.length != values.length) {
64: throw new InvalidInputException("Signatures with Values");
65: }
66:
67: MBeanServer server = request.getThread().getServer()
68: .getServer();
69: server.createMBean(mbeanClass, objectName, loaderName, values,
70: signatures);
71: ctx.put("domain", domain);
72: ctx.put("status",
73: "MBean created successfully. <br>MBean Info: objectname="
74: + _objectName + ", classname=" + mbeanClass);
75: }
76:
77: public static String[] split(String sp, String delim) {
78: StringTokenizer st = new StringTokenizer(sp, delim);
79: String[] array = new String[st.countTokens()];
80: int i = 0;
81: while (st.hasMoreTokens()) {
82: array[i] = st.nextToken().trim();
83: i++;
84: }
85: return array;
86: }
87:
88: public static void main(String[] args) {
89:
90: }
91: }
|