Path: blob/master/src/java.base/share/classes/javax/security/auth/callback/TextOutputCallback.java
41161 views
/*1* Copyright (c) 1999, 2019, 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 TextOutputCallback} to the {@code handle}30* method of a {@code CallbackHandler} to display information messages,31* warning messages and error messages.32*33* @since 1.434* @see javax.security.auth.callback.CallbackHandler35*/36public class TextOutputCallback implements Callback, java.io.Serializable {3738@java.io.Serial39private static final long serialVersionUID = 1689502495511663102L;4041/** Information message. */42public static final int INFORMATION = 0;43/** Warning message. */44public static final int WARNING = 1;45/** Error message. */46public static final int ERROR = 2;4748/**49* @serial50* @since 1.451*/52private int messageType;53/**54* @serial55* @since 1.456*/57private String message;5859/**60* Construct a TextOutputCallback with a message type and message61* to be displayed.62*63* @param messageType the message type ({@code INFORMATION},64* {@code WARNING} or {@code ERROR}).65*66* @param message the message to be displayed.67*68* @exception IllegalArgumentException if {@code messageType}69* is not either {@code INFORMATION},70* {@code WARNING} or {@code ERROR},71* if {@code message} is null,72* or if {@code message} has a length of 0.73*/74public TextOutputCallback(int messageType, String message) {75if ((messageType != INFORMATION &&76messageType != WARNING && messageType != ERROR) ||77message == null || message.isEmpty())78throw new IllegalArgumentException();7980this.messageType = messageType;81this.message = message;82}8384/**85* Get the message type.86*87* @return the message type ({@code INFORMATION},88* {@code WARNING} or {@code ERROR}).89*/90public int getMessageType() {91return messageType;92}9394/**95* Get the message to be displayed.96*97* @return the message to be displayed.98*/99public String getMessage() {100return message;101}102}103104105