1 7 8 package com.sun.jmx.mbeanserver; 9 10 11 12 14 import java.lang.reflect.Method ; 15 import java.lang.reflect.Constructor ; 16 import java.lang.reflect.InvocationTargetException ; 17 import java.util.Hashtable ; 18 import java.util.Iterator ; 19 import java.io.PrintWriter ; 20 import java.io.StringWriter ; 21 22 import javax.management.* ; 24 import com.sun.jmx.trace.Trace; 25 26 33 public class MetaDataImpl implements MetaData { 34 35 36 private final static String dbgTag = "MetaDataImpl"; 37 38 39 private final DynamicMetaDataImpl dynamic; 40 private final StandardMetaDataImpl standard; 41 42 45 protected final MBeanInstantiator instantiator; 46 47 private final class PrivateStandardMeta extends StandardMetaDataImpl { 49 PrivateStandardMeta() { 50 super(); 51 } 52 protected Class findClass(String className, ClassLoader loader) 56 throws ReflectionException { 57 return MetaDataImpl.this.findClass(className,loader); 58 } 59 protected Class [] findSignatureClasses(String [] signature, 60 ClassLoader loader) 61 throws ReflectionException { 62 return MetaDataImpl.this.findSignatureClasses(signature,loader); 63 } 64 65 } 66 67 private final class PrivateDynamicMeta extends DynamicMetaDataImpl { 69 PrivateDynamicMeta() { 70 super(); 71 } 72 protected Class findClass(String className, ClassLoader loader) 76 throws ReflectionException { 77 return MetaDataImpl.this.findClass(className,loader); 78 } 79 protected Class [] findSignatureClasses(String [] signature, 80 ClassLoader loader) 81 throws ReflectionException { 82 return MetaDataImpl.this.findSignatureClasses(signature,loader); 83 } 84 85 } 86 87 94 public MetaDataImpl(MBeanInstantiator instantiator) { 95 if (instantiator == null) throw new 96 IllegalArgumentException ("instantiator must not be null."); 97 this.instantiator = instantiator; 98 this.dynamic = new PrivateDynamicMeta(); 99 this.standard = new PrivateStandardMeta(); 100 } 103 104 105 protected MetaData getMetaData(Class c) { 106 if (DynamicMBean.class.isAssignableFrom(c)) 107 return dynamic; 108 else 109 return standard; 110 } 111 112 protected MetaData getMetaData(Object moi) { 113 if (moi instanceof DynamicMBean) 114 return dynamic; 115 else 116 return standard; 117 } 118 119 122 public synchronized void testCompliance(Class c) 123 throws NotCompliantMBeanException { 124 final MetaData meta = getMetaData(c); 125 meta.testCompliance(c); 126 } 127 128 129 132 public Class getMBeanInterfaceFromClass(Class c) { 133 return standard.getMBeanInterfaceFromClass(c); 134 } 135 136 137 152 public MBeanInfo getMBeanInfoFromClass(Class beanClass) 153 throws IntrospectionException, NotCompliantMBeanException { 154 return standard.getMBeanInfoFromClass(beanClass); 155 } 156 157 158 164 public final String getMBeanClassName(Object moi) 165 throws IntrospectionException, NotCompliantMBeanException { 166 final MetaData meta = getMetaData(moi); 167 return meta.getMBeanClassName(moi); 168 } 169 170 public final MBeanInfo getMBeanInfo(Object moi) 171 throws IntrospectionException { 172 final MetaData meta = getMetaData(moi); 173 return meta.getMBeanInfo(moi); 174 } 175 176 public final Object getAttribute(Object instance, String attribute) 177 throws MBeanException, AttributeNotFoundException, 178 ReflectionException { 179 180 final MetaData meta = getMetaData(instance); 181 return meta.getAttribute(instance,attribute); 182 } 183 184 public final AttributeList getAttributes(Object instance, 185 String [] attributes) 186 throws ReflectionException { 187 188 final MetaData meta = getMetaData(instance); 189 return meta.getAttributes(instance, attributes); 190 } 191 192 public final AttributeList setAttributes(Object instance, 193 AttributeList attributes) 194 throws ReflectionException { 195 196 final MetaData meta = getMetaData(instance); 197 return meta.setAttributes(instance,attributes); 198 } 199 200 201 public final Object setAttribute(Object instance, Attribute attribute) 202 throws AttributeNotFoundException, InvalidAttributeValueException, 203 MBeanException, ReflectionException { 204 205 final MetaData meta = getMetaData(instance); 206 return meta.setAttribute(instance,attribute); 207 } 208 209 public final Object invoke(Object instance, String operationName, 210 Object params[], String signature[]) 211 throws MBeanException, ReflectionException { 212 213 if (operationName == null) { 214 final RuntimeException r = 215 new IllegalArgumentException ("Operation name cannot be null"); 216 throw new RuntimeOperationsException(r, 217 "Exception occured trying to invoke the operation on the MBean"); 218 } 219 final MetaData meta = getMetaData(instance); 220 return meta.invoke(instance,operationName,params,signature); 221 } 222 223 public boolean isInstanceOf(Object instance, String className) 224 throws ReflectionException { 225 226 final MetaData meta = getMetaData(instance); 228 return meta.isInstanceOf(instance,className); 229 } 230 231 public ObjectName preRegisterInvoker(Object moi, ObjectName name, 232 MBeanServer mbs) 233 throws InstanceAlreadyExistsException, MBeanRegistrationException { 234 235 if (!(moi instanceof MBeanRegistration)) return name; 236 final MetaData meta = getMetaData(moi); 237 return meta.preRegisterInvoker(moi,name,mbs); 238 } 239 240 public void postRegisterInvoker(Object moi, boolean registrationDone) { 241 if (!(moi instanceof MBeanRegistration)) return; 242 243 final MetaData meta = getMetaData(moi); 244 meta.postRegisterInvoker(moi,registrationDone); 245 } 246 247 public void preDeregisterInvoker(Object moi) 248 throws MBeanRegistrationException { 249 if (!(moi instanceof MBeanRegistration)) return; 250 final MetaData meta = getMetaData(moi); 251 meta.preDeregisterInvoker(moi); 252 } 253 254 255 public void postDeregisterInvoker(Object moi) { 256 if (!(moi instanceof MBeanRegistration)) return; 257 final MetaData meta = getMetaData(moi); 258 meta.postDeregisterInvoker(moi); 259 } 260 261 264 protected Class findClass(String className, ClassLoader loader) 265 throws ReflectionException { 266 return instantiator.findClass(className, loader); 267 } 268 269 272 protected Class [] findSignatureClasses(String [] signature, 273 ClassLoader loader) 274 throws ReflectionException { 275 return ((signature == null)?null: 276 instantiator.findSignatureClasses(signature,loader)); 277 } 278 279 282 private static boolean isTraceOn() { 283 return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_MBEANSERVER); 284 } 285 286 private static void trace(String clz, String func, String info) { 287 Trace.send(Trace.LEVEL_TRACE, Trace.INFO_MBEANSERVER, clz, func, info); 288 } 289 290 private static void trace(String func, String info) { 291 trace(dbgTag, func, info); 292 } 293 294 private static boolean isDebugOn() { 295 return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_MBEANSERVER); 296 } 297 298 private static void debug(String clz, String func, String info) { 299 Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_MBEANSERVER, clz, func, info); 300 } 301 302 private static void debug(String func, String info) { 303 debug(dbgTag, func, info); 304 } 305 306 private static void debugX(String func,Throwable e) { 307 if (isDebugOn()) { 308 final StringWriter s = new StringWriter (); 309 e.printStackTrace(new PrintWriter (s)); 310 final String stack = s.toString(); 311 312 debug(dbgTag,func,"Exception caught in "+ func+"(): "+e); 313 debug(dbgTag,func,stack); 314 315 } 319 } 320 321 } 322 | Popular Tags |