1 10 11 package org.mule.config.i18n; 12 13 import java.io.Serializable ; 14 15 21 public class Message implements Serializable 22 { 23 26 private static final long serialVersionUID = -6109760447384477924L; 27 28 public static final int STATIC_ERROR_CODE = -1; 29 30 private static final transient Object [] EMPTY_ARGS = new Object []{}; 31 32 private int code = 0; 33 private Object [] args; 34 private String message; 35 private String bundle = Messages.DEFAULT_BUNDLE; 36 private Message nextMessage; 37 38 private Message(String 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 [] args) 53 { 54 this.code = code; 55 this.args = args; 56 message = Messages.get(code, args); 57 } 58 59 public Message(int code, Object arg1) 60 { 61 this.code = code; 62 if (arg1 == null) 63 { 64 arg1 = "null"; 65 } 66 args = new Object []{arg1}; 67 message = Messages.get(code, args); 68 } 69 70 public Message(int code, Object arg1, Object 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 []{arg1, arg2}; 82 message = Messages.get(code, args); 83 } 84 85 public Message(int code, Object arg1, Object arg2, Object 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 []{arg1, arg2, arg3}; 101 message = Messages.get(code, args); 102 } 103 104 public Message(String 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 bundle, int code, Object [] 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 bundle, int code, Object arg1) 121 { 122 this.code = code; 123 if (arg1 == null) 124 { 125 arg1 = "null"; 126 } 127 args = new Object []{arg1}; 128 message = Messages.get(bundle, code, args); 129 this.bundle = bundle; 130 } 131 132 public Message(String bundle, int code, Object arg1, Object 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 []{arg1, arg2}; 144 message = Messages.get(bundle, code, args); 145 this.bundle = bundle; 146 } 147 148 public Message(String bundle, int code, Object arg1, Object arg2, Object 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 []{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 [] getArgs() 174 { 175 return args; 176 } 177 178 public String 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 getBundle() 195 { 196 return bundle; 197 } 198 199 public static Message createStaticMessage(String message) 200 { 201 return new Message(message); 202 } 203 204 public String toString() 205 { 206 return getMessage(); 207 } 208 } 209 | Popular Tags |