src/java.base/share/classes/javax/security/auth/callback/ConfirmationCallback.java
author redestad
Thu, 13 Dec 2018 15:31:05 +0100
changeset 53018 8bf9268df0e2
parent 47216 71c04702a3d5
child 53563 a4b7ea85d668
permissions -rw-r--r--
8215281: Use String.isEmpty() when applicable in java.base Reviewed-by: dfuchs, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
29492
a4bf9a570035 8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents: 25859
diff changeset
     2
 * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.security.auth.callback;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * <p> Underlying security services instantiate and pass a
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
    30
 * {@code ConfirmationCallback} to the {@code handle}
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
    31
 * method of a {@code CallbackHandler} to ask for YES/NO,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * OK/CANCEL, YES/NO/CANCEL or other similar confirmations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *
45434
4582657c7260 8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents: 29492
diff changeset
    34
 * @since 1.4
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * @see javax.security.auth.callback.CallbackHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
public class ConfirmationCallback implements Callback, java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    private static final long serialVersionUID = -9095656433782481624L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     * Unspecified option type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
    44
     * <p> The {@code getOptionType} method returns this
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
    45
     * value if this {@code ConfirmationCallback} was instantiated
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
    46
     * with {@code options} instead of an {@code optionType}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    public static final int UNSPECIFIED_OPTION          = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * YES/NO confirmation option.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * <p> An underlying security service specifies this as the
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
    54
     * {@code optionType} to a {@code ConfirmationCallback}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * constructor if it requires a confirmation which can be answered
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
    56
     * with either {@code YES} or {@code NO}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public static final int YES_NO_OPTION               = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * YES/NO/CANCEL confirmation confirmation option.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * <p> An underlying security service specifies this as the
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
    64
     * {@code optionType} to a {@code ConfirmationCallback}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * constructor if it requires a confirmation which can be answered
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
    66
     * with either {@code YES}, {@code NO} or {@code CANCEL}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public static final int YES_NO_CANCEL_OPTION        = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * OK/CANCEL confirmation confirmation option.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * <p> An underlying security service specifies this as the
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
    74
     * {@code optionType} to a {@code ConfirmationCallback}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * constructor if it requires a confirmation which can be answered
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
    76
     * with either {@code OK} or {@code CANCEL}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public static final int OK_CANCEL_OPTION            = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * YES option.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
    83
     * <p> If an {@code optionType} was specified to this
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
    84
     * {@code ConfirmationCallback}, this option may be specified as a
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
    85
     * {@code defaultOption} or returned as the selected index.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public static final int YES                         = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * NO option.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
    92
     * <p> If an {@code optionType} was specified to this
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
    93
     * {@code ConfirmationCallback}, this option may be specified as a
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
    94
     * {@code defaultOption} or returned as the selected index.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public static final int NO                          = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * CANCEL option.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   101
     * <p> If an {@code optionType} was specified to this
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   102
     * {@code ConfirmationCallback}, this option may be specified as a
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   103
     * {@code defaultOption} or returned as the selected index.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public static final int CANCEL                      = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * OK option.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   110
     * <p> If an {@code optionType} was specified to this
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   111
     * {@code ConfirmationCallback}, this option may be specified as a
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   112
     * {@code defaultOption} or returned as the selected index.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public static final int OK                          = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /** INFORMATION message type.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public static final int INFORMATION                 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /** WARNING message type. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public static final int WARNING                     = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    /** ERROR message type. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public static final int ERROR                       = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    private String prompt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    private int messageType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    private int optionType = UNSPECIFIED_OPTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    private int defaultOption;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    private String[] options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    private int selection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    /**
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   156
     * Construct a {@code ConfirmationCallback} with a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * message type, an option type and a default option.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * <p> Underlying security services use this constructor if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * they require either a YES/NO, YES/NO/CANCEL or OK/CANCEL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * confirmation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   163
     * @param messageType the message type ({@code INFORMATION},
29492
a4bf9a570035 8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents: 25859
diff changeset
   164
     *                  {@code WARNING} or {@code ERROR}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   166
     * @param optionType the option type ({@code YES_NO_OPTION},
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   167
     *                  {@code YES_NO_CANCEL_OPTION} or
29492
a4bf9a570035 8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents: 25859
diff changeset
   168
     *                  {@code OK_CANCEL_OPTION}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @param defaultOption the default option
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   171
     *                  from the provided optionType ({@code YES},
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   172
     *                  {@code NO}, {@code CANCEL} or
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   173
     *                  {@code OK}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @exception IllegalArgumentException if messageType is not either
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   176
     *                  {@code INFORMATION}, {@code WARNING},
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   177
     *                  or {@code ERROR}, if optionType is not either
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   178
     *                  {@code YES_NO_OPTION},
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   179
     *                  {@code YES_NO_CANCEL_OPTION}, or
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   180
     *                  {@code OK_CANCEL_OPTION},
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   181
     *                  or if {@code defaultOption}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *                  does not correspond to one of the options in
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   183
     *                  {@code optionType}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    public ConfirmationCallback(int messageType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                int optionType, int defaultOption) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        if (messageType < INFORMATION || messageType > ERROR ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            optionType < YES_NO_OPTION || optionType > OK_CANCEL_OPTION)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        switch (optionType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        case YES_NO_OPTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            if (defaultOption != YES && defaultOption != NO)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        case YES_NO_CANCEL_OPTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            if (defaultOption != YES && defaultOption != NO &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                defaultOption != CANCEL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        case OK_CANCEL_OPTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            if (defaultOption != OK && defaultOption != CANCEL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        this.messageType = messageType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        this.optionType = optionType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        this.defaultOption = defaultOption;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /**
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   214
     * Construct a {@code ConfirmationCallback} with a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * message type, a list of options and a default option.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * <p> Underlying security services use this constructor if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * they require a confirmation different from the available preset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * confirmations provided (for example, CONTINUE/ABORT or STOP/GO).
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   220
     * The confirmation options are listed in the {@code options} array,
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   221
     * and are displayed by the {@code CallbackHandler} implementation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * in a manner consistent with the way preset options are displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *
29492
a4bf9a570035 8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents: 25859
diff changeset
   224
     * @param messageType the message type ({@code INFORMATION},
a4bf9a570035 8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents: 25859
diff changeset
   225
     *                  {@code WARNING} or {@code ERROR}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *
29492
a4bf9a570035 8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents: 25859
diff changeset
   227
     * @param options the list of confirmation options.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @param defaultOption the default option, represented as an index
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   230
     *                  into the {@code options} array.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @exception IllegalArgumentException if messageType is not either
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   233
     *                  {@code INFORMATION}, {@code WARNING},
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   234
     *                  or {@code ERROR}, if {@code options} is null,
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   235
     *                  if {@code options} has a length of 0,
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   236
     *                  if any element from {@code options} is null,
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   237
     *                  if any element from {@code options}
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   238
     *                  has a length of 0, or if {@code defaultOption}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *                  does not lie within the array boundaries of
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   240
     *                  {@code options}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public ConfirmationCallback(int messageType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                String[] options, int defaultOption) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if (messageType < INFORMATION || messageType > ERROR ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            options == null || options.length == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            defaultOption < 0 || defaultOption >= options.length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        for (int i = 0; i < options.length; i++) {
53018
8bf9268df0e2 8215281: Use String.isEmpty() when applicable in java.base
redestad
parents: 47216
diff changeset
   251
            if (options[i] == null || options[i].isEmpty())
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        this.messageType = messageType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        this.options = options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        this.defaultOption = defaultOption;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    /**
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   261
     * Construct a {@code ConfirmationCallback} with a prompt,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * message type, an option type and a default option.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * <p> Underlying security services use this constructor if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * they require either a YES/NO, YES/NO/CANCEL or OK/CANCEL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * confirmation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *
29492
a4bf9a570035 8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents: 25859
diff changeset
   268
     * @param prompt the prompt used to describe the list of options.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   270
     * @param messageType the message type ({@code INFORMATION},
29492
a4bf9a570035 8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents: 25859
diff changeset
   271
     *                  {@code WARNING} or {@code ERROR}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   273
     * @param optionType the option type ({@code YES_NO_OPTION},
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   274
     *                  {@code YES_NO_CANCEL_OPTION} or
29492
a4bf9a570035 8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents: 25859
diff changeset
   275
     *                  {@code OK_CANCEL_OPTION}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @param defaultOption the default option
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   278
     *                  from the provided optionType ({@code YES},
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   279
     *                  {@code NO}, {@code CANCEL} or
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   280
     *                  {@code OK}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   282
     * @exception IllegalArgumentException if {@code prompt} is null,
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   283
     *                  if {@code prompt} has a length of 0,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     *                  if messageType is not either
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   285
     *                  {@code INFORMATION}, {@code WARNING},
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   286
     *                  or {@code ERROR}, if optionType is not either
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   287
     *                  {@code YES_NO_OPTION},
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   288
     *                  {@code YES_NO_CANCEL_OPTION}, or
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   289
     *                  {@code OK_CANCEL_OPTION},
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   290
     *                  or if {@code defaultOption}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *                  does not correspond to one of the options in
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   292
     *                  {@code optionType}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    public ConfirmationCallback(String prompt, int messageType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                int optionType, int defaultOption) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
53018
8bf9268df0e2 8215281: Use String.isEmpty() when applicable in java.base
redestad
parents: 47216
diff changeset
   297
        if (prompt == null || prompt.isEmpty() ||
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            messageType < INFORMATION || messageType > ERROR ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            optionType < YES_NO_OPTION || optionType > OK_CANCEL_OPTION)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        switch (optionType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        case YES_NO_OPTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            if (defaultOption != YES && defaultOption != NO)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        case YES_NO_CANCEL_OPTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            if (defaultOption != YES && defaultOption != NO &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                defaultOption != CANCEL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        case OK_CANCEL_OPTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            if (defaultOption != OK && defaultOption != CANCEL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        this.prompt = prompt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        this.messageType = messageType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        this.optionType = optionType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        this.defaultOption = defaultOption;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    /**
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   325
     * Construct a {@code ConfirmationCallback} with a prompt,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * message type, a list of options and a default option.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * <p> Underlying security services use this constructor if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * they require a confirmation different from the available preset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * confirmations provided (for example, CONTINUE/ABORT or STOP/GO).
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   331
     * The confirmation options are listed in the {@code options} array,
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   332
     * and are displayed by the {@code CallbackHandler} implementation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * in a manner consistent with the way preset options are displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *
29492
a4bf9a570035 8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents: 25859
diff changeset
   335
     * @param prompt the prompt used to describe the list of options.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   337
     * @param messageType the message type ({@code INFORMATION},
29492
a4bf9a570035 8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents: 25859
diff changeset
   338
     *                  {@code WARNING} or {@code ERROR}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *
29492
a4bf9a570035 8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents: 25859
diff changeset
   340
     * @param options the list of confirmation options.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @param defaultOption the default option, represented as an index
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   343
     *                  into the {@code options} array.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   345
     * @exception IllegalArgumentException if {@code prompt} is null,
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   346
     *                  if {@code prompt} has a length of 0,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     *                  if messageType is not either
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   348
     *                  {@code INFORMATION}, {@code WARNING},
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   349
     *                  or {@code ERROR}, if {@code options} is null,
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   350
     *                  if {@code options} has a length of 0,
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   351
     *                  if any element from {@code options} is null,
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   352
     *                  if any element from {@code options}
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   353
     *                  has a length of 0, or if {@code defaultOption}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     *                  does not lie within the array boundaries of
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   355
     *                  {@code options}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    public ConfirmationCallback(String prompt, int messageType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                String[] options, int defaultOption) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
53018
8bf9268df0e2 8215281: Use String.isEmpty() when applicable in java.base
redestad
parents: 47216
diff changeset
   360
        if (prompt == null || prompt.isEmpty() ||
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            messageType < INFORMATION || messageType > ERROR ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            options == null || options.length == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            defaultOption < 0 || defaultOption >= options.length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        for (int i = 0; i < options.length; i++) {
53018
8bf9268df0e2 8215281: Use String.isEmpty() when applicable in java.base
redestad
parents: 47216
diff changeset
   367
            if (options[i] == null || options[i].isEmpty())
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        this.prompt = prompt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        this.messageType = messageType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        this.options = options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        this.defaultOption = defaultOption;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * Get the prompt.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   380
     * @return the prompt, or null if this {@code ConfirmationCallback}
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   381
     *          was instantiated without a {@code prompt}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    public String getPrompt() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        return prompt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * Get the message type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   390
     * @return the message type ({@code INFORMATION},
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   391
     *          {@code WARNING} or {@code ERROR}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    public int getMessageType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        return messageType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * Get the option type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   400
     * <p> If this method returns {@code UNSPECIFIED_OPTION}, then this
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   401
     * {@code ConfirmationCallback} was instantiated with
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   402
     * {@code options} instead of an {@code optionType}.
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   403
     * In this case, invoke the {@code getOptions} method
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * to determine which confirmation options to display.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   406
     * @return the option type ({@code YES_NO_OPTION},
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   407
     *          {@code YES_NO_CANCEL_OPTION} or
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   408
     *          {@code OK_CANCEL_OPTION}), or
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   409
     *          {@code UNSPECIFIED_OPTION} if this
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   410
     *          {@code ConfirmationCallback} was instantiated with
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   411
     *          {@code options} instead of an {@code optionType}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    public int getOptionType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        return optionType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * Get the confirmation options.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * @return the list of confirmation options, or null if this
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   421
     *          {@code ConfirmationCallback} was instantiated with
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   422
     *          an {@code optionType} instead of {@code options}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    public String[] getOptions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        return options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * Get the default option.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * @return the default option, represented as
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   432
     *          {@code YES}, {@code NO}, {@code OK} or
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   433
     *          {@code CANCEL} if an {@code optionType}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     *          was specified to the constructor of this
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   435
     *          {@code ConfirmationCallback}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *          Otherwise, this method returns the default option as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     *          an index into the
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   438
     *          {@code options} array specified to the constructor
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   439
     *          of this {@code ConfirmationCallback}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    public int getDefaultOption() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        return defaultOption;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * Set the selected confirmation option.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     *
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   448
     * @param selection the selection represented as {@code YES},
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   449
     *          {@code NO}, {@code OK} or {@code CANCEL}
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   450
     *          if an {@code optionType} was specified to the constructor
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   451
     *          of this {@code ConfirmationCallback}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     *          Otherwise, the selection represents the index into the
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   453
     *          {@code options} array specified to the constructor
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   454
     *          of this {@code ConfirmationCallback}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * @see #getSelectedIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    public void setSelectedIndex(int selection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        this.selection = selection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * Get the selected confirmation option.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * @return the selected confirmation option represented as
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   466
     *          {@code YES}, {@code NO}, {@code OK} or
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   467
     *          {@code CANCEL} if an {@code optionType}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     *          was specified to the constructor of this
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   469
     *          {@code ConfirmationCallback}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     *          Otherwise, this method returns the selected confirmation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     *          option as an index into the
18830
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   472
     *          {@code options} array specified to the constructor
90956ead732f 8020557: javadoc cleanup in javax.security
juh
parents: 5506
diff changeset
   473
     *          of this {@code ConfirmationCallback}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * @see #setSelectedIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    public int getSelectedIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        return selection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
}