1 7 8 package javax.security.auth.callback; 9 10 19 public class ConfirmationCallback implements Callback , java.io.Serializable { 20 21 private static final long serialVersionUID = -9095656433782481624L; 22 23 30 public static final int UNSPECIFIED_OPTION = -1; 31 32 40 public static final int YES_NO_OPTION = 0; 41 42 50 public static final int YES_NO_CANCEL_OPTION = 1; 51 52 60 public static final int OK_CANCEL_OPTION = 2; 61 62 69 public static final int YES = 0; 70 71 78 public static final int NO = 1; 79 80 87 public static final int CANCEL = 2; 88 89 96 public static final int OK = 3; 97 98 99 public static final int INFORMATION = 0; 100 101 102 public static final int WARNING = 1; 103 104 105 public static final int ERROR = 2; 106 110 private String prompt; 111 115 private int messageType; 116 120 private int optionType = UNSPECIFIED_OPTION; 121 125 private int defaultOption; 126 130 private String [] options; 131 135 private int selection; 136 137 169 public ConfirmationCallback(int messageType, 170 int optionType, int defaultOption) { 171 172 if (messageType < INFORMATION || messageType > ERROR || 173 optionType < YES_NO_OPTION || optionType > OK_CANCEL_OPTION) 174 throw new IllegalArgumentException (); 175 176 switch (optionType) { 177 case YES_NO_OPTION: 178 if (defaultOption != YES && defaultOption != NO) 179 throw new IllegalArgumentException (); 180 break; 181 case YES_NO_CANCEL_OPTION: 182 if (defaultOption != YES && defaultOption != NO && 183 defaultOption != CANCEL) 184 throw new IllegalArgumentException (); 185 break; 186 case OK_CANCEL_OPTION: 187 if (defaultOption != OK && defaultOption != CANCEL) 188 throw new IllegalArgumentException (); 189 break; 190 } 191 192 this.messageType = messageType; 193 this.optionType = optionType; 194 this.defaultOption = defaultOption; 195 } 196 197 228 public ConfirmationCallback(int messageType, 229 String [] options, int defaultOption) { 230 231 if (messageType < INFORMATION || messageType > ERROR || 232 options == null || options.length == 0 || 233 defaultOption < 0 || defaultOption >= options.length) 234 throw new IllegalArgumentException (); 235 236 for (int i = 0; i < options.length; i++) { 237 if (options[i] == null || options[i].length() == 0) 238 throw new IllegalArgumentException (); 239 } 240 241 this.messageType = messageType; 242 this.options = options; 243 this.defaultOption = defaultOption; 244 } 245 246 282 public ConfirmationCallback(String prompt, int messageType, 283 int optionType, int defaultOption) { 284 285 if (prompt == null || prompt.length() == 0 || 286 messageType < INFORMATION || messageType > ERROR || 287 optionType < YES_NO_OPTION || optionType > OK_CANCEL_OPTION) 288 throw new IllegalArgumentException (); 289 290 switch (optionType) { 291 case YES_NO_OPTION: 292 if (defaultOption != YES && defaultOption != NO) 293 throw new IllegalArgumentException (); 294 break; 295 case YES_NO_CANCEL_OPTION: 296 if (defaultOption != YES && defaultOption != NO && 297 defaultOption != CANCEL) 298 throw new IllegalArgumentException (); 299 break; 300 case OK_CANCEL_OPTION: 301 if (defaultOption != OK && defaultOption != CANCEL) 302 throw new IllegalArgumentException (); 303 break; 304 } 305 306 this.prompt = prompt; 307 this.messageType = messageType; 308 this.optionType = optionType; 309 this.defaultOption = defaultOption; 310 } 311 312 347 public ConfirmationCallback(String prompt, int messageType, 348 String [] options, int defaultOption) { 349 350 if (prompt == null || prompt.length() == 0 || 351 messageType < INFORMATION || messageType > ERROR || 352 options == null || options.length == 0 || 353 defaultOption < 0 || defaultOption >= options.length) 354 throw new IllegalArgumentException (); 355 356 for (int i = 0; i < options.length; i++) { 357 if (options[i] == null || options[i].length() == 0) 358 throw new IllegalArgumentException (); 359 } 360 361 this.prompt = prompt; 362 this.messageType = messageType; 363 this.options = options; 364 this.defaultOption = defaultOption; 365 } 366 367 375 public String getPrompt() { 376 return prompt; 377 } 378 379 387 public int getMessageType() { 388 return messageType; 389 } 390 391 409 public int getOptionType() { 410 return optionType; 411 } 412 413 422 public String [] getOptions() { 423 return options; 424 } 425 426 441 public int getDefaultOption() { 442 return defaultOption; 443 } 444 445 460 public void setSelectedIndex(int selection) { 461 this.selection = selection; 462 } 463 464 481 public int getSelectedIndex() { 482 return selection; 483 } 484 } 485 | Popular Tags |