KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*_############################################################################
2   _##
3   _## SNMP4J-Agent - SnmpTagValue.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.MOAccess;
25 import org.snmp4j.smi.SMIConstants;
26 import org.snmp4j.agent.mo.MOMutableColumn;
27 import org.snmp4j.smi.Variable;
28 import org.snmp4j.smi.OctetString;
29 import org.snmp4j.mp.SnmpConstants;
30
31 public class SnmpTagValue extends MOMutableColumn {
32
33   public SnmpTagValue(int columnID, MOAccess access, OctetString defaultValue) {
34     super(columnID, SMIConstants.SYNTAX_OCTET_STRING, access, defaultValue);
35   }
36
37   public SnmpTagValue(int columnID, MOAccess access,
38                       OctetString defaultValue, boolean mutableInService) {
39     super(columnID, SMIConstants.SYNTAX_OCTET_STRING, access, defaultValue,
40           mutableInService);
41   }
42
43   public static boolean isDelimiter(byte b) {
44     return ((b == 32) || (b == 9) || (b == 13) || (b == 11));
45   }
46
47   public synchronized int validate(Variable newValue, Variable oldValue) {
48     int status = super.validate(newValue, oldValue);
49     if (status == SnmpConstants.SNMP_ERROR_SUCCESS) {
50       status = isValidTagValue(newValue);
51     }
52     return status;
53   }
54
55   public static int isValidTagValue(Variable newValue) {
56     if (!(newValue instanceof OctetString)) {
57       return SnmpConstants.SNMP_ERROR_WRONG_TYPE;
58     }
59     int status = SnmpConstants.SNMP_ERROR_SUCCESS;
60     OctetString os = (OctetString)newValue;
61     if (os.length() > 255) {
62       status = SnmpConstants.SNMP_ERROR_WRONG_LENGTH;
63     }
64     else {
65       for (int i = 0; i < os.length(); i++) {
66         if (isDelimiter(os.get(i))) {
67           status = SnmpConstants.SNMP_ERROR_BAD_VALUE;
68           break;
69         }
70       }
71     }
72     return status;
73   }
74
75 }
76
Popular Tags