1. /*
  2. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  3. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  4. */
  5. package javax.security.auth.callback;
  6. /**
  7. * <p> Underlying security services instantiate and pass a
  8. * <code>NameCallback</code> to the <code>invokeCallback</code>
  9. * method of a <code>CallbackHandler</code> to retrieve name information.
  10. *
  11. * @version 1.6, 01/11/00
  12. * @see javax.security.auth.callback.CallbackHandler
  13. */
  14. public class NameCallback implements Callback {
  15. private String prompt;
  16. private String defaultName;
  17. private String inputName;
  18. /**
  19. * Construct a <code>NameCallback</code> with a prompt.
  20. *
  21. * <p>
  22. *
  23. * @param prompt the prompt used to request the name.
  24. *
  25. * @exception IllegalArgumentException if <code>prompt</code> is null
  26. * or if <code>prompt</code> has a length of 0.
  27. */
  28. public NameCallback(String prompt) {
  29. if (prompt == null || prompt.length() == 0)
  30. throw new IllegalArgumentException();
  31. this.prompt = prompt;
  32. }
  33. /**
  34. * Construct a <code>NameCallback</code> with a prompt
  35. * and default name.
  36. *
  37. * <p>
  38. *
  39. * @param prompt the prompt used to request the information. <p>
  40. *
  41. * @param defaultName the name to be used as the default name displayed
  42. * with the prompt.
  43. *
  44. * @exception IllegalArgumentException if <code>prompt</code> is null,
  45. * if <code>prompt</code> has a length of 0,
  46. * if <code>defaultName</code> is null,
  47. * or if <code>defaultName</code> has a length of 0.
  48. */
  49. public NameCallback(String prompt, String defaultName) {
  50. if (prompt == null || prompt.length() == 0 ||
  51. defaultName == null || defaultName.length() == 0)
  52. throw new IllegalArgumentException();
  53. this.prompt = prompt;
  54. this.defaultName = defaultName;
  55. }
  56. /**
  57. * Get the prompt.
  58. *
  59. * <p>
  60. *
  61. * @return the prompt.
  62. */
  63. public String getPrompt() {
  64. return prompt;
  65. }
  66. /**
  67. * Get the default name.
  68. *
  69. * <p>
  70. *
  71. * @return the default name, or null if this <code>NameCallback</code>
  72. * was not instantiated with a <code>defaultName</code>.
  73. */
  74. public String getDefaultName() {
  75. return defaultName;
  76. }
  77. /**
  78. * Set the retrieved name.
  79. *
  80. * <p>
  81. *
  82. * @param name the retrieved name (which may be null).
  83. */
  84. public void setName(String name) {
  85. this.inputName = name;
  86. }
  87. /**
  88. * Get the retrieved name.
  89. *
  90. * <p>
  91. *
  92. * @return the retrieved name (which may be null)
  93. */
  94. public String getName() {
  95. return inputName;
  96. }
  97. }