001 /*
002 * Copyright 1999-2003 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package javax.security.auth.callback;
027
028 /**
029 * <p> Underlying security services instantiate and pass a
030 * <code>TextOutputCallback</code> to the <code>handle</code>
031 * method of a <code>CallbackHandler</code> to display information messages,
032 * warning messages and error messages.
033 *
034 * @version 1.22, 05/05/07
035 * @see javax.security.auth.callback.CallbackHandler
036 */
037 public class TextOutputCallback implements Callback,
038 java.io.Serializable {
039
040 private static final long serialVersionUID = 1689502495511663102L;
041
042 /** Information message. */
043 public static final int INFORMATION = 0;
044 /** Warning message. */
045 public static final int WARNING = 1;
046 /** Error message. */
047 public static final int ERROR = 2;
048
049 /**
050 * @serial
051 * @since 1.4
052 */
053 private int messageType;
054 /**
055 * @serial
056 * @since 1.4
057 */
058 private String message;
059
060 /**
061 * Construct a TextOutputCallback with a message type and message
062 * to be displayed.
063 *
064 * <p>
065 *
066 * @param messageType the message type (<code>INFORMATION</code>,
067 * <code>WARNING</code> or <code>ERROR</code>). <p>
068 *
069 * @param message the message to be displayed. <p>
070 *
071 * @exception IllegalArgumentException if <code>messageType</code>
072 * is not either <code>INFORMATION</code>,
073 * <code>WARNING</code> or <code>ERROR</code>,
074 * if <code>message</code> is null,
075 * or if <code>message</code> has a length of 0.
076 */
077 public TextOutputCallback(int messageType, String message) {
078 if ((messageType != INFORMATION && messageType != WARNING && messageType != ERROR)
079 || message == null || message.length() == 0)
080 throw new IllegalArgumentException();
081
082 this .messageType = messageType;
083 this .message = message;
084 }
085
086 /**
087 * Get the message type.
088 *
089 * <p>
090 *
091 * @return the message type (<code>INFORMATION</code>,
092 * <code>WARNING</code> or <code>ERROR</code>).
093 */
094 public int getMessageType() {
095 return messageType;
096 }
097
098 /**
099 * Get the message to be displayed.
100 *
101 * <p>
102 *
103 * @return the message to be displayed.
104 */
105 public String getMessage() {
106 return message;
107 }
108 }
|