KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > core > error > OSSInvalidDataException


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: OSSInvalidDataException.java,v 1.8 2007/01/07 06:14:50 bastafidli Exp $
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21
22 package org.opensubsystems.core.error;
23
24 import org.opensubsystems.core.util.Messages;
25
26 /**
27  * Exception thrown when there was a problem with invalid data asked to be processed.
28  * Example of problems are overflow (length limit for String exceeded, range
29  * limit for int exceeded, ...) or in case of unique constrains problems (unique
30  * login name, unique file name, ...). This can occur when user enters some data,
31  * which do not satisfy the constraints set by business logic or persistence layer.
32  *
33  * @version $Id: OSSInvalidDataException.java,v 1.8 2007/01/07 06:14:50 bastafidli Exp $
34  * @author Peter Satury
35  * @code.reviewer Miro Halas
36  * @code.reviewed 1.6 2006/04/07 04:22:06 bastafidli
37  */

38 public class OSSInvalidDataException extends OSSMultiException
39 {
40    // Attributes ///////////////////////////////////////////////////////////////
41

42    /**
43     * Generated serial version id for this class.
44     */

45    private static final long serialVersionUID = 5370198119942638443L;
46
47    /**
48     * Error messages for all invalid data errors
49     */

50    protected Messages m_errorMessages;
51  
52    // Constructors /////////////////////////////////////////////////////////////
53

54    /**
55     * Create new exception
56     */

57    public OSSInvalidDataException()
58    {
59       super();
60       m_errorMessages = new Messages();
61    }
62
63    /**
64     * Create new exception
65     *
66     * @param message - message to display
67     */

68    public OSSInvalidDataException(String JavaDoc message)
69    {
70       super(message);
71       m_errorMessages = new Messages();
72       m_errorMessages.addErrorMessage(message);
73    }
74
75    /**
76     * Create new exception
77     *
78     * @param message - message to display
79     * @param cause - cause for error
80     */

81    public OSSInvalidDataException(String JavaDoc message, Throwable JavaDoc cause)
82    {
83       super(message, cause);
84       m_errorMessages = new Messages();
85       m_errorMessages.addErrorMessage(message);
86    }
87
88    /**
89     * Create new exception
90     *
91     * @param cause - cause for error
92     */

93    public OSSInvalidDataException(Throwable JavaDoc cause)
94    {
95       super(cause);
96       m_errorMessages = new Messages();
97    }
98    
99    /**
100     * @return Messages - error messages object
101     */

102    public Messages getErrorMessages()
103    {
104       return m_errorMessages;
105    }
106
107    /**
108     * @param errorMessages - Messages
109     */

110    public void setErrorMessages(Messages errorMessages)
111    {
112       m_errorMessages = errorMessages;
113    }
114
115    /**
116     * Adds message to an exiting exception or if that exception doesn't exists
117     * create a new one, add the message to it and return the newly created
118     * exception.
119     *
120     * @param inputException - exception to add message to or null if the exception
121     * doesn't exist
122     * @param messageCategory - message category to add the message to (see Messages
123     * class)
124     * @param strMessage - message to add
125     * @return OSSInvalidDataException - new created or modified exception
126     */

127    public static OSSInvalidDataException addException(
128       OSSInvalidDataException inputException,
129       Object JavaDoc messageCategory,
130       String JavaDoc strMessage
131    )
132    {
133       if (inputException == null)
134       {
135          inputException = new OSSInvalidDataException();
136       }
137       inputException.getErrorMessages().addMessage(messageCategory, strMessage);
138       return inputException;
139    }
140
141    /**
142     * Adds message to an exiting exception or if that exception doesn't exists
143     * create a new one, add the message to it and return the newly created
144     * exception.
145     *
146     * @param inputException - exception to add message to or null if the exception
147     * doesn't exist
148     * @param messageCategory - message category to add the message to (see Messages
149     * class)
150     * @param strMessage - message to add
151     * @param thr - exception which cause the error
152     * @return OSSInvalidDataException - new created or modified exception
153     */

154    public static OSSInvalidDataException addException(
155       OSSInvalidDataException inputException,
156       Object JavaDoc messageCategory,
157       String JavaDoc strMessage,
158       Throwable JavaDoc thr
159    )
160    {
161       if (inputException == null)
162       {
163          inputException = new OSSInvalidDataException(strMessage);
164       }
165       inputException.getErrorMessages().addMessage(messageCategory, strMessage);
166       inputException.add(thr);
167       return inputException;
168    }
169 }
170
Popular Tags