KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > agent > mo > snmp > StorageType


1 /*_############################################################################
2   _##
3   _## SNMP4J-Agent - StorageType.java
4   _##
5   _## Copyright (C) 2005-2007 Frank Fock (SNMP4J.org)
6   _##
7   _## Licensed under the Apache License, Version 2.0 (the "License");
8   _## you may not use this file except in compliance with the License.
9   _## 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
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