Module org.snmp4j

Class DictionaryOIDTextFormat

java.lang.Object
org.snmp4j.util.SimpleOIDTextFormat
org.snmp4j.util.DictionaryOIDTextFormat
All Implemented Interfaces:
OIDTextFormat

public class DictionaryOIDTextFormat extends SimpleOIDTextFormat
The DictionaryOIDTextFormat provides a simple OID formatter based on a dictionary of object name to object identifier mappings.
Since:
3.5.0
Author:
Frank Fock
  • Constructor Details

    • DictionaryOIDTextFormat

      public DictionaryOIDTextFormat()
      Creates an empty DictionaryOIDTextFormat that acts like its superclass SimpleOIDTextFormat unless dictionary entries are added with put(String) or put(String, String). dictionaryOIOTextFormat.parse("ifAdminStatus") will return new int[] { 1,3,6,1,2,1,2,2,1,7 } if dictionaryOIOTextFormat.put("ifAdminStatus=1.3.6.1.2.1.2.2.1.7") was called before. Otherwise, a ParseException will be thrown. An the other hand, dictionaryOIOTextFormat.format(new int[] { 1,3,6,1,2,1,2,2,1,7,1000 }) will return "ifAdminStatus.1000" in the first case, i.e. with dictionary entry.
    • DictionaryOIDTextFormat

      public DictionaryOIDTextFormat(String... objectNameToDottedNumbers)
      Create a dictionary based OID formatter from a list of object name to OID mappings of the form 'sysDescr=1.3.6.1.2.1.1.1'.
      Parameters:
      objectNameToDottedNumbers - an object name to OID mapping of the form "<oid>=<object-name>
  • Method Details

    • put

      public OID put(String objectName, String dottedNumbersOidString)
      Put an object name to oid mapping into the internal dictionary used for the OID/text formatting.
      Parameters:
      objectName - an SMI object name like 'sysDescr'.
      dottedNumbersOidString - the SMI object identifier registered for the given objectName in dotted number format, e.g. '1.3.6.1.2.1.1.1' for 'sysDescr'.
      Returns:
      the parsed OID or null if the oid string contains characters other than digits and '.'. In that case, the dictionary is not changed.
    • put

      public OID put(String objectNameEqualsDottedNumberString)
      Put an object name to oid mapping into the internal dictionary used for the OID/text formatting that is parsed from a string of the form 'sysDescr = 1.3.6.1.2.1.1.1' or 'sysDescr=1.3.6.1.2.1.1.1'.
      Parameters:
      objectNameEqualsDottedNumberString - a string with an SMI object name, a single equals sign, and after that equals sign a dotted number OID string: e.g. 'sysDescr=1.3.6.1.2.1.1.1'.
      Returns:
      the parsed OID or null if the oid string contains characters other than digits and '.'. In that case, the dictionary is not changed.
    • size

      public int size()
      Return the size of the dictionary.
      Returns:
      the number of entries in the OID formatting dictionary.
    • format

      public String format(int[] value)
      Description copied from class: SimpleOIDTextFormat
      Returns a textual representation of a raw object ID as dotted string ("1.3.6.1.4").
      Specified by:
      format in interface OIDTextFormat
      Overrides:
      format in class SimpleOIDTextFormat
      Parameters:
      value - the OID value to format.
      Returns:
      the textual representation.
    • parse

      public int[] parse(String text) throws ParseException
      Description copied from class: SimpleOIDTextFormat
      Parses a textual representation of an object ID as dotted string (e.g. "1.3.6.1.2.1.1") and returns its raw value.
      Specified by:
      parse in interface OIDTextFormat
      Overrides:
      parse in class SimpleOIDTextFormat
      Parameters:
      text - a textual representation of an OID.
      Returns:
      the raw OID value.
      Throws:
      ParseException - if the OID cannot be parsed successfully.