KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*_############################################################################
2   _##
3   _## SNMP4J-Agent - EnumeratedScalar.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.MOScalar;
25 import org.snmp4j.smi.Integer32;
26 import org.snmp4j.agent.MOAccess;
27 import org.snmp4j.smi.OID;
28 import org.snmp4j.agent.request.SubRequest;
29 import org.snmp4j.mp.SnmpConstants;
30 import org.snmp4j.agent.mo.snmp.smi.EnumerationConstraint;
31
32 /**
33  * The <code>EnumeratedScalar</code> class represents enumerated SMI INTEGER
34  * types for scalar objects.
35  *
36  * @author Frank Fock
37  * @version 1.0
38  */

39 public class EnumeratedScalar extends MOScalar {
40
41   private EnumerationConstraint constraint;
42
43   /**
44    * Creates an enumerated INTEGER scalar with specifying a set of possible
45    * values. To constraint the possible values
46    * assignable to this object, you will have to set the corrsponding
47    * {@link EnumerationConstraint} with {@link #setConstraint} or use an
48    * appropriate value validation listener.
49    * @param oid
50    * the instance oid (with ".0" suffix) of the scalar.
51    * @param access
52    * the maximum access for this column.
53    * @param value
54    * the initial value.
55    */

56   public EnumeratedScalar(OID oid,
57                           MOAccess access,
58                           Integer32 value) {
59     super(oid, access, value);
60   }
61
62   /**
63    * Creates an enumerated INTEGER scalar with specifying a set of possible
64    * values.
65    * @param oid
66    * the instance oid (with ".0" suffix) of the scalar.
67    * @param access
68    * the maximum access for this column.
69    * @param value
70    * the initial value.
71    * @param allowedValues
72    * an array of possible values for this object.
73    */

74   public EnumeratedScalar(OID oid,
75                           MOAccess access,
76                           Integer32 value,
77                           int[] allowedValues) {
78     super(oid, access, value);
79     this.constraint = new EnumerationConstraint(allowedValues);
80   }
81
82   public int isValueOK(SubRequest request) {
83     int result = super.isValueOK(request);
84     if ((constraint != null) && (result == SnmpConstants.SNMP_ERROR_SUCCESS)) {
85       return constraint.validate(request.getVariableBinding().getVariable());
86     }
87     return result;
88   }
89
90   protected void setConstraint(EnumerationConstraint constraint) {
91     this.constraint = constraint;
92   }
93 }
94
Popular Tags