1 7 8 package com.sun.jmx.mbeanserver; 9 10 11 12 import java.util.Iterator ; 14 import java.io.PrintWriter ; 15 import java.io.StringWriter ; 16 17 import javax.management.* ; 19 import com.sun.jmx.trace.Trace; 20 21 29 class DynamicMetaDataImpl extends BaseMetaDataImpl { 30 31 32 private final static String dbgTag = "DynamicMetaDataImpl"; 33 34 35 38 public DynamicMetaDataImpl() { 39 } 42 43 44 47 public void testCompliance(Class c) 48 throws NotCompliantMBeanException { 49 if (DynamicMBean.class.isAssignableFrom(c)) return; 52 throw new NotCompliantMBeanException( 53 "Only DynamicMBeans are supported by this implementation"); 54 } 55 56 57 63 public MBeanInfo getMBeanInfo(Object moi) 64 throws IntrospectionException { 65 66 try { 67 return (MBeanInfo) 68 ((javax.management.DynamicMBean )moi).getMBeanInfo(); 69 } catch (RuntimeMBeanException r) { 70 throw r; 71 } catch (RuntimeErrorException r) { 72 throw r; 73 } catch (RuntimeException r) { 74 debugX("getMBeanInfo",r); 75 throw new RuntimeMBeanException((RuntimeException )r, 76 "Runtime Exception thrown by getMBeanInfo method of Dynamic MBean"); 77 } catch (Error e ) { 78 debugX("getMBeanInfo",e); 79 throw new RuntimeErrorException((Error )e, 80 "Error thrown by getMBeanInfo method of Dynamic MBean"); 81 } 82 83 } 84 85 public Object getAttribute(Object instance, String attribute) 86 throws MBeanException, AttributeNotFoundException, 87 ReflectionException { 88 if (attribute == null) { 89 final RuntimeException r = 90 new IllegalArgumentException ("Attribute name cannot be null"); 91 throw new RuntimeOperationsException(r, 92 "Exception occured trying to invoke the getter on the MBean"); 93 } 94 95 try { 96 return ((javax.management.DynamicMBean )instance). 97 getAttribute(attribute); 98 } catch (RuntimeOperationsException r) { 99 throw r; 100 } catch (RuntimeErrorException r) { 101 throw r; 102 } catch (RuntimeException e) { 103 debugX("getAttribute",e); 104 throw new RuntimeMBeanException(e, "RuntimeException" + 105 " thrown by the getAttribute method of the DynamicMBean" + 106 " for the attribute " + attribute); 107 } catch (Error e) { 108 debugX("getAttribute",e); 109 throw new RuntimeErrorException((Error )e, "Error" + 110 " thrown by the getAttribute method of the DynamicMBean "+ 111 " for the attribute " + attribute); 112 } 113 } 114 115 public AttributeList getAttributes(Object instance, String [] attributes) 116 throws ReflectionException { 117 118 if (attributes == null) { 119 throw new RuntimeOperationsException(new 120 IllegalArgumentException ("Attributes cannot be null"), 121 "Exception occured trying to invoke the getter on the MBean"); 122 } 123 124 try { 125 return ((javax.management.DynamicMBean )instance). 126 getAttributes(attributes); 127 } catch (RuntimeOperationsException r) { 128 throw r; 129 } catch (RuntimeErrorException r) { 130 throw r; 131 } catch (RuntimeException e) { 132 debugX("getAttributes",e); 133 throw new RuntimeOperationsException(e, "RuntimeException" + 134 " thrown by the getAttributes method of the DynamicMBean"); 135 } catch (Error e) { 136 debugX("getAttributes",e); 137 throw new RuntimeErrorException((Error )e, "Error" + 138 " thrown by the getAttributes method of the DynamicMBean"); 139 } 140 } 141 142 143 public AttributeList setAttributes(Object instance, 144 AttributeList attributes) 145 throws ReflectionException { 146 147 try { 148 return ((javax.management.DynamicMBean )instance). 149 setAttributes(attributes); 150 } catch (RuntimeOperationsException r) { 151 throw r; 152 } catch (RuntimeErrorException r) { 153 throw r; 154 } catch (RuntimeException e) { 155 debugX("setAttributes",e); 156 throw new RuntimeOperationsException(e, 157 "RuntimeException thrown by the setAttributes " + 158 "method of the Dynamic MBean"); 159 } catch (Error e) { 160 debugX("setAttributes",e); 161 throw new RuntimeErrorException((Error )e, 162 "Error thrown by the setAttributes " + 163 "method of the Dynamic MBean"); 164 } 165 } 166 167 168 public Object setAttribute(Object instance, Attribute attribute) 169 throws AttributeNotFoundException, InvalidAttributeValueException, 170 MBeanException, ReflectionException { 171 172 if (attribute == null) { 173 final RuntimeException r = 174 new IllegalArgumentException ("Attribute name cannot be null"); 175 throw new RuntimeOperationsException(r, 176 "Exception occured trying to invoke the setter on the MBean"); 177 } 178 179 try { 180 ((javax.management.DynamicMBean )instance). 181 setAttribute(attribute); 182 return attribute.getValue(); 183 } catch (RuntimeOperationsException r) { 184 throw r; 185 } catch (RuntimeErrorException r) { 186 throw r; 187 } catch (RuntimeException e) { 188 debugX("setAttribute",e); 189 throw new RuntimeMBeanException(e, 190 "RuntimeException thrown by the setAttribute " + 191 attribute + "method of the Dynamic MBean"); 192 } catch (Error e) { 193 debugX("setAttribute",e); 194 throw new RuntimeErrorException((Error )e, 195 "Error thrown by the setAttribute " + attribute + 196 "method of the Dynamic MBean"); 197 } 198 } 199 200 201 public Object invoke(Object instance, String operationName, 202 Object params[], String signature[]) 203 throws MBeanException, ReflectionException { 204 205 if (operationName == null) { 206 final RuntimeException r = 207 new IllegalArgumentException ("Operation name cannot be null"); 208 throw new RuntimeOperationsException(r, 209 "Exception occured trying to invoke the operation on the MBean"); 210 } 211 212 try { 213 return (((javax.management.DynamicMBean )instance). 214 invoke(operationName, params, signature)); 215 } catch (ReflectionException e) { 216 debugX("invoke",e); 217 throw e; 218 } catch (MBeanException e) { 219 debugX("invoke",e); 220 throw e; 221 } catch (RuntimeOperationsException r) { 222 throw r; 223 } catch (RuntimeErrorException r) { 224 throw r; 225 } catch (RuntimeException e) { 226 debugX("invoke",e); 227 throw new RuntimeMBeanException(e, "RuntimeException" + 228 " thrown by the invoke method of the Dynamic MBean"); 229 } catch (Error e) { 230 debugX("invoke",e); 231 throw new RuntimeErrorException((Error )e, "Error" + 232 " thrown by the invoke method of the Dynamic MBean"); 233 } 234 } 235 236 237 240 private static boolean isTraceOn() { 241 return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_MBEANSERVER); 242 } 243 244 private static void trace(String clz, String func, String info) { 245 Trace.send(Trace.LEVEL_TRACE, Trace.INFO_MBEANSERVER, clz, func, info); 246 } 247 248 private static void trace(String func, String info) { 249 trace(dbgTag, func, info); 250 } 251 252 private static boolean isDebugOn() { 253 return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_MBEANSERVER); 254 } 255 256 private static void debug(String clz, String func, String info) { 257 Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_MBEANSERVER, clz, func, info); 258 } 259 260 private static void debug(String func, String info) { 261 debug(dbgTag, func, info); 262 } 263 264 private static void debugX(String func,Throwable e) { 265 if (isDebugOn()) { 266 final StringWriter s = new StringWriter (); 267 e.printStackTrace(new PrintWriter (s)); 268 final String stack = s.toString(); 269 270 debug(dbgTag,func,"Exception caught in "+ func+"(): "+e); 271 debug(dbgTag,func,stack); 272 } 276 } 277 } 278 | Popular Tags |