Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/security/auth/callback/NameCallback.java
38918 views
/*1* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.security.auth.callback;2627/**28* <p> Underlying security services instantiate and pass a29* {@code NameCallback} to the {@code handle}30* method of a {@code CallbackHandler} to retrieve name information.31*32* @see javax.security.auth.callback.CallbackHandler33*/34public class NameCallback implements Callback, java.io.Serializable {3536private static final long serialVersionUID = 3770938795909392253L;3738/**39* @serial40* @since 1.441*/42private String prompt;43/**44* @serial45* @since 1.446*/47private String defaultName;48/**49* @serial50* @since 1.451*/52private String inputName;5354/**55* Construct a {@code NameCallback} with a prompt.56*57* <p>58*59* @param prompt the prompt used to request the name.60*61* @exception IllegalArgumentException if {@code prompt} is null62* or if {@code prompt} has a length of 0.63*/64public NameCallback(String prompt) {65if (prompt == null || prompt.length() == 0)66throw new IllegalArgumentException();67this.prompt = prompt;68}6970/**71* Construct a {@code NameCallback} with a prompt72* and default name.73*74* <p>75*76* @param prompt the prompt used to request the information. <p>77*78* @param defaultName the name to be used as the default name displayed79* with the prompt.80*81* @exception IllegalArgumentException if {@code prompt} is null,82* if {@code prompt} has a length of 0,83* if {@code defaultName} is null,84* or if {@code defaultName} has a length of 0.85*/86public NameCallback(String prompt, String defaultName) {87if (prompt == null || prompt.length() == 0 ||88defaultName == null || defaultName.length() == 0)89throw new IllegalArgumentException();9091this.prompt = prompt;92this.defaultName = defaultName;93}9495/**96* Get the prompt.97*98* <p>99*100* @return the prompt.101*/102public String getPrompt() {103return prompt;104}105106/**107* Get the default name.108*109* <p>110*111* @return the default name, or null if this {@code NameCallback}112* was not instantiated with a {@code defaultName}.113*/114public String getDefaultName() {115return defaultName;116}117118/**119* Set the retrieved name.120*121* <p>122*123* @param name the retrieved name (which may be null).124*125* @see #getName126*/127public void setName(String name) {128this.inputName = name;129}130131/**132* Get the retrieved name.133*134* <p>135*136* @return the retrieved name (which may be null)137*138* @see #setName139*/140public String getName() {141return inputName;142}143}144145146