KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)TextInputCallback.java 1.14 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>TextInputCallback</code> to the <code>handle</code>
13  * method of a <code>CallbackHandler</code> to retrieve generic text
14  * information.
15  *
16  * @version 1.14, 12/19/03
17  * @see javax.security.auth.callback.CallbackHandler
18  */

19 public class TextInputCallback implements Callback JavaDoc, java.io.Serializable JavaDoc {
20
21     private static final long serialVersionUID = -8064222478852811804L;
22
23     /**
24      * @serial
25      * @since 1.4
26      */

27     private String JavaDoc prompt;
28     /**
29      * @serial
30      * @since 1.4
31      */

32     private String JavaDoc defaultText;
33     /**
34      * @serial
35      * @since 1.4
36      */

37     private String JavaDoc inputText;
38
39     /**
40      * Construct a <code>TextInputCallback</code> with a prompt.
41      *
42      * <p>
43      *
44      * @param prompt the prompt used to request the information.
45      *
46      * @exception IllegalArgumentException if <code>prompt</code> is null
47      * or if <code>prompt</code> has a length of 0.
48      */

49     public TextInputCallback(String JavaDoc prompt) {
50     if (prompt == null || prompt.length() == 0)
51         throw new IllegalArgumentException JavaDoc();
52     this.prompt = prompt;
53     }
54
55     /**
56      * Construct a <code>TextInputCallback</code> with a prompt
57      * and default input value.
58      *
59      * <p>
60      *
61      * @param prompt the prompt used to request the information. <p>
62      *
63      * @param defaultText the text to be used as the default text displayed
64      * with the prompt.
65      *
66      * @exception IllegalArgumentException if <code>prompt</code> is null,
67      * if <code>prompt</code> has a length of 0,
68      * if <code>defaultText</code> is null
69      * or if <code>defaultText</code> has a length of 0.
70      */

71     public TextInputCallback(String JavaDoc prompt, String JavaDoc defaultText) {
72     if (prompt == null || prompt.length() == 0 ||
73         defaultText == null || defaultText.length() == 0)
74         throw new IllegalArgumentException JavaDoc();
75
76     this.prompt = prompt;
77     this.defaultText = defaultText;
78     }
79
80     /**
81      * Get the prompt.
82      *
83      * <p>
84      *
85      * @return the prompt.
86      */

87     public String JavaDoc getPrompt() {
88     return prompt;
89     }
90
91     /**
92      * Get the default text.
93      *
94      * <p>
95      *
96      * @return the default text, or null if this <code>TextInputCallback</code>
97      * was not instantiated with <code>defaultText</code>.
98      */

99     public String JavaDoc getDefaultText() {
100     return defaultText;
101     }
102
103     /**
104      * Set the retrieved text.
105      *
106      * <p>
107      *
108      * @param text the retrieved text, which may be null.
109      *
110      * @see #getText
111      */

112     public void setText(String JavaDoc text) {
113     this.inputText = text;
114     }
115
116     /**
117      * Get the retrieved text.
118      *
119      * <p>
120      *
121      * @return the retrieved text, which may be null.
122      *
123      * @see #setText
124      */

125     public String JavaDoc getText() {
126     return inputText;
127     }
128 }
129
Popular Tags