Save This Page
Home » openjdk-7 » javax.security » auth » callback » [javadoc | source]
    1   /*
    2    * Copyright 1999-2003 Sun Microsystems, Inc.  All Rights Reserved.
    3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    4    *
    5    * This code is free software; you can redistribute it and/or modify it
    6    * under the terms of the GNU General Public License version 2 only, as
    7    * published by the Free Software Foundation.  Sun designates this
    8    * particular file as subject to the "Classpath" exception as provided
    9    * by Sun in the LICENSE file that accompanied this code.
   10    *
   11    * This code is distributed in the hope that it will be useful, but WITHOUT
   12    * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13    * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   14    * version 2 for more details (a copy is included in the LICENSE file that
   15    * accompanied this code).
   16    *
   17    * You should have received a copy of the GNU General Public License version
   18    * 2 along with this work; if not, write to the Free Software Foundation,
   19    * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   20    *
   21    * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   22    * CA 95054 USA or visit www.sun.com if you need additional information or
   23    * have any questions.
   24    */
   25   
   26   package javax.security.auth.callback;
   27   
   28   /**
   29    * <p> Underlying security services instantiate and pass a
   30    * <code>TextOutputCallback</code> to the <code>handle</code>
   31    * method of a <code>CallbackHandler</code> to display information messages,
   32    * warning messages and error messages.
   33    *
   34    * @see javax.security.auth.callback.CallbackHandler
   35    */
   36   public class TextOutputCallback implements Callback, java.io.Serializable {
   37   
   38       private static final long serialVersionUID = 1689502495511663102L;
   39   
   40       /** Information message. */
   41       public static final int INFORMATION         = 0;
   42       /** Warning message. */
   43       public static final int WARNING             = 1;
   44       /** Error message. */
   45       public static final int ERROR               = 2;
   46   
   47       /**
   48        * @serial
   49        * @since 1.4
   50        */
   51       private int messageType;
   52       /**
   53        * @serial
   54        * @since 1.4
   55        */
   56       private String message;
   57   
   58       /**
   59        * Construct a TextOutputCallback with a message type and message
   60        * to be displayed.
   61        *
   62        * <p>
   63        *
   64        * @param messageType the message type (<code>INFORMATION</code>,
   65        *                  <code>WARNING</code> or <code>ERROR</code>). <p>
   66        *
   67        * @param message the message to be displayed. <p>
   68        *
   69        * @exception IllegalArgumentException if <code>messageType</code>
   70        *                  is not either <code>INFORMATION</code>,
   71        *                  <code>WARNING</code> or <code>ERROR</code>,
   72        *                  if <code>message</code> is null,
   73        *                  or if <code>message</code> has a length of 0.
   74        */
   75       public TextOutputCallback(int messageType, String message) {
   76           if ((messageType != INFORMATION &&
   77                   messageType != WARNING && messageType != ERROR) ||
   78               message == null || message.length() == 0)
   79               throw new IllegalArgumentException();
   80   
   81           this.messageType = messageType;
   82           this.message = message;
   83       }
   84   
   85       /**
   86        * Get the message type.
   87        *
   88        * <p>
   89        *
   90        * @return the message type (<code>INFORMATION</code>,
   91        *                  <code>WARNING</code> or <code>ERROR</code>).
   92        */
   93       public int getMessageType() {
   94           return messageType;
   95       }
   96   
   97       /**
   98        * Get the message to be displayed.
   99        *
  100        * <p>
  101        *
  102        * @return the message to be displayed.
  103        */
  104       public String getMessage() {
  105           return message;
  106       }
  107   }

Save This Page
Home » openjdk-7 » javax.security » auth » callback » [javadoc | source]