1. /*
  2. * @(#)TextOutputCallback.java 1.13 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>TextOutputCallback</code> to the <code>handle</code>
  11. * method of a <code>CallbackHandler</code> to display information messages,
  12. * warning messages and error messages.
  13. *
  14. * @version 1.13, 01/23/03
  15. * @see javax.security.auth.callback.CallbackHandler
  16. */
  17. public class TextOutputCallback implements Callback, java.io.Serializable {
  18. /** Information message. */
  19. public static final int INFORMATION = 0;
  20. /** Warning message. */
  21. public static final int WARNING = 1;
  22. /** Error message. */
  23. public static final int ERROR = 2;
  24. /**
  25. * @serial
  26. * @since 1.4
  27. */
  28. private int messageType;
  29. /**
  30. * @serial
  31. * @since 1.4
  32. */
  33. private String message;
  34. /**
  35. * Construct a TextOutputCallback with a message type and message
  36. * to be displayed.
  37. *
  38. * <p>
  39. *
  40. * @param messageType the message type (<code>INFORMATION</code>,
  41. * <code>WARNING</code> or <code>ERROR</code>). <p>
  42. *
  43. * @param message the message to be displayed. <p>
  44. *
  45. * @exception IllegalArgumentException if <code>messageType</code>
  46. * is not either <code>INFORMATION</code>,
  47. * <code>WARNING</code> or <code>ERROR</code>,
  48. * if <code>message</code> is null,
  49. * or if <code>message</code> has a length of 0.
  50. */
  51. public TextOutputCallback(int messageType, String message) {
  52. if ((messageType != INFORMATION &&
  53. messageType != WARNING && messageType != ERROR) ||
  54. message == null || message.length() == 0)
  55. throw new IllegalArgumentException();
  56. this.messageType = messageType;
  57. this.message = message;
  58. }
  59. /**
  60. * Get the message type.
  61. *
  62. * <p>
  63. *
  64. * @return the message type (<code>INFORMATION</code>,
  65. * <code>WARNING</code> or <code>ERROR</code>).
  66. */
  67. public int getMessageType() {
  68. return messageType;
  69. }
  70. /**
  71. * Get the message to be displayed.
  72. *
  73. * <p>
  74. *
  75. * @return the message to be displayed.
  76. */
  77. public String getMessage() {
  78. return message;
  79. }
  80. }