1. /*
  2. * @(#)TextInputCallback.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>TextInputCallback</code> to the <code>handle</code>
  11. * method of a <code>CallbackHandler</code> to retrieve generic text
  12. * information.
  13. *
  14. * @version 1.12, 01/23/03
  15. * @see javax.security.auth.callback.CallbackHandler
  16. */
  17. public class TextInputCallback implements Callback, java.io.Serializable {
  18. /**
  19. * @serial
  20. * @since 1.4
  21. */
  22. private String prompt;
  23. /**
  24. * @serial
  25. * @since 1.4
  26. */
  27. private String defaultText;
  28. /**
  29. * @serial
  30. * @since 1.4
  31. */
  32. private String inputText;
  33. /**
  34. * Construct a <code>TextInputCallback</code> with a prompt.
  35. *
  36. * <p>
  37. *
  38. * @param prompt the prompt used to request the information.
  39. *
  40. * @exception IllegalArgumentException if <code>prompt</code> is null
  41. * or if <code>prompt</code> has a length of 0.
  42. */
  43. public TextInputCallback(String prompt) {
  44. if (prompt == null || prompt.length() == 0)
  45. throw new IllegalArgumentException();
  46. this.prompt = prompt;
  47. }
  48. /**
  49. * Construct a <code>TextInputCallback</code> with a prompt
  50. * and default input value.
  51. *
  52. * <p>
  53. *
  54. * @param prompt the prompt used to request the information. <p>
  55. *
  56. * @param defaultText the text to be used as the default text 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>defaultText</code> is null
  62. * or if <code>defaultText</code> has a length of 0.
  63. */
  64. public TextInputCallback(String prompt, String defaultText) {
  65. if (prompt == null || prompt.length() == 0 ||
  66. defaultText == null || defaultText.length() == 0)
  67. throw new IllegalArgumentException();
  68. this.prompt = prompt;
  69. this.defaultText = defaultText;
  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 text.
  83. *
  84. * <p>
  85. *
  86. * @return the default text, or null if this <code>TextInputCallback</code>
  87. * was not instantiated with <code>defaultText</code>.
  88. */
  89. public String getDefaultText() {
  90. return defaultText;
  91. }
  92. /**
  93. * Set the retrieved text.
  94. *
  95. * <p>
  96. *
  97. * @param text the retrieved text, which may be null.
  98. *
  99. * @see #getText
  100. */
  101. public void setText(String text) {
  102. this.inputText = text;
  103. }
  104. /**
  105. * Get the retrieved text.
  106. *
  107. * <p>
  108. *
  109. * @return the retrieved text, which may be null.
  110. *
  111. * @see #setText
  112. */
  113. public String getText() {
  114. return inputText;
  115. }
  116. }