1 7 8 package javax.security.auth.callback; 9 10 19 public class ChoiceCallback implements Callback , java.io.Serializable { 20 21 private static final long serialVersionUID = -3975664071579892167L; 22 23 27 private String prompt; 28 32 private String [] choices; 33 37 private int defaultChoice; 38 43 private boolean multipleSelectionsAllowed; 44 49 private int[] selections; 50 51 81 public ChoiceCallback(String prompt, String [] choices, 82 int defaultChoice, boolean multipleSelectionsAllowed) { 83 84 if (prompt == null || prompt.length() == 0 || 85 choices == null || choices.length == 0 || 86 defaultChoice < 0 || defaultChoice >= choices.length) 87 throw new IllegalArgumentException (); 88 89 for (int i = 0; i < choices.length; i++) { 90 if (choices[i] == null || choices[i].length() == 0) 91 throw new IllegalArgumentException (); 92 } 93 94 this.prompt = prompt; 95 this.choices = choices; 96 this.defaultChoice = defaultChoice; 97 this.multipleSelectionsAllowed = multipleSelectionsAllowed; 98 } 99 100 107 public String getPrompt() { 108 return prompt; 109 } 110 111 118 public String [] getChoices() { 119 return choices; 120 } 121 122 130 public int getDefaultChoice() { 131 return defaultChoice; 132 } 133 134 142 public boolean allowMultipleSelections() { 143 return multipleSelectionsAllowed; 144 } 145 146 156 public void setSelectedIndex(int selection) { 157 this.selections = new int[1]; 158 this.selections[0] = selection; 159 } 160 161 175 public void setSelectedIndexes(int[] selections) { 176 if (!multipleSelectionsAllowed) 177 throw new UnsupportedOperationException (); 178 this.selections = selections; 179 } 180 181 191 public int[] getSelectedIndexes() { 192 return selections; 193 } 194 } 195 | Popular Tags |