AlertException.java 3.01 KB
Newer Older
1 2
/* AlertException.java -- exceptions generated by SSL alerts.
   Copyright (C) 2006  Free Software Foundation, Inc.
Tom Tromey committed
3

4
This file is a part of GNU Classpath.
Tom Tromey committed
5 6 7

GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
8 9
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.
Tom Tromey committed
10 11 12 13 14 15 16

GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
17 18 19
along with GNU Classpath; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
Tom Tromey committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.

As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module.  An independent module is a module which is not derived from
or based on this library.  If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version.  */
Tom Tromey committed
37 38


39
package gnu.javax.net.ssl.provider;
Tom Tromey committed
40

41
import javax.net.ssl.SSLException;
Tom Tromey committed
42

43 44 45 46
/**
 * An exception generated by an SSL alert.
 */
public class AlertException extends SSLException
Tom Tromey committed
47 48
{

49
  // Fields.
Tom Tromey committed
50 51
  // -------------------------------------------------------------------------

52 53
  private final Alert alert;
  private final boolean isLocal;
Tom Tromey committed
54 55 56 57

  // Constructor.
  // -------------------------------------------------------------------------

58
  public AlertException(Alert alert, boolean isLocal)
59
  {
60
    super(alert.description().toString());
61 62 63 64
    this.alert = alert;
    this.isLocal = isLocal;
  }

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
  public AlertException(Alert alert)
  {
    this(alert, true);
  }
  
  public AlertException(Alert alert, boolean isLocal, Throwable cause)
  {
    super(alert.description().toString(), cause);
    this.alert = alert;
    this.isLocal = isLocal;
  }
  
  public AlertException(Alert alert, Throwable cause)
  {
    this(alert, true, cause);
  }

82 83 84 85 86
  // Instance methods.
  // -------------------------------------------------------------------------

  public String getMessage()
  {
87
    return alert.description() + ": " +
88
      (isLocal ? "locally generated; " : "remotely generated; ") +
89
      alert.level();
90 91
  }

92
  public Alert alert ()
Tom Tromey committed
93
  {
94
    return alert;
Tom Tromey committed
95
  }
96 97 98 99 100
  
  public boolean isLocal()
  {
    return isLocal;
  }
Tom Tromey committed
101
}