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