本文整理汇总了Java中javax.security.auth.callback.ConfirmationCallback.getOptions方法的典型用法代码示例。如果您正苦于以下问题:Java ConfirmationCallback.getOptions方法的具体用法?Java ConfirmationCallback.getOptions怎么用?Java ConfirmationCallback.getOptions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.security.auth.callback.ConfirmationCallback
的用法示例。
在下文中一共展示了ConfirmationCallback.getOptions方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testConfirmationCallback_09
import javax.security.auth.callback.ConfirmationCallback; //导入方法依赖的package包/类
/**
* test of methods getOptionType(), getDefaultOption(), getMessageType()
* getOptions(), set/getSelectedIndex
*/
public final void testConfirmationCallback_09() throws IllegalArgumentException {
String[] opt = {"CONTINUE", "ABORT"};
String[] s;
cc = new ConfirmationCallback("prompt", mt[0], opt, 1);
assertEquals(1, cc.getDefaultOption());
assertEquals(ConfirmationCallback.INFORMATION, cc.getMessageType());
assertEquals(opt,cc.getOptions());
s = cc.getOptions();
for (int i = 0; i < opt.length; i++){
assertEquals(opt[i], s[i]);
}
assertEquals("prompt", cc.getPrompt());
assertEquals(-1, cc.getOptionType());
assertEquals(ConfirmationCallback.UNSPECIFIED_OPTION, cc.getOptionType());
assertNotNull(cc.getOptions());
cc.setSelectedIndex(1);
assertEquals(1, cc.getSelectedIndex());
}
示例2: setCallback
import javax.security.auth.callback.ConfirmationCallback; //导入方法依赖的package包/类
void setCallback(ConfirmationCallback callback)
throws UnsupportedCallbackException
{
this.callback = callback;
int confirmationOptionType = callback.getOptionType();
switch (confirmationOptionType) {
case ConfirmationCallback.YES_NO_OPTION:
optionType = JOptionPane.YES_NO_OPTION;
translations = new int[] {
JOptionPane.YES_OPTION, ConfirmationCallback.YES,
JOptionPane.NO_OPTION, ConfirmationCallback.NO,
JOptionPane.CLOSED_OPTION, ConfirmationCallback.NO
};
break;
case ConfirmationCallback.YES_NO_CANCEL_OPTION:
optionType = JOptionPane.YES_NO_CANCEL_OPTION;
translations = new int[] {
JOptionPane.YES_OPTION, ConfirmationCallback.YES,
JOptionPane.NO_OPTION, ConfirmationCallback.NO,
JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
};
break;
case ConfirmationCallback.OK_CANCEL_OPTION:
optionType = JOptionPane.OK_CANCEL_OPTION;
translations = new int[] {
JOptionPane.OK_OPTION, ConfirmationCallback.OK,
JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
};
break;
case ConfirmationCallback.UNSPECIFIED_OPTION:
options = callback.getOptions();
/*
* There's no way to know if the default option means
* to cancel the login, but there isn't a better way
* to guess this.
*/
translations = new int[] {
JOptionPane.CLOSED_OPTION, callback.getDefaultOption()
};
break;
default:
throw new UnsupportedCallbackException(
callback,
"Unrecognized option type: " + confirmationOptionType);
}
int confirmationMessageType = callback.getMessageType();
switch (confirmationMessageType) {
case ConfirmationCallback.WARNING:
messageType = JOptionPane.WARNING_MESSAGE;
break;
case ConfirmationCallback.ERROR:
messageType = JOptionPane.ERROR_MESSAGE;
break;
case ConfirmationCallback.INFORMATION:
messageType = JOptionPane.INFORMATION_MESSAGE;
break;
default:
throw new UnsupportedCallbackException(
callback,
"Unrecognized message type: " + confirmationMessageType);
}
}
示例3: processConfirmationCallback
import javax.security.auth.callback.ConfirmationCallback; //导入方法依赖的package包/类
private void processConfirmationCallback(final JDialog callbackDialog,
List<ActionListener> proceedActions, JPanel optionPanel,
final ConfirmationCallback cc, boolean hasInput)
throws UnsupportedCallbackException {
GridBagConstraints constraints = new GridBagConstraints();
constraints.insets = DEFAULT_INSETS;
constraints.gridx = GridBagConstraints.RELATIVE;
constraints.gridy = GridBagConstraints.RELATIVE;
constraints.gridwidth = 1;
constraints.weightx = 0.0d;
constraints.fill = GridBagConstraints.NONE;
int confirmationOptionType = cc.getOptionType();
if (confirmationOptionType == ConfirmationCallback.UNSPECIFIED_OPTION) {
for (int i = 0; i < cc.getOptions().length; i++) {
final int optionIndex = i;
JButton optionButton = new JButton(cc.getOptions()[i]);
optionButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
cc.setSelectedIndex(optionIndex);
callbackDialog.dispose();
}
});
optionPanel.add(optionButton, constraints);
}
} else {
if (locale == null) {
locale = Locale.getDefault();
}
switch (confirmationOptionType) {
case ConfirmationCallback.YES_NO_OPTION:
optionPanel.add(
createOptionButton(callbackDialog, cc, ConfirmationCallback.YES,
translationProvider.getTranslation("yes", locale),
proceedActions), constraints);
optionPanel.add(
createOptionButton(callbackDialog, cc, ConfirmationCallback.NO,
translationProvider.getTranslation("no", locale),
proceedActions), constraints);
break;
case ConfirmationCallback.YES_NO_CANCEL_OPTION:
optionPanel.add(
createOptionButton(callbackDialog, cc, ConfirmationCallback.YES,
translationProvider.getTranslation("yes", locale),
proceedActions), constraints);
optionPanel.add(
createOptionButton(callbackDialog, cc, ConfirmationCallback.NO,
translationProvider.getTranslation("no", locale),
proceedActions), constraints);
optionPanel.add(
createOptionButton(callbackDialog, cc,
ConfirmationCallback.CANCEL,
translationProvider.getTranslation("cancel", locale),
proceedActions), constraints);
break;
case ConfirmationCallback.OK_CANCEL_OPTION:
optionPanel.add(
createOptionButton(callbackDialog, cc, ConfirmationCallback.OK,
translationProvider.getTranslation("ok", locale),
proceedActions), constraints);
if (hasInput) {
optionPanel.add(
createOptionButton(callbackDialog, cc,
ConfirmationCallback.CANCEL,
translationProvider.getTranslation("cancel", locale),
proceedActions), constraints);
}
break;
default:
throw new UnsupportedCallbackException(cc,
"Unrecognized option type: " + confirmationOptionType);
}
}
}