1 /*
   2  * Copyright (c) 1997, 2007, Oracle and/or its affiliates. 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 
  27 package com.sun.jmx.snmp;
  28 
  29 
  30 
  31 /**
  32  * Reports an error which occurred during a get/set operation on a mib node.
  33  *
  34  * This exception includes a status error code as defined in the SNMP protocol.
  35  *
  36  * <p><b>This API is a Sun Microsystems internal API  and is subject
  37  * to change without notice.</b></p>
  38  */
  39 
  40 public class SnmpStatusException extends Exception implements SnmpDefinitions {
  41     private static final long serialVersionUID = 5809485694133115675L;
  42 
  43     /**
  44      * Error code as defined in RFC 1448 for: <CODE>noSuchName</CODE>.
  45      */
  46     public static final int noSuchName         = 2 ;
  47 
  48     /**
  49      * Error code as defined in RFC 1448 for: <CODE>badValue</CODE>.
  50      */
  51     public static final int badValue           = 3 ;
  52 
  53     /**
  54      * Error code as defined in RFC 1448 for: <CODE>readOnly</CODE>.
  55      */
  56     public static final int readOnly           = 4 ;
  57 
  58 
  59     /**
  60      * Error code as defined in RFC 1448 for: <CODE>noAccess</CODE>.
  61      */
  62     public static final int noAccess           = 6 ;
  63 
  64     /**
  65      * Error code for reporting a no such instance error.
  66      */
  67     public static final int noSuchInstance     = 0xE0;
  68 
  69     /**
  70      * Error code for reporting a no such object error.
  71      */
  72     public static final int noSuchObject     = 0xE1;
  73 
  74     /**
  75      * Constructs a new <CODE>SnmpStatusException</CODE> with the specified status error.
  76      * @param status The error status.
  77      */
  78     public SnmpStatusException(int status) {
  79         errorStatus = status ;
  80     }
  81 
  82     /**
  83      * Constructs a new <CODE>SnmpStatusException</CODE> with the specified status error and status index.
  84      * @param status The error status.
  85      * @param index The error index.
  86      */
  87     public SnmpStatusException(int status, int index) {
  88         errorStatus = status ;
  89         errorIndex = index ;
  90     }
  91 
  92     /**
  93      * Constructs a new <CODE>SnmpStatusException</CODE> with an error message.
  94      * The error status is set to 0 (noError) and the index to -1.
  95      * @param s The error message.
  96      */
  97     public SnmpStatusException(String s) {
  98         super(s);
  99     }
 100 
 101     /**
 102      * Constructs a new <CODE>SnmpStatusException</CODE> with an error index.
 103      * @param x The original <CODE>SnmpStatusException</CODE>.
 104      * @param index The error index.
 105      */
 106     public SnmpStatusException(SnmpStatusException x, int index) {
 107         super(x.getMessage());
 108         errorStatus= x.errorStatus;
 109         errorIndex= index;
 110     }
 111 
 112     /**
 113      * Return the error status.
 114      * @return The error status.
 115      */
 116     public int getStatus() {
 117         return errorStatus ;
 118     }
 119 
 120     /**
 121      * Returns the index of the error.
 122      * A value of -1 means that the index is not known/applicable.
 123      * @return The error index.
 124      */
 125     public int getErrorIndex() {
 126         return errorIndex;
 127     }
 128 
 129 
 130     // PRIVATE VARIABLES
 131     //--------------------
 132 
 133     /**
 134      * Status of the error.
 135      * @serial
 136      */
 137     private int errorStatus = 0 ;
 138 
 139     /**
 140      * Index of the error.
 141      * If different from -1, indicates the index where the error occurs.
 142      * @serial
 143      */
 144     private int errorIndex= -1;
 145 
 146 }