private PersistenceBrokerException createException ( final Exception ex , String message , final Object objectToIdentify , Class topLevelClass , Class realClass , Object [ ] pks ) { final String eol = SystemUtils . LINE_SEPARATOR ; StringBuffer msg = new StringBuffer ( ) ; if ( message == null ) { msg . append ( "Unexpected error: " ) ; } else { msg . append ( message ) . append ( " :" ) ; } if ( topLevelClass != null ) msg . append ( eol ) . append ( "objectTopLevelClass=" ) . append ( topLevelClass . getName ( ) ) ; if ( realClass != null ) msg . append ( eol ) . append ( "objectRealClass=" ) . append ( realClass . getName ( ) ) ; if ( pks != null ) msg . append ( eol ) . append ( "pkValues=" ) . append ( ArrayUtils . toString ( pks ) ) ; if ( objectToIdentify != null ) msg . append ( eol ) . append ( "object to identify: " ) . append ( objectToIdentify ) ; if ( ex != null ) { // add causing stack trace Throwable rootCause = ExceptionUtils . getRootCause ( ex ) ; if ( rootCause != null ) { msg . append ( eol ) . append ( "The root stack trace is --> " ) ; String rootStack = ExceptionUtils . getStackTrace ( rootCause ) ; msg . append ( eol ) . append ( rootStack ) ; } return new PersistenceBrokerException ( msg . toString ( ) , ex ) ; } else { return new PersistenceBrokerException ( msg . toString ( ) ) ; } }
Helper method which supports creation of proper error messages .