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>TextInputCallback</code> to the <code>invokeCallback</code>
  9. * method of a <code>CallbackHandler</code> to retrieve generic text
  10. * information.
  11. *
  12. * @version 1.6, 01/11/00
  13. * @see javax.security.auth.callback.CallbackHandler
  14. */
  15. public class TextInputCallback implements Callback {
  16. private String prompt;
  17. private String defaultText;
  18. private String inputText;
  19. /**
  20. * Construct a <code>TextInputCallback</code> with a prompt.
  21. *
  22. * <p>
  23. *
  24. * @param prompt the prompt used to request the information.
  25. *
  26. * @exception IllegalArgumentException if <code>prompt</code> is null
  27. * or if <code>prompt</code> has a length of 0.
  28. */
  29. public TextInputCallback(String prompt) {
  30. if (prompt == null || prompt.length() == 0)
  31. throw new IllegalArgumentException();
  32. this.prompt = prompt;
  33. }
  34. /**
  35. * Construct a <code>TextInputCallback</code> with a prompt
  36. * and default input value.
  37. *
  38. * <p>
  39. *
  40. * @param prompt the prompt used to request the information. <p>
  41. *
  42. * @param defaultText the text to be used as the default text displayed
  43. * with the prompt.
  44. *
  45. * @exception IllegalArgumentException if <code>prompt</code> is null,
  46. * if <code>prompt</code> has a length of 0,
  47. * if <code>defaultText</code> is null
  48. * or if <code>defaultText</code> has a length of 0.
  49. */
  50. public TextInputCallback(String prompt, String defaultText) {
  51. if (prompt == null || prompt.length() == 0 ||
  52. defaultText == null || defaultText.length() == 0)
  53. throw new IllegalArgumentException();
  54. this.prompt = prompt;
  55. this.defaultText = defaultText;
  56. }
  57. /**
  58. * Get the prompt.
  59. *
  60. * <p>
  61. *
  62. * @return the prompt.
  63. */
  64. public String getPrompt() {
  65. return prompt;
  66. }
  67. /**
  68. * Get the default text.
  69. *
  70. * <p>
  71. *
  72. * @return the default text, or null if this <code>TextInputCallback</code>
  73. * was not instantiated with <code>defaultText</code>.
  74. */
  75. public String getDefaultText() {
  76. return defaultText;
  77. }
  78. /**
  79. * Set the retrieved text.
  80. *
  81. * <p>
  82. *
  83. * @param text the retrieved text, which may be null.
  84. */
  85. public void setText(String text) {
  86. this.inputText = text;
  87. }
  88. /**
  89. * Get the retrieved text.
  90. *
  91. * <p>
  92. *
  93. * @return the retrieved text, which may be null.
  94. */
  95. public String getText() {
  96. return inputText;
  97. }
  98. }