KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > agent > mo > snmp > tc > TruthValueTC


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