73a58f78c12556795ea9a2c5e2b6eb4098e4f0cd.svn-base 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package xin.glue.user.common;
  2. import java.io.FileNotFoundException;
  3. import java.io.IOException;
  4. import jxl.write.WriteException;
  5. import com.posdata.glue.PosException;
  6. import com.posdata.glue.biz.activity.PosActivity;
  7. import com.posdata.glue.biz.constants.PosBizControlConstants;
  8. import com.posdata.glue.context.PosContext;
  9. import com.posdata.glue.dao.PosDaoException;
  10. /**
  11. *
  12. * @Description 错误管理
  13. * @author 梅贵平{meiguiping}
  14. * @date 2008-10-29 下午05:49:51
  15. * @JDK Version jdk1.4.2
  16. */
  17. public class PosErrorHandler extends PosActivity
  18. {
  19. public String runActivity(PosContext context)
  20. {
  21. Throwable th = context.getException();
  22. /*PosMessage errorMessage = context.getMessage();
  23. String message = "";
  24. if(errorMessage != null)
  25. {
  26. message = (String)errorMessage.get("errorMsg");
  27. }
  28. if("".equals(message))
  29. {
  30. message = "发生未知异常,请咨询管理者";
  31. }*/
  32. String msg = (String)context.get("errorMsg");
  33. String message = "发生未知异常,请咨询管理者";
  34. if(msg != null && !"".equals(msg))
  35. {
  36. message = msg;
  37. }
  38. if (th != null)
  39. {
  40. if (th instanceof PosDaoException)
  41. {
  42. message = "DB处理中发生了错误,请咨询管理者";
  43. }
  44. else if (th instanceof PosException)
  45. {
  46. message = "系统发生了错误,请咨询管理者";
  47. }
  48. else if (th instanceof FileNotFoundException)
  49. {
  50. message = "创建文件时发生了错误,请咨询管理者。\r\n一般原因是:\r\n(1)文件名命名不规范\r\n(2)文件路径不正确\r\n(3)文件正在被使用";
  51. message = message.replaceAll ( "\r", "" );
  52. message = message.replaceAll ( "\n", "\\"+System.getProperty("line.separator"));
  53. }
  54. else if (th instanceof IOException)
  55. {
  56. message = "读写文件时发生了错误,请咨询管理者";
  57. }
  58. else if (th instanceof WriteException)
  59. {
  60. message = "导出EXCEL时发生了错误,请咨询管理者";
  61. }
  62. }
  63. //new Exception("ddd");
  64. context.setException(new PosException(message));
  65. this.rollbackTransaction("tx1");
  66. return PosBizControlConstants.SUCCESS;
  67. }
  68. }