KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > system > jmx > JMXUtil


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 JavaDoc;
21 import java.util.List JavaDoc;
22 import java.util.Set JavaDoc;
23 import javax.management.MBeanAttributeInfo JavaDoc;
24 import javax.management.MBeanConstructorInfo JavaDoc;
25 import javax.management.MBeanInfo JavaDoc;
26 import javax.management.MBeanNotificationInfo JavaDoc;
27 import javax.management.MBeanOperationInfo JavaDoc;
28 import javax.management.MBeanParameterInfo JavaDoc;
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: 485321 $ $Date: 2006-12-10 19:14:46 -0500 (Sun, 10 Dec 2006) $
40  */

41 public final class JMXUtil {
42     private JMXUtil() {
43     }
44
45     public static MBeanInfo JavaDoc toMBeanInfo(GBeanInfo gBeanInfo) {
46         String JavaDoc className = gBeanInfo.getClassName();
47         String JavaDoc description = "No description available";
48
49         // attributes
50
Set JavaDoc gbeanAttributes = gBeanInfo.getAttributes();
51         MBeanAttributeInfo JavaDoc[] attributes = new MBeanAttributeInfo JavaDoc[gbeanAttributes.size()];
52         int a = 0;
53         for (Iterator JavaDoc iterator = gbeanAttributes.iterator(); iterator.hasNext();) {
54             GAttributeInfo gAttributeInfo = (GAttributeInfo) iterator.next();
55             attributes[a] = new MBeanAttributeInfo JavaDoc(gAttributeInfo.getName(), gAttributeInfo.getType(), "no description available", gAttributeInfo.isReadable(), gAttributeInfo.isWritable(), isIs(gAttributeInfo));
56             a++;
57         }
58
59         //we don't expose managed constructors
60
MBeanConstructorInfo JavaDoc[] constructors = new MBeanConstructorInfo JavaDoc[0];
61
62         // operations
63
Set JavaDoc gbeanOperations = gBeanInfo.getOperations();
64         MBeanOperationInfo JavaDoc[] operations = new MBeanOperationInfo JavaDoc[gbeanOperations.size()];
65         int o = 0;
66         for (Iterator JavaDoc iterator = gbeanOperations.iterator(); iterator.hasNext();) {
67             GOperationInfo gOperationInfo = (GOperationInfo) iterator.next();
68             //list of class names
69
List JavaDoc gparameters = gOperationInfo.getParameterList();
70             MBeanParameterInfo JavaDoc[] parameters = new MBeanParameterInfo JavaDoc[gparameters.size()];
71             int p = 0;
72             for (Iterator JavaDoc piterator = gparameters.iterator(); piterator.hasNext();) {
73                 String JavaDoc type = (String JavaDoc) piterator.next();
74                 parameters[p] = new MBeanParameterInfo JavaDoc("parameter" + p, type, "no description available");
75                 p++;
76             }
77             operations[o] = new MBeanOperationInfo JavaDoc(gOperationInfo.getName(), "no description available", parameters, gOperationInfo.getReturnType() , MBeanOperationInfo.UNKNOWN);
78             o++;
79         }
80
81         MBeanNotificationInfo JavaDoc[] notifications = new MBeanNotificationInfo JavaDoc[1];
82         notifications[0] = new MBeanNotificationInfo JavaDoc(NotificationType.TYPES, "javax.management.Notification", "J2EE Notifications");
83
84         MBeanInfo JavaDoc mbeanInfo = new MBeanInfo JavaDoc(className, description, attributes, constructors, operations, notifications);
85         return mbeanInfo;
86     }
87
88     private static boolean isIs(GAttributeInfo gAttributeInfo) {
89         String JavaDoc getterName = gAttributeInfo.getGetterName();
90         if (getterName == null) {
91             return false;
92         }
93         return getterName.startsWith("is");
94     }
95 }
96
Popular Tags