1 /**
2 This file is part of GoldenGate Project (named also GoldenGate or GG).
3
4 Copyright 2009, Frederic Bregier, and individual contributors by the @author
5 tags. See the COPYRIGHT.txt in the distribution for a full listing of
6 individual contributors.
7
8 All GoldenGate Project is free software: you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as published
10 by the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 GoldenGate is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GoldenGate . If not, see <http://www.gnu.org/licenses/>.
20 */
21 package openr66.context;
22
23 /**
24 * This enum class keeps all code that will be returned into the result
25 * and store (char representation) into the runner.
26 *
27 * @author Frederic Bregier
28 *
29 */
30 public enum ErrorCode {
31 /**
32 * Code stands for initialization ok (internal connection, authentication)
33 */
34 InitOk("Initialization step ok", 'i'),
35 /**
36 * Code stands for pre processing ok
37 */
38 PreProcessingOk(
39 "PreProcessing step ok",
40 'B'),
41 /**
42 * Code stands for transfer OK
43 */
44 TransferOk("Transfer step ok", 'X'),
45 /**
46 * Code stands for post processing ok
47 */
48 PostProcessingOk(
49 "PostProcessing step ok",
50 'P'),
51 /**
52 * Code stands for All action are completed ok
53 */
54 CompleteOk("Operation completed", 'O'),
55 /**
56 * Code stands for connection is impossible (remote or local reason)
57 */
58 ConnectionImpossible(
59 "Connection Impossible",
60 'C'),
61 /**
62 * Code stands for connection is impossible now due to limits(remote or local reason)
63 */
64 ServerOverloaded(
65 "Connection delayed due to exceed of capacity",
66 'l'),
67 /**
68 * Code stands for bad authentication (remote or local)
69 */
70 BadAuthent("Bad Authentication", 'A'),
71 /**
72 * Code stands for External operation in error (pre, post or error processing)
73 */
74 ExternalOp(
75 "External Operation as Task in error",
76 'E'),
77 /**
78 * Code stands for Transfer is in error
79 */
80 TransferError("Bad Transfer", 'T'),
81 /**
82 * Code stands for Transfer in error due to MD5
83 */
84 MD5Error(
85 "MD5 during transfer in error",
86 'M'),
87 /**
88 * Code stands for Network disconnection
89 */
90 Disconnection("Disconnection before end", 'D'),
91 /**
92 * Code stands for Remote Shutdown
93 */
94 RemoteShutdown("Disconnection before end due to a remote shutdown", 'r'),
95 /**
96 * Code stands for final action (like moving file) is in error
97 */
98 FinalOp(
99 "Final Operation on the result file in error",
100 'F'),
101 /**
102 * Code stands for unimplemented feature
103 */
104 Unimplemented("Function not implemented", 'U'),
105 /**
106 * Code stands for shutdown is in progress
107 */
108 Shutdown(
109 "Shutdown order",
110 'S'),
111 /**
112 * Code stands for a remote error is received
113 */
114 RemoteError("Error due to remote", 'R'),
115 /**
116 * Code stands for an internal error
117 */
118 Internal(
119 "Internal Error",
120 'I'),
121 /**
122 * Code stands for a request of stopping transfer
123 */
124 StoppedTransfer("Stopped Transfer", 'H'),
125 /**
126 * Code stands for a request of canceling transfer
127 */
128 CanceledTransfer("Canceled Transfer", 'K'),
129 /**
130 * Warning in execution
131 */
132 Warning("Warning during pre or post execution", 'W'),
133 /**
134 * Code stands for unknown type of error
135 */
136 Unknown("Unknown status", '-'),
137 /**
138 * Code stands for a request that is already remotely finished
139 */
140 QueryAlreadyFinished("Restart Query for a transfer already finished", 'Q'),
141 /**
142 * Code stands for request that is still running
143 */
144 QueryStillRunning("Restart Query for a transfer still running", 's'),
145 /**
146 * Code stands for not known host
147 */
148 NotKnownHost("Not known remote host", 'N'),
149 /**
150 * Code stands for self requested host starting request is invalid
151 */
152 LoopSelfRequestedHost("Host tries to start a self requested transfer", 'N'),
153 /**
154 * Code stands for request should exist but is not found on remote host
155 */
156 QueryRemotelyUnknown("Not known remote asked query", 'u'),
157 /**
158 * Code stands for File not found error
159 */
160 FileNotFound("File not found", 'f'),
161 /**
162 * Code stands for Command not found error
163 */
164 CommandNotFound("Command not found", 'c'),
165 /**
166 * Code stands for a request in PassThroughMode and required action is incompatible with this mode
167 */
168 PassThroughMode("Error since action cannot be taken on PassThroughMode", 'p'),
169 /**
170 * Code stands for running step
171 */
172 Running("Current step in running", 'z');
173
174 /**
175 * Literal for this code
176 */
177 public String mesg;
178 /**
179 * Code could be used to switch case operations
180 */
181 public char code;
182
183 private ErrorCode(String mesg, char code) {
184 this.mesg = mesg;
185 this.code = code;
186 }
187
188 public String getCode() {
189 return String.valueOf(code);
190 }
191 /**
192 * Code is either the 1 char code or the exact name in Enum
193 * @param code
194 * @return the ErrorCode according to the code
195 */
196 public static ErrorCode getFromCode(String code) {
197 switch (code.charAt(0)) {
198 case 'i':
199 return InitOk;
200 case 'B':
201 return PreProcessingOk;
202 case 'P':
203 return PostProcessingOk;
204 case 'X':
205 return TransferOk;
206 case 'O':
207 return CompleteOk;
208 case 'C':
209 return ConnectionImpossible;
210 case 'A':
211 return BadAuthent;
212 case 'E':
213 return ExternalOp;
214 case 'T':
215 return TransferError;
216 case 'M':
217 return MD5Error;
218 case 'D':
219 return Disconnection;
220 case 'r':
221 return RemoteShutdown;
222 case 'F':
223 return FinalOp;
224 case 'U':
225 return Unimplemented;
226 case 'S':
227 return Shutdown;
228 case 'R':
229 return RemoteError;
230 case 'I':
231 return Internal;
232 case 'H':
233 return StoppedTransfer;
234 case 'K':
235 return CanceledTransfer;
236 case 'W':
237 return Warning;
238 case '-':
239 return Unknown;
240 case 'Q':
241 return QueryAlreadyFinished;
242 case 's':
243 return QueryStillRunning;
244 case 'N':
245 return NotKnownHost;
246 case 'L':
247 return LoopSelfRequestedHost;
248 case 'u':
249 return QueryRemotelyUnknown;
250 case 'f':
251 return FileNotFound;
252 case 'z':
253 return Running;
254 case 'c':
255 return CommandNotFound;
256 case 'p':
257 return PassThroughMode;
258 case 'l':
259 return ServerOverloaded;
260 default:
261 ErrorCode ecode = Unknown;
262 try {
263 ecode = ErrorCode.valueOf(code.trim());
264 } catch (IllegalArgumentException e) {
265 return Unknown;
266 }
267 return ecode;
268 }
269 }
270 }