View Javadoc
1   /*
2    * This file is part of Waarp Project (named also Waarp or GG).
3    *
4    *  Copyright (c) 2019, Waarp SAS, and individual contributors by the @author
5    *  tags. See the COPYRIGHT.txt in the distribution for a full listing of
6    * individual contributors.
7    *
8    *  All Waarp Project is free software: you can redistribute it and/or
9    * modify it under the terms of the GNU General Public License as published by
10   * the Free Software Foundation, either version 3 of the License, or (at your
11   * option) any later version.
12   *
13   * Waarp is distributed in the hope that it will be useful, but WITHOUT ANY
14   * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15   * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16   *
17   *  You should have received a copy of the GNU General Public License along with
18   * Waarp . If not, see <http://www.gnu.org/licenses/>.
19   */
20  package org.waarp.snmp.utils;
21  
22  import org.snmp4j.smi.Counter32;
23  import org.snmp4j.smi.Counter64;
24  import org.snmp4j.smi.Gauge32;
25  import org.snmp4j.smi.Integer32;
26  import org.snmp4j.smi.IpAddress;
27  import org.snmp4j.smi.Null;
28  import org.snmp4j.smi.OID;
29  import org.snmp4j.smi.OctetString;
30  import org.snmp4j.smi.Opaque;
31  import org.snmp4j.smi.SMIConstants;
32  import org.snmp4j.smi.TimeTicks;
33  import org.snmp4j.smi.Variable;
34  import org.waarp.snmp.interf.WaarpInterfaceVariableFactory;
35  
36  /**
37   * Default VariableFactory
38   */
39  public class WaarpDefaultVariableFactory
40      implements WaarpInterfaceVariableFactory {
41  
42    @Override
43    public final Variable getVariable(final OID oid, final int type,
44                                      final int mibLevel, final int entry) {
45      final Variable var;
46      switch (type) {
47        case SMIConstants.SYNTAX_INTEGER:
48          // case SMIConstants.SYNTAX_INTEGER32:
49          var = new Integer32();
50          break;
51        case SMIConstants.SYNTAX_OCTET_STRING:
52          // case SMIConstants.SYNTAX_BITS:
53          var = new OctetString();
54          break;
55        case SMIConstants.SYNTAX_NULL:
56          var = new Null();
57          break;
58        case SMIConstants.SYNTAX_OBJECT_IDENTIFIER:
59          var = new OID();
60          break;
61        case SMIConstants.SYNTAX_IPADDRESS:
62          var = new IpAddress();
63          break;
64        case SMIConstants.SYNTAX_COUNTER32:
65          var = new Counter32();
66          break;
67        case SMIConstants.SYNTAX_GAUGE32:
68          // case SMIConstants.SYNTAX_UNSIGNED_INTEGER32:
69          var = new Gauge32();
70          break;
71        case SMIConstants.SYNTAX_TIMETICKS:
72          var = new TimeTicks();
73          break;
74        case SMIConstants.SYNTAX_OPAQUE:
75          var = new Opaque();
76          break;
77        case SMIConstants.SYNTAX_COUNTER64:
78          var = new Counter64();
79          break;
80        default:
81          throw new IllegalArgumentException("Unmanaged Type: " + type);
82      }
83      return var;
84    }
85  
86  }