KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ist > coach > coachEmfServicesComponents > SnmpAdapterProviderComposition > connectorSegImpl


1 /*====================================================================
2
3 This file was produced by the OpenCCM CIF_JIMPL generator.
4
5 OpenCCM: The Open CORBA Component Model Platform
6 Copyright (C) 2000-2003 INRIA - USTL - LIFL - GOAL
7 Contact: openccm@objectweb.org
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 USA
23
24 Initial developer(s): Christophe Demarey.
25 Contributor(s): ______________________________________.
26
27 ====================================================================*/

28
29 package ist.coach.coachEmfServicesComponents.SnmpAdapterProviderComposition;
30
31 //import ist.coach.coachEmfServicesComponents.SnmpObjectData;
32
import org.opennms.protocols.snmp.*;
33
34 import ist.coach.coachEmfCommon.Utils;
35 import ist.coach.coachEmfCommon.ExceptionMessages;
36 import ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError;
37 import ist.coach.coachEmfCommon.DataTypeImpl;
38 import ist.coach.coachEmfServices.SnmpAdapter.DataType;
39 import ist.coach.coachEmfServicesComponents.SnmpAdapterProviderPackage.trap_targetConnection;
40 //import ist.coach.coachEmfServicesComponents.SnmpProtocolConverter;
41

42 import org.omg.CORBA.Any JavaDoc;
43 /**
44  * This is the CIDL-based implementation of the
45  * OMG IDL3 CIDL:coach.ist/coachEmfServicesComponents/SnmpAdapterProviderComposition/SnmpAdapterProviderHome_impl/SnmpAdapterProvider_impl/connectorSeg:1.0 segment type.
46  *
47  * @author OpenCCM CIF_Jimpl Compiler.
48  */

49 public class connectorSegImpl
50      extends ist.coach.coachEmfServicesComponents.SnmpAdapterProviderComposition.connectorSeg
51 {
52     // ==================================================================
53
//
54
// Internal states.
55
//
56
// ==================================================================
57
/**
58      ** Private ORB reference (used to create Anys)
59      **/

60     private org.omg.CORBA.ORB JavaDoc orb;
61     // ==================================================================
62
//
63
// Constructors.
64
//
65
// ==================================================================
66

67     public connectorSegImpl()
68     {
69             orb = org.objectweb.ccm.CORBA.TheORB.getORB();
70     }
71
72     // ==================================================================
73
//
74
// Methods.
75
//
76
// ==================================================================
77

78     /**
79      * Implementation of the ::coachEmfServices::SnmpAdapter::SnmpConnector::getSnmpTable operation.
80      */

81     public ist.coach.coachEmfServices.SnmpAdapter.DataType[]
82     getSnmpTable(String JavaDoc tableStart, String JavaDoc host, int port, String JavaDoc community)
83     throws ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError
84     {
85         //
86
// DONE : implement
87
//
88

89
90     SnmpProtocolConverter snmpConverter = new SnmpProtocolConverter(host, community, port, tableStart);
91
92     snmpConverter.snmpWalk();
93
94     if (snmpConverter.agentResponded() == false) {
95
96         System.err.println("Agent did not respond!");
97         throw new SnmpApplicationError(ExceptionMessages.agent_response_error);
98     }
99
100
101     DataTypeImpl [] snmpTable = new DataTypeImpl[snmpConverter.resultSet.size()];
102
103     for (int i = 0; i < snmpConverter.resultSet.size(); i++) {
104
105         SnmpVarBind vb = (SnmpVarBind)snmpConverter.resultSet.get(i);
106         Any JavaDoc value = orb.create_any();
107         value = SnmpAdapterProviderImpl.convertSnmpSyntaxToAny(vb.getValue());
108         if (value == null) {
109             System.err.println("SnmpAdapter>Could not encapsulate SNMP attribute value into a CORBA Any");
110             throw new SnmpApplicationError(ExceptionMessages.agent_create_error);
111         }
112         else {
113             snmpTable[i] = new DataTypeImpl(vb.getName().toString(), value, vb.getValue().typeId());
114
115         }
116     }
117
118         return snmpTable;
119     }
120
121     /**
122      * Implementation of the ::coachEmfServices::SnmpAdapter::SnmpConnector::getNext operation.
123      */

124     public ist.coach.coachEmfServices.SnmpAdapter.DataType
125     getNext(String JavaDoc identifier, String JavaDoc host, int port, String JavaDoc community)
126     throws ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError
127     {
128        //
129
// DONE : implement
130
//
131

132     SnmpProtocolConverter snmpConverter = new SnmpProtocolConverter(host, community, port, null);
133
134     snmpConverter.snmpGetNext(new SnmpObjectId(identifier));
135
136     if (snmpConverter.agentResponded() == false) {
137
138         System.err.println("Agent did not respond!");
139         throw new SnmpApplicationError(ExceptionMessages.agent_response_error);
140     }
141
142     if (snmpConverter.resultSet.size() == 0) {
143
144         System.err.println("Could not retrieve attribute with oid " + identifier);
145         throw new SnmpApplicationError(ExceptionMessages.agent_get_error);
146     }
147
148     Any JavaDoc value = this.orb.create_any();
149     SnmpVarBind vb = (SnmpVarBind)snmpConverter.resultSet.elementAt(0);
150     String JavaDoc oid = vb.getName().toString();
151     value = SnmpAdapterProviderImpl.convertSnmpSyntaxToAny(vb.getValue());
152
153     if (value == null) {
154         System.err.println("Could not retrieve attribute with oid " + identifier);
155         throw new SnmpApplicationError(ExceptionMessages.agent_get_error);
156     }
157
158     DataTypeImpl result = new DataTypeImpl(oid, value, vb.getValue().typeId());
159
160     return result;
161
162     }
163
164     /**
165      * Implementation of the ::coachEmfServices::SnmpAdapter::Connector::get operation.
166      */

167     public ist.coach.coachEmfServices.SnmpAdapter.DataType
168     get(String JavaDoc identifier, String JavaDoc host, int port, String JavaDoc community)
169     throws ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError
170     {
171         //
172
// DONE : implement
173
//
174
//System.err.println("SnmpAdapter>get " + identifier + " on " + host + ":" + port +
175
// " community = " + community);
176
SnmpProtocolConverter snmpConverter = new SnmpProtocolConverter(host, community, port, null);
177
178     SnmpVarBind [] vblist = new SnmpVarBind[1];
179     vblist[0] = new SnmpVarBind(new SnmpObjectId(identifier));
180
181     snmpConverter.snmpGet(vblist);
182
183     if (snmpConverter.agentResponded() == false) {
184
185         System.err.println("Agent did not respond!");
186         throw new SnmpApplicationError(ExceptionMessages.agent_response_error);
187     }
188
189     if (snmpConverter.resultSet.size() == 0) {
190
191         System.err.println("Could not retrieve attribute with oid " + identifier);
192         throw new SnmpApplicationError(ExceptionMessages.agent_get_error);
193     }
194
195     //System.err.println("Got " + ((SnmpVarBind)snmpConverter.resultSet.elementAt(0)).toString());
196

197     Any JavaDoc value = this.orb.create_any();
198     SnmpVarBind vb = (SnmpVarBind)snmpConverter.resultSet.elementAt(0);
199     String JavaDoc oid = vb.getName().toString();
200     value = SnmpAdapterProviderImpl.convertSnmpSyntaxToAny(vb.getValue());
201
202     if (value == null) {
203         System.err.println("Could not retrieve attribute with oid " + identifier);
204         throw new SnmpApplicationError(ExceptionMessages.agent_get_error);
205     }
206
207     DataTypeImpl result = new DataTypeImpl(oid, value, vb.getValue().typeId());
208
209     return result;
210     }
211
212     /**
213      * Implementation of the ::coachEmfServices::SnmpAdapter::Connector::getBulk operation.
214      */

215     public ist.coach.coachEmfServices.SnmpAdapter.DataType[]
216     getBulk(String JavaDoc[] identifiers, String JavaDoc host, int port, String JavaDoc community)
217     throws ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError
218     {
219         //
220
// DONE : implement
221
//
222
SnmpProtocolConverter snmpConverter = new SnmpProtocolConverter(host, community, port, null);
223
224     int numRequested = identifiers.length;
225
226     SnmpVarBind [] vblist = new SnmpVarBind[numRequested];
227
228     for (int i = 0; i < numRequested; i++)
229         vblist[i] = new SnmpVarBind(new SnmpObjectId(identifiers[i]));
230
231     snmpConverter.snmpGet(vblist);
232
233     if (snmpConverter.agentResponded() == false) {
234
235         System.err.println("Agent did not respond!");
236         throw new SnmpApplicationError(ExceptionMessages.agent_response_error);
237     }
238
239     if (snmpConverter.resultSet.size() == 0) {
240         System.err.println("Could not retrieve attributes with requested identifiers");
241         throw new SnmpApplicationError(ExceptionMessages.agent_get_error);
242     }
243
244     DataTypeImpl [] result = new DataTypeImpl[snmpConverter.resultSet.size()];
245
246
247     for (int i = 0; i < snmpConverter.resultSet.size(); i++) {
248
249         Any JavaDoc value = this.orb.create_any();
250         SnmpVarBind vb = (SnmpVarBind)snmpConverter.resultSet.elementAt(i);
251         String JavaDoc oid = vb.getName().toString();
252         value = SnmpAdapterProviderImpl.convertSnmpSyntaxToAny(vb.getValue());
253
254         if (value == null) {
255             System.err.println("Could not encapsulate SNMP attribute value into a CORBA Any");
256             throw new SnmpApplicationError(ExceptionMessages.agent_create_error);
257         }
258         else
259             result[i] = new DataTypeImpl(((SnmpVarBind)snmpConverter.resultSet.elementAt(i)).getName().toString(), value, vb.getValue().typeId());
260     }
261
262     //System.err.println("getBulk is ready to return!!");
263
return result;
264
265     }
266
267     /**
268      * Implementation of the ::coachEmfServices::SnmpAdapter::Connector::set operation.
269      */

270     public void
271     set(ist.coach.coachEmfServices.SnmpAdapter.DataType data, String JavaDoc host, int port, String JavaDoc community)
272     throws ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError
273     {
274         //
275
// DONE : implement
276
//
277
SnmpProtocolConverter snmpConverter = new SnmpProtocolConverter(host, community, port, null);
278
279         SnmpVarBind [] vblist = new SnmpVarBind[1];
280         SnmpSyntax value = SnmpAdapterProviderImpl.convertAnyToSnmpSyntax(data.value, data.code);
281         if (value == null) {
282             System.err.println("Could not convert DataType to an SnmpSyntax");
283             throw new SnmpApplicationError(ExceptionMessages.agent_create_error);
284         }
285
286         vblist[0] = new SnmpVarBind(new SnmpObjectId(data.identifier), value);
287
288         snmpConverter.snmpSet(vblist);
289
290         if (snmpConverter.agentResponded() == false) {
291
292             System.err.println("Agent did not respond!");
293             throw new SnmpApplicationError(ExceptionMessages.agent_response_error);
294         }
295
296         if (snmpConverter.resultSet.size() == 0) {
297
298             System.err.println("Could not set attribute with oid " + data.identifier);
299             throw new SnmpApplicationError(ExceptionMessages.agent_set_error);
300         }
301     }
302
303     /**
304      * Implementation of the ::coachEmfServices::SnmpAdapter::Connector::setBulk operation.
305      */

306     public void
307     setBulk(ist.coach.coachEmfServices.SnmpAdapter.DataType[] data, String JavaDoc host, int port, String JavaDoc community)
308     throws ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError
309     {
310         //
311
// DONE : implement
312
//
313
SnmpProtocolConverter snmpConverter = new SnmpProtocolConverter(host, community, port, null);
314         int numRequested = data.length;
315         //System.err.println("SnmpAdapter:setBulk> Data size = " + numRequested);
316
SnmpVarBind [] vblist = new SnmpVarBind[numRequested];
317
318         for (int i = 0; i < numRequested; i++) {
319             //System.err.println("[" + i + "] = ");
320

321             SnmpSyntax value = SnmpAdapterProviderImpl.convertAnyToSnmpSyntax(data[i].value, data[i].code);
322             vblist[i] = new SnmpVarBind(new SnmpObjectId(data[i].identifier), value);
323             //System.err.println("identifier = " +
324
// data[i].identifier + " value = " + value);
325
}
326
327         snmpConverter.snmpSet(vblist);
328
329         if (snmpConverter.agentResponded() == false) {
330
331             System.err.println("Agent did not respond!");
332             throw new SnmpApplicationError(ExceptionMessages.agent_response_error);
333         }
334
335         if (snmpConverter.resultSet.size() == 0) {
336             System.err.println("setBulk>Could not set attributes");
337
338             throw new SnmpApplicationError(ExceptionMessages.agent_get_error);
339         }
340     }
341
342 }
343
Popular Tags