KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

31     private String JavaDoc defaultName;
32     /**
33      * @serial
34      * @since 1.4
35      */

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

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

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

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

98     public String JavaDoc getDefaultName() {
99     return defaultName;
100     }
101
102     /**
103      * Set the retrieved name.
104      *
105      * <p>
106      *
107      * @param name the retrieved name (which may be null).
108      *
109      * @see #getName
110      */

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

124     public String JavaDoc getName() {
125     return inputName;
126     }
127 }
128
Popular Tags