231 *
232 * @exception IllegalArgumentException if messageType is not either
233 * {@code INFORMATION}, {@code WARNING},
234 * or {@code ERROR}, if {@code options} is null,
235 * if {@code options} has a length of 0,
236 * if any element from {@code options} is null,
237 * if any element from {@code options}
238 * has a length of 0, or if {@code defaultOption}
239 * does not lie within the array boundaries of
240 * {@code options}.
241 */
242 public ConfirmationCallback(int messageType,
243 String[] options, int defaultOption) {
244
245 if (messageType < INFORMATION || messageType > ERROR ||
246 options == null || options.length == 0 ||
247 defaultOption < 0 || defaultOption >= options.length)
248 throw new IllegalArgumentException();
249
250 for (int i = 0; i < options.length; i++) {
251 if (options[i] == null || options[i].length() == 0)
252 throw new IllegalArgumentException();
253 }
254
255 this.messageType = messageType;
256 this.options = options;
257 this.defaultOption = defaultOption;
258 }
259
260 /**
261 * Construct a {@code ConfirmationCallback} with a prompt,
262 * message type, an option type and a default option.
263 *
264 * <p> Underlying security services use this constructor if
265 * they require either a YES/NO, YES/NO/CANCEL or OK/CANCEL
266 * confirmation.
267 *
268 * @param prompt the prompt used to describe the list of options.
269 *
270 * @param messageType the message type ({@code INFORMATION},
271 * {@code WARNING} or {@code ERROR}).
277 * @param defaultOption the default option
278 * from the provided optionType ({@code YES},
279 * {@code NO}, {@code CANCEL} or
280 * {@code OK}).
281 *
282 * @exception IllegalArgumentException if {@code prompt} is null,
283 * if {@code prompt} has a length of 0,
284 * if messageType is not either
285 * {@code INFORMATION}, {@code WARNING},
286 * or {@code ERROR}, if optionType is not either
287 * {@code YES_NO_OPTION},
288 * {@code YES_NO_CANCEL_OPTION}, or
289 * {@code OK_CANCEL_OPTION},
290 * or if {@code defaultOption}
291 * does not correspond to one of the options in
292 * {@code optionType}.
293 */
294 public ConfirmationCallback(String prompt, int messageType,
295 int optionType, int defaultOption) {
296
297 if (prompt == null || prompt.length() == 0 ||
298 messageType < INFORMATION || messageType > ERROR ||
299 optionType < YES_NO_OPTION || optionType > OK_CANCEL_OPTION)
300 throw new IllegalArgumentException();
301
302 switch (optionType) {
303 case YES_NO_OPTION:
304 if (defaultOption != YES && defaultOption != NO)
305 throw new IllegalArgumentException();
306 break;
307 case YES_NO_CANCEL_OPTION:
308 if (defaultOption != YES && defaultOption != NO &&
309 defaultOption != CANCEL)
310 throw new IllegalArgumentException();
311 break;
312 case OK_CANCEL_OPTION:
313 if (defaultOption != OK && defaultOption != CANCEL)
314 throw new IllegalArgumentException();
315 break;
316 }
317
340 * @param options the list of confirmation options.
341 *
342 * @param defaultOption the default option, represented as an index
343 * into the {@code options} array.
344 *
345 * @exception IllegalArgumentException if {@code prompt} is null,
346 * if {@code prompt} has a length of 0,
347 * if messageType is not either
348 * {@code INFORMATION}, {@code WARNING},
349 * or {@code ERROR}, if {@code options} is null,
350 * if {@code options} has a length of 0,
351 * if any element from {@code options} is null,
352 * if any element from {@code options}
353 * has a length of 0, or if {@code defaultOption}
354 * does not lie within the array boundaries of
355 * {@code options}.
356 */
357 public ConfirmationCallback(String prompt, int messageType,
358 String[] options, int defaultOption) {
359
360 if (prompt == null || prompt.length() == 0 ||
361 messageType < INFORMATION || messageType > ERROR ||
362 options == null || options.length == 0 ||
363 defaultOption < 0 || defaultOption >= options.length)
364 throw new IllegalArgumentException();
365
366 for (int i = 0; i < options.length; i++) {
367 if (options[i] == null || options[i].length() == 0)
368 throw new IllegalArgumentException();
369 }
370
371 this.prompt = prompt;
372 this.messageType = messageType;
373 this.options = options;
374 this.defaultOption = defaultOption;
375 }
376
377 /**
378 * Get the prompt.
379 *
380 * @return the prompt, or null if this {@code ConfirmationCallback}
381 * was instantiated without a {@code prompt}.
382 */
383 public String getPrompt() {
384 return prompt;
385 }
386
387 /**
|
231 *
232 * @exception IllegalArgumentException if messageType is not either
233 * {@code INFORMATION}, {@code WARNING},
234 * or {@code ERROR}, if {@code options} is null,
235 * if {@code options} has a length of 0,
236 * if any element from {@code options} is null,
237 * if any element from {@code options}
238 * has a length of 0, or if {@code defaultOption}
239 * does not lie within the array boundaries of
240 * {@code options}.
241 */
242 public ConfirmationCallback(int messageType,
243 String[] options, int defaultOption) {
244
245 if (messageType < INFORMATION || messageType > ERROR ||
246 options == null || options.length == 0 ||
247 defaultOption < 0 || defaultOption >= options.length)
248 throw new IllegalArgumentException();
249
250 for (int i = 0; i < options.length; i++) {
251 if (options[i] == null || options[i].isEmpty())
252 throw new IllegalArgumentException();
253 }
254
255 this.messageType = messageType;
256 this.options = options;
257 this.defaultOption = defaultOption;
258 }
259
260 /**
261 * Construct a {@code ConfirmationCallback} with a prompt,
262 * message type, an option type and a default option.
263 *
264 * <p> Underlying security services use this constructor if
265 * they require either a YES/NO, YES/NO/CANCEL or OK/CANCEL
266 * confirmation.
267 *
268 * @param prompt the prompt used to describe the list of options.
269 *
270 * @param messageType the message type ({@code INFORMATION},
271 * {@code WARNING} or {@code ERROR}).
277 * @param defaultOption the default option
278 * from the provided optionType ({@code YES},
279 * {@code NO}, {@code CANCEL} or
280 * {@code OK}).
281 *
282 * @exception IllegalArgumentException if {@code prompt} is null,
283 * if {@code prompt} has a length of 0,
284 * if messageType is not either
285 * {@code INFORMATION}, {@code WARNING},
286 * or {@code ERROR}, if optionType is not either
287 * {@code YES_NO_OPTION},
288 * {@code YES_NO_CANCEL_OPTION}, or
289 * {@code OK_CANCEL_OPTION},
290 * or if {@code defaultOption}
291 * does not correspond to one of the options in
292 * {@code optionType}.
293 */
294 public ConfirmationCallback(String prompt, int messageType,
295 int optionType, int defaultOption) {
296
297 if (prompt == null || prompt.isEmpty() ||
298 messageType < INFORMATION || messageType > ERROR ||
299 optionType < YES_NO_OPTION || optionType > OK_CANCEL_OPTION)
300 throw new IllegalArgumentException();
301
302 switch (optionType) {
303 case YES_NO_OPTION:
304 if (defaultOption != YES && defaultOption != NO)
305 throw new IllegalArgumentException();
306 break;
307 case YES_NO_CANCEL_OPTION:
308 if (defaultOption != YES && defaultOption != NO &&
309 defaultOption != CANCEL)
310 throw new IllegalArgumentException();
311 break;
312 case OK_CANCEL_OPTION:
313 if (defaultOption != OK && defaultOption != CANCEL)
314 throw new IllegalArgumentException();
315 break;
316 }
317
340 * @param options the list of confirmation options.
341 *
342 * @param defaultOption the default option, represented as an index
343 * into the {@code options} array.
344 *
345 * @exception IllegalArgumentException if {@code prompt} is null,
346 * if {@code prompt} has a length of 0,
347 * if messageType is not either
348 * {@code INFORMATION}, {@code WARNING},
349 * or {@code ERROR}, if {@code options} is null,
350 * if {@code options} has a length of 0,
351 * if any element from {@code options} is null,
352 * if any element from {@code options}
353 * has a length of 0, or if {@code defaultOption}
354 * does not lie within the array boundaries of
355 * {@code options}.
356 */
357 public ConfirmationCallback(String prompt, int messageType,
358 String[] options, int defaultOption) {
359
360 if (prompt == null || prompt.isEmpty() ||
361 messageType < INFORMATION || messageType > ERROR ||
362 options == null || options.length == 0 ||
363 defaultOption < 0 || defaultOption >= options.length)
364 throw new IllegalArgumentException();
365
366 for (int i = 0; i < options.length; i++) {
367 if (options[i] == null || options[i].isEmpty())
368 throw new IllegalArgumentException();
369 }
370
371 this.prompt = prompt;
372 this.messageType = messageType;
373 this.options = options;
374 this.defaultOption = defaultOption;
375 }
376
377 /**
378 * Get the prompt.
379 *
380 * @return the prompt, or null if this {@code ConfirmationCallback}
381 * was instantiated without a {@code prompt}.
382 */
383 public String getPrompt() {
384 return prompt;
385 }
386
387 /**
|