FileDocCategorySizeDatePackage
SnmpVarBindList.javaAPI DocJava SE 5 API21436Fri Aug 26 14:55:04 BST 2005com.sun.jmx.snmp

SnmpVarBindList

public class SnmpVarBindList extends Vector
Contains a list of SnmpVarBind objects. This class helps to create an SnmpVarBindList from a list of MIB variable names. In addition, it contains different forms of methods which can copy or clone the list. This list is required by any SNMP entity which specifies a list of variables to query.

This API is a Sun Microsystems internal API and is subject to change without notice.

Fields Summary
public String
identity
A name given to the SnmpVarBindList. Useful for debugging. The default name is "VarBindList".
Timestamp
timestamp
Timestamp when this SnmpVarBindList was updated. Valid only for SnmpGet and SnmpGetNext operations. SnmpTimestamp is null by default. Also, when the list is cloned without value the timestamp is not copied.
Constructors Summary
public SnmpVarBindList()
Prepares an empty list. The initial capacity and the capacity increment are initialized to 5.

    
    
    // CONSTRUCTORS
    //-------------

                        
      
        super(5, 5) ;
    
public SnmpVarBindList(int initialCapacity)
Prepares an empty list.

param
initialCapacity The initial capacity of the SnmpVarBindList.

        super(initialCapacity) ;
    
public SnmpVarBindList(String name)
Prepares an empty list with a String to print while debugging.

param
name The name of the newly created SnmpVarBindList.

        super(5, 5) ;
        identity = name ;
    
public SnmpVarBindList(SnmpVarBindList list)
Similar to the copy constructor. Does a shallow copy of the elements. Individual elements are not cloned.

param
list The SnmpVarBindList to copy.

        super(list.size(), 5) ;
        list.copyInto(elementData) ;
        elementCount = list.size() ;
    
public SnmpVarBindList(Vector list)
Creates a new SnmpVarBindList object from a plain vector of SnmpVarBind objects. Objects in the specified vector can be SnmpVarBind objects or derivatives.

param
list The vector of SnmpVarBind objects to copy.

        super(list.size(), 5);
        for (Enumeration e = list.elements(); e.hasMoreElements();) {
            final SnmpVarBind varBind = (SnmpVarBind)e.nextElement();
            addElement((SnmpVarBind)varBind.clone());
        }
    
public SnmpVarBindList(String name, Vector list)
Creates a new SnmpVarBindList object from a plain vector of SnmpVarBind objects. Objects in the specified vector can be SnmpVarBind objects or derivatives.

param
name The name of the newly created SnmpVarBindList.
param
list The vector of SnmpVarBind objects to copy.

        this(list);
        identity = name;
    
Methods Summary
public synchronized voidaddInstance(java.lang.String inst)
Adds the string as an instance part to all OIDs in this list. This method should be used with caution because it affects all OIDs in the list.

param
inst The String to add as an instance part.
exception
SnmpStatusException An error occurred while accessing a MIB node.

        int max= size();
        for (int i = 0; i < max;  i++) {
            ((SnmpVarBind)elementData[i]).addInstance(inst) ;
        }
    
public final synchronized voidaddVarBind(java.lang.String[] list, java.lang.String inst)
Prepares a vector of SnmpVarBindList from an array of SNMP MIB variables and instances.

param
list An array of String containing MIB variable names.
param
inst A common instance for each of the MIB variables in vlist.
exception
SnmpStatusException An error occurred while accessing a MIB node.

        for (int i = 0; i < list.length; i++) {
            SnmpVarBind avar = new SnmpVarBind(list[i]) ;
            avar.addInstance(inst) ;
            addElement(avar) ;
        }
    
public synchronized voidaddVarBind(java.lang.String[] list)
Adds an array of MIB variable names to the list. For example:

String mylist[] = {"sysUpTime.0", "ifInOctets.0"}
vb.addVarBind(mylist) ;

param
list The array of MIB variable names.
exception
SnmpStatusException An error occurred while accessing a MIB node.

        addVarBind(list, null) ;
    
public synchronized voidaddVarBind(java.lang.String name)
Creates an SnmpVarBind object from the given MIB variable and appends it to the existing SnmpVarBindList. It creates a new SnmpVarBindList if one did not exist.

param
name A MIB variable name.
exception
SnmpStatusException An error occurred while accessing a MIB node.

        SnmpVarBind avar ;
        avar = new SnmpVarBind(name) ;
        addVarBind(avar) ;
    
public synchronized voidaddVarBind(SnmpVarBind var)
Appends the given SnmpVarBind object to the existing SnmpVarBindList. It creates a new SnmpVarBindList if one did not exist.

param
var The SnmpVarBind object to be appended.

        addElement(var) ;
    
public synchronized voidaddVarBindList(com.sun.jmx.snmp.SnmpVarBindList list)
Appends an SnmpVarBindList at the end of the current SnmpVarBindList object.

param
list The SnmpVarBindList to append.

        ensureCapacity(list.size() + size()) ;
        for (int i = 0; i < list.size(); i++) {
            addElement(list.getVarBindAt(i)) ;
        }
    
public synchronized booleancheckForUnspecifiedValue()
Returns true if there is a value that is not specified.

return
true if there is a value that is not specified, false otherwise.

        int max= this.size();
        for (int i = 0; i < max ; i++) {
            SnmpVarBind avar = (SnmpVarBind)elementData[i] ;
            if (avar.isUnspecifiedValue())
                return true ;
        }
        return false ;
    
public synchronized booleancheckForValidValues()
Returns false if any of the variables does not contain a valid value. Typically used for SnmpSet operations.

return
false if any of the variables does not contain a valid value, true otherwise.

        int max= this.size();
        for (int i = 0; i < max ; i++) {
            SnmpVarBind avar = (SnmpVarBind)elementData[i] ;
            if (avar.isValidValue() == false)
                return false ;
        }
        return true ;
    
public synchronized java.lang.Objectclone()
Clones the SnmpVarBindList. A new copy of the SnmpVarBindList is created. It is a real deep copy.

return
The object clone.

        return cloneWithValue() ;
    
public synchronized com.sun.jmx.snmp.SnmpVarBindListcloneWithValue()
Clones the SnmpVarBindList. A new copy of the SnmpVarBindList is created. It is a real deep copy.

return
The SnmpVarBindList clone.

        SnmpVarBindList newvb = new SnmpVarBindList() ;
        newvb.setTimestamp(this.getTimestamp()) ;
        newvb.ensureCapacity(this.size()) ;
        for (int i = 0; i < this.size() ; i++) {
            SnmpVarBind avar = (SnmpVarBind)elementData[i] ;
            newvb.addElement(avar.clone()) ;
        }
        return newvb ;
    
public synchronized com.sun.jmx.snmp.SnmpVarBindListcloneWithoutValue()
Clones the SnmpVarBindList. It does not clone the value part of the variable. It is a deep copy (except for the value portion).

return
The SnmpVarBindList clone.

        SnmpVarBindList newvb = new SnmpVarBindList() ;
        int max = this.size();
        newvb.ensureCapacity(max) ;
        for (int i = 0; i < max ; i++) {
            SnmpVarBind avar = (SnmpVarBind)elementData[i] ;
            newvb.addElement(avar.cloneWithoutValue()) ;
        }
        return newvb ;
    
public final synchronized voidconcat(java.util.Vector list)
Adds elements in the specified SnmpVarBindList to this list. The elements are not cloned.

param
list A vector of SnmpVarBind.

        ensureCapacity(size() + list.size()) ;
        for (Enumeration e = list.elements() ; e.hasMoreElements() ; ) {
            addElement(e.nextElement()) ;
        }
    
public voidfinalize()
Finalizer of the SnmpVarBindList objects. This method is called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

Removes all the elements from this SnmpVarBindList object.

        removeAllElements() ;
    
public TimestampgetTimestamp()
Gets the timestamp associated with this SnmpVarBindList.

return
The timestamp.

        return timestamp ;
    
public final synchronized SnmpVarBindgetVarBindAt(int pos)
Gets an SnmpVarBind object.

param
pos The position in the list.
return
The SnmpVarBind object at the specified position.
exception
java.lang.ArrayIndexOutOfBoundsException If the specified pos is beyond range.

        return (SnmpVarBind)(elementAt(pos)) ;
    
public synchronized intgetVarBindCount()
Gets the number of elements in this list.

return
The number of elements in the list.

        return size() ;
    
public synchronized java.util.EnumerationgetVarBindList()
This is a convenience function that returns an enumeration. This can be used to traverse the list. This is advantageous as it hides the implementation of the class of the list which keeps the variables.

return
An enumeration object of SnmpVarBind objects.

        return elements() ;
    
public synchronized intindexOfOid(SnmpVarBind var, int min, int max)
Gives the index of an OID in the SnmpVarBindList. The index returned must be greater than or equal to the start parameter and smaller than the end parameter. Otherwise the method returns -1.

param
var The SnmpVarBind object with the requested OID.
param
min The min index in SnmpVarBindList.
param
max The max index in SnmpVarBindList.
return
The index of the OID in SnmpVarBindList.

        SnmpOid oidarg = var.getOid() ;
        for (int i = min; i < max ; i++) {
            SnmpVarBind avar = (SnmpVarBind)elementData[i] ;
            if (oidarg.equals(avar.getOid()))
                return i ;
        }
        return -1 ;
    
public synchronized intindexOfOid(SnmpVarBind var)
Gives the index of an OID in the SnmpVarBindList.

param
var The SnmpVarBind object with the requested OID.
return
The index of the OID in SnmpVarBindList.

        return indexOfOid(var, 0, size()) ;
    
public synchronized intindexOfOid(SnmpOid oid)
Gives the index of an OID in the SnmpVarBindList.

param
oid The SnmpOid object with the requested OID.
return
The index of the OID in SnmpVarBindList.

        int max = size();
        for (int i = 0; i < max ; i++) {
            SnmpVarBind avar = (SnmpVarBind)elementData[i] ;
            if (oid.equals(avar.getOid()))
                return i ;
        }
        return -1 ;
    
public java.lang.StringoidListToString()
Returns a String containing the ASCII representation of all OIDs in the list.

return
An ASCII list of all OIDs in this list.

        StringBuffer s = new StringBuffer(300) ;
        for (int i = 0 ; i < elementCount ; i++) {
            SnmpVarBind avar = (SnmpVarBind)elementData[i] ;
            s.append(avar.getOid().toString() + "\n") ;
        }
        return s.toString() ;
    
public synchronized booleanremoveVarBind(java.lang.String[] list, java.lang.String inst)
Removes the array of SNMP MIB variables and instances from the existing SnmpVarBindList.

param
list An array of String containing MIB variable names.
param
inst A common instance for each of the MIB variables in vlist.
return
true if all the SNMP MIB variables were components of this SnmpVarBindList, false otherwise.
exception
SnmpStatusException An error occurred while accessing a MIB node.

        boolean result = true;
        for (int i = 0; i < list.length; i++) {
            SnmpVarBind avar = new SnmpVarBind(list[i]) ;
            avar.addInstance(inst) ;
            int indexOid = indexOfOid(avar) ;
            try {
                removeElementAt(indexOid) ;
            } catch (ArrayIndexOutOfBoundsException e) {
                result = false ;
            }
        }
        return result ;
    
public synchronized booleanremoveVarBind(java.lang.String[] list)
Removes the array of SNMP MIB variables from the existing SnmpVarBindList.

param
list Array of strings containing MIB variable names.
return
true if all the SNMP MIB variables were components of this SnmpVarBindList, false otherwise.
exception
SnmpStatusException An error occurred while accessing a MIB node.

        return removeVarBind(list, null) ;
    
public synchronized booleanremoveVarBind(java.lang.String name)
Removes the SnmpVarBind object corresponding to the given MIB variable from the existing SnmpVarBindList.

param
name A MIB variable name.
return
true if the SNMP MIB variable was a component of this SnmpVarBindList, false otherwise.
exception
SnmpStatusException An error occurred while accessing a MIB node.

        SnmpVarBind avar ;
        int indexOid ;
        avar = new SnmpVarBind(name) ;
        indexOid = indexOfOid(avar) ;
        try {
            removeElementAt(indexOid) ;
            return true ;
        } catch (ArrayIndexOutOfBoundsException e) {
            return false ;
        }
    
public synchronized booleanremoveVarBind(SnmpVarBind var)
Removes the given SnmpVarBind object from the existing SnmpVarBindList.

param
var The SnmpVarBind object to be removed.
return
true if the SnmpVarBind object was a component of this SnmpVarBindList, false otherwise.

        return removeElement(var) ;
    
public synchronized booleanremoveVarBindList(com.sun.jmx.snmp.SnmpVarBindList list)
Removes all the SnmpVarBind objects of the given SnmpVarBindList from the existing SnmpVarBindList.

param
list The SnmpVarBindList to be removed.
return
true if all the SnmpVarBind objects were components of this SnmpVarBindList, false otherwise.

        boolean result = true;
        for (int i = 0; i < list.size(); i++) {
            result = removeElement(list.getVarBindAt(i)) ;
        }
        return result;
    
public final synchronized voidreplaceVarBind(SnmpVarBind var, int pos)
Replaces an element at a specified location with the new element.

param
var The replacement variable.
param
pos The location in the SnmpVarBindList.
exception
java.lang.ArrayIndexOutOfBoundsException If the specified pos is beyond range.

        setElementAt(var, pos) ;
    
public voidsetTimestamp(Timestamp tstamp)
Records the sysUpTime and the actual time when this SnmpVarBindList was changed or created. This needs to be set explicitly.

param
tstamp The SnmpTimestamp of the device for which the values hold true.

        timestamp = tstamp ;
    
public final synchronized voidsetVarBindList(java.util.Vector list)
Replaces the current variable binding list of SnmpVarBind with the new specified variable binding list of SnmpVarBind objects. This method only clones the vector. It does not clone the SnmpVarBind objects contained in the list.

param
list A vector of SnmpVarBind objects.

        setVarBindList(list, false) ;
    
public final synchronized voidsetVarBindList(java.util.Vector list, boolean copy)
Replaces the current variable binding list of SnmpVarBind objects with the new variable binding list of SnmpVarBind objects. If copy is true, it will clone each SnmpVarBind object contained in the list.

param
list A vector of SnmpVarBind objects.
param
copy The flag indicating whether each object in the list should be cloned.

        synchronized (list) {
            final int max = list.size();
            setSize(max) ;
            list.copyInto(this.elementData) ;
            if (copy) { 	// do deepcopy of all vars.
                for (int i = 0; i < max ; i++) {
                    SnmpVarBind avar = (SnmpVarBind)elementData[i] ;
                    elementData[i] = avar.clone() ;
                }
            }
        }
    
public synchronized com.sun.jmx.snmp.SnmpVarBindListsplitAt(int pos)
Splits the SnmpVarBindList.

param
pos The position at which to split the SnmpVarBindList
return
The SnmpVarBindList list from the beginning up to the split position.

        SnmpVarBindList splitVb = null ;
        if (pos > elementCount)
            return splitVb ;
        splitVb = new SnmpVarBindList() ; // size() - atPosition) ;
        int max= size();
        for (int i = pos; i < max ; i++)
            splitVb.addElement(elementData[i]) ;
        elementCount = pos ;
        trimToSize() ;
        return splitVb ;
    
public synchronized java.util.VectortoVector(boolean copy)
Copies the SnmpVarBindList into a plain vector of SnmpVarBind objects. If the copy flag is false, does a shallow copy of the list. Otherwise, individual elements will be cloned.

param
copy The flag indicating whether each object in the list should be cloned.
return
A new vector of SnmpVarBind objects.

        final int count = elementCount;
        if (copy == false) return (Vector) super.clone();
        Vector result = new Vector(count,5);
        for (int i = 0; i < count ; i++) {
            SnmpVarBind avar = (SnmpVarBind)elementData[i] ;
            result.addElement(avar.clone()) ;
        }
        return result;
    
public synchronized java.lang.StringvarBindListToString()
Constructs a String containing details of each SnmpVarBindList (oid+value). This is typically used in debugging.

return
A detailed String of all in the SnmpVarBindList.

        StringBuffer s = new StringBuffer(300) ;
        for (int i = 0; i < elementCount ; i++) {
            s.append(elementData[i].toString() + "\n")  ;
        }
        return s.toString() ;