FileDocCategorySizeDatePackage
ChoiceCallback.javaAPI DocJava SE 5 API5239Fri Aug 26 14:57:46 BST 2005javax.security.auth.callback

ChoiceCallback

public class ChoiceCallback extends Object implements Callback, Serializable

Underlying security services instantiate and pass a ChoiceCallback to the handle method of a CallbackHandler to display a list of choices and to retrieve the selected choice(s).

version
1.17, 12/19/03
see
javax.security.auth.callback.CallbackHandler

Fields Summary
private static final long
serialVersionUID
private String
prompt
private String[]
choices
private int
defaultChoice
private boolean
multipleSelectionsAllowed
private int[]
selections
Constructors Summary
public ChoiceCallback(String prompt, String[] choices, int defaultChoice, boolean multipleSelectionsAllowed)
Construct a ChoiceCallback with a prompt, a list of choices, a default choice, and a boolean specifying whether or not multiple selections from the list of choices are allowed.

param
prompt the prompt used to describe the list of choices.

param
choices the list of choices.

param
defaultChoice the choice to be used as the default choice when the list of choices are displayed. This value is represented as an index into the choices array.

param
multipleSelectionsAllowed boolean specifying whether or not multiple selections can be made from the list of choices.
exception
IllegalArgumentException if prompt is null, if prompt has a length of 0, if choices is null, if choices has a length of 0, if any element from choices is null, if any element from choices has a length of 0 or if defaultChoice does not fall within the array boundaries of choices.


                                                                			         			      			        			       			        			      			   			      			      			    			       			       			     
        
                    

	if (prompt == null || prompt.length() == 0 ||
	    choices == null || choices.length == 0 ||
	    defaultChoice < 0 || defaultChoice >= choices.length)
	    throw new IllegalArgumentException();

	for (int i = 0; i < choices.length; i++) {
	    if (choices[i] == null || choices[i].length() == 0)
		throw new IllegalArgumentException();
	}

	this.prompt = prompt;
	this.choices = choices;
	this.defaultChoice = defaultChoice;
	this.multipleSelectionsAllowed = multipleSelectionsAllowed;
    
Methods Summary
public booleanallowMultipleSelections()
Get the boolean determining whether multiple selections from the choices list are allowed.

return
whether multiple selections are allowed.

	return multipleSelectionsAllowed;
    
public java.lang.String[]getChoices()
Get the list of choices.

return
the list of choices.

	return choices;
    
public intgetDefaultChoice()
Get the defaultChoice.

return
the defaultChoice, represented as an index into the choices list.

	return defaultChoice;
    
public java.lang.StringgetPrompt()
Get the prompt.

return
the prompt.

	return prompt;
    
public int[]getSelectedIndexes()
Get the selected choices.

return
the selected choices, represented as indexes into the choices list.
see
#setSelectedIndexes

	return selections;
    
public voidsetSelectedIndex(int selection)
Set the selected choice.

param
selection the selection represented as an index into the choices list.
see
#getSelectedIndexes

	this.selections = new int[1];
	this.selections[0] = selection;
    
public voidsetSelectedIndexes(int[] selections)
Set the selected choices.

param
selections the selections represented as indexes into the choices list.
exception
UnsupportedOperationException if multiple selections are not allowed, as determined by allowMultipleSelections.
see
#getSelectedIndexes

	if (!multipleSelectionsAllowed)
	    throw new UnsupportedOperationException();
	this.selections = selections;