KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ist > coach > coachEmsCommon > SnmpUtils


1 package ist.coach.coachEmsCommon;
2
3 import ist.coach.coachEmfServices.SnmpAdapter.DataType;
4
5
6 public class SnmpUtils {
7
8   public static synchronized int[]
9   getIntColumnData(DataType [] snmpTable,
10                   int tableRows,
11                   int[] indexRows) {
12
13         int numOfEntries = snmpTable.length;
14         int numOfRows = numOfEntries/tableRows;
15
16         int [] snmp_values = new int[numOfRows];
17
18         for (int i = 0; i < numOfRows; i++) {
19
20             for (int j = 0; j < indexRows.length; j++) {
21
22                 int position = (indexRows[j] - 1)*numOfRows + i;
23
24                 if (position >= numOfEntries) {
25                     System.err.println("SnmpUtils: getIntColumnData> " +
26                         "Cannot determine table indexes!");
27                     return null;
28                 }
29
30                 snmp_values[i] = snmpTable[position].value.extract_long();
31             }
32         }
33
34         return snmp_values;
35     }
36
37   public static synchronized String JavaDoc[]
38   getStringColumnData(DataType [] snmpTable,
39                   int tableRows,
40                   int[] indexRows) {
41
42         int numOfEntries = snmpTable.length;
43         int numOfRows = numOfEntries/tableRows;
44
45         String JavaDoc [] snmp_values = new String JavaDoc[numOfRows];
46
47         for (int i = 0; i < numOfRows; i++) {
48
49             for (int j = 0; j < indexRows.length; j++) {
50
51                 int position = (indexRows[j] - 1)*numOfRows + i;
52
53                 if (position >= numOfEntries) {
54                     System.err.println("SnmpUtils: getStringColumnData> " +
55                         "Cannot determine table indexes!");
56                     return null;
57                 }
58
59                 snmp_values[i] = snmpTable[position].value.extract_string();
60             }
61         }
62
63         return snmp_values;
64     }
65
66   public static synchronized String JavaDoc[]
67   getOctetColumnData(DataType [] snmpTable,
68                   int tableRows,
69                   int[] indexRows) {
70
71         int numOfEntries = snmpTable.length;
72         int numOfRows = numOfEntries/tableRows;
73
74         String JavaDoc [] snmp_values = new String JavaDoc[numOfRows];
75
76         for (int i = 0; i < numOfRows; i++) {
77
78             for (int j = 0; j < indexRows.length; j++) {
79
80                 int position = (indexRows[j] - 1)*numOfRows + i;
81
82                 if (position >= numOfEntries) {
83                     System.err.println("SnmpUtils: getOctetColumnData> " +
84                           "Cannot determine interface descriptions!");
85                     return null;
86                 }
87                 snmp_values[i] = new String JavaDoc(
88                 org.omg.CORBA.OctetSeqHelper.extract(snmpTable[position].value));
89                 //System.err.println("snmp_values[" + i + "] = " + snmp_values[i]);
90
//by digi
91
//snmp_values[i] = snmpTable[position].value.extract_string();
92
}
93         }
94         return snmp_values;
95     }
96
97   public static synchronized byte[][]
98   getOctetColumnDataAsBytes(DataType [] snmpTable,
99                   int tableRows,
100                   int[] indexRows) {
101
102         int numOfEntries = snmpTable.length;
103         int numOfRows = numOfEntries/tableRows;
104
105         byte[][] snmp_values = new byte[numOfRows][];
106
107         for (int i = 0; i < numOfRows; i++) {
108
109             for (int j = 0; j < indexRows.length; j++) {
110
111                 int position = (indexRows[j] - 1)*numOfRows + i;
112
113                 if (position >= numOfEntries) {
114                     System.err.println("SnmpUtils: getOctetColumnData> " +
115                           "Cannot determine interface descriptions!");
116                     return null;
117                 }
118                 snmp_values[i] = org.omg.CORBA.OctetSeqHelper.extract(snmpTable[position].value);
119                 //System.err.println("snmp_values[" + i + "] = " + snmp_values[i]);
120
//by digi
121
//snmp_values[i] = snmpTable[position].value.extract_string();
122
}
123         }
124         return snmp_values;
125     }
126 }
127
Popular Tags