KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*_############################################################################
2   _##
3   _## SNMP4J-Agent - SnmpAdminString.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.*;
25 import org.snmp4j.agent.mo.*;
26 import org.snmp4j.smi.*;
27 import org.snmp4j.mp.SnmpConstants;
28
29 public class SnmpAdminString extends MOMutableColumn {
30
31   private int minLength = 0;
32   private int maxLength = 255;
33
34   public SnmpAdminString(int columnID,
35                          MOAccess access,
36                          Variable defaultValue,
37                          boolean mutableInService) {
38     super(columnID, SMIConstants.SYNTAX_OCTET_STRING,
39           access, defaultValue, mutableInService);
40   }
41
42   public SnmpAdminString(int columnID,
43                          MOAccess access,
44                          Variable defaultValue,
45                          boolean mutableInService,
46                          int minLength,
47                          int maxLength) {
48     super(columnID, SMIConstants.SYNTAX_OCTET_STRING,
49           access, defaultValue, mutableInService);
50     setMinLength(minLength);
51     setMaxLength(maxLength);
52   }
53
54   public int getMaxLength() {
55     return maxLength;
56   }
57
58   public int getMinLength() {
59     return minLength;
60   }
61
62   public void setMaxLength(int maxLength) {
63     this.maxLength = maxLength;
64   }
65
66   public void setMinLength(int minLength) {
67     this.minLength = minLength;
68   }
69
70   public synchronized int validate(Variable newValue, Variable oldValue) {
71     OctetString os = (OctetString) newValue;
72     if ((os.length() < minLength) || (os.length() > maxLength)) {
73       return SnmpConstants.SNMP_ERROR_WRONG_LENGTH;
74     }
75     return super.validate(newValue, oldValue);
76   }
77
78 }
79
Popular Tags