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