A Callback of this type represents a request to ask the user a yes/no or multiple-choice question. A CallbackHandler should first call getPrompt( ) to obtain the text of the question. It should also call getMessageType( ) to determine the message type ( INFORMATION , WARNING , or ERROR ) and present the question to the user in a suitable manner based on that type. Next, the CallbackHandler must determine the appropriate set of responses to the question. It does this by calling getOptionType( ) . The return values have the following meanings:
In each of these cases, the CallbackHandler should also call getdefaultOption( ) to determine which response should be presented as the default response. If getOptionType( ) returned UNSPECIFIED_TYPE , then getdefaultOption( ) returns an index into the array of options returned by getOptions( ) . Otherwise getdefaultOption( ) returns one of the constants YES , NO , OK , or CANCEL . When the user has selected a response to the callback, the CallbackHandler should pass that response to setSelectedIndex( ) . The response value should be one of the constants YES , NO , OK , or CANCEL , or an index into the array of options returned by getOptions( ) . Figure 19-7. javax.security.auth.callback.ConfirmationCallbackpublic class ConfirmationCallback implements Callback, Serializable { // Public Constructors public ConfirmationCallback (int messageType , String[ ] options , int defaultOption ); public ConfirmationCallback (int messageType , int optionType , int defaultOption ); public ConfirmationCallback (String prompt , int messageType , String[ ] options , int defaultOption ); public ConfirmationCallback (String prompt , int messageType , int optionType , int defaultOption ); // Public Constants public static final int CANCEL ; =2 public static final int ERROR ; =2 public static final int INFORMATION ; =0 public static final int NO ; =1 public static final int OK ; =3 public static final int OK_CANCEL_OPTION ; =2 public static final int UNSPECIFIED_OPTION ; =-1 public static final int WARNING ; =1 public static final int YES ; =0 public static final int YES_NO_CANCEL_OPTION ; =1 public static final int YES_NO_OPTION ; =0 // Public Instance Methods public int getDefaultOption ( ); public int getMessageType ( ); public String[ ] getOptions ( ); public int getOptionType ( ); public String getPrompt ( ); public int getSelectedIndex ( ); public void setSelectedIndex (int selection ); } |