01: /*_############################################################################
02: _##
03: _## SNMP4J-Agent - EnumeratedScalar.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.MOScalar;
24: import org.snmp4j.smi.Integer32;
25: import org.snmp4j.agent.MOAccess;
26: import org.snmp4j.smi.OID;
27: import org.snmp4j.agent.request.SubRequest;
28: import org.snmp4j.mp.SnmpConstants;
29: import org.snmp4j.agent.mo.snmp.smi.EnumerationConstraint;
30:
31: /**
32: * The <code>EnumeratedScalar</code> class represents enumerated SMI INTEGER
33: * types for scalar objects.
34: *
35: * @author Frank Fock
36: * @version 1.0
37: */
38: public class EnumeratedScalar extends MOScalar {
39:
40: private EnumerationConstraint constraint;
41:
42: /**
43: * Creates an enumerated INTEGER scalar with specifying a set of possible
44: * values. To constraint the possible values
45: * assignable to this object, you will have to set the corrsponding
46: * {@link EnumerationConstraint} with {@link #setConstraint} or use an
47: * appropriate value validation listener.
48: * @param oid
49: * the instance oid (with ".0" suffix) of the scalar.
50: * @param access
51: * the maximum access for this column.
52: * @param value
53: * the initial value.
54: */
55: public EnumeratedScalar(OID oid, MOAccess access, Integer32 value) {
56: super (oid, access, value);
57: }
58:
59: /**
60: * Creates an enumerated INTEGER scalar with specifying a set of possible
61: * values.
62: * @param oid
63: * the instance oid (with ".0" suffix) of the scalar.
64: * @param access
65: * the maximum access for this column.
66: * @param value
67: * the initial value.
68: * @param allowedValues
69: * an array of possible values for this object.
70: */
71: public EnumeratedScalar(OID oid, MOAccess access, Integer32 value,
72: int[] allowedValues) {
73: super (oid, access, value);
74: this .constraint = new EnumerationConstraint(allowedValues);
75: }
76:
77: public int isValueOK(SubRequest request) {
78: int result = super .isValueOK(request);
79: if ((constraint != null)
80: && (result == SnmpConstants.SNMP_ERROR_SUCCESS)) {
81: return constraint.validate(request.getVariableBinding()
82: .getVariable());
83: }
84: return result;
85: }
86:
87: protected void setConstraint(EnumerationConstraint constraint) {
88: this.constraint = constraint;
89: }
90: }
|