KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > config > i18n > Message


1 /*
2  * $Id: Message.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.config.i18n;
12
13 import java.io.Serializable JavaDoc;
14
15 /**
16  * <code>Message</code> constructs a
17  *
18  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
19  * @version $Revision: 3798 $
20  */

21 public class Message implements Serializable JavaDoc
22 {
23     /**
24      * Serial version
25      */

26     private static final long serialVersionUID = -6109760447384477924L;
27
28     public static final int STATIC_ERROR_CODE = -1;
29
30     private static final transient Object JavaDoc[] EMPTY_ARGS = new Object JavaDoc[]{};
31
32     private int code = 0;
33     private Object JavaDoc[] args;
34     private String JavaDoc message;
35     private String JavaDoc bundle = Messages.DEFAULT_BUNDLE;
36     private Message nextMessage;
37
38     private Message(String JavaDoc message)
39     {
40         this.code = STATIC_ERROR_CODE;
41         args = EMPTY_ARGS;
42         this.message = message;
43     }
44
45     public Message(int code)
46     {
47         this.code = code;
48         args = EMPTY_ARGS;
49         message = Messages.get(code, args);
50     }
51
52     public Message(int code, Object JavaDoc[] args)
53     {
54         this.code = code;
55         this.args = args;
56         message = Messages.get(code, args);
57     }
58
59     public Message(int code, Object JavaDoc arg1)
60     {
61         this.code = code;
62         if (arg1 == null)
63         {
64             arg1 = "null";
65         }
66         args = new Object JavaDoc[]{arg1};
67         message = Messages.get(code, args);
68     }
69
70     public Message(int code, Object JavaDoc arg1, Object JavaDoc arg2)
71     {
72         this.code = code;
73         if (arg1 == null)
74         {
75             arg1 = "null";
76         }
77         if (arg2 == null)
78         {
79             arg2 = "null";
80         }
81         args = new Object JavaDoc[]{arg1, arg2};
82         message = Messages.get(code, args);
83     }
84
85     public Message(int code, Object JavaDoc arg1, Object JavaDoc arg2, Object JavaDoc arg3)
86     {
87         this.code = code;
88         if (arg1 == null)
89         {
90             arg1 = "null";
91         }
92         if (arg2 == null)
93         {
94             arg2 = "null";
95         }
96         if (arg3 == null)
97         {
98             arg3 = "null";
99         }
100         args = new Object JavaDoc[]{arg1, arg2, arg3};
101         message = Messages.get(code, args);
102     }
103
104     public Message(String JavaDoc bundle, int code)
105     {
106         this.code = code;
107         args = EMPTY_ARGS;
108         message = Messages.get(bundle, code, args);
109         this.bundle = bundle;
110     }
111
112     public Message(String JavaDoc bundle, int code, Object JavaDoc[] args)
113     {
114         this.code = code;
115         this.args = args;
116         message = Messages.get(bundle, code, args);
117         this.bundle = bundle;
118     }
119
120     public Message(String JavaDoc bundle, int code, Object JavaDoc arg1)
121     {
122         this.code = code;
123         if (arg1 == null)
124         {
125             arg1 = "null";
126         }
127         args = new Object JavaDoc[]{arg1};
128         message = Messages.get(bundle, code, args);
129         this.bundle = bundle;
130     }
131
132     public Message(String JavaDoc bundle, int code, Object JavaDoc arg1, Object JavaDoc arg2)
133     {
134         this.code = code;
135         if (arg1 == null)
136         {
137             arg1 = "null";
138         }
139         if (arg2 == null)
140         {
141             arg2 = "null";
142         }
143         args = new Object JavaDoc[]{arg1, arg2};
144         message = Messages.get(bundle, code, args);
145         this.bundle = bundle;
146     }
147
148     public Message(String JavaDoc bundle, int code, Object JavaDoc arg1, Object JavaDoc arg2, Object JavaDoc arg3)
149     {
150         this.code = code;
151         if (arg1 == null)
152         {
153             arg1 = "null";
154         }
155         if (arg2 == null)
156         {
157             arg2 = "null";
158         }
159         if (arg3 == null)
160         {
161             arg3 = "null";
162         }
163         args = new Object JavaDoc[]{arg1, arg2, arg3};
164         message = Messages.get(bundle, code, args);
165         this.bundle = bundle;
166     }
167
168     public int getCode()
169     {
170         return code;
171     }
172
173     public Object JavaDoc[] getArgs()
174     {
175         return args;
176     }
177
178     public String JavaDoc getMessage()
179     {
180         return message + (nextMessage != null ? ". " + nextMessage.getMessage() : "");
181     }
182
183     public Message setNextMessage(Message nextMessage)
184     {
185         this.nextMessage = nextMessage;
186         return this;
187     }
188
189     public Message getNextMessage()
190     {
191         return nextMessage;
192     }
193
194     public String JavaDoc getBundle()
195     {
196         return bundle;
197     }
198
199     public static Message createStaticMessage(String JavaDoc message)
200     {
201         return new Message(message);
202     }
203
204     public String JavaDoc toString()
205     {
206         return getMessage();
207     }
208 }
209
Popular Tags