1 23 24 27 28 package com.sun.enterprise.admin.mbeans; 29 30 import javax.management.MBeanException ; 31 32 38 public final class MBeanExceptionFormatter 39 { 40 47 public static MBeanException toMBeanException( final Exception e, 48 final String msg ) 49 { 50 final String s = getMessage(e, msg); 51 final Exception cause = (e != null) ? e : new Exception (s); 52 MBeanException mbe = new MBeanException (cause, s); 53 mbe.initCause(cause); 54 return mbe; 55 } 56 57 62 public static String getMessage(final Throwable t, final String cause1) 63 { 64 if (null == t) { return cause1; } 65 final String cause = t.getMessage(); 66 final Throwable x = (t instanceof MBeanException ) ? 67 ((MBeanException )t).getTargetException() : t.getCause(); 68 final String s = getMessage(x, cause); 69 return formatMessage(cause1, s); 70 } 71 72 private static String formatMessage(String a, String b) 73 { 74 final StringBuffer sb = new StringBuffer (""); 75 boolean isValidA = (null != a) && (a.length() > 0); 76 boolean isValidB = (null != b) && (b.length() > 0); 77 if (isValidA) { sb.append(a); } 78 if (isValidA && isValidB) { sb.append('('); } 79 if (isValidB) { sb.append(b); } 80 if (isValidA && isValidB) { sb.append(')'); } 81 return sb.toString(); 82 } 83 } 84 | Popular Tags |