KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > security > auth > callback > TextOutputCallback


1 /*
2  * @(#)TextOutputCallback.java 1.15 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.security.auth.callback;
9
10 /**
11  * <p> Underlying security services instantiate and pass a
12  * <code>TextOutputCallback</code> to the <code>handle</code>
13  * method of a <code>CallbackHandler</code> to display information messages,
14  * warning messages and error messages.
15  *
16  * @version 1.15, 12/19/03
17  * @see javax.security.auth.callback.CallbackHandler
18  */

19 public class TextOutputCallback implements Callback JavaDoc, java.io.Serializable JavaDoc {
20
21     private static final long serialVersionUID = 1689502495511663102L;
22
23     /** Information message. */
24     public static final int INFORMATION = 0;
25     /** Warning message. */
26     public static final int WARNING = 1;
27     /** Error message. */
28     public static final int ERROR = 2;
29
30     /**
31      * @serial
32      * @since 1.4
33      */

34     private int messageType;
35     /**
36      * @serial
37      * @since 1.4
38      */

39     private String JavaDoc message;
40
41     /**
42      * Construct a TextOutputCallback with a message type and message
43      * to be displayed.
44      *
45      * <p>
46      *
47      * @param messageType the message type (<code>INFORMATION</code>,
48      * <code>WARNING</code> or <code>ERROR</code>). <p>
49      *
50      * @param message the message to be displayed. <p>
51      *
52      * @exception IllegalArgumentException if <code>messageType</code>
53      * is not either <code>INFORMATION</code>,
54      * <code>WARNING</code> or <code>ERROR</code>,
55      * if <code>message</code> is null,
56      * or if <code>message</code> has a length of 0.
57      */

58     public TextOutputCallback(int messageType, String JavaDoc message) {
59     if ((messageType != INFORMATION &&
60         messageType != WARNING && messageType != ERROR) ||
61         message == null || message.length() == 0)
62         throw new IllegalArgumentException JavaDoc();
63
64     this.messageType = messageType;
65     this.message = message;
66     }
67
68     /**
69      * Get the message type.
70      *
71      * <p>
72      *
73      * @return the message type (<code>INFORMATION</code>,
74      * <code>WARNING</code> or <code>ERROR</code>).
75      */

76     public int getMessageType() {
77     return messageType;
78     }
79
80     /**
81      * Get the message to be displayed.
82      *
83      * <p>
84      *
85      * @return the message to be displayed.
86      */

87     public String JavaDoc getMessage() {
88     return message;
89     }
90 }
91
Popular Tags