KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*_############################################################################
2   _##
3   _## SNMP4J-Agent - Enumerated.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.snmp.smi.EnumerationConstraint;
31
32 /**
33  * The <code>Enumerated</code> class represents enumerated SMI INTEGER types
34  * for columnar objects.
35  *
36  * @author Frank Fock
37  * @version 1.0
38  */

39 public class Enumerated extends MOMutableColumn {
40
41   private EnumerationConstraint constraint;
42
43   /**
44    * Creates an enumerated INTEGER column with specifying a set of possible
45    * values.
46    * @param columnID
47    * the column ID (sub-identifier) of the column.
48    * @param access
49    * the maximum access for this column.
50    * @param defaultValue
51    * the default value used for new rows.
52    * @param mutableInService
53    * specifies whether this column can be changed while in service (active).
54    * @param allowedValues
55    * an array of possible values for this object.
56    */

57   public Enumerated(int columnID,
58                     MOAccess access,
59                     Integer32 defaultValue,
60                     boolean mutableInService,
61                     int[] allowedValues) {
62     super(columnID, SMIConstants.SYNTAX_INTEGER,
63           access, defaultValue, mutableInService);
64     this.constraint = new EnumerationConstraint(allowedValues);
65   }
66
67   /**
68    * Creates an enumerated INTEGER column. To constraint the possible values
69    * assignable to this object, you will have to set the corrsponding
70    * {@link EnumerationConstraint} with {@link #setConstraint} or use an
71    * appropriate value validation listener.
72    * @param columnID
73    * the column ID (sub-identifier) of the column.
74    * @param access
75    * the maximum access for this column.
76    * @param defaultValue
77    * the default value used for new rows.
78    * @param mutableInService
79    * specifies whether this column can be changed while in service (active).
80    */

81   public Enumerated(int columnID,
82                     MOAccess access,
83                     Integer32 defaultValue,
84                     boolean mutableInService) {
85     super(columnID, SMIConstants.SYNTAX_INTEGER,
86           access, defaultValue, mutableInService);
87   }
88
89   /**
90    * Creates an enumerated INTEGER column. To constraint the possible values
91    * assignable to this object, you will have to set the corrsponding
92    * {@link EnumerationConstraint} with {@link #setConstraint} or use an
93    * appropriate value validation listener.
94    * @param columnID
95    * the column ID (sub-identifier) of the column.
96    * @param access
97    * the maximum access for this column.
98    */

99   public Enumerated(int columnID,
100                     MOAccess access,
101                     Integer32 defaultValue) {
102     super(columnID, SMIConstants.SYNTAX_INTEGER,
103           access, defaultValue);
104   }
105
106   public synchronized int validate(Variable newValue, Variable oldValue) {
107     int result = super.validate(newValue, oldValue);
108     if ((constraint != null) &&
109         (result == SnmpConstants.SNMP_ERROR_SUCCESS)) {
110       return constraint.validate(newValue);
111     }
112     return result;
113   }
114
115   protected void setConstraint(EnumerationConstraint constraint) {
116     this.constraint = constraint;
117   }
118
119 }
120
Popular Tags