1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package com.finalist.util.genelv.exceptions;
19
20 import com.finalist.util.ejb.validation.ModelErrors;
21 import com.finalist.util.ejb.validation.ModelError;
22
23 /***
24 * This exception is thrown for all problems that occur in the EJB
25 * Container code of the application. This class defines a few
26 * typical error types to help the developer find the error
27 * cause.
28 */
29 public class BusinessLogicException extends Exception implements java.io.Serializable {
30
31 /*** The wrapped business exception */
32 private Exception wrappedBusinessException;
33 /*** The error code indicating the type of exception */
34 private String errorCode;
35 /*** The business logic validation errors */
36 ModelErrors businessLogicValidationErrors;
37
38
39 /*** Create new Business logic exception, with no wrapped business logic exception and empty ModelErrors.
40 */
41 public BusinessLogicException() {
42 super();
43 businessLogicValidationErrors = new ModelErrors();
44 }
45
46
47 /*** Create new Business logic exception, with the given ModelErrors object.
48 */
49 public BusinessLogicException(ModelErrors errors) {
50 super();
51 this.businessLogicValidationErrors = errors;
52 }
53
54
55 /*** Create new Business logic exception, with an empty ModelErrors object, and the given exception to be wrapped.
56 */
57 public BusinessLogicException(Exception exception) {
58 this();
59 this.wrappedBusinessException = exception;
60 this.errorCode = ExceptionUtil.determineErrorCode(exception);
61 }
62
63
64 /*** Create new Business logic exception, with the given ModelErrors object, and exception to be wrapped.
65 */
66 public BusinessLogicException(ModelErrors errors, Exception exception) {
67 this(errors);
68 this.wrappedBusinessException = exception;
69 this.errorCode = ExceptionUtil.determineErrorCode(exception);
70 }
71
72
73
74
75 /*** Retrieve all business logic errors. */
76 public ModelErrors getBusinessLogicErrors() {
77 return this.businessLogicValidationErrors;
78 }
79
80
81 /*** Add a general business logic error to <code>ModelErrors.GENERAL_ERROR</code>. */
82 public void addBusinessLogicError(ModelError error) {
83 this.businessLogicValidationErrors.add(ModelErrors.GLOBAL_ERROR, error);
84 }
85
86
87 /*** Add a business logic error for the given property. */
88 public void addBusinessLogicError(String property, ModelError error) {
89 this.businessLogicValidationErrors.add(property, error);
90 }
91
92
93
94 /*** Get the ApplicationResource (action) error key indicating the cause of the (wrapped EJB) exception. */
95 public String getErrorCode() {
96 return errorCode;
97 }
98
99
100 /*** Set the ApplicationResource (action) error key indicating the cause of the (wrapped EJB) exception. */
101 public void setErrorCode(String errorCode) {
102 this.errorCode = errorCode;
103 }
104
105 }