/*
*
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
// Copyright (c) 1995-96 by Cisco Systems, Inc.
package com.sun.jmx.snmp;
// java import
//
import java.util.Vector;
import java.util.Enumeration;
import java.util.logging.Level;
import java.util.Hashtable;
//RI import
import static com.sun.jmx.defaults.JmxProperties.SNMP_LOGGER;
import com.sun.jmx.snmp.SnmpOidTable;
import com.sun.jmx.snmp.SnmpOidRecord;
import com.sun.jmx.snmp.SnmpStatusException;
/**
* Contains metadata definitions for MIB variables.
* A name can be resolved against a table of MIB variables.
* Each entry in the table is an SnmpOidRecord
object that contains a name, a dot-separated OID string,
* and the corresponding SMI type of the variable.
*
* If you need to load a specific SnmpOidTable
, just call the static method
* {@link com.sun.jmx.snmp.SnmpOid#setSnmpOidTable SnmpOid.setSnmpOidTable(myOidTable)
}.
*
*
This API is a Sun Microsystems internal API and is subject * to change without notice.
* @see com.sun.jmx.snmp.SnmpOidRecord * */ public class SnmpOidTableSupport implements SnmpOidTable { /** * Creates anSnmpOidTableSupport
with the specified name.
* This name identifies the MIB to which belong the MIB variables contained
* in this SnmpOidTableSupport
object.
* @param name The OID table name.
*/
public SnmpOidTableSupport(String name) {
myName=name;
}
/**
* Searches for a MIB variable given its logical name and returns an {@link com.sun.jmx.snmp.SnmpOidRecord} object
* containing information on the variable.
*
* @param name The name of the MIB variable.
* @return The SnmpOidRecord
object containing information on the variable.
* @exception SnmpStatusException If the variable is not found.
*/
public SnmpOidRecord resolveVarName(String name) throws SnmpStatusException {
SnmpOidRecord var = oidStore.get(name) ;
if (var != null) {
return var;
} else {
throw new SnmpStatusException("Variable name <" + name + "> not found in Oid repository") ;
}
}
/**
* Searches for a MIB variable given its OID and returns an {@link com.sun.jmx.snmp.SnmpOidRecord} object
* containing information on the variable.
*
* @param oid The OID of the MIB variable.
* @return The SnmpOidRecord
object containing information on the variable.
* @exception SnmpStatusException If the variable is not found.
*/
public SnmpOidRecord resolveVarOid(String oid) throws SnmpStatusException {
// Try to see if the variable name is actually an OID to resolve.
//
int index = oid.indexOf('.') ;
if (index < 0) {
throw new SnmpStatusException("Variable oid <" + oid + "> not found in Oid repository") ;
}
if (index == 0) {
// The oid starts with a '.' ala CMU.
//
oid= oid.substring(1, oid.length());
}
// Go through the oidStore ... Good luck !
//
for(Enumeration list= oidStore.elements(); list.hasMoreElements(); ) {
SnmpOidRecord element= (SnmpOidRecord) list.nextElement();
if (element.getOid().equals(oid))
return element;
}
throw new SnmpStatusException("Variable oid <" + oid + "> not found in Oid repository") ;
}
/**
* Returns a list that can be used to traverse all the entries in this SnmpOidTable
.
* @return A vector of {@link com.sun.jmx.snmp.SnmpOidRecord} objects.
*/
public VectorObject
is equal to this SnmpOidTableSupport
.
* @param object The Object
to be compared.
* @return true
if object
is an SnmpOidTableSupport
instance and equals to this,
* false
otherwise.
*/
public boolean equals(Object object) {
if (!(object instanceof SnmpOidTableSupport)) {
return false;
}
SnmpOidTableSupport val = (SnmpOidTableSupport) object;
return myName.equals(val.getName());
}
/**
* Returns the name identifying this SnmpOidTableSupport
object.
* @return The OID table name.
*/
public String getName() {
return myName;
}
/*
* ------------------------------------------
* PRIVATE METHODS
* ------------------------------------------
*/
private Hashtable