1 17 18 package org.apache.geronimo.kernel.jmx; 19 20 import java.util.Set ; 21 import java.util.Iterator ; 22 import java.util.List ; 23 import javax.management.MalformedObjectNameException ; 24 import javax.management.ObjectName ; 25 import javax.management.MBeanInfo ; 26 import javax.management.MBeanAttributeInfo ; 27 import javax.management.MBeanConstructorInfo ; 28 import javax.management.MBeanOperationInfo ; 29 import javax.management.MBeanParameterInfo ; 30 import javax.management.MBeanNotificationInfo ; 31 32 import org.apache.geronimo.gbean.GBeanInfo; 33 import org.apache.geronimo.gbean.GAttributeInfo; 34 import org.apache.geronimo.gbean.GOperationInfo; 35 import org.apache.geronimo.kernel.management.NotificationType; 36 37 38 43 public final class JMXUtil { 44 private JMXUtil() { 45 } 46 47 54 public static ObjectName getObjectName(String name) throws IllegalArgumentException { 55 try { 56 return new ObjectName (name); 57 } catch (MalformedObjectNameException e) { 58 throw new IllegalArgumentException ("Malformed ObjectName: " + name); 59 } 60 } 61 62 public static MBeanInfo toMBeanInfo(GBeanInfo gBeanInfo) { 63 String className = gBeanInfo.getClassName(); 64 String description = "No description available"; 65 66 Set gbeanAttributes = gBeanInfo.getAttributes(); 68 MBeanAttributeInfo [] attributes = new MBeanAttributeInfo [gbeanAttributes.size()]; 69 int a = 0; 70 for (Iterator iterator = gbeanAttributes.iterator(); iterator.hasNext();) { 71 GAttributeInfo gAttributeInfo = (GAttributeInfo) iterator.next(); 72 attributes[a] = new MBeanAttributeInfo (gAttributeInfo.getName(), gAttributeInfo.getType(), "no description available", gAttributeInfo.isReadable(), gAttributeInfo.isWritable(), isIs(gAttributeInfo)); 73 a++; 74 } 75 76 MBeanConstructorInfo [] constructors = new MBeanConstructorInfo [0]; 78 79 Set gbeanOperations = gBeanInfo.getOperations(); 81 MBeanOperationInfo [] operations = new MBeanOperationInfo [gbeanOperations.size()]; 82 int o = 0; 83 for (Iterator iterator = gbeanOperations.iterator(); iterator.hasNext();) { 84 GOperationInfo gOperationInfo = (GOperationInfo) iterator.next(); 85 List gparameters = gOperationInfo.getParameterList(); 87 MBeanParameterInfo [] parameters = new MBeanParameterInfo [gparameters.size()]; 88 int p = 0; 89 for (Iterator piterator = gparameters.iterator(); piterator.hasNext();) { 90 String type = (String ) piterator.next(); 91 parameters[p] = new MBeanParameterInfo ("parameter" + p, type, "no description available"); 92 p++; 93 } 94 operations[o] = new MBeanOperationInfo (gOperationInfo.getName(), "no description available", parameters, "java.lang.Object", MBeanOperationInfo.UNKNOWN); 95 o++; 96 } 97 98 MBeanNotificationInfo [] notifications = new MBeanNotificationInfo [1]; 99 notifications[0] = new MBeanNotificationInfo (NotificationType.TYPES, "javax.management.Notification", "J2EE Notifications"); 100 101 MBeanInfo mbeanInfo = new MBeanInfo (className, description, attributes, constructors, operations, notifications); 102 return mbeanInfo; 103 } 104 105 private static boolean isIs(GAttributeInfo gAttributeInfo) { 106 String getterName = gAttributeInfo.getGetterName(); 107 if (getterName == null) { 108 return false; 109 } 110 return getterName.startsWith("is"); 111 } 112 } 113 | Popular Tags |