Search in sources :

Example 1 with AssignableFromString

use of org.snmp4j.smi.AssignableFromString in project nifi by apache.

the class SetSNMP method stringToVariable.

/**
 * Method to create the variable from the attribute value and the given SMI syntax value
 * @param value attribute value
 * @param smiSyntax attribute SMI Syntax
 * @return variable
 */
private Variable stringToVariable(String value, int smiSyntax) {
    Variable var = AbstractVariable.createFromSyntax(smiSyntax);
    try {
        if (var instanceof AssignableFromString) {
            ((AssignableFromString) var).setValue(value);
        } else if (var instanceof AssignableFromInteger) {
            ((AssignableFromInteger) var).setValue(Integer.valueOf(value));
        } else if (var instanceof AssignableFromLong) {
            ((AssignableFromLong) var).setValue(Long.valueOf(value));
        } else {
            this.getLogger().error("Unsupported conversion of [" + value + "] to " + var.getSyntaxString());
            var = null;
        }
    } catch (IllegalArgumentException e) {
        this.getLogger().error("Unsupported conversion of [" + value + "] to " + var.getSyntaxString(), e);
        var = null;
    }
    return var;
}
Also used : AbstractVariable(org.snmp4j.smi.AbstractVariable) Variable(org.snmp4j.smi.Variable) AssignableFromInteger(org.snmp4j.smi.AssignableFromInteger) AssignableFromString(org.snmp4j.smi.AssignableFromString) AssignableFromLong(org.snmp4j.smi.AssignableFromLong)

Aggregations

AbstractVariable (org.snmp4j.smi.AbstractVariable)1 AssignableFromInteger (org.snmp4j.smi.AssignableFromInteger)1 AssignableFromLong (org.snmp4j.smi.AssignableFromLong)1 AssignableFromString (org.snmp4j.smi.AssignableFromString)1 Variable (org.snmp4j.smi.Variable)1