KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > error > BasicError


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.error;
8
9
10 import java.io.Serializable JavaDoc;
11 import java.text.MessageFormat JavaDoc;
12 import java.util.Locale JavaDoc;
13
14
15 /**
16  * This class is a simple JavaBean that holds onto an error.
17  *
18  * @author Brian Pontarelli
19  */

20 public class BasicError implements Serializable JavaDoc {
21
22     private String JavaDoc message;
23     private Locale JavaDoc locale;
24
25
26     /**
27      * Constructs an empty error
28      */

29     public BasicError() {
30         // Default constructor
31
}
32
33     /**
34      * Constructs an error with the given message
35      *
36      * @param msg The message of the error
37      */

38     public BasicError(String JavaDoc msg) {
39         setMessage(msg);
40     }
41
42     /**
43      * Constructs an error with the given message and Locale, which can be used
44      * to decode the String contents.
45      *
46      * @param msg The message of the error
47      * @param locale (Optional) The Locale of the message
48      */

49     public BasicError(String JavaDoc msg, Locale JavaDoc locale) {
50         setMessage(msg);
51         this.locale = locale;
52     }
53
54     /**
55      * Constructs an error with the given parameterized error and list of parameters.
56      * This should conform to the java.text.MessageFormat classes specification for
57      * parameterized strings.
58      *
59      * @param msg The parameterized string message
60      * @param params The parameters to the string message
61      */

62     public BasicError(String JavaDoc msg, Object JavaDoc [] params) {
63         setMessage(MessageFormat.format(msg, params));
64     }
65
66     /**
67      * Constructs an error with the given parameterized error and list of
68      * parameters. This should conform to the java.text.MessageFormat classes
69      * specification for parameterized strings. This also takes a Locale, which
70      * can be used to decode the String contents.
71      *
72      * @param msg The parameterized string message
73      * @param params The parameters to the string message
74      * @param locale (Optional) The Locale of the message
75      */

76     public BasicError(String JavaDoc msg, Object JavaDoc [] params, Locale JavaDoc locale) {
77         setMessage(MessageFormat.format(msg, params));
78         this.locale = locale;
79     }
80
81
82     /**
83      * Gets the message of the error
84      *
85      * @return The message of the error
86      */

87     public String JavaDoc getMessage() {
88         return message;
89     }
90
91     /**
92      * Gets the Locale of the error or null if the Locale is the default Locale
93      *
94      * @return The Locale of the error
95      */

96     public Locale JavaDoc getLocale() {
97         return locale;
98     }
99
100     /**
101      * Sets The message of the error
102      *
103      * @param message The message of the error
104      * @throws IllegalArgumentException If the message given is null or empty
105      */

106     public void setMessage(String JavaDoc message) {
107         this.message = message;
108     }
109
110     /**
111      * Returns the message associated with this error
112      */

113     public String JavaDoc toString() {
114         return message;
115     }
116 }
Popular Tags