1 /**
2 *
3 * Copyright 2003-2004 The Apache Software Foundation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package org.apache.geronimo.system.jmx;
19
20 import java.util.Iterator;
21 import java.util.List;
22 import java.util.Set;
23 import javax.management.MBeanAttributeInfo;
24 import javax.management.MBeanConstructorInfo;
25 import javax.management.MBeanInfo;
26 import javax.management.MBeanNotificationInfo;
27 import javax.management.MBeanOperationInfo;
28 import javax.management.MBeanParameterInfo;
29
30 import org.apache.geronimo.gbean.GAttributeInfo;
31 import org.apache.geronimo.gbean.GBeanInfo;
32 import org.apache.geronimo.gbean.GOperationInfo;
33 import org.apache.geronimo.kernel.management.NotificationType;
34
35
36 /**
37 * Helper class for JMX Operations
38 *
39 * @version $Rev: 430508 $ $Date: 2006-08-10 12:56:47 -0700 (Thu, 10 Aug 2006) $
40 */
41 public final class JMXUtil {
42 private JMXUtil() {
43 }
44
45 public static MBeanInfo toMBeanInfo(GBeanInfo gBeanInfo) {
46 String className = gBeanInfo.getClassName();
47 String description = "No description available";
48
49
50 Set gbeanAttributes = gBeanInfo.getAttributes();
51 MBeanAttributeInfo[] attributes = new MBeanAttributeInfo[gbeanAttributes.size()];
52 int a = 0;
53 for (Iterator iterator = gbeanAttributes.iterator(); iterator.hasNext();) {
54 GAttributeInfo gAttributeInfo = (GAttributeInfo) iterator.next();
55 attributes[a] = new MBeanAttributeInfo(gAttributeInfo.getName(), gAttributeInfo.getType(), "no description available", gAttributeInfo.isReadable(), gAttributeInfo.isWritable(), isIs(gAttributeInfo));
56 a++;
57 }
58
59
60 MBeanConstructorInfo[] constructors = new MBeanConstructorInfo[0];
61
62
63 Set gbeanOperations = gBeanInfo.getOperations();
64 MBeanOperationInfo[] operations = new MBeanOperationInfo[gbeanOperations.size()];
65 int o = 0;
66 for (Iterator iterator = gbeanOperations.iterator(); iterator.hasNext();) {
67 GOperationInfo gOperationInfo = (GOperationInfo) iterator.next();
68
69 List gparameters = gOperationInfo.getParameterList();
70 MBeanParameterInfo[] parameters = new MBeanParameterInfo[gparameters.size()];
71 int p = 0;
72 for (Iterator piterator = gparameters.iterator(); piterator.hasNext();) {
73 String type = (String) piterator.next();
74 parameters[p] = new MBeanParameterInfo("parameter" + p, type, "no description available");
75 p++;
76 }
77 operations[o] = new MBeanOperationInfo(gOperationInfo.getName(), "no description available", parameters, "java.lang.Object", MBeanOperationInfo.UNKNOWN);
78 o++;
79 }
80
81 MBeanNotificationInfo[] notifications = new MBeanNotificationInfo[1];
82 notifications[0] = new MBeanNotificationInfo(NotificationType.TYPES, "javax.management.Notification", "J2EE Notifications");
83
84 MBeanInfo mbeanInfo = new MBeanInfo(className, description, attributes, constructors, operations, notifications);
85 return mbeanInfo;
86 }
87
88 private static boolean isIs(GAttributeInfo gAttributeInfo) {
89 String getterName = gAttributeInfo.getGetterName();
90 if (getterName == null) {
91 return false;
92 }
93 return getterName.startsWith("is");
94 }
95 }