1 /**
2 * This file is part of GoldenGate Project (named also GoldenGate or GG).
3 *
4 * Copyright 2009, Frederic Bregier, 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 GoldenGate 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 * GoldenGate 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 * GoldenGate . If not, see <http://www.gnu.org/licenses/>.
19 */
20 package goldengate.snmp.utils;
21
22 import goldengate.snmp.GgMOFactory;
23 import goldengate.snmp.interf.GgInterfaceMib;
24
25 import org.snmp4j.agent.DuplicateRegistrationException;
26 import org.snmp4j.agent.MOGroup;
27 import org.snmp4j.agent.MOServer;
28 import org.snmp4j.smi.OID;
29 import org.snmp4j.smi.OctetString;
30 import org.snmp4j.smi.Variable;
31
32 /**
33 * MORow implementation for GoldenGate
34 *
35 * @author Frederic Bregier
36 *
37 */
38 public class GgMORow implements MOGroup {
39 /**
40 * Row access
41 */
42 public GgMOScalar[] row;
43 /**
44 * Type access
45 */
46 public int[] type;
47 /**
48 * Base OID
49 */
50 public OID reference;
51 /**
52 * MIB from which this Row is issued
53 */
54 public GgInterfaceMib mib;
55 /**
56 * Mib Level entry identification
57 */
58 public int mibLevel;
59 /**
60 *
61 * @param mib
62 * @param reference
63 * @param entries
64 * @param mibLevel this integer identifies this Row in the MIB
65 */
66 public GgMORow(GgInterfaceMib mib, OID reference, GgEntry[] entries,
67 int mibLevel) {
68 this.mib = mib;
69 this.reference = reference;
70 this.mibLevel = mibLevel;
71 row = new GgMOScalar[entries.length];
72 type = new int[entries.length];
73 int[] ref = this.reference.getValue();
74 int[] add = new int[2];
75 add[1] = 0;
76 for (int i = 0; i < entries.length; i ++) {
77 GgEntry entry = entries[i];
78 type[i] = entry.smiConstantsType;
79 add[0] = i + 1;
80 OID oid = new OID(ref, add);
81 // the value is null at the creation, meaning values have to be
82 // setup once just after
83 row[i] = GgMOFactory.create(oid, null, entry.smiConstantsType,
84 entry.access, this, mibLevel, i);
85 }
86 }
87
88 /**
89 * Set a Value in this Row
90 * @param index
91 * @param value
92 * @throws IllegalArgumentException
93 */
94 public void setValue(int index, Object value)
95 throws IllegalArgumentException {
96 if (index >= row.length)
97 throw new IllegalArgumentException("Index exceed Row size");
98 Variable var = row[index].getValue();
99 GgMOFactory.setVariable(var, value, type[index]);
100 }
101
102 /*
103 * (non-Javadoc)
104 *
105 * @see org.snmp4j.agent.MOGroup#registerMOs(org.snmp4j.agent.MOServer,
106 * org.snmp4j.smi.OctetString)
107 */
108 @Override
109 public void registerMOs(MOServer server, OctetString context)
110 throws DuplicateRegistrationException {
111 for (int i = 0; i < row.length; i ++) {
112 GgMOScalar scalar = row[i];
113 server.register(scalar, context);
114 }
115 }
116
117 /*
118 * (non-Javadoc)
119 *
120 * @see org.snmp4j.agent.MOGroup#unregisterMOs(org.snmp4j.agent.MOServer,
121 * org.snmp4j.smi.OctetString)
122 */
123 @Override
124 public void unregisterMOs(MOServer server, OctetString context) {
125 for (int i = 0; i < row.length; i ++) {
126 GgMOScalar scalar = row[i];
127 server.unregister(scalar, context);
128 }
129 }
130 }