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