- java.lang.Object
-
- org.snmp4j.util.SimpleOIDTextFormat
-
- org.snmp4j.util.DictionaryOIDTextFormat
-
- All Implemented Interfaces:
OIDTextFormat
public class DictionaryOIDTextFormat extends SimpleOIDTextFormat
TheDictionaryOIDTextFormatprovides a simple OID formatter based on a dictionary of object name to object identifier mappings.- Since:
- 3.5.0
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,OID>nameToOidMapprivate java.util.TreeMap<OID,java.lang.String>oidToNameMap
-
Constructor Summary
Constructors Constructor Description DictionaryOIDTextFormat()Creates an emptyDictionaryOIDTextFormatthat acts like its superclassSimpleOIDTextFormatunless dictionary entries are added withput(String)orput(String, String).DictionaryOIDTextFormat(java.lang.String... objectNameToDottedNumbers)Create a dictionary based OID formatter from a list of object name toOIDmappings of the form 'sysDescr=1.3.6.1.2.1.1.1'.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Stringformat(int[] value)Returns a textual representation of a raw object ID as dotted string ("1.3.6.1.4").int[]parse(java.lang.String text)Parses a textual representation of an object ID as dotted string (e.g.OIDput(java.lang.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'.OIDput(java.lang.String objectName, java.lang.String dottedNumbersOidString)Put an object name to oid mapping into the internal dictionary used for the OID/text formatting.intsize()Return the size of the dictionary.-
Methods inherited from class org.snmp4j.util.SimpleOIDTextFormat
formatForRoundTrip, formatOID, parseOID
-
-
-
-
Constructor Detail
-
DictionaryOIDTextFormat
public DictionaryOIDTextFormat()
Creates an emptyDictionaryOIDTextFormatthat acts like its superclassSimpleOIDTextFormatunless dictionary entries are added withput(String)orput(String, String).dictionaryOIOTextFormat.parse("ifAdminStatus")will returnnew int[] { 1,3,6,1,2,1,2,2,1,7 }ifdictionaryOIOTextFormat.put("ifAdminStatus=1.3.6.1.2.1.2.2.1.7")was called before. Otherwise, aParseExceptionwill 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(java.lang.String... objectNameToDottedNumbers)
Create a dictionary based OID formatter from a list of object name toOIDmappings 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 Detail
-
put
public OID put(java.lang.String objectName, java.lang.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 givenobjectNamein dotted number format, e.g. '1.3.6.1.2.1.1.1' for 'sysDescr'.- Returns:
- the parsed
OIDornullif the oid string contains characters other than digits and '.'. In that case, the dictionary is not changed.
-
put
public OID put(java.lang.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
OIDornullif 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 java.lang.String format(int[] value)
Description copied from class:SimpleOIDTextFormatReturns a textual representation of a raw object ID as dotted string ("1.3.6.1.4").- Specified by:
formatin interfaceOIDTextFormat- Overrides:
formatin classSimpleOIDTextFormat- Parameters:
value- the OID value to format.- Returns:
- the textual representation.
-
parse
public int[] parse(java.lang.String text) throws java.text.ParseExceptionDescription copied from class:SimpleOIDTextFormatParses 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:
parsein interfaceOIDTextFormat- Overrides:
parsein classSimpleOIDTextFormat- Parameters:
text- a textual representation of an OID.- Returns:
- the raw OID value.
- Throws:
java.text.ParseException- if the OID cannot be parsed successfully.
-
-