1 /*
   2  * Copyright (c) 2003, 2012, 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 package sun.management.snmp.jvmmib;
  27 
  28 //
  29 // Generated by mibgen version 5.0 (06/02/03) when compiling JVM-MANAGEMENT-MIB in standard metadata mode.
  30 //
  31 
  32 // java imports
  33 //
  34 import java.io.Serializable;
  35 
  36 // jmx imports
  37 //
  38 import javax.management.MBeanServer;
  39 import com.sun.jmx.snmp.SnmpCounter;
  40 import com.sun.jmx.snmp.SnmpCounter64;
  41 import com.sun.jmx.snmp.SnmpGauge;
  42 import com.sun.jmx.snmp.SnmpInt;
  43 import com.sun.jmx.snmp.SnmpUnsignedInt;
  44 import com.sun.jmx.snmp.SnmpIpAddress;
  45 import com.sun.jmx.snmp.SnmpTimeticks;
  46 import com.sun.jmx.snmp.SnmpOpaque;
  47 import com.sun.jmx.snmp.SnmpString;
  48 import com.sun.jmx.snmp.SnmpStringFixed;
  49 import com.sun.jmx.snmp.SnmpOid;
  50 import com.sun.jmx.snmp.SnmpNull;
  51 import com.sun.jmx.snmp.SnmpValue;
  52 import com.sun.jmx.snmp.SnmpVarBind;
  53 import com.sun.jmx.snmp.SnmpStatusException;
  54 
  55 // jdmk imports
  56 //
  57 import com.sun.jmx.snmp.agent.SnmpMib;
  58 import com.sun.jmx.snmp.agent.SnmpMibGroup;
  59 import com.sun.jmx.snmp.agent.SnmpStandardObjectServer;
  60 import com.sun.jmx.snmp.agent.SnmpStandardMetaServer;
  61 import com.sun.jmx.snmp.agent.SnmpMibSubRequest;
  62 import com.sun.jmx.snmp.agent.SnmpMibTable;
  63 import com.sun.jmx.snmp.EnumRowStatus;
  64 import com.sun.jmx.snmp.SnmpDefinitions;
  65 
  66 /**
  67  * The class is used for representing SNMP metadata for the "JvmClassLoading" group.
  68  * The group is defined with the following oid: 1.3.6.1.4.1.42.2.145.3.163.1.1.1.
  69  */
  70 public class JvmClassLoadingMeta extends SnmpMibGroup
  71      implements Serializable, SnmpStandardMetaServer {
  72 
  73     static final long serialVersionUID = 5722857476941218568L;
  74     /**
  75      * Constructor for the metadata associated to "JvmClassLoading".
  76      */
  77     public JvmClassLoadingMeta(SnmpMib myMib, SnmpStandardObjectServer objserv) {
  78         objectserver = objserv;
  79         try {
  80             registerObject(4);
  81             registerObject(3);
  82             registerObject(2);
  83             registerObject(1);
  84         } catch (IllegalAccessException e) {
  85             throw new RuntimeException(e.getMessage());
  86         }
  87     }
  88 
  89     /**
  90      * Get the value of a scalar variable
  91      */
  92     public SnmpValue get(long var, Object data)
  93         throws SnmpStatusException {
  94         switch((int)var) {
  95             case 4:
  96                 return new SnmpInt(node.getJvmClassesVerboseLevel());
  97 
  98             case 3:
  99                 return new SnmpCounter64(node.getJvmClassesUnloadedCount());
 100 
 101             case 2:
 102                 return new SnmpCounter64(node.getJvmClassesTotalLoadedCount());
 103 
 104             case 1:
 105                 return new SnmpGauge(node.getJvmClassesLoadedCount());
 106 
 107             default:
 108                 break;
 109         }
 110         throw new SnmpStatusException(SnmpStatusException.noSuchObject);
 111     }
 112 
 113     /**
 114      * Set the value of a scalar variable
 115      */
 116     public SnmpValue set(SnmpValue x, long var, Object data)
 117         throws SnmpStatusException {
 118         switch((int)var) {
 119             case 4:
 120                 if (x instanceof SnmpInt) {
 121                     try  {
 122                         node.setJvmClassesVerboseLevel( new EnumJvmClassesVerboseLevel (((SnmpInt)x).toInteger()));
 123                     } catch(IllegalArgumentException e)  {
 124                         throw new SnmpStatusException(SnmpStatusException.snmpRspWrongValue);
 125                     }
 126                     return new SnmpInt(node.getJvmClassesVerboseLevel());
 127                 } else {
 128                     throw new SnmpStatusException(SnmpStatusException.snmpRspWrongType);
 129                 }
 130 
 131             case 3:
 132                 throw new SnmpStatusException(SnmpStatusException.snmpRspNotWritable);
 133 
 134             case 2:
 135                 throw new SnmpStatusException(SnmpStatusException.snmpRspNotWritable);
 136 
 137             case 1:
 138                 throw new SnmpStatusException(SnmpStatusException.snmpRspNotWritable);
 139 
 140             default:
 141                 break;
 142         }
 143         throw new SnmpStatusException(SnmpStatusException.snmpRspNotWritable);
 144     }
 145 
 146     /**
 147      * Check the value of a scalar variable
 148      */
 149     public void check(SnmpValue x, long var, Object data)
 150         throws SnmpStatusException {
 151         switch((int) var) {
 152             case 4:
 153                 if (x instanceof SnmpInt) {
 154                     try  {
 155                         node.checkJvmClassesVerboseLevel( new EnumJvmClassesVerboseLevel (((SnmpInt)x).toInteger()));
 156                     } catch(IllegalArgumentException e)  {
 157                         throw new SnmpStatusException(SnmpStatusException.snmpRspWrongValue);
 158                     }
 159                 } else {
 160                     throw new SnmpStatusException(SnmpStatusException.snmpRspWrongType);
 161                 }
 162                 break;
 163 
 164             case 3:
 165                 throw new SnmpStatusException(SnmpStatusException.snmpRspNotWritable);
 166 
 167             case 2:
 168                 throw new SnmpStatusException(SnmpStatusException.snmpRspNotWritable);
 169 
 170             case 1:
 171                 throw new SnmpStatusException(SnmpStatusException.snmpRspNotWritable);
 172 
 173             default:
 174                 throw new SnmpStatusException(SnmpStatusException.snmpRspNotWritable);
 175         }
 176     }
 177 
 178     /**
 179      * Allow to bind the metadata description to a specific object.
 180      */
 181     protected void setInstance(JvmClassLoadingMBean var) {
 182         node = var;
 183     }
 184 
 185 
 186     // ------------------------------------------------------------
 187     //
 188     // Implements the "get" method defined in "SnmpMibGroup".
 189     // See the "SnmpMibGroup" Javadoc API for more details.
 190     //
 191     // ------------------------------------------------------------
 192 
 193     public void get(SnmpMibSubRequest req, int depth)
 194         throws SnmpStatusException {
 195         objectserver.get(this,req,depth);
 196     }
 197 
 198 
 199     // ------------------------------------------------------------
 200     //
 201     // Implements the "set" method defined in "SnmpMibGroup".
 202     // See the "SnmpMibGroup" Javadoc API for more details.
 203     //
 204     // ------------------------------------------------------------
 205 
 206     public void set(SnmpMibSubRequest req, int depth)
 207         throws SnmpStatusException {
 208         objectserver.set(this,req,depth);
 209     }
 210 
 211 
 212     // ------------------------------------------------------------
 213     //
 214     // Implements the "check" method defined in "SnmpMibGroup".
 215     // See the "SnmpMibGroup" Javadoc API for more details.
 216     //
 217     // ------------------------------------------------------------
 218 
 219     public void check(SnmpMibSubRequest req, int depth)
 220         throws SnmpStatusException {
 221         objectserver.check(this,req,depth);
 222     }
 223 
 224     /**
 225      * Returns true if "arc" identifies a scalar object.
 226      */
 227     public boolean isVariable(long arc) {
 228 
 229         switch((int)arc) {
 230             case 4:
 231             case 3:
 232             case 2:
 233             case 1:
 234                 return true;
 235             default:
 236                 break;
 237         }
 238         return false;
 239     }
 240 
 241     /**
 242      * Returns true if "arc" identifies a readable scalar object.
 243      */
 244     public boolean isReadable(long arc) {
 245 
 246         switch((int)arc) {
 247             case 4:
 248             case 3:
 249             case 2:
 250             case 1:
 251                 return true;
 252             default:
 253                 break;
 254         }
 255         return false;
 256     }
 257 
 258 
 259     // ------------------------------------------------------------
 260     //
 261     // Implements the "skipVariable" method defined in "SnmpMibGroup".
 262     // See the "SnmpMibGroup" Javadoc API for more details.
 263     //
 264     // ------------------------------------------------------------
 265 
 266     public boolean  skipVariable(long var, Object data, int pduVersion) {
 267         switch((int)var) {
 268             case 3:
 269             case 2:
 270                 if (pduVersion==SnmpDefinitions.snmpVersionOne) return true;
 271                 break;
 272             default:
 273                 break;
 274         }
 275         return super.skipVariable(var,data,pduVersion);
 276     }
 277 
 278     /**
 279      * Return the name of the attribute corresponding to the SNMP variable identified by "id".
 280      */
 281     public String getAttributeName(long id)
 282         throws SnmpStatusException {
 283         switch((int)id) {
 284             case 4:
 285                 return "JvmClassesVerboseLevel";
 286 
 287             case 3:
 288                 return "JvmClassesUnloadedCount";
 289 
 290             case 2:
 291                 return "JvmClassesTotalLoadedCount";
 292 
 293             case 1:
 294                 return "JvmClassesLoadedCount";
 295 
 296             default:
 297                 break;
 298         }
 299         throw new SnmpStatusException(SnmpStatusException.noSuchObject);
 300     }
 301 
 302     /**
 303      * Returns true if "arc" identifies a table object.
 304      */
 305     public boolean isTable(long arc) {
 306 
 307         switch((int)arc) {
 308             default:
 309                 break;
 310         }
 311         return false;
 312     }
 313 
 314     /**
 315      * Returns the table object identified by "arc".
 316      */
 317     public SnmpMibTable getTable(long arc) {
 318         return null;
 319     }
 320 
 321     /**
 322      * Register the group's SnmpMibTable objects with the meta-data.
 323      */
 324     public void registerTableNodes(SnmpMib mib, MBeanServer server) {
 325     }
 326 
 327     protected JvmClassLoadingMBean node;
 328     protected SnmpStandardObjectServer objectserver = null;
 329 }