1 7 8 package com.sun.jmx.mbeanserver; 9 10 import java.lang.reflect.InvocationTargetException ; 11 import java.lang.reflect.Method ; 12 import java.lang.reflect.Type ; 13 import java.util.WeakHashMap ; 14 import javax.management.Descriptor ; 15 import javax.management.ImmutableDescriptor ; 16 import javax.management.IntrospectionException ; 17 import javax.management.MBeanAttributeInfo ; 18 import javax.management.MBeanException ; 19 import javax.management.MBeanOperationInfo ; 20 import javax.management.NotCompliantMBeanException ; 21 import javax.management.NotificationBroadcaster ; 22 import javax.management.NotificationBroadcasterSupport ; 23 24 27 class StandardMBeanIntrospector extends MBeanIntrospector<Method > { 28 private static final StandardMBeanIntrospector instance = 29 new StandardMBeanIntrospector(); 30 31 static StandardMBeanIntrospector getInstance() { 32 return instance; 33 } 34 35 @Override 36 PerInterfaceMap<Method > getPerInterfaceMap() { 37 return perInterfaceMap; 38 } 39 40 @Override 41 MBeanInfoMap getMBeanInfoMap() { 42 return mbeanInfoMap; 43 } 44 45 @Override 46 MBeanAnalyzer<Method > getAnalyzer(Class <?> mbeanInterface) 47 throws NotCompliantMBeanException { 48 return MBeanAnalyzer.analyzer(mbeanInterface, this); 49 } 50 51 @Override 52 boolean isMXBean() { 53 return false; 54 } 55 56 @Override 57 Method mFrom(Method m) { 58 return m; 59 } 60 61 @Override 62 String getName(Method m) { 63 return m.getName(); 64 } 65 66 @Override 67 Type getGenericReturnType(Method m) { 68 return m.getGenericReturnType(); 69 } 70 71 @Override 72 Type [] getGenericParameterTypes(Method m) { 73 return m.getGenericParameterTypes(); 74 } 75 76 @Override 77 String [] getSignature(Method m) { 78 Class <?>[] params = m.getParameterTypes(); 79 String [] sig = new String [params.length]; 80 for (int i = 0; i < params.length; i++) 81 sig[i] = params[i].getName(); 82 return sig; 83 } 84 85 @Override 86 void checkMethod(Method m) { 87 } 88 89 @Override 90 Object invokeM2(Method m, Object target, Object [] args, Object cookie) 91 throws InvocationTargetException , IllegalAccessException , 92 MBeanException { 93 return m.invoke(target, args); 94 } 95 96 @Override 97 boolean validParameter(Method m, Object value, int paramNo, Object cookie) { 98 return isValidParameter(m, value, paramNo); 99 } 100 101 @Override 102 MBeanAttributeInfo getMBeanAttributeInfo(String attributeName, 103 Method getter, Method setter) { 104 105 final String description = "Attribute exposed for management"; 106 try { 107 return new MBeanAttributeInfo (attributeName, description, 108 getter, setter); 109 } catch (IntrospectionException e) { 110 throw new RuntimeException (e); } 112 } 113 114 @Override 115 MBeanOperationInfo getMBeanOperationInfo(String operationName, 116 Method operation) { 117 final String description = "Operation exposed for management"; 118 return new MBeanOperationInfo (description, operation); 119 } 120 121 @Override 122 Descriptor getBasicMBeanDescriptor() { 123 126 return ImmutableDescriptor.EMPTY_DESCRIPTOR; 127 } 128 129 @Override 130 Descriptor getMBeanDescriptor(Class <?> resourceClass) { 131 boolean immutable = isDefinitelyImmutableInfo(resourceClass); 132 return new ImmutableDescriptor ("mxbean=false", 133 "immutableInfo=" + immutable); 134 } 135 136 144 static boolean isDefinitelyImmutableInfo(Class <?> implClass) { 145 if (!NotificationBroadcaster .class.isAssignableFrom(implClass)) 146 return true; 147 synchronized (definitelyImmutable) { 148 Boolean immutable = definitelyImmutable.get(implClass); 149 if (immutable == null) { 150 final Class <NotificationBroadcasterSupport > nbs = 151 NotificationBroadcasterSupport .class; 152 if (nbs.isAssignableFrom(implClass)) { 153 try { 154 Method m = implClass.getMethod("getNotificationInfo"); 155 immutable = (m.getDeclaringClass() == nbs); 156 } catch (Exception e) { 157 return false; 159 } 160 } else 161 immutable = false; 162 definitelyImmutable.put(implClass, immutable); 163 } 164 return immutable; 165 } 166 } 167 private static final WeakHashMap <Class <?>, Boolean > definitelyImmutable = 168 new WeakHashMap <Class <?>, Boolean >(); 169 170 private static final PerInterfaceMap<Method > 171 perInterfaceMap = new PerInterfaceMap<Method >(); 172 173 private static final MBeanInfoMap mbeanInfoMap = new MBeanInfoMap(); 174 } 175 | Popular Tags |