1 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 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 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 MBeanConstructorInfo [] constructors = new MBeanConstructorInfo [0]; 61 62 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 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, gOperationInfo.getReturnType() , 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 } 96 | Popular Tags |