1 /* 2 * Copyright (c) 2000, 2014, 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 com.sun.jmx.snmp.agent; 27 28 // java imports 29 // 30 import com.sun.jmx.snmp.SnmpDefinitions; 31 import java.io.Serializable; 32 import com.sun.jmx.snmp.SnmpStatusException; 33 34 /** 35 * Represents a node in an SNMP MIB which corresponds to a table entry 36 * meta node. 37 * <P> 38 * This class is used by the class generated by <CODE>mibgen</CODE>. 39 * You should not need to use this class directly. 40 * 41 * <p><b>This API is a Sun Microsystems internal API and is subject 42 * to change without notice.</b></p> 43 */ 44 @SuppressWarnings("serial") // JDK implementation class 45 public abstract class SnmpMibEntry extends SnmpMibNode 46 implements Serializable { 47 48 /** 49 * Tells whether the given arc identifies a variable (scalar object) in 50 * this entry. 51 * 52 * @param arc An OID arc. 53 * 54 * @return <CODE>true</CODE> if `arc' leads to a variable. 55 */ 56 public abstract boolean isVariable(long arc); 57 58 /** 59 * Tells whether the given arc identifies a readable scalar object in 60 * this entry. 61 * 62 * @param arc An OID arc. 63 * 64 * @return <CODE>true</CODE> if `arc' leads to a readable variable. 65 */ 66 public abstract boolean isReadable(long arc); 67 68 /** 69 * Get the next OID arc corresponding to a readable scalar variable. 70 * 71 */ 72 public long getNextVarId(long id, Object userData) 73 throws SnmpStatusException { 74 long nextvar = super.getNextVarId(id,userData); 75 while (!isReadable(nextvar)) 76 nextvar = super.getNextVarId(nextvar,userData); 77 return nextvar; 78 } 79 80 /** 81 * Checks whether the given OID arc identifies a variable (columnar 82 * object). 83 * 84 * @param userData A contextual object containing user-data. 85 * This object is allocated through the <code> 86 * {@link com.sun.jmx.snmp.agent.SnmpUserDataFactory}</code> 87 * for each incoming SNMP request. 88 * 89 * @exception If the given `arc' does not identify any variable in this 90 * group, throws an SnmpStatusException. 91 */ 92 public void validateVarId(long arc, Object userData) 93 throws SnmpStatusException { 94 if (isVariable(arc) == false) { 95 throw new SnmpStatusException(SnmpDefinitions.snmpRspNoSuchName); 96 } 97 } 98 99 /** 100 * Generic handling of the <CODE>get</CODE> operation. 101 * <p>The actual implementation of this method will be generated 102 * by mibgen. Usually, this implementation only delegates the 103 * job to some other provided runtime class, which knows how to 104 * access the MBean. The current toolkit thus provides two 105 * implementations: 106 * <ul><li>The standard implementation will directly access the 107 * MBean through a java reference,</li> 108 * <li>The generic implementation will access the MBean through 109 * the MBean server.</li> 110 * </ul> 111 * <p>Both implementations rely upon specific - and distinct, set of 112 * mibgen generated methods. 113 * <p> You can override this method if you need to implement some 114 * specific policies for minimizing the accesses made to some remote 115 * underlying resources. 116 * <p> 117 * 118 * @param req The sub-request that must be handled by this node. 119 * 120 * @param depth The depth reached in the OID tree. 121 * 122 * @exception SnmpStatusException An error occurred while accessing 123 * the MIB node. 124 */ 125 abstract public void get(SnmpMibSubRequest req, int depth) 126 throws SnmpStatusException; 127 128 /** 129 * Generic handling of the <CODE>set</CODE> operation. 130 * <p>The actual implementation of this method will be generated 131 * by mibgen. Usually, this implementation only delegates the 132 * job to some other provided runtime class, which knows how to 133 * access the MBean. The current toolkit thus provides two 134 * implementations: 135 * <ul><li>The standard implementation will directly access the 136 * MBean through a java reference,</li> 137 * <li>The generic implementation will access the MBean through 138 * the MBean server.</li> 139 * </ul> 140 * <p>Both implementations rely upon specific - and distinct, set of 141 * mibgen generated methods. 142 * <p> You can override this method if you need to implement some 143 * specific policies for minimizing the accesses made to some remote 144 * underlying resources. 145 * <p> 146 * 147 * @param req The sub-request that must be handled by this node. 148 * 149 * @param depth The depth reached in the OID tree. 150 * 151 * @exception SnmpStatusException An error occurred while accessing 152 * the MIB node. 153 */ 154 abstract public void set(SnmpMibSubRequest req, int depth) 155 throws SnmpStatusException; 156 157 /** 158 * Generic handling of the <CODE>check</CODE> operation. 159 * 160 * <p>The actual implementation of this method will be generated 161 * by mibgen. Usually, this implementation only delegates the 162 * job to some other provided runtime class, which knows how to 163 * access the MBean. The current toolkit thus provides two 164 * implementations: 165 * <ul><li>The standard implementation will directly access the 166 * MBean through a java reference,</li> 167 * <li>The generic implementation will access the MBean through 168 * the MBean server.</li> 169 * </ul> 170 * <p>Both implementations rely upon specific - and distinct, set of 171 * mibgen generated methods. 172 * <p> You can override this method if you need to implement some 173 * specific policies for minimizing the accesses made to some remote 174 * underlying resources, or if you need to implement some consistency 175 * checks between the different values provided in the varbind list. 176 * <p> 177 * 178 * @param req The sub-request that must be handled by this node. 179 * 180 * @param depth The depth reached in the OID tree. 181 * 182 * @exception SnmpStatusException An error occurred while accessing 183 * the MIB node. 184 */ 185 abstract public void check(SnmpMibSubRequest req, int depth) 186 throws SnmpStatusException; 187 188 }