1 22 package org.jboss.mx.server; 23 24 import javax.management.Attribute ; 25 import javax.management.AttributeList ; 26 import javax.management.AttributeNotFoundException ; 27 import javax.management.DynamicMBean ; 28 import javax.management.InvalidAttributeValueException ; 29 import javax.management.MBeanException ; 30 import javax.management.MBeanInfo ; 31 import javax.management.MBeanRegistration ; 32 import javax.management.MBeanServer ; 33 import javax.management.NotCompliantMBeanException ; 34 import javax.management.ObjectName ; 35 import javax.management.ReflectionException ; 36 37 38 43 public class RawDynamicInvoker 44 extends AbstractMBeanInvoker 45 { 46 47 private DynamicMBean typedRes = null; 48 49 public RawDynamicInvoker(DynamicMBean resource) 50 { 51 super(resource); 52 this.typedRes = resource; 53 } 54 55 57 public void setAttribute(Attribute attribute) throws AttributeNotFoundException , 58 InvalidAttributeValueException , MBeanException , ReflectionException 59 { 60 ClassLoader mbeanTCL = resourceEntry.getClassLoader(); 61 final ClassLoader ccl = TCLAction.UTIL.getContextClassLoader(); 62 boolean setCl = ccl != mbeanTCL && mbeanTCL != null; 63 if(setCl) 64 { 65 TCLAction.UTIL.setContextClassLoader(mbeanTCL); 66 } 67 68 try 69 { 70 typedRes.setAttribute(attribute); 71 } 72 finally 73 { 74 if(setCl) 75 { 76 TCLAction.UTIL.setContextClassLoader(ccl); 77 } 78 } 79 } 80 81 public AttributeList setAttributes(AttributeList attributes) 82 { 83 ClassLoader mbeanTCL = resourceEntry.getClassLoader(); 84 final ClassLoader ccl = TCLAction.UTIL.getContextClassLoader(); 85 boolean setCl = ccl != mbeanTCL && mbeanTCL != null; 86 if(setCl) 87 { 88 TCLAction.UTIL.setContextClassLoader(mbeanTCL); 89 } 90 91 try 92 { 93 return typedRes.setAttributes(attributes); 94 } 95 finally 96 { 97 if(setCl) 98 { 99 TCLAction.UTIL.setContextClassLoader(ccl); 100 } 101 } 102 } 103 104 public Object getAttribute(String name) throws AttributeNotFoundException , 105 MBeanException , ReflectionException 106 { 107 ClassLoader mbeanTCL = resourceEntry.getClassLoader(); 108 final ClassLoader ccl = TCLAction.UTIL.getContextClassLoader(); 109 boolean setCl = ccl != mbeanTCL && mbeanTCL != null; 110 if(setCl) 111 { 112 TCLAction.UTIL.setContextClassLoader(mbeanTCL); 113 } 114 115 try 116 { 117 return typedRes.getAttribute(name); 118 } 119 finally 120 { 121 if(setCl) 122 { 123 TCLAction.UTIL.setContextClassLoader(ccl); 124 } 125 } 126 } 127 128 public AttributeList getAttributes(String [] attributes) 129 { 130 ClassLoader mbeanTCL = resourceEntry.getClassLoader(); 131 final ClassLoader ccl = TCLAction.UTIL.getContextClassLoader(); 132 boolean setCl = ccl != mbeanTCL && mbeanTCL != null; 133 if(setCl) 134 { 135 TCLAction.UTIL.setContextClassLoader(mbeanTCL); 136 } 137 138 try 139 { 140 return typedRes.getAttributes(attributes); 141 } 142 finally 143 { 144 if(setCl) 145 { 146 TCLAction.UTIL.setContextClassLoader(ccl); 147 } 148 } 149 } 150 151 public Object invoke(String name, Object [] args, String [] signature) throws 152 MBeanException , ReflectionException 153 { 154 ClassLoader mbeanTCL = resourceEntry.getClassLoader(); 155 final ClassLoader ccl = TCLAction.UTIL.getContextClassLoader(); 156 boolean setCl = ccl != mbeanTCL && mbeanTCL != null; 157 if(setCl) 158 { 159 TCLAction.UTIL.setContextClassLoader(mbeanTCL); 160 } 161 162 try 163 { 164 return typedRes.invoke(name, args, signature); 165 } 166 finally 167 { 168 if(setCl) 169 { 170 TCLAction.UTIL.setContextClassLoader(ccl); 171 } 172 } 173 } 174 175 public MBeanInfo getMBeanInfo() 176 { 177 ClassLoader mbeanTCL = resourceEntry.getClassLoader(); 178 final ClassLoader ccl = TCLAction.UTIL.getContextClassLoader(); 179 boolean setCl = ccl != mbeanTCL && mbeanTCL != null; 180 if(setCl) 181 { 182 TCLAction.UTIL.setContextClassLoader(mbeanTCL); 183 } 184 185 try 186 { 187 return typedRes.getMBeanInfo(); 188 } 189 finally 190 { 191 if(setCl) 192 { 193 TCLAction.UTIL.setContextClassLoader(ccl); 194 } 195 } 196 } 197 198 public ObjectName preRegister(MBeanServer server, ObjectName oname) throws Exception 200 { 201 this.resourceEntry = AbstractMBeanInvoker.getMBeanEntry(); 202 203 try 204 { 205 this.info = getMBeanInfo(); 206 } 207 catch (Exception e) 208 { 209 throw new NotCompliantMBeanException ("Cannot obtain MBeanInfo, for: " + oname); 210 } 211 212 ClassLoader mbeanTCL = resourceEntry.getClassLoader(); 213 final ClassLoader ccl = TCLAction.UTIL.getContextClassLoader(); 214 boolean setCl = ccl != mbeanTCL && mbeanTCL != null; 215 if(setCl) 216 { 217 TCLAction.UTIL.setContextClassLoader(mbeanTCL); 218 } 219 220 try 221 { 222 if (getResource() instanceof MBeanRegistration ) 223 return ((MBeanRegistration )getResource()).preRegister(server, oname); 224 else 225 return oname; 226 } 227 finally 228 { 229 if(setCl) 230 { 231 TCLAction.UTIL.setContextClassLoader(ccl); 232 } 233 } 234 } 235 236 public void postRegister(Boolean b) 237 { 238 ClassLoader mbeanTCL = resourceEntry.getClassLoader(); 239 final ClassLoader ccl = TCLAction.UTIL.getContextClassLoader(); 240 boolean setCl = ccl != mbeanTCL && mbeanTCL != null; 241 if(setCl) 242 { 243 TCLAction.UTIL.setContextClassLoader(mbeanTCL); 244 } 245 246 try 247 { 248 if (getResource() instanceof MBeanRegistration ) 249 ((MBeanRegistration )getResource()).postRegister(b); 250 } 251 finally 252 { 253 TCLAction.UTIL.setContextClassLoader(ccl); 254 } 255 } 256 257 public void preDeregister() throws Exception 258 { 259 ClassLoader mbeanTCL = resourceEntry.getClassLoader(); 260 final ClassLoader ccl = TCLAction.UTIL.getContextClassLoader(); 261 boolean setCl = ccl != mbeanTCL && mbeanTCL != null; 262 if(setCl) 263 { 264 TCLAction.UTIL.setContextClassLoader(mbeanTCL); 265 } 266 267 try 268 { 269 if (getResource() instanceof MBeanRegistration ) 270 ((MBeanRegistration )getResource()).preDeregister(); 271 } 272 finally 273 { 274 if(setCl) 275 { 276 TCLAction.UTIL.setContextClassLoader(ccl); 277 } 278 } 279 } 280 281 public void postDeregister() 282 { 283 ClassLoader mbeanTCL = resourceEntry.getClassLoader(); 284 final ClassLoader ccl = TCLAction.UTIL.getContextClassLoader(); 285 boolean setCl = ccl != mbeanTCL && mbeanTCL != null; 286 if(setCl) 287 { 288 TCLAction.UTIL.setContextClassLoader(mbeanTCL); 289 } 290 291 try 292 { 293 if (getResource() instanceof MBeanRegistration ) 294 ((MBeanRegistration )getResource()).postDeregister(); 295 } 296 finally 297 { 298 if(setCl) 299 { 300 TCLAction.UTIL.setContextClassLoader(ccl); 301 } 302 } 303 } 304 } 305 | Popular Tags |