FileDocCategorySizeDatePackage
MBeanExceptionFormatter.javaAPI DocGlassfish v2 API4044Fri May 04 22:24:10 BST 2007com.sun.enterprise.admin.mbeans

MBeanExceptionFormatter

public final class MBeanExceptionFormatter extends Object
Helper class that formats the chained exception messages. The format of the returned message will be cause1(cause2(...)). It also initializes the cause of the MBeanException which otherwise is not initialized during MBeanException creation.

Fields Summary
Constructors Summary
Methods Summary
private static java.lang.StringformatMessage(java.lang.String a, java.lang.String b)

        final StringBuffer sb = new StringBuffer("");
        boolean isValidA = (null != a) && (a.length() > 0);
        boolean isValidB = (null != b) && (b.length() > 0);
        if (isValidA) { sb.append(a); }
        if (isValidA && isValidB) { sb.append('("); }
        if (isValidB) { sb.append(b); }
        if (isValidA && isValidB) { sb.append(')"); }
        return sb.toString();
    
public static java.lang.StringgetMessage(java.lang.Throwable t, java.lang.String cause1)

param
t
param
cause1
return
Returns the formatted message cause1(cause2(...))

        if (null == t) { return cause1; }
        final String cause = t.getMessage();
        final Throwable x = (t instanceof MBeanException) ? 
            ((MBeanException)t).getTargetException() : t.getCause();
        final String s = getMessage(x, cause);
        return formatMessage(cause1, s);
    
public static javax.management.MBeanExceptiontoMBeanException(java.lang.Exception e, java.lang.String msg)
This method returns an MBeanException instance with the message formatted as msg(msg1(msg2...)). It also inits the cause of the MBeanException.

param
e The cause.
param
msg
return
A new instance of MBeanException.

        final String s = getMessage(e, msg);
        final Exception cause = (e != null) ? e : new Exception(s);
        MBeanException mbe = new MBeanException(cause, s);
        mbe.initCause(cause);
        return mbe;