1 23 24 29 30 33 34 package com.sun.enterprise.admin.jmx.remote.internal; 35 36 import javax.management.*; 37 import java.io.IOException ; 38 import java.io.NotSerializableException ; 39 40 59 60 public class MBeanServerConnectionExceptionThrower { 61 62 63 private MBeanServerConnectionExceptionThrower() { 64 } 65 66 public static void addNotificationListenerObjectName(Exception e) throws 67 InstanceNotFoundException, IOException { 68 if (e instanceof InstanceNotFoundException) 69 throw (InstanceNotFoundException)e; 70 else if (e instanceof RuntimeException ) 71 throw (RuntimeException )e; 72 else if (e instanceof NotSerializableException ) 73 throw wrappedSerializationException(e); 74 else 75 throw wrappingIoException(e); 76 } 77 78 public static void addNotificationListeners(Exception e) throws 79 InstanceNotFoundException, IOException { 80 addNotificationListenerObjectName(e); 81 } 82 83 public static void createMBean(Exception e) throws ReflectionException, 84 InstanceAlreadyExistsException, MBeanRegistrationException, 85 MBeanException, NotCompliantMBeanException, IOException { 86 if (e instanceof ReflectionException) 87 throw (ReflectionException)e; 88 else if (e instanceof InstanceAlreadyExistsException) 89 throw (InstanceAlreadyExistsException)e; 90 else if (e instanceof MBeanRegistrationException) 91 throw (MBeanRegistrationException)e; 92 else if (e instanceof MBeanException) 93 throw (MBeanException)e; 94 else if (e instanceof NotCompliantMBeanException) 95 throw (NotCompliantMBeanException)e; 96 else if (e instanceof RuntimeException ) 97 throw (RuntimeException )e; 98 else if (e instanceof NotSerializableException ) 99 throw wrappedSerializationException(e); 100 else 101 throw wrappingIoException(e); 102 } 103 104 public static void createMBeanParams(Exception e) throws ReflectionException, 105 InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, 106 NotCompliantMBeanException, IOException { 107 createMBean(e); } 109 110 public static void createMBeanLoader(Exception e) throws ReflectionException, 111 InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, 112 NotCompliantMBeanException, InstanceNotFoundException, IOException { 113 if (e instanceof ReflectionException) 114 throw (ReflectionException)e; 115 else if (e instanceof InstanceAlreadyExistsException) 116 throw (InstanceAlreadyExistsException)e; 117 else if (e instanceof MBeanRegistrationException) 118 throw (MBeanRegistrationException)e; 119 else if (e instanceof MBeanException) 120 throw (MBeanException)e; 121 else if (e instanceof NotCompliantMBeanException) 122 throw (NotCompliantMBeanException)e; 123 else if (e instanceof InstanceNotFoundException) 124 throw (InstanceNotFoundException)e; 125 else if (e instanceof RuntimeException ) 126 throw (RuntimeException )e; 127 else if (e instanceof NotSerializableException ) 128 throw wrappedSerializationException(e); 129 else 130 throw wrappingIoException(e); 131 } 132 133 public static void createMBeanLoaderParams(Exception e) throws ReflectionException, 134 InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, 135 NotCompliantMBeanException, InstanceNotFoundException, IOException { 136 createMBeanLoader(e); } 138 139 public static void getAttribute(Exception e) throws 140 MBeanException, AttributeNotFoundException, InstanceNotFoundException, 141 ReflectionException, IOException { 142 if (e instanceof MBeanException) 143 throw (MBeanException)e; 144 else if (e instanceof AttributeNotFoundException) 145 throw (AttributeNotFoundException)e; 146 else if (e instanceof InstanceNotFoundException) 147 throw (InstanceNotFoundException)e; 148 else if (e instanceof ReflectionException) 149 throw (ReflectionException)e; 150 else if (e instanceof RuntimeException ) 151 throw (RuntimeException )e; 152 else if (e instanceof NotSerializableException ) 153 throw wrappedSerializationException(e); 154 else throw wrappingIoException(e); 156 } 157 158 public static void getAttributes(Exception e) throws 159 InstanceNotFoundException, ReflectionException, IOException { 160 if (e instanceof InstanceNotFoundException) 161 throw (InstanceNotFoundException)e; 162 else if (e instanceof ReflectionException) 163 throw (ReflectionException)e; 164 else if (e instanceof RuntimeException ) 165 throw (RuntimeException )e; 166 else if (e instanceof NotSerializableException ) 167 throw wrappedSerializationException(e); 168 else 169 throw wrappingIoException(e); 170 } 171 172 private static void getIOException(Exception e) throws IOException { 173 throw wrappingIoException(e); } 175 176 public static void getDefaultDomain(Exception e) throws IOException { 177 getIOException(e); } 179 public static void getDomains(Exception e) throws IOException { 180 getIOException(e); } 182 public static void getMBeanCount(Exception e) throws IOException { 183 getIOException(e); } 185 public static void isRegistered(Exception e) throws IOException { 186 getIOException(e); } 188 189 public static void getMBeanInfo(Exception e) throws 190 InstanceNotFoundException, IntrospectionException, ReflectionException, IOException { 191 if (e instanceof InstanceNotFoundException) 192 throw (InstanceNotFoundException)e; 193 else if (e instanceof IntrospectionException) 194 throw (IntrospectionException)e; 195 else if (e instanceof ReflectionException) 196 throw (ReflectionException)e; 197 else if (e instanceof RuntimeException ) 198 throw (RuntimeException )e; 199 else if (e instanceof NotSerializableException ) 200 throw wrappedSerializationException(e); 201 else 202 throw wrappingIoException(e); 203 } 204 205 public static void getObjectInstance(Exception e) throws 206 InstanceNotFoundException, IOException { 207 if (e instanceof InstanceNotFoundException) 208 throw (InstanceNotFoundException)e; 209 else if (e instanceof RuntimeException ) 210 throw (RuntimeException )e; 211 else if (e instanceof NotSerializableException ) 212 throw wrappedSerializationException(e); 213 else 214 throw wrappingIoException(e); 215 } 216 217 public static void invoke(Exception e) throws InstanceNotFoundException, 218 MBeanException, ReflectionException, IOException { 219 if (e instanceof InstanceNotFoundException) 220 throw (InstanceNotFoundException)e; 221 else if (e instanceof MBeanException) 222 throw (MBeanException)e; 223 else if (e instanceof ReflectionException) 224 throw (ReflectionException)e; 225 else if (e instanceof RuntimeException ) 226 throw (RuntimeException )e; 227 else if (e instanceof NotSerializableException ) 228 throw wrappedSerializationException(e); 229 else throw wrappingIoException(e); 231 } 232 233 public static void isInstanceOf(Exception e) throws 234 InstanceNotFoundException, IOException { 235 if (e instanceof InstanceNotFoundException) 236 throw (InstanceNotFoundException)e; 237 else if (e instanceof RuntimeException ) 238 throw (RuntimeException )e; 239 else if (e instanceof NotSerializableException ) 240 throw wrappedSerializationException(e); 241 else 242 throw wrappingIoException(e); 243 } 244 245 public static void queryMBeans(Exception e) throws IOException { 246 if (e instanceof NotSerializableException ) 247 throw wrappedSerializationException(e); 248 getIOException(e); } 250 251 public static void queryNames(Exception e) throws IOException { 252 if (e instanceof NotSerializableException ) 253 throw wrappedSerializationException(e); 254 getIOException(e); } 256 257 public static void removeNotificationListener(Exception e) throws 258 InstanceNotFoundException, ListenerNotFoundException, IOException { 259 if (e instanceof InstanceNotFoundException) 260 throw (InstanceNotFoundException)e; 261 else if (e instanceof ListenerNotFoundException) 262 throw (ListenerNotFoundException)e; 263 else if (e instanceof RuntimeException ) 264 throw (RuntimeException )e; 265 else if (e instanceof NotSerializableException ) 266 throw wrappedSerializationException(e); 267 else 268 throw wrappingIoException(e); 269 } 270 271 public static void removeNotificationListenerFilterHandback(Exception e) throws 272 InstanceNotFoundException, ListenerNotFoundException, IOException { 273 removeNotificationListener(e); 274 } 275 276 public static void removeNotificationListenerObjectName(Exception e) throws 277 InstanceNotFoundException, ListenerNotFoundException, IOException { 278 removeNotificationListener(e); 279 } 280 281 public static void removeNotificationListenerObjectNameFilterHandback(Exception e) throws 282 InstanceNotFoundException, ListenerNotFoundException, IOException { 283 removeNotificationListener(e); 284 } 285 286 public static void setAttribute(Exception e) throws InstanceNotFoundException, 287 AttributeNotFoundException, InvalidAttributeValueException, MBeanException, 288 ReflectionException, IOException { 289 if (e instanceof AttributeNotFoundException) 290 throw (AttributeNotFoundException)e; 291 else if (e instanceof InstanceNotFoundException) 292 throw (InstanceNotFoundException)e; 293 else if (e instanceof InvalidAttributeValueException) 294 throw (InvalidAttributeValueException)e; 295 else if (e instanceof MBeanException) 296 throw (MBeanException)e; 297 else if (e instanceof RuntimeException ) 298 throw (RuntimeException )e; 299 else if (e instanceof NotSerializableException ) 300 throw wrappedSerializationException(e); 301 else 302 throw wrappingIoException(e); 303 } 304 305 public static void setAttributes(Exception e) throws InstanceNotFoundException, 306 ReflectionException, IOException { 307 if (e instanceof InstanceNotFoundException) 308 throw (InstanceNotFoundException)e; 309 else if (e instanceof ReflectionException) 310 throw (ReflectionException)e; 311 else if (e instanceof RuntimeException ) 312 throw (RuntimeException )e; 313 else if (e instanceof NotSerializableException ) 314 throw wrappedSerializationException(e); 315 else 316 throw wrappingIoException(e); 317 } 318 319 public static void unregisterMBean(Exception e) throws 320 InstanceNotFoundException, MBeanRegistrationException, IOException { 321 if (e instanceof InstanceNotFoundException) 322 throw (InstanceNotFoundException)e; 323 else if (e instanceof MBeanRegistrationException) 324 throw (MBeanRegistrationException)e; 325 else if (e instanceof RuntimeException ) 326 throw (RuntimeException )e; 327 else if (e instanceof NotSerializableException ) 328 throw wrappedSerializationException(e); 329 else 330 throw wrappingIoException(e); 331 } 332 333 344 private static IOException wrappingIoException(final Throwable t) { 345 final String dm = t.getMessage(); 346 final Throwable cause = t.getCause(); 347 final StackTraceElement [] st = t.getStackTrace(); 348 final IOException ioe = new IOException (dm); 349 if (cause != null) { 350 ioe.initCause(cause); 351 } 352 if (st != null) { 353 ioe.setStackTrace(st); 354 } 355 return ( ioe ); 356 } 357 358 372 373 private static RuntimeException wrappedSerializationException(Exception e) { 374 final String dm = e.getMessage(); 375 final Throwable cause = e.getCause(); 376 final StackTraceElement [] st = e.getStackTrace(); 377 final RuntimeException re = new RuntimeException (dm); 378 if (cause != null) { 379 re.initCause(cause); 380 } 381 if (st != null) { 382 re.setStackTrace(st); 383 } 384 return ( re ); 385 } 386 } | Popular Tags |