01: /*_############################################################################
02: _##
03: _## SNMP4J-Agent - StorageType.java
04: _##
05: _## Copyright (C) 2005-2007 Frank Fock (SNMP4J.org)
06: _##
07: _## Licensed under the Apache License, Version 2.0 (the "License");
08: _## you may not use this file except in compliance with the License.
09: _## You may obtain a copy of the License at
10: _##
11: _## http://www.apache.org/licenses/LICENSE-2.0
12: _##
13: _## Unless required by applicable law or agreed to in writing, software
14: _## distributed under the License is distributed on an "AS IS" BASIS,
15: _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: _## See the License for the specific language governing permissions and
17: _## limitations under the License.
18: _##
19: _##########################################################################*/
20:
21: package org.snmp4j.agent.mo.snmp;
22:
23: import org.snmp4j.agent.mo.MOMutableColumn;
24: import org.snmp4j.agent.MOAccess;
25: import org.snmp4j.smi.Variable;
26: import org.snmp4j.smi.SMIConstants;
27: import org.snmp4j.smi.Integer32;
28: import org.snmp4j.mp.SnmpConstants;
29: import org.snmp4j.agent.mo.MOTableRow;
30:
31: public class StorageType extends MOMutableColumn {
32:
33: public static final int other = 1;
34: public static final int volatile_ = 2;
35: public static final int nonVolatile = 3;
36: public static final int permanent = 4;
37: public static final int readOnly = 5;
38:
39: public StorageType(int columnID, MOAccess access,
40: Integer32 defaultValue, boolean mutableInService) {
41: super (columnID, SMIConstants.SYNTAX_INTEGER, access,
42: defaultValue, mutableInService);
43: }
44:
45: public StorageType(int columnID, MOAccess access,
46: Integer32 defaultValue) {
47: super (columnID, SMIConstants.SYNTAX_INTEGER, access,
48: defaultValue);
49: }
50:
51: public synchronized int validate(Variable newValue,
52: Variable oldValue) {
53: int v = (((Integer32) newValue).getValue());
54: if ((v < 1) || (v > 5)) {
55: return SnmpConstants.SNMP_ERROR_WRONG_VALUE;
56: }
57: if (oldValue != null) {
58: int ov = (((Integer32) oldValue).getValue());
59: if ((ov < 4) && (v >= 4)) {
60: return SnmpConstants.SNMP_ERROR_WRONG_VALUE;
61: }
62: if (ov >= 4) {
63: return SnmpConstants.SNMP_ERROR_WRONG_VALUE;
64: }
65: }
66: return super .validate(newValue, oldValue);
67: }
68:
69: public boolean isVolatile(MOTableRow row, int column) {
70: Integer32 value = (Integer32) row.getValue(column);
71: if (value != null) {
72: int storageType = value.getValue();
73: switch (storageType) {
74: case other:
75: case volatile_:
76: case readOnly: {
77: return true;
78: }
79: default:
80: return false;
81: }
82: }
83: return false;
84: }
85:
86: }
|