| 1 20 21 22 package org.snmp4j.agent.mo.snmp; 23 24 import org.snmp4j.agent.MOAccess; 25 import org.snmp4j.smi.SMIConstants; 26 import org.snmp4j.agent.mo.MOMutableColumn; 27 import org.snmp4j.smi.Variable; 28 import org.snmp4j.smi.OctetString; 29 import org.snmp4j.mp.SnmpConstants; 30 31 public class SnmpTagValue extends MOMutableColumn { 32 33 public SnmpTagValue(int columnID, MOAccess access, OctetString defaultValue) { 34 super(columnID, SMIConstants.SYNTAX_OCTET_STRING, access, defaultValue); 35 } 36 37 public SnmpTagValue(int columnID, MOAccess access, 38 OctetString defaultValue, boolean mutableInService) { 39 super(columnID, SMIConstants.SYNTAX_OCTET_STRING, access, defaultValue, 40 mutableInService); 41 } 42 43 public static boolean isDelimiter(byte b) { 44 return ((b == 32) || (b == 9) || (b == 13) || (b == 11)); 45 } 46 47 public synchronized int validate(Variable newValue, Variable oldValue) { 48 int status = super.validate(newValue, oldValue); 49 if (status == SnmpConstants.SNMP_ERROR_SUCCESS) { 50 status = isValidTagValue(newValue); 51 } 52 return status; 53 } 54 55 public static int isValidTagValue(Variable newValue) { 56 if (!(newValue instanceof OctetString)) { 57 return SnmpConstants.SNMP_ERROR_WRONG_TYPE; 58 } 59 int status = SnmpConstants.SNMP_ERROR_SUCCESS; 60 OctetString os = (OctetString)newValue; 61 if (os.length() > 255) { 62 status = SnmpConstants.SNMP_ERROR_WRONG_LENGTH; 63 } 64 else { 65 for (int i = 0; i < os.length(); i++) { 66 if (isDelimiter(os.get(i))) { 67 status = SnmpConstants.SNMP_ERROR_BAD_VALUE; 68 break; 69 } 70 } 71 } 72 return status; 73 } 74 75 } 76 | Popular Tags |