1 21 package oracle.toplink.essentials.internal.ejb.cmp3.base; 23 24 import java.io.StringWriter ; 25 import java.io.PrintWriter ; 26 import java.sql.SQLException ; 27 import javax.transaction.SystemException ; 28 import javax.transaction.RollbackException ; 29 30 public class ExceptionFactory { 31 public ExceptionFactory() { 32 } 33 34 protected String stackTraceString(Exception ex) { 35 StringWriter swriter = new StringWriter (); 36 PrintWriter writer = new PrintWriter (swriter, true); 37 ex.printStackTrace(writer); 38 writer.close(); 39 return swriter.toString(); 40 } 41 42 public SystemException newSystemException(String str) { 43 return new SystemException (str); 44 } 45 46 public SystemException newSystemException(Exception ex) { 47 return new SystemException ("Real nested exception: " + stackTraceString(ex)); 48 } 49 50 public RollbackException rollbackException(SQLException sqlEx) { 51 return new RollbackException (sqlEx.toString()); 52 } 53 54 public SystemException txMarkedForRollbackException() { 55 return newSystemException("Transaction marked for rollback"); 56 } 57 58 public SystemException txActiveException() { 59 return newSystemException("Transaction is already active"); 60 } 61 62 public SystemException txNotActiveException() { 63 return newSystemException("No transaction is active"); 64 } 65 66 public SystemException invalidStateException(int state) { 67 return newSystemException("Cannot complete operation, invalid state: " + state); 68 } 69 } 70 | Popular Tags |