01: /*_############################################################################
02: _##
03: _## SNMP4J-Agent - TruthValueTC.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.tc;
22:
23: import org.snmp4j.agent.*;
24: import org.snmp4j.agent.mo.*;
25: import org.snmp4j.smi.*;
26: import org.snmp4j.agent.mo.snmp.smi.EnumerationConstraint;
27: import org.snmp4j.agent.mo.snmp.smi.ValueConstraintValidator;
28: import org.snmp4j.mp.SnmpConstants;
29:
30: public class TruthValueTC implements TextualConvention {
31:
32: public static final int TRUE = 1;
33: public static final int FALSE = 2;
34:
35: private EnumerationConstraint constraint = new EnumerationConstraint(
36: new int[] { TRUE, FALSE });
37:
38: public TruthValueTC() {
39: }
40:
41: public MOColumn createColumn(int columnID, int syntax,
42: MOAccess access, Variable defaultValue,
43: boolean mutableInService) {
44: MOColumn c;
45: if (access.isAccessibleForWrite()) {
46: c = new MOMutableColumn(columnID,
47: SMIConstants.SYNTAX_INTEGER32, access, defaultValue);
48: ((MOMutableColumn) c)
49: .addMOValueValidationListener(new ValueConstraintValidator(
50: constraint));
51: } else {
52: c = new MOColumn(columnID, SMIConstants.SYNTAX_INTEGER32,
53: access);
54: }
55: return c;
56: }
57:
58: public MOScalar createScalar(OID oid, MOAccess access,
59: Variable value) {
60: MOScalar scalar = new MOScalar(oid, access, value);
61: if (constraint.validate(value) != SnmpConstants.SNMP_ERROR_SUCCESS) {
62: throw new IllegalArgumentException("Illegal TruthValue "
63: + value);
64: }
65: scalar
66: .addMOValueValidationListener(new ValueConstraintValidator(
67: constraint));
68: return scalar;
69: }
70:
71: public String getModuleName() {
72: return "SNMPv2-TC";
73: }
74:
75: public String getName() {
76: return "TruthValue";
77: }
78:
79: public final static Integer32 getValue(boolean b) {
80: return (b) ? new Integer32(TRUE) : new Integer32(FALSE);
81: }
82:
83: }
|