1 23 24 package com.sun.enterprise.admin.common; 25 26 import javax.management.ObjectName ; 28 import javax.management.MalformedObjectNameException ; 29 30 import com.sun.enterprise.admin.util.ArgChecker; 31 import com.sun.enterprise.admin.common.exception.*; 32 import com.sun.enterprise.admin.common.ObjectNameHelper; 33 34 public class JMXExceptionTranslator 35 { 36 private static final String NULL_ARGUMENT = "null-arg"; 37 38 public static AFException translate(Exception e) 39 { 40 ArgChecker.check((e != null), NULL_ARGUMENT); 41 42 AFException afe = new AFException(e.getMessage()); 43 if (e instanceof javax.management.MBeanException ) 44 { 45 Exception targetException = 46 ((javax.management.MBeanException )e).getTargetException(); 47 if (targetException instanceof AFException) 48 { 49 afe = (AFException) targetException; 50 } 51 else if(targetException instanceof AFRuntimeException) 53 { 54 throw (AFRuntimeException)targetException; 55 } 56 else if (targetException instanceof javax.management.MBeanException ) 57 { 58 Exception excpn = 59 ((javax.management.MBeanException )targetException).getTargetException(); 60 if (excpn != null) { 61 if (excpn instanceof javax.management.InvalidAttributeValueException ) { 62 afe = new com.sun.enterprise.admin.common.exception.InvalidAttributeValueException( 63 excpn.getLocalizedMessage()); 64 } 65 } 66 } 67 else 69 { 70 afe = new AFOtherException(targetException); 71 } 72 } 73 else if (e instanceof javax.management.InstanceNotFoundException ) 74 { 75 String msg = convertInstanceNotFoundExceptionMessage(e); 76 afe = new AFTargetNotFoundException(msg); 77 } 78 else if (e instanceof javax.management.ReflectionException ) 79 { 80 afe = new AFOtherException(e); 81 } 82 else if (e instanceof javax.management.AttributeNotFoundException ) 83 { 84 afe = new AttributeNotFoundException(e.getLocalizedMessage()); 85 } 86 else if (e instanceof javax.management.InvalidAttributeValueException ) 87 { 88 afe = new InvalidAttributeValueException(e.getLocalizedMessage()); 89 } 90 else if (e instanceof java.lang.RuntimeException ) 91 { 92 throw (java.lang.RuntimeException ) e; 93 } 94 return afe; 95 } 96 97 private static String convertInstanceNotFoundExceptionMessage(Exception e) 98 { 99 101 String type = null; 102 String name = null; 103 try 104 { 105 ObjectName objectName = new ObjectName (e.getMessage()); 106 type = ObjectNameHelper.getType(objectName); 107 name = ObjectNameHelper.getName(objectName); 108 } 109 catch (MalformedObjectNameException mfone) 110 { 111 } 112 String msg; 113 if(type!=null) 114 { 115 if(name!=null) 116 msg = type + " '" + name +"' is not found."; 117 else 118 msg = type + " is not found."; 119 } 120 else 121 { 122 msg = e.getLocalizedMessage(); 124 } 125 return msg; 126 } 127 } 128 | Popular Tags |