View Javadoc

1   /*   Copyright (C) 2004 Finalist IT Group
2    *
3    *   This file is part of JAG - the Java J2EE Application Generator
4    *
5    *   JAG is free software; you can redistribute it and/or modify
6    *   it under the terms of the GNU General Public License as published by
7    *   the Free Software Foundation; either version 2 of the License, or
8    *   (at your option) any later version.
9    *   JAG is distributed in the hope that it will be useful,
10   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   *   GNU General Public License for more details.
13   *   You should have received a copy of the GNU General Public License
14   *   along with JAG; if not, write to the Free Software
15   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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     // ################## CONSTRUCTORS ##################
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     // ################## MEMBERS ##################
73  
74     // logic errors
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     // wrapped exception
93     // // error code
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 }