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. package javax.security.auth.callback;
  8. /**
  9. * <p> Underlying security services instantiate and pass a
  10. * <code>NameCallback</code> to the <code>handle</code>
  11. * method of a <code>CallbackHandler</code> to retrieve name information.
  12. *
  13. * @version 1.14, 12/19/03
  14. * @see javax.security.auth.callback.CallbackHandler
  15. */
  16. public class NameCallback implements Callback, java.io.Serializable {
  17. private static final long serialVersionUID = 3770938795909392253L;
  18. /**
  19. * @serial
  20. * @since 1.4
  21. */
  22. private String prompt;
  23. /**
  24. * @serial
  25. * @since 1.4
  26. */
  27. private String defaultName;
  28. /**
  29. * @serial
  30. * @since 1.4
  31. */
  32. private String inputName;
  33. /**
  34. * Construct a <code>NameCallback</code> with a prompt.
  35. *
  36. * <p>
  37. *
  38. * @param prompt the prompt used to request the name.
  39. *
  40. * @exception IllegalArgumentException if <code>prompt</code> is null
  41. * or if <code>prompt</code> has a length of 0.
  42. */
  43. public NameCallback(String prompt) {
  44. if (prompt == null || prompt.length() == 0)
  45. throw new IllegalArgumentException();
  46. this.prompt = prompt;
  47. }
  48. /**
  49. * Construct a <code>NameCallback</code> with a prompt
  50. * and default name.
  51. *
  52. * <p>
  53. *
  54. * @param prompt the prompt used to request the information. <p>
  55. *
  56. * @param defaultName the name to be used as the default name displayed
  57. * with the prompt.
  58. *
  59. * @exception IllegalArgumentException if <code>prompt</code> is null,
  60. * if <code>prompt</code> has a length of 0,
  61. * if <code>defaultName</code> is null,
  62. * or if <code>defaultName</code> has a length of 0.
  63. */
  64. public NameCallback(String prompt, String defaultName) {
  65. if (prompt == null || prompt.length() == 0 ||
  66. defaultName == null || defaultName.length() == 0)
  67. throw new IllegalArgumentException();
  68. this.prompt = prompt;
  69. this.defaultName = defaultName;
  70. }
  71. /**
  72. * Get the prompt.
  73. *
  74. * <p>
  75. *
  76. * @return the prompt.
  77. */
  78. public String getPrompt() {
  79. return prompt;
  80. }
  81. /**
  82. * Get the default name.
  83. *
  84. * <p>
  85. *
  86. * @return the default name, or null if this <code>NameCallback</code>
  87. * was not instantiated with a <code>defaultName</code>.
  88. */
  89. public String getDefaultName() {
  90. return defaultName;
  91. }
  92. /**
  93. * Set the retrieved name.
  94. *
  95. * <p>
  96. *
  97. * @param name the retrieved name (which may be null).
  98. *
  99. * @see #getName
  100. */
  101. public void setName(String name) {
  102. this.inputName = name;
  103. }
  104. /**
  105. * Get the retrieved name.
  106. *
  107. * <p>
  108. *
  109. * @return the retrieved name (which may be null)
  110. *
  111. * @see #setName
  112. */
  113. public String getName() {
  114. return inputName;
  115. }
  116. }