001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id: Message.java 3823 2006-12-14 21:00:46Z elu $
023: */
024:
025: package com.bostechcorp.cbesb.common.i18n;
026:
027: import java.io.Serializable;
028:
029: /**
030: * <code>Message</code> constructs a
031: *
032: */
033: public class Message implements Serializable {
034: public static final int STATIC_ERROR_CODE = -1;
035:
036: private static final transient Object[] EMPTY_ARGS = new Object[] {};
037:
038: private int code = 0;
039: private Object[] args;
040: private String message;
041: private String bundle = Messages.DEFAULT_BUNDLE;
042: private Message nextMessage;
043:
044: private Message(String message) {
045: this .code = STATIC_ERROR_CODE;
046: args = EMPTY_ARGS;
047: this .message = message;
048: }
049:
050: public Message(int code) {
051: this .code = code;
052: args = EMPTY_ARGS;
053: message = Messages.get(code, args);
054: }
055:
056: public Message(int code, Object[] args) {
057: this .code = code;
058: this .args = args;
059: message = Messages.get(code, args);
060: }
061:
062: public Message(int code, Object arg1) {
063: this .code = code;
064: if (arg1 == null) {
065: arg1 = "null";
066: }
067: args = new Object[] { arg1 };
068: message = Messages.get(code, args);
069: }
070:
071: public Message(int code, Object arg1, Object arg2) {
072: this .code = code;
073: if (arg1 == null) {
074: arg1 = "null";
075: }
076: if (arg2 == null) {
077: arg2 = "null";
078: }
079: args = new Object[] { arg1, arg2 };
080: message = Messages.get(code, args);
081: }
082:
083: public Message(int code, Object arg1, Object arg2, Object arg3) {
084: this .code = code;
085: if (arg1 == null) {
086: arg1 = "null";
087: }
088: if (arg2 == null) {
089: arg2 = "null";
090: }
091: if (arg3 == null) {
092: arg3 = "null";
093: }
094: args = new Object[] { arg1, arg2, arg3 };
095: message = Messages.get(code, args);
096: }
097:
098: public Message(String bundle, int code) {
099: this .code = code;
100: args = EMPTY_ARGS;
101: message = Messages.get(bundle, code, args);
102: this .bundle = bundle;
103: }
104:
105: public Message(String bundle, int code, Object[] args) {
106: this .code = code;
107: this .args = args;
108: message = Messages.get(bundle, code, args);
109: this .bundle = bundle;
110: }
111:
112: public Message(String bundle, int code, Object arg1) {
113: this .code = code;
114: if (arg1 == null) {
115: arg1 = "null";
116: }
117: args = new Object[] { arg1 };
118: message = Messages.get(bundle, code, args);
119: this .bundle = bundle;
120: }
121:
122: public Message(String bundle, int code, Object arg1, Object arg2) {
123: this .code = code;
124: if (arg1 == null) {
125: arg1 = "null";
126: }
127: if (arg2 == null) {
128: arg2 = "null";
129: }
130: args = new Object[] { arg1, arg2 };
131: message = Messages.get(bundle, code, args);
132: this .bundle = bundle;
133: }
134:
135: public Message(String bundle, int code, Object arg1, Object arg2,
136: Object arg3) {
137: this .code = code;
138: if (arg1 == null) {
139: arg1 = "null";
140: }
141: if (arg2 == null) {
142: arg2 = "null";
143: }
144: if (arg3 == null) {
145: arg3 = "null";
146: }
147: args = new Object[] { arg1, arg2, arg3 };
148: message = Messages.get(bundle, code, args);
149: this .bundle = bundle;
150: }
151:
152: public int getCode() {
153: return code;
154: }
155:
156: public Object[] getArgs() {
157: return args;
158: }
159:
160: public String getMessage() {
161: return message
162: + (nextMessage != null ? ". "
163: + nextMessage.getMessage() : "");
164: }
165:
166: public Message setNextMessage(Message nextMessage) {
167: this .nextMessage = nextMessage;
168: return this ;
169: }
170:
171: public Message getNextMessage() {
172: return nextMessage;
173: }
174:
175: public String getBundle() {
176: return bundle;
177: }
178:
179: public static Message createStaticMessage(String message) {
180: return new Message(message);
181: }
182:
183: public String toString() {
184: return getMessage();
185: }
186: }
|