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