📄 confirmationcallback.java
字号:
/* ConfirmationCallback.java -- callback for confirmations. Copyright (C) 2003, Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. */package javax.security.auth.callback;import java.io.Serializable;/** * Underlying security services instantiate and pass a * <code>ConfirmationCallback</code> to the <code>handle()</code> method of a * {@link CallbackHandler} to ask for YES/NO, OK/CANCEL, YES/NO/CANCEL or other * similar confirmations. * * @see CallbackHandler */public class ConfirmationCallback implements Callback, Serializable{ // Constants and variables // ------------------------------------------------------------------------- /** * <p>Unspecified option type.</p> * * <p>The <code>getOptionType</code> method returns this value if this * <code>ConfirmationCallback</code> was instantiated with <code>options</code> * instead of an <code>optionType</code>.</p> */ public static final int UNSPECIFIED_OPTION = -1; /** * <p>YES/NO confirmation option.</p> * * <p>An underlying security service specifies this as the <code>optionType</code> * to a <code>ConfirmationCallback</code> constructor if it requires a * confirmation which can be answered with either <code>YES</code> or * <code>NO</code>.</p> */ public static final int YES_NO_OPTION = 0; /** * <p>YES/NO/CANCEL confirmation confirmation option.</p> * * <p>An underlying security service specifies this as the <code>optionType</code> * to a <code>ConfirmationCallback</code> constructor if it requires a * confirmation which can be answered with either <code>YES</code>, * <code>NO</code> or <code>CANCEL</code>. */ public static final int YES_NO_CANCEL_OPTION = 1; /** * <p>OK/CANCEL confirmation confirmation option.</p> * * <p>An underlying security service specifies this as the <code>optionType</code> * to a <code>ConfirmationCallback</code> constructor if it requires a * confirmation which can be answered with either <code>OK</code> or * <code>CANCEL</code>.</p> */ public static final int OK_CANCEL_OPTION = 2; /** * <p>YES option.</p> * * <p>If an <code>optionType</code> was specified to this * <code>ConfirmationCallback</code>, this option may be specified as a * <code>defaultOption</code> or returned as the selected index.</p> */ public static final int YES = 0; /** * <p>NO option.</p> * * <p>If an <code>optionType</code> was specified to this * <code>ConfirmationCallback</code>, this option may be specified as a * <code>defaultOption</code> or returned as the selected index.</p> */ public static final int NO = 1; /** * <p>CANCEL option.</p> * * <p>If an <code>optionType</code> was specified to this * <code>ConfirmationCallback</code>, this option may be specified as a * <code>defaultOption</code> or returned as the selected index.</p> */ public static final int CANCEL = 2; /** * <p>OK option.</p> * * <p>If an <code>optionType</code> was specified to this * <code>ConfirmationCallback</code>, this option may be specified as a * <code>defaultOption</code> or returned as the selected index.</p> */ public static final int OK = 3; /** INFORMATION message type. */ public static final int INFORMATION = 0; /** WARNING message type. */ public static final int WARNING = 1; /** ERROR message type. */ public static final int ERROR = 2; /** * @serial * @since 1.4 */ private String prompt; /** * @serial * @since 1.4 */ private int messageType; /** * @serial * @since 1.4 */ private int optionType; /** * @serial * @since 1.4 */ private int defaultOption; /** * @serial * @since 1.4 */ private String[] options = null; /** * @serial * @since 1.4 */ private int selection; // Constructor(s) // ------------------------------------------------------------------------- /** * <p>Construct a <code>ConfirmationCallback</code> with a message type, an * option type and a default option.</p> * * <p>Underlying security services use this constructor if they require * either a YES/NO, YES/NO/CANCEL or OK/CANCEL confirmation.</p> * * @param messageType the message type (INFORMATION, WARNING or ERROR). * @param optionType the option type (YES_NO_OPTION, YES_NO_CANCEL_OPTION or * OK_CANCEL_OPTION). * @param defaultOption the default option from the provided optionType (YES, * NO, CANCEL or OK). * @throws IllegalArgumentException if <code>messageType</code> is not either * <code>INFORMATION</code>, <code>WARNING</code>, or <code>ERROR</code>, if * <code>optionType</code> is not either <code>YES_NO_OPTION</code>, * <code>YES_NO_CANCEL_OPTION</code>, or <code>OK_CANCEL_OPTION</code>, or if * <code>defaultOption</code> does not correspond to one of the options in * <code>optionType</code>. */ public ConfirmationCallback(int messageType, int optionType, int defaultOption) throws IllegalArgumentException { super(); setMessageType(messageType); setOptionType(optionType, defaultOption); this.defaultOption = defaultOption; } /** * <p>Construct a <code>ConfirmationCallback</code> with a message type, a * list of options and a default option.</p> * * <p>Underlying security services use this constructor if they require a * confirmation different from the available preset confirmations provided * (for example, CONTINUE/ABORT or STOP/GO). The confirmation options are * listed in the <code>options</code> array, and are displayed by the * {@link CallbackHandler} implementation in a manner consistent with the * way preset options are displayed.</p> * * @param messageType the message type (INFORMATION, WARNING or ERROR). * @param options the list of confirmation options. * @param defaultOption the default option, represented as an index into the * <code>options</code> array. * @throws IllegalArgumentException if <code>messageType</code> is not either * <code>INFORMATION</code>, <code>WARNING</code>, or <code>ERROR</code>, if * <code>options</code> is <code>null</code>, if <code>options</code> has a * length of <code>0</code>, if any element from <code>options</code> is * <code>null</code>, if any element from <code>options</code> has a length * of <code>0</code>, or if <code>defaultOption</code> does not lie within * the array boundaries of <code>options</code>. */ public ConfirmationCallback(int messageType, String[] options, int defaultOption) { super(); setMessageType(messageType); setOptions(options, defaultOption); this.defaultOption = defaultOption; } /** * <p>Construct a <code>ConfirmationCallback</code> with a prompt, message * type, an option type and a default option.</p> * * <p>Underlying security services use this constructor if they require * either a YES/NO, YES/NO/CANCEL or OK/CANCEL confirmation.</p> * * @param prompt the prompt used to describe the list of options. * @param messageType the message type (INFORMATION, WARNING or ERROR). * @param optionType the option type (YES_NO_OPTION, YES_NO_CANCEL_OPTION or * OK_CANCEL_OPTION). * @param defaultOption the default option from the provided optionType (YES, * NO, CANCEL or OK).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -