1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package eteg.sinon.executor;
24
25 /***
26 * Class that represents the different type of actions to be taken
27 * after the handling of an error by method
28 * {@link eteg.sinon.listener.ErrorListener#onError}.
29 *
30 * @author <a href="mailto:thiagohp at users.sourceforge.net">Thiago H. de Paula Figueiredo</a>
31 * @author Last modified by $Author: thiagohp $
32 * @version $Revision: 1.2 $
33 * @since 0.0
34 * @see eteg.sinon.listener.ErrorListener
35 * @see eteg.sinon.listener.ErrorListener#onError
36 */
37 public class ErrorResponse {
38
39 /***
40 * Constant that defines the action of stopping.
41 */
42 final public static ErrorResponse STOP;
43
44 /***
45 * Constant that defines the action of trying again.
46 */
47 final public static ErrorResponse RETRY;
48
49 /***
50 * Constant that defines the action of ignoring the error.
51 */
52 final public static ErrorResponse RESUME_NEXT;
53
54 /***
55 * Constant that defines the action of stopping.
56 */
57 final private static int STOP_ID = 0;
58
59 /***
60 * Constant that defines the action of trying again.
61 */
62 final private static int RETRY_ID = 1;
63
64 /***
65 * Constant that defines the action of ignoring the error.
66 */
67 final private static int RESUME_NEXT_ID = 2;
68
69 static {
70
71 STOP = new ErrorResponse(STOP_ID);
72 RETRY = new ErrorResponse(RETRY_ID);
73 RESUME_NEXT = new ErrorResponse(RESUME_NEXT_ID);
74
75 }
76
77 /***
78 * Action identifier.
79 */
80 private int actionId;
81
82 /***
83 * Single constructor of this class. The only valid values are
84 * {@link #STOP_ID}, {@link #RETRY_ID} e {@link #RESUME_NEXT_ID}.
85 * @param actionId an <code>int</code>
86 * @throws java.lang.IllegalArgumentException if <code>actionId</code>
87 * is not valid.
88 */
89 private ErrorResponse(int actionId) {
90
91 if (actionId < STOP_ID || actionId > RESUME_NEXT_ID) {
92
93 throw new IllegalArgumentException(
94 "Parameter does not have a valid value : " + actionId);
95
96 }
97
98 this.actionId = actionId;
99
100 }
101
102 /***
103 * Returns <code>true</code> if the action to be taken is stopping.
104 * @return <code>true</code> if the action to be taken is stopping,
105 * <code>false</code> otherwise.
106 */
107 public boolean isStop() {
108 return (actionId == STOP_ID);
109 }
110
111 /***
112 * Returns <code>true</code> if the action to be taken is trying again.
113 * @return <code>true</code> if the action to be taken is trying again,
114 * <code>false</code> otherwise.
115 */
116 public boolean isRetry() {
117 return (actionId == STOP_ID);
118 }
119
120 /***
121 * Returns <code>true</code> if the action to be taken is ignoring the
122 * error.
123 * @return <code>true</code> if the action to be taken is ignoring the
124 * error, <code>false</code> otherwise.
125 */
126 public boolean isResumeNext() {
127 return (actionId == RESUME_NEXT_ID);
128 }
129
130 public boolean equals(final Object other) {
131
132 if (other instanceof ErrorResponse == false) {
133 return false;
134 }
135
136 ErrorResponse castOther = (ErrorResponse) other;
137 return this.actionId == castOther.actionId;
138
139 }
140
141
142 }