1 20 21 22 package org.snmp4j.agent.mo.snmp; 23 24 import org.snmp4j.agent.mo.MOMutableColumn; 25 import org.snmp4j.agent.MOAccess; 26 import org.snmp4j.smi.Variable; 27 import org.snmp4j.smi.SMIConstants; 28 import org.snmp4j.smi.Integer32; 29 import org.snmp4j.mp.SnmpConstants; 30 import org.snmp4j.agent.mo.MOTableRow; 31 32 public class StorageType extends MOMutableColumn { 33 34 public static final int other = 1; 35 public static final int volatile_ = 2; 36 public static final int nonVolatile = 3; 37 public static final int permanent = 4; 38 public static final int readOnly = 5; 39 40 41 public StorageType(int columnID, MOAccess access, 42 Integer32 defaultValue, boolean mutableInService) { 43 super(columnID, SMIConstants.SYNTAX_INTEGER, 44 access, defaultValue, mutableInService); 45 } 46 47 public StorageType(int columnID, MOAccess access, 48 Integer32 defaultValue) { 49 super(columnID, SMIConstants.SYNTAX_INTEGER, 50 access, defaultValue); 51 } 52 53 54 public synchronized int validate(Variable newValue, Variable oldValue) { 55 int v = (((Integer32)newValue).getValue()); 56 if ((v < 1) || (v > 5)) { 57 return SnmpConstants.SNMP_ERROR_WRONG_VALUE; 58 } 59 if (oldValue != null) { 60 int ov = (((Integer32)oldValue).getValue()); 61 if ((ov < 4) && (v >= 4)) { 62 return SnmpConstants.SNMP_ERROR_WRONG_VALUE; 63 } 64 if (ov >= 4) { 65 return SnmpConstants.SNMP_ERROR_WRONG_VALUE; 66 } 67 } 68 return super.validate(newValue, oldValue); 69 } 70 71 public boolean isVolatile(MOTableRow row, int column) { 72 Integer32 value = (Integer32) row.getValue(column); 73 if (value != null) { 74 int storageType = value.getValue(); 75 switch (storageType) { 76 case other: 77 case volatile_: 78 case readOnly: { 79 return true; 80 } 81 default: 82 return false; 83 } 84 } 85 return false; 86 } 87 88 } 89 | Popular Tags |