KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ist > coach > coachEmfServicesComponents > SnmpAdapterProviderMonolithicImpl


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

21 package ist.coach.coachEmfServicesComponents JavaDoc;
22
23 import java.util.LinkedList JavaDoc;
24 import java.util.ListIterator JavaDoc;
25
26 import org.opennms.protocols.snmp.*;
27
28 import ist.coach.coachEmfCommon.Utils;
29 import ist.coach.coachEmfCommon.ExceptionMessages;
30 import ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError JavaDoc;
31 import ist.coach.coachEmfCommon.DataTypeImpl;
32 import ist.coach.coachEmfServices.SnmpAdapter.DataType JavaDoc;
33 import ist.coach.coachEmfServicesComponents.SnmpAdapterProviderPackage.trap_targetConnection JavaDoc;
34
35 import org.omg.CORBA.Any JavaDoc;
36 import org.omg.CosNaming.NameComponent JavaDoc;
37 /**
38  ** Implementation skeleton class for the ::coachEmfServicesComponents::SnmpAdapterProvider component.
39  **/

40 public class SnmpAdapterProviderMonolithicImpl
41        extends org.omg.CORBA.LocalObject JavaDoc
42        implements CCM_SnmpAdapterProvider,
43                   ist.coach.coachEmfServices.SnmpAdapter.CCM_SnmpConnector JavaDoc,
44                   ist.coach.coachEmfServices.SnmpAdapter.CCM_SnmpTrapDaemon JavaDoc,
45                   org.omg.Components.SessionComponent,
46                     Runnable JavaDoc,
47           SnmpTrapHandler
48 {
49     // ==================================================================
50
//
51
// Internal State.
52
//
53
// ===================================================================
54
trap_targetConnection[] trap_target_facades = null;
55
56     /**
57      ** Context reference.
58      **/

59     private CCM_SnmpAdapterProvider_Context the_context_;
60     /**
61      ** Private ORB reference (used to create Anys)
62      **/

63     private org.omg.CORBA.ORB JavaDoc orb;
64     /**
65      ** Linked List used by SnmpTrapHandler to store registered objects.
66      **/

67     private LinkedList JavaDoc linkedList;
68     /**
69      ** Configuration Object used by SnmpTrapDaemon
70      **/

71     private Configuration config;
72     /**
73      ** Declaration of the identifier used to identify SNMP trap types
74      **/

75     private static final SnmpObjectId SNMPv2_MIB_snmpTrapOid =
76     new SnmpObjectId(".1.3.6.1.6.3.1.1.4.1.0");
77
78     public static final int SNMP_TRAP_PORT = 2010;
79     /**
80      ** SnmpTrapDaemon Listener Thread
81      **/

82     private Thread JavaDoc listenerThread;
83     /**
84      ** Declaration of Unknown Trap
85      **/

86     private static final int UNKNOWN_TRAP_TYPE = 0;
87    // ==================================================================
88
//
89
// Constructor.
90
//
91
// ===================================================================
92
/**
93      ** The default constructor.
94      **/

95     public
96     SnmpAdapterProviderMonolithicImpl()
97     {
98         the_context_ = null;
99         this.linkedList = new LinkedList JavaDoc();
100
101     }
102     // ==================================================================
103
//
104
// Internal methods.
105
//
106
// ===================================================================
107

108     private void listener_init() {
109         if (listenerThread == null) {
110             listenerThread = new Thread JavaDoc(this, "Listener");
111             listenerThread.start();
112         }
113     }
114
115     private void listener_stop() {
116
117         Thread JavaDoc dummyThread =listenerThread;
118         listenerThread = null;
119         dummyThread.interrupt();
120
121     }
122
123     private Any JavaDoc convertSnmpSyntaxToAny(SnmpSyntax data) {
124
125         Any JavaDoc value = this.orb.create_any();
126
127
128         switch (data.typeId()) {
129             case SnmpSMI.SMI_OBJECTID:
130                 value.insert_string( new String JavaDoc(((SnmpObjectId)data).toString()));
131                 break;
132             case SnmpSMI.SMI_COUNTER32:
133                 value.insert_longlong( ((SnmpCounter32)data).getValue());
134                 break;
135             case SnmpSMI.SMI_COUNTER64: //Same as SnmpSMI.SMI_UNSIGNED32
136
value.insert_longlong( ((SnmpCounter64)data).getValue().longValue());
137                 break;
138             case SnmpSMI.SMI_GAUGE32:
139                 value.insert_longlong( ((SnmpGauge32)data).getValue());
140                 break;
141             case SnmpSMI.SMI_INTEGER:
142                 value.insert_long( ((SnmpInt32)data).getValue());
143                 break;
144             case SnmpSMI.SMI_TIMETICKS:
145                 value.insert_longlong( ((SnmpTimeTicks)data).getValue());
146                 break;
147             case SnmpSMI.SMI_IPADDRESS:
148                 value.insert_string( new String JavaDoc(((SnmpIPAddress)data).toString()));
149                 break;
150             case SnmpSMI.SMI_STRING:
151                 //fset HACK
152
// It seems that orbacus has problems handling anys as strings if these contain
153
// non printable characters. NOT RESOLVED BUT BYPASSED....
154
//System.err.println("SnmpSMI.SMI_STRING length= " + ((SnmpOctetString)data).getLength());
155
//System.err.print("As string = " + ((SnmpOctetString)data).toString() +
156
// " as bytes = " + new String(((SnmpOctetString)data).getString()));
157
/*********
158                 if (octetData.toString().indexOf("RAW") < 0) {
159                   //System.err.println(" Type is HEX");
160                   value.insert_string("Hello");
161                  }
162                  else {
163                   //System.err.println(" Type is RAW");
164                   value.insert_string( new String(((SnmpOctetString)data).getString()));
165                 }
166                 ******/

167                 SnmpOctetString octetData = (SnmpOctetString) data;
168                 byte[] octetDataBytes = octetData.getString();
169                 org.omg.CORBA.OctetSeqHelper.insert(value, octetDataBytes);
170
171                 //initially by digi
172
//value.insert_string( new String(((SnmpOctetString)data).getString()));
173
break;
174             case SnmpSMI.SMI_OPAQUE:
175                 value.insert_string( new String JavaDoc(((SnmpOpaque)data).getString()));
176                 break;
177             case SnmpSMI.SMI_NOSUCHOBJECT:
178                 //value = null;
179
// Is this good...???
180
value.insert_string("No Such Object");
181                 break;
182             case SnmpSMI.SMI_NOSUCHINSTANCE:
183                 //value = null;
184
// Is this good...???
185
value.insert_string( "No Such Instance");
186                 break;
187             default:
188                 System.err.println("Unknown Variable Binding.");
189                 value = null;
190                 break;
191
192         }
193
194         return value;
195
196     }
197
198     private SnmpSyntax convertAnyToSnmpSyntax(Any JavaDoc data, byte code) {
199
200         SnmpSyntax value = null;
201
202         switch (code) {
203
204             case SnmpSMI.SMI_COUNTER32:
205                 value = ((SnmpSyntax)new SnmpCounter32(data.extract_longlong()));
206                 break;
207             case SnmpSMI.SMI_COUNTER64:
208                 value = ((SnmpSyntax)new SnmpCounter64(data.extract_longlong()));
209                 break;
210             case SnmpSMI.SMI_UNSIGNED32: // same as SnmpSMI.SMI_GAUGE32
211
value = ((SnmpSyntax)new SnmpGauge32(data.extract_longlong()));
212                 break;
213             case SnmpSMI.SMI_INTEGER:
214                 value = ((SnmpSyntax)new SnmpInt32(data.extract_long()));
215                 break;
216             case SnmpSMI.SMI_IPADDRESS:
217                 value = ((SnmpSyntax)new SnmpIPAddress(data.extract_string().getBytes()));
218                 break;
219             case SnmpSMI.SMI_OBJECTID:
220                 value = ((SnmpSyntax)new SnmpObjectId(data.extract_string()));
221                 break;
222             case SnmpSMI.SMI_OPAQUE:
223                 value = ((SnmpSyntax)new SnmpOpaque(data.extract_string().getBytes()));
224                 break;
225             case SnmpSMI.SMI_STRING:
226                 value = (SnmpSyntax)new SnmpOctetString(org.omg.CORBA.OctetSeqHelper.extract(data));
227                 //initially by digi
228
//value = ((SnmpSyntax)new SnmpOctetString(data.extract_string().getBytes()));
229
break;
230             case SnmpSMI.SMI_TIMETICKS:
231                 value = ((SnmpSyntax)new SnmpTimeTicks(data.extract_longlong()));
232                 break;
233             default:
234                 System.err.println("SnmpAdapter:convertAnyToSnmpSyntax> " +
235                     " Unknown (or un-supported) SMI Type");
236                 break;
237         }
238
239         return value;
240     }
241
242     private void processTrapData(
243         java.net.InetAddress JavaDoc agent,
244         SnmpOctetString community,
245         SnmpPduPacket pdu)
246     throws SnmpApplicationError{
247
248         int snmpTrapType = 0;
249         String JavaDoc trapObjectIdentifier = null;
250         int k = pdu.getLength();
251         DataTypeImpl[] dataSetType = new DataTypeImpl[k];
252
253         for (int i = 0; i < k ; i++ ) {
254
255             SnmpVarBind vb = pdu.getVarBindAt(i);
256
257             String JavaDoc oid = vb.getName().toString();
258             Any JavaDoc value = this.orb.create_any();
259
260             switch (vb.getValue().typeId()) {
261                 case SnmpSMI.SMI_OBJECTID:
262                     value.insert_string( ((SnmpObjectId)vb.getValue()).toString());
263                     break;
264                 case SnmpSMI.SMI_COUNTER32:
265                     value.insert_longlong( ((SnmpCounter32)vb.getValue()).getValue());
266                     break;
267                 case SnmpSMI.SMI_COUNTER64:
268                     value.insert_longlong( ((SnmpCounter64)vb.getValue()).getValue().longValue());
269                     break;
270                 case SnmpSMI.SMI_GAUGE32:
271                     value.insert_longlong( ((SnmpGauge32)vb.getValue()).getValue());
272                     break;
273                 case SnmpSMI.SMI_INTEGER:
274                     value.insert_long( ((SnmpInt32)vb.getValue()).getValue());
275                     break;
276                 case SnmpSMI.SMI_TIMETICKS:
277                     value.insert_longlong( ((SnmpTimeTicks)vb.getValue()).getValue());
278                     break;
279                 case SnmpSMI.SMI_IPADDRESS:
280                     value.insert_string( ((SnmpIPAddress)vb.getValue()).toString());
281                     break;
282                 case SnmpSMI.SMI_STRING:
283                     SnmpOctetString octetData = (SnmpOctetString) vb.getValue();
284                     byte[] octetDataBytes = octetData.getString();
285                     org.omg.CORBA.OctetSeqHelper.insert(value, octetDataBytes);
286                     //by digi
287
//value.insert_string( new String(((SnmpOctetString)vb.getValue()).getString()));
288
break;
289                 default:
290                     System.err.println("SnmpAdapter: processTrapData> Unknown Variable Binding.");
291                     break;
292
293             }
294
295             if (vb.getName().compare(SNMPv2_MIB_snmpTrapOid) == 0)
296                 trapObjectIdentifier = ((SnmpObjectId)vb.getValue()).toString();
297
298             dataSetType[i] = new DataTypeImpl(oid, value);
299
300         }
301
302         snmpTrapType = determineTrapType(trapObjectIdentifier);
303         if (snmpTrapType == UNKNOWN_TRAP_TYPE)
304             throw new SnmpApplicationError(ExceptionMessages.uknown_trap_error);
305
306         String JavaDoc objectClass = determineObjectClass(snmpTrapType);
307         if (objectClass == null) {
308             System.err.println("SnmpAdapter: processTrapData> Trap could not be mapped to an object class");
309             throw new SnmpApplicationError("Trap could not be mapped to an object class");
310         }
311
312         System.err.println("SnmpAdapter: processTrapData> Trap is " + trapTypeToString(snmpTrapType) +
313             " (trap type " + snmpTrapType +
314             " ), thrown by objects of objectclass " + objectClass);
315
316         NameComponent JavaDoc [] name = null;
317
318         if (isRootObject(objectClass)) {
319             name = findRegisteredRootObject(objectClass, agent.getHostAddress());
320             if (name == null) {
321                 System.err.println("SnmpAdapter: processTrapData> Trap could not be mapped to a registered (root) object.");
322                 throw new SnmpApplicationError(ExceptionMessages.uknown_trap_origin_error);
323             }
324         }
325         else {
326
327             boolean valueIsNeeded = determineIfValueIsNeeded(objectClass);
328
329             Any JavaDoc value = null;
330
331             if (valueIsNeeded == true) {
332                 value = determineValue(objectClass, dataSetType);
333
334                 if (value == null) {
335                     System.err.println("SnmpAdapter: processTrapData> Could not determine value for trap!");
336                     throw new SnmpApplicationError(ExceptionMessages.trap_misconfig_error);
337                 }
338             }
339
340             name = findRegisteredLeafObject(objectClass, agent.getHostAddress(), value);
341             if (name == null) {
342                 System.err.println("SnmpAdapter: processTrapData> Trap could not be mapped to a registered (leaf) object.");
343                 throw new SnmpApplicationError(ExceptionMessages.uknown_trap_origin_error);
344             }
345         }
346
347         String JavaDoc objectFacadeKind = Utils.name2facade(Utils.name2string(name));
348         String JavaDoc facadeNameKind = null;
349         boolean facadeFound = false;
350
351         System.err.println("SnmpAdapter: processTrapData> Object with name " + Utils.name2string(name) +
352             " is accessible through a facade with kind " + objectFacadeKind);
353
354         int index = 0;
355         String JavaDoc facadeName = new String JavaDoc();
356         for (index = 0; index < trap_target_facades.length; index++) {
357
358             facadeName = trap_target_facades[index].objref.facade_name();
359             facadeNameKind = Utils.name2facade(facadeName);
360
361             //System.err.println("Checking with facade with name " +
362
// facadeName + " which has a kind " + facadeNameKind);
363

364             if (objectFacadeKind.equals(facadeNameKind)) {
365
366                 System.err.println("SnmpAdapter: processTrapData> Object with name " +
367                       Utils.name2string(name) +
368                     " is accessible through facade with name " + facadeName +
369                         " found at position " + index);
370
371                 facadeFound = true;
372
373                 break;
374
375             }
376         }
377
378         if (facadeFound == false) {
379
380             System.err.println("SnmpAdapter: processTrapData> Could not find a facade to send trap to");
381             throw new SnmpApplicationError("No Facade trap sink found");
382         }
383
384         int varBindNumber = pdu.getLength();
385
386         DataTypeImpl [] trapData = new DataTypeImpl[varBindNumber];
387
388         for (int j = 0; j < varBindNumber; j++) {
389
390             SnmpVarBind vb = pdu.getVarBindAt(j);
391
392             trapData[j] = new DataTypeImpl(vb.getName().toString(),
393                 convertSnmpSyntaxToAny(vb.getValue()),
394                 vb.getValue().typeId());
395
396         }
397
398         String JavaDoc community_str = (community != null) ?
399                             new String JavaDoc(community.getString()) : new String JavaDoc();
400
401         //System.err.println("Calling notifyTrap with arguments: ");
402
//System.err.println("Name: " + name);
403
//System.err.println("Community: " + community_str);
404
//System.err.println("RequestId: " + pdu.getRequestId());
405
//System.err.println("SnmpTrapType: " + snmpTrapType);
406
//System.err.println("Length of trap data: " + trapData.length);
407

408         try {
409             ist.coach.coachEmfServices.SnmpAdapter.TrapCallback JavaDoc facade_callback =
410                         trap_target_facades[index].objref;
411
412             if (facade_callback != null) {
413                 facade_callback.notifyTrap( name,
414                                         community_str,
415                                         pdu.getRequestId(),
416                                         snmpTrapType,
417                                         trapData);
418             }
419             else
420                 System.err.println("SnmpAdapter: processTrapData> Could not retrieve reference to facade of " +
421                     Utils.name2string(name));
422         }
423         catch(SnmpApplicationError snmp_ex) {
424             System.err.println("SnmpAdapterProvider: SnmpApplicationError exception caught " +
425                 " while trying to forward trap to " + Utils.name2string(name));
426         }
427         catch(intt.itu.itut_x780.ApplicationError app_exc) {
428             System.err.println("SnmpAdapterProvider: ApplicationError exception caught " +
429                 " while trying to forward trap to " + Utils.name2string(name));
430         }
431
432     }
433
434     private int determineTrapType(String JavaDoc trapObjectIdentifier) {
435
436
437         int snmpTrapType = UNKNOWN_TRAP_TYPE;
438
439         for (int i = 0; i < this.config.availableTraps.length; i++) {
440             if (trapObjectIdentifier.equals(
441                 this.config.availableTraps[i].oid.toString())) {
442
443                 snmpTrapType = this.config.availableTraps[i].identifier;
444                 break;
445             }
446         }
447
448         return snmpTrapType;
449
450     }
451
452     private String JavaDoc determineObjectClass(int snmpTrapType) {
453
454         for (int i = 0; i < this.config.availableTraps.length; i++) {
455             if (snmpTrapType == this.config.availableTraps[i].identifier) {
456                 return this.config.availableTraps[i].objectclass;
457             }
458         }
459
460         return null;
461
462     }
463
464     private boolean determineIfValueIsNeeded(String JavaDoc objectClass) {
465
466         boolean valueNeeded = false;
467
468         for (int i = 0; i < this.config.availableTraps.length; i++) {
469
470             if (objectClass.equalsIgnoreCase(this.config.availableTraps[i].objectclass)) {
471
472                 if (this.config.availableTraps[i].valueOid == null) {
473                     System.err.println("SnmpAdapter: determineIfValueIsNeeded> No value needed to fetch " +
474                         "leaf object of objectclass " + objectClass);
475                     valueNeeded = false;
476                 }
477                 else
478                     valueNeeded = true;
479             }
480         }
481
482         return valueNeeded;
483     }
484
485
486     private Any JavaDoc determineValue(String JavaDoc objectClass, DataType [] varBindings) {
487
488         String JavaDoc valueOid = null;
489
490         //System.err.println("SnmpAdapter: determineValue> Determining value for objectClass..." +
491
// objectClass + ", with " + varBindings.length + " variable bindings");
492

493
494         for (int i = 0; i < this.config.availableTraps.length; i++) {
495
496             if (objectClass.equalsIgnoreCase(this.config.availableTraps[i].objectclass)) {
497
498                 if (this.config.availableTraps[i].valueOid != null)
499                     valueOid = new String JavaDoc(this.config.availableTraps[i].valueOid.toString());
500                 //else
501
// System.err.println("SnmpAdapter: determineValue> No value need to fetch leaf object of objectclass "
502
// + objectClass);
503

504                 break;
505             }
506
507         }
508
509         if (valueOid != null) {
510             for (int i = 0; i < varBindings.length; i++) {
511                 if (varBindings[i].identifier.equals(
512                     valueOid)) {
513                     return (varBindings[i].value);
514                 }
515             }
516         }
517         //System.err.println("SnmpAdapter: determineValue> Returning null");
518
return null;
519
520     }
521
522     private String JavaDoc trapTypeToString(int snmpTrapType) {
523         for (int i = 0; i < this.config.availableTraps.length; i++) {
524             if (this.config.availableTraps[i].identifier == snmpTrapType) {
525
526                 return this.config.availableTraps[i].id;
527             }
528
529         }
530
531         return null;
532     }
533
534     /**
535      * @param objectClass
536      * @param ipAddress
537      * @return NameComponent[]
538      *
539      * Returns the name of a root-object with the given
540      * objectclass and IP Address.
541      */

542     private NameComponent JavaDoc[] findRegisteredRootObject(
543         String JavaDoc objectClass, String JavaDoc ipAddress) {
544
545         ListIterator JavaDoc li = this.linkedList.listIterator();
546
547         //System.err.println("SnmpAdapter: findRegisteredRootObject> Trying to find Root object with object class " +
548
// objectClass + " and IP Address " + ipAddress);
549

550         while (li.hasNext()) {
551
552             ObjectData objData = (ObjectData)li.next();
553
554             NameComponent JavaDoc [] name = objData.getName();
555             String JavaDoc myObjectClass = name[name.length - 2].kind;
556             String JavaDoc myIpAddress = objData.getIPAddress();
557
558             //System.out.println("Comparing to object class " +
559
//myObjectClass + " and IP Address " + myIpAddress);
560

561             if (myObjectClass.equals(objectClass) &&
562                 myIpAddress.equals(ipAddress)) {
563
564                 //System.err.println("-----> Matched with object named " +
565
// Utils.name2string(objData.getName()));
566
return objData.getName();
567             }
568         }
569
570         return null;
571     }
572
573     /**
574      * @param objectClass
575      * @param ipAddress
576      * @param value
577      * @return NameComponent[]
578      *
579      * Returns the name of a registered leaf object with
580      * the given name, IP Address, registered with the
581      * given value.
582      */

583
584     private NameComponent JavaDoc[] findRegisteredLeafObject(
585         String JavaDoc objectClass, String JavaDoc ipAddress, Any JavaDoc value) {
586
587         ListIterator JavaDoc li = this.linkedList.listIterator();
588
589         //System.err.println("SnmpAdapter> Trying to find Leaf object with object class " +
590
// objectClass + " and IP Address " + ipAddress);
591

592         while (li.hasNext()) {
593
594             ObjectData objData = (ObjectData)li.next();
595
596             NameComponent JavaDoc [] name = objData.getName();
597             String JavaDoc myObjectClass = getObjectClass(name);
598             String JavaDoc myIpAddress = objData.getIPAddress();
599
600             if (myObjectClass.equals(objectClass) &&
601                 myIpAddress.equals(ipAddress)) {
602
603                 if (value != null) {
604                     if (objData.value.equal(value)) {
605
606                         //System.err.println("-----> Matched with object named" +
607
// Utils.name2string(objData.getName()));
608
return objData.getName();
609                     }
610                 }
611                 else {
612                     //System.err.println("-----> Matched with object named" +
613
// Utils.name2string(objData.getName()));
614
return objData.getName();
615                 }
616             }
617         }
618
619         return null;
620     }
621
622     /**
623      * @param objectClass
624      * @return boolean
625      *
626      * Returns whether an object with the given objectclass
627      * is considered to be a root object or not.
628      */

629
630     private boolean isRootObject(String JavaDoc objectClass) {
631
632         for (int i = 0; i < config.rootObjects.length; i++)
633             if (config.rootObjects[i].equals(objectClass))
634                 return true;
635
636         return false;
637     }
638
639     private String JavaDoc getObjectClass(NameComponent JavaDoc[] name) {
640         return name[name.length - 2].kind;
641     }
642
643     private boolean nameExists(NameComponent JavaDoc[] name) {
644
645         ListIterator JavaDoc li = this.linkedList.listIterator();
646
647         while (li.hasNext()) {
648             ObjectData objData = (ObjectData) li.next();
649             if (objData.getName().equals(name)) {
650                 return true;
651             }
652         }
653         return false;
654      }
655     private boolean rootObjectExists(String JavaDoc ipAddress,
656         NameComponent JavaDoc[] name) {
657
658         ListIterator JavaDoc li = this.linkedList.listIterator();
659
660         while (li.hasNext()) {
661
662             ObjectData objData = (ObjectData)li.next();
663             //System.err.println("Examining object with IPAddress = *" +
664
//objData.getIPAddress() + "* against *" + ipAddress + "*");
665

666             if (objData.getIPAddress().equals(ipAddress) &&
667                 isRootObject(getObjectClass(objData.getName())) &&
668                 Utils.isChild(name, objData.getName()))
669                     return true;
670         }
671
672         return false;
673     }
674
675
676
677     private ObjectData findObjectWithName(NameComponent JavaDoc[] name) {
678
679         String JavaDoc name_str = Utils.name2string(name);
680
681         ListIterator JavaDoc li = this.linkedList.listIterator();
682
683         ObjectData objData = null;
684
685         while (li.hasNext()) {
686             objData = (ObjectData) li.next();
687             if (Utils.name2string(objData.getName()).equals(name_str)) {
688                 return objData;
689             }
690         }
691         return null;
692      }
693
694     private class ObjectData {
695
696         private NameComponent JavaDoc[] name;
697         private String JavaDoc IPAddress;
698         private Any JavaDoc value;
699
700         ObjectData(NameComponent JavaDoc[] name, String JavaDoc IPAddress, Any JavaDoc value) {
701             this.name = name;
702             this.IPAddress = IPAddress;
703             this.value = value;
704         }
705
706         ObjectData (NameComponent JavaDoc[] name, String JavaDoc IPAddress) {
707             this.name = name;
708             this.IPAddress = IPAddress;
709             this.value = null;
710         }
711
712         public NameComponent JavaDoc[] getName() {
713             return this.name;
714         }
715
716         public String JavaDoc getIPAddress() {
717             return this.IPAddress;
718         }
719      }
720
721     // ==================================================================
722
//
723
// Runnable Interface methods.
724
//
725
// ===================================================================
726
public void run() {
727
728         Thread JavaDoc myThread = Thread.currentThread();
729         SnmpTrapSession trapSession = null;
730         while (listenerThread == myThread) {
731
732             try {
733                 trapSession = new SnmpTrapSession(this,
734                             SNMP_TRAP_PORT);
735                 System.err.println("SNMP Trap Receiver Started");
736                 synchronized(trapSession)
737                 {
738                     trapSession.wait();
739                 }
740             }
741             catch (InterruptedException JavaDoc ie) {
742                 System.err.println("SNMP Trap Receiver Exiting");
743                 trapSession.close();
744             }
745             catch (Exception JavaDoc e) {
746                 System.err.println("Exception in init(): " + e);
747                 e.printStackTrace();
748             }
749         }
750      }
751
752
753     // ==================================================================
754
//
755
// SnmpTrapHandler Interface methods.
756
//
757
// ===================================================================
758

759
760     /**
761      * Method from SnmpHandler interface, used to parse SNMPv2 Traps
762      */

763     public void snmpReceivedTrap(
764          SnmpTrapSession session,
765          java.net.InetAddress JavaDoc agent,
766          int port,
767          SnmpOctetString community,
768          SnmpPduPacket pdu) {
769
770         System.err.println("V2 Trap from agent " + agent.toString() + " on port " + port);
771         System.err.println("V2 Trap Community........... " + new String JavaDoc(community.getString()));
772         System.err.println("V2 Trap PDU command......... " + pdu.getCommand());
773         System.err.println("V2 Trap PDU ID.............. " + pdu.getRequestId());
774         System.err.println("V2 Trap PDU Length.......... " + pdu.getLength());
775
776         if(pdu instanceof SnmpPduRequest)
777         {
778             System.err.println("V2 Trap PDU Error Status.... " + ((SnmpPduRequest)pdu).getErrorStatus());
779             System.err.println("V2 Trap PDU Error Index..... " + ((SnmpPduRequest)pdu).getErrorIndex());
780         }
781
782         int k = pdu.getLength();
783
784         for (int i = 0; i < k ; i++ )
785         {
786             SnmpVarBind vb = pdu.getVarBindAt(i);
787             System.err.print("Varbind[" + i + "] := " + vb.getName().toString());
788             System.err.println(" --> " + vb.getValue().toString());
789         }
790
791         try {
792
793             processTrapData(agent, community, pdu);
794         }
795         catch (SnmpApplicationError e) {
796             System.err.println("Unable to process trap!");
797         }
798
799      }
800
801     /**
802      * Method from SnmpHandler interface used to parse SNMPv1 traps.
803      *
804      * @param session The Trap Session that received the PDU.
805      * @param agent The address of the remote sender.
806      * @param port The remote port where the pdu was transmitted from.
807      * @param community The decoded community string.
808      * @param pdu The decoded V1 trap pdu.
809      *
810      */

811     public void snmpReceivedTrap(
812         SnmpTrapSession session,
813          java.net.InetAddress JavaDoc agent,
814          int port,
815          SnmpOctetString community,
816          SnmpPduTrap pdu)
817
818     {
819
820         System.err.println("V1 Trap from agent " + agent.toString() + " on port " + port);
821         System.err.println("Ip Address................. " + pdu.getAgentAddress() );
822         System.err.println("Enterprise Id.............. " + pdu.getEnterprise() );
823         System.err.println("Generic ................... " + pdu.getGeneric() );
824         System.err.println("Specific .................. " + pdu.getSpecific() );
825         System.err.println("TimeStamp ................. " + pdu.getTimeStamp() );
826         System.err.println("Length..................... " + pdu.getLength() );
827
828
829         int k = pdu.getLength();
830         for (int i = 0; i < k ; i++ )
831         {
832             SnmpVarBind vb = pdu.getVarBindAt(i);
833             System.err.print("Varbind[" + i + "] := " + vb.getName().toString());
834             System.err.println(" --> " + vb.getValue().toString());
835         }
836         System.err.println("");
837
838         //synchronized(session)
839
//{
840
//session.notify();
841
//}
842
}
843
844     /**
845      * Process session errors.
846      *
847      * @param session The trap session in error.
848      * @param error The error condition.
849      * @param ref The reference object, if any.
850      */

851     public void snmpTrapSessionError(
852         SnmpTrapSession session,
853         int error,
854         java.lang.Object JavaDoc ref)
855     {
856
857         System.err.println("SnmpAdapter:snmpTrapSessionError> An error occured in the trap session");
858         System.err.println("Session error code = " + error);
859         if(ref != null)
860         {
861             System.err.println("SnmpAdapter:snmpTrapSessionError> Session error reference: " + ref.toString());
862         }
863
864         if(error == SnmpTrapSession.ERROR_EXCEPTION)
865         {
866             synchronized(session)
867             {
868                 session.notify(); // close the session
869
}
870         }
871      }
872
873     // ==================================================================
874
//
875
// Public methods.
876
//
877
// ===================================================================
878
/**
879      ** To obtain the context.
880      **
881      ** @return The context that has been previously set by
882      ** the set_session_context operation.
883      **/

884     public CCM_SnmpAdapterProvider_Context
885     getContext()
886     {
887         return the_context_;
888     }
889     // ==================================================================
890
//
891
// Methods for the OMG IDL Components::EnterpriseComponent local interface.
892
//
893
// ==================================================================
894
//
895
// IDL:omg.org/Components/EnterpriseComponent/configuration_complete:1.0
896
//
897
/**
898      ** Completes the component configuration.
899      **
900      ** @throws org.omg.Components.InvalidConfiguration
901      ** Thrown if the configuration is invalid.
902      **/

903     public void
904     configuration_complete()
905     throws org.omg.Components.InvalidConfiguration
906     {
907         //
908
// DONE : implement !!!
909
//
910

911         this.config = Configuration.getInstance();
912
913         if (config == null) {
914             System.err.println("Could not create a valid configuration. Exiting...");
915             throw new org.omg.Components.InvalidConfiguration();
916         }
917
918         this.orb = org.objectweb.ccm.CORBA.TheORB.getORB();
919         listener_init();
920
921
922         if ((trap_target_facades = the_context_.get_connections_trap_target()) == null) {
923             System.err.println("SnmpAdapter is not configured with Facades to serve....");
924         }
925
926         System.err.println("SnmpAdapterProvider configuration completed...");
927      }
928     // ==================================================================
929
//
930
// Methods for the OMG IDL Components::SessionComponent local interface.
931
//
932
// ==================================================================
933
//
934
// IDL:omg.org/Components/SessionComponent/set_session_context:1.0
935
//
936
/**
937      * Called by the container when the component session context will be fixed.
938      *
939      * @param context The session context.
940      *
941      * @throws org.omg.Components.CCMException
942      * Thrown if a system level error occured.
943      */

944     public void
945     set_session_context(org.omg.Components.SessionContext context)
946     throws org.omg.Components.CCMException
947     {
948         the_context_ = (CCM_SnmpAdapterProvider_Context)context;
949     }
950     //
951
// IDL:omg.org/Components/SessionComponent/ccm_activate:1.0
952
//
953
/**
954      *
955      * Called by the container when the component will be activated.
956      *
957      * @throws org.omg.Components.CCMException
958      * Thrown if a system level error occured.
959      */

960     public void
961     ccm_activate()
962     throws org.omg.Components.CCMException
963     {
964         //
965
// Unused by actual OpenCCM containers
966
//
967
}
968     //
969
// IDL:omg.org/Components/SessionComponent/ccm_passivate:1.0
970
//
971
/**
972      *
973      * Called by the container when the component will be passivated.
974      *
975      * @throws org.omg.Components.CCMException
976      * Thrown if a system level error occured.
977      */

978     public void
979     ccm_passivate()
980     throws org.omg.Components.CCMException
981     {
982         //
983
// Unused by actual OpenCCM containers
984
//
985
}
986     //
987
// IDL:omg.org/Components/SessionComponent/ccm_remove:1.0
988
//
989
/**
990      *
991      * Called by the container when the component will be removed.
992      *
993      * @throws org.omg.Components.CCMException
994      * Thrown if a system level error occured.
995      */

996     public void
997     ccm_remove()
998     throws org.omg.Components.CCMException
999     {
1000        //
1001
// DONE: implement !!!
1002
//
1003

1004        listener_stop();
1005    }
1006    // ==================================================================
1007
//
1008
// Public methods for the CCM_SnmpAdapterProvider local interface.
1009
//
1010
// ==================================================================
1011
//
1012
// IDL:coach.ist/coachEmfServicesComponents/CCM_SnmpAdapterProvider/get_connector:1.0
1013
//
1014
/**
1015     ** Implementation of the ::coachEmfServicesComponents::CCM_SnmpAdapterProvider::get_connector operation.
1016     **/

1017    public ist.coach.coachEmfServices.SnmpAdapter.CCM_SnmpConnector JavaDoc
1018    get_connector()
1019    {
1020        return this;
1021    }
1022    //
1023
// IDL:coach.ist/coachEmfServicesComponents/CCM_SnmpAdapterProvider/get_config:1.0
1024
//
1025
/**
1026     ** Implementation of the ::coachEmfServicesComponents::CCM_SnmpAdapterProvider::get_config operation.
1027     **/

1028    public ist.coach.coachEmfServices.SnmpAdapter.CCM_SnmpTrapDaemon JavaDoc
1029    get_config()
1030    {
1031        return this;
1032    }
1033    // ==================================================================
1034
//
1035
// Public methods for the ::coachEmfServices::SnmpAdapter::CCM_SnmpConnector local interface.
1036
//
1037
// ==================================================================
1038
//
1039
// IDL:coach.ist/coachEmfServices/SnmpAdapter/SnmpConnector/getSnmpTable:1.0
1040
//
1041
/**
1042     ** Implementation of the ::coachEmfServices::SnmpAdapter::SnmpConnector::getSnmpTable operation.
1043     **/

1044    public ist.coach.coachEmfServices.SnmpAdapter.DataType JavaDoc[]
1045    getSnmpTable(java.lang.String JavaDoc tableStart,
1046                java.lang.String JavaDoc host,
1047                int port,
1048                java.lang.String JavaDoc community)
1049    throws ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError JavaDoc
1050    {
1051        //
1052
// DONE : implement
1053
//
1054

1055
1056    SnmpProtocolConverter snmpConverter = new SnmpProtocolConverter(host, community, port, tableStart);
1057
1058    snmpConverter.snmpWalk();
1059
1060    if (snmpConverter.agentResponded() == false) {
1061
1062        System.err.println("Agent did not respond!");
1063        throw new SnmpApplicationError(ExceptionMessages.agent_response_error);
1064    }
1065
1066
1067    DataTypeImpl [] snmpTable = new DataTypeImpl[snmpConverter.resultSet.size()];
1068
1069    for (int i = 0; i < snmpConverter.resultSet.size(); i++) {
1070
1071        SnmpVarBind vb = (SnmpVarBind)snmpConverter.resultSet.get(i);
1072        Any JavaDoc value = this.orb.create_any();
1073        value = convertSnmpSyntaxToAny(vb.getValue());
1074        if (value == null) {
1075            System.err.println("SnmpAdapter>Could not encapsulate SNMP attribute value into a CORBA Any");
1076            throw new SnmpApplicationError(ExceptionMessages.agent_create_error);
1077        }
1078        else {
1079            snmpTable[i] = new DataTypeImpl(vb.getName().toString(), value, vb.getValue().typeId());
1080
1081        }
1082    }
1083
1084        return snmpTable;
1085    }
1086    //
1087
// IDL:coach.ist/coachEmfServices/SnmpAdapter/SnmpConnector/genNext:1.0
1088
//
1089
/**
1090     ** Implementation of the ::coachEmfServices::SnmpAdapter::SnmpConnector::genNext operation.
1091     **/

1092    public ist.coach.coachEmfServices.SnmpAdapter.DataType JavaDoc
1093    getNext(java.lang.String JavaDoc identifier,
1094                java.lang.String JavaDoc host,
1095                int port,
1096                java.lang.String JavaDoc community)
1097    throws ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError JavaDoc
1098    {
1099        //
1100
// DONE : implement
1101
//
1102

1103    SnmpProtocolConverter snmpConverter = new SnmpProtocolConverter(host, community, port, null);
1104
1105    snmpConverter.snmpGetNext(new SnmpObjectId(identifier));
1106
1107    if (snmpConverter.agentResponded() == false) {
1108
1109        System.err.println("Agent did not respond!");
1110        throw new SnmpApplicationError(ExceptionMessages.agent_response_error);
1111    }
1112
1113    if (snmpConverter.resultSet.size() == 0) {
1114
1115        System.err.println("Could not retrieve attribute with oid " + identifier);
1116        throw new SnmpApplicationError(ExceptionMessages.agent_get_error);
1117    }
1118
1119    Any JavaDoc value = this.orb.create_any();
1120    SnmpVarBind vb = (SnmpVarBind)snmpConverter.resultSet.elementAt(0);
1121    String JavaDoc oid = vb.getName().toString();
1122    value = convertSnmpSyntaxToAny(vb.getValue());
1123
1124    if (value == null) {
1125        System.err.println("Could not retrieve attribute with oid " + identifier);
1126        throw new SnmpApplicationError(ExceptionMessages.agent_get_error);
1127    }
1128
1129    DataTypeImpl result = new DataTypeImpl(oid, value, vb.getValue().typeId());
1130
1131    return result;
1132
1133    }
1134    //
1135
// IDL:coach.ist/coachEmfServices/SnmpAdapter/Connector/get:1.0
1136
//
1137
/**
1138     ** Implementation of the ::coachEmfServices::SnmpAdapter::Connector::get operation.
1139     **/

1140    public ist.coach.coachEmfServices.SnmpAdapter.DataType JavaDoc
1141    get(java.lang.String JavaDoc identifier,
1142                java.lang.String JavaDoc host,
1143                int port,
1144                java.lang.String JavaDoc community)
1145    throws ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError JavaDoc
1146    {
1147        //
1148
// DONE : implement
1149
//
1150

1151    SnmpProtocolConverter snmpConverter = new SnmpProtocolConverter(host, community, port, null);
1152
1153    SnmpVarBind [] vblist = new SnmpVarBind[1];
1154    vblist[0] = new SnmpVarBind(new SnmpObjectId(identifier));
1155
1156    snmpConverter.snmpGet(vblist);
1157
1158    if (snmpConverter.agentResponded() == false) {
1159
1160        System.err.println("Agent did not respond!");
1161        throw new SnmpApplicationError(ExceptionMessages.agent_response_error);
1162    }
1163
1164    if (snmpConverter.resultSet.size() == 0) {
1165
1166        System.err.println("Could not retrieve attribute with oid " + identifier);
1167        throw new SnmpApplicationError(ExceptionMessages.agent_get_error);
1168    }
1169
1170    //System.err.println("Got " + ((SnmpVarBind)snmpConverter.resultSet.elementAt(0)).toString());
1171

1172    Any JavaDoc value = this.orb.create_any();
1173    SnmpVarBind vb = (SnmpVarBind)snmpConverter.resultSet.elementAt(0);
1174    String JavaDoc oid = vb.getName().toString();
1175    value = convertSnmpSyntaxToAny(vb.getValue());
1176
1177    if (value == null) {
1178        System.err.println("Could not retrieve attribute with oid " + identifier);
1179        throw new SnmpApplicationError(ExceptionMessages.agent_get_error);
1180    }
1181
1182    DataTypeImpl result = new DataTypeImpl(oid, value, vb.getValue().typeId());
1183
1184    return result;
1185    }
1186    //
1187
// IDL:coach.ist/coachEmfServices/SnmpAdapter/Connector/getBulk:1.0
1188
//
1189
/**
1190     ** Implementation of the ::coachEmfServices::SnmpAdapter::Connector::getBulk operation.
1191     **/

1192    public ist.coach.coachEmfServices.SnmpAdapter.DataType JavaDoc[]
1193    getBulk(java.lang.String JavaDoc[] identifiers,
1194                java.lang.String JavaDoc host,
1195                int port,
1196                java.lang.String JavaDoc community)
1197    throws ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError JavaDoc
1198    {
1199        //
1200
// DONE : implement
1201
//
1202
SnmpProtocolConverter snmpConverter = new SnmpProtocolConverter(host, community, port, null);
1203
1204    int numRequested = identifiers.length;
1205
1206    SnmpVarBind [] vblist = new SnmpVarBind[numRequested];
1207
1208    for (int i = 0; i < numRequested; i++)
1209        vblist[i] = new SnmpVarBind(new SnmpObjectId(identifiers[i]));
1210
1211    snmpConverter.snmpGet(vblist);
1212
1213    if (snmpConverter.agentResponded() == false) {
1214
1215        System.err.println("Agent did not respond!");
1216        throw new SnmpApplicationError(ExceptionMessages.agent_response_error);
1217    }
1218
1219    if (snmpConverter.resultSet.size() == 0) {
1220        System.err.println("Could not retrieve attributes with requested identifiers");
1221        throw new SnmpApplicationError(ExceptionMessages.agent_get_error);
1222    }
1223
1224    DataTypeImpl [] result = new DataTypeImpl[snmpConverter.resultSet.size()];
1225
1226
1227    for (int i = 0; i < snmpConverter.resultSet.size(); i++) {
1228
1229        Any JavaDoc value = this.orb.create_any();
1230        SnmpVarBind vb = (SnmpVarBind)snmpConverter.resultSet.elementAt(i);
1231        String JavaDoc oid = vb.getName().toString();
1232        value = convertSnmpSyntaxToAny(vb.getValue());
1233
1234        if (value == null) {
1235            System.err.println("Could not encapsulate SNMP attribute value into a CORBA Any");
1236            throw new SnmpApplicationError(ExceptionMessages.agent_create_error);
1237        }
1238        else
1239            result[i] = new DataTypeImpl(((SnmpVarBind)snmpConverter.resultSet.elementAt(i)).getName().toString(), value, vb.getValue().typeId());
1240    }
1241
1242    //System.err.println("getBulk is ready to return!!");
1243
return result;
1244
1245    }
1246    //
1247
// IDL:coach.ist/coachEmfServices/SnmpAdapter/Connector/set:1.0
1248
//
1249
/**
1250     ** Implementation of the ::coachEmfServices::SnmpAdapter::Connector::set operation.
1251     **/

1252    public void
1253    set(ist.coach.coachEmfServices.SnmpAdapter.DataType JavaDoc data,
1254                java.lang.String JavaDoc host,
1255                int port,
1256                java.lang.String JavaDoc community)
1257    throws ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError JavaDoc
1258    {
1259        //
1260
// DONE : implement
1261
//
1262
SnmpProtocolConverter snmpConverter = new SnmpProtocolConverter(host, community, port, null);
1263
1264        SnmpVarBind [] vblist = new SnmpVarBind[1];
1265        SnmpSyntax value = convertAnyToSnmpSyntax(data.value, data.code);
1266        if (value == null) {
1267            System.err.println("Could not convert DataType to an SnmpSyntax");
1268            throw new SnmpApplicationError(ExceptionMessages.agent_create_error);
1269        }
1270
1271        vblist[0] = new SnmpVarBind(new SnmpObjectId(data.identifier), value);
1272
1273        snmpConverter.snmpSet(vblist);
1274
1275        if (snmpConverter.agentResponded() == false) {
1276
1277            System.err.println("Agent did not respond!");
1278            throw new SnmpApplicationError(ExceptionMessages.agent_response_error);
1279        }
1280
1281        if (snmpConverter.resultSet.size() == 0) {
1282
1283            System.err.println("Could not set attribute with oid " + data.identifier);
1284            throw new SnmpApplicationError(ExceptionMessages.agent_set_error);
1285        }
1286
1287    }
1288    //
1289
// IDL:coach.ist/coachEmfServices/SnmpAdapter/Connector/setBulk:1.0
1290
//
1291
/**
1292     ** Implementation of the ::coachEmfServices::SnmpAdapter::Connector::setBulk operation.
1293     **/

1294    public void
1295    setBulk(ist.coach.coachEmfServices.SnmpAdapter.DataType JavaDoc[] data,
1296                java.lang.String JavaDoc host,
1297                int port,
1298                java.lang.String JavaDoc community)
1299    throws ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError JavaDoc
1300    {
1301        //
1302
// DONE : implement
1303
//
1304
SnmpProtocolConverter snmpConverter = new SnmpProtocolConverter(host, community, port, null);
1305        int numRequested = data.length;
1306        //System.err.println("SnmpAdapter:setBulk> Data size = " + numRequested);
1307
SnmpVarBind [] vblist = new SnmpVarBind[numRequested];
1308
1309        for (int i = 0; i < numRequested; i++) {
1310            //System.err.println("[" + i + "] = ");
1311

1312            SnmpSyntax value = convertAnyToSnmpSyntax(data[i].value, data[i].code);
1313            vblist[i] = new SnmpVarBind(new SnmpObjectId(data[i].identifier), value);
1314            //System.err.println("identifier = " +
1315
// data[i].identifier + " value = " + value);
1316
}
1317
1318        snmpConverter.snmpSet(vblist);
1319
1320        if (snmpConverter.agentResponded() == false) {
1321
1322            System.err.println("Agent did not respond!");
1323            throw new SnmpApplicationError(ExceptionMessages.agent_response_error);
1324        }
1325
1326        if (snmpConverter.resultSet.size() == 0) {
1327            System.err.println("setBulk>Could not set attributes");
1328
1329            throw new SnmpApplicationError(ExceptionMessages.agent_get_error);
1330        }
1331      //System.err.println("setBulk is ready to return");
1332
}
1333    // ==================================================================
1334
//
1335
// Public methods for the ::coachEmfServices::SnmpAdapter::CCM_SnmpTrapDaemon local interface.
1336
//
1337
// ==================================================================
1338
//
1339
// IDL:coach.ist/coachEmfServices/SnmpAdapter/SnmpTrapDaemon/registerIP:1.0
1340
//
1341
/**
1342     ** Implementation of the ::coachEmfServices::SnmpAdapter::SnmpTrapDaemon::registerIP operation.
1343     **/

1344    public void
1345    registerIP(org.omg.CosNaming.NameComponent JavaDoc[] name, java.lang.String JavaDoc ipAddress)
1346    throws ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError JavaDoc
1347    {
1348        //
1349
// DONE : implement
1350
//
1351
if (nameExists (name)) {
1352        System.err.println("Could not register object with Name " +
1353                Utils.name2string(name) + " because it already exists!");
1354        throw new SnmpApplicationError(ExceptionMessages.snmp_register_error);
1355
1356    }
1357    else {
1358        ObjectData objData = new ObjectData (name, ipAddress);
1359        this.linkedList.add(objData);
1360        //System.err.println("SnmpAdapter> Registered object with Name " +
1361
//Utils.name2string(name) + " and IP Address *" + ipAddress + "*");
1362
}
1363    }
1364    //
1365
// IDL:coach.ist/coachEmfServices/SnmpAdapter/SnmpTrapDaemon/registerValue:1.0
1366
//
1367
/**
1368     ** Implementation of the ::coachEmfServices::SnmpAdapter::SnmpTrapDaemon::registerValue operation.
1369     **/

1370    public void
1371    registerValue(org.omg.CosNaming.NameComponent JavaDoc[] name, java.lang.String JavaDoc ipAddress, org.omg.CORBA.Any JavaDoc value)
1372    throws ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError JavaDoc
1373    {
1374        //
1375
// DONE : implement
1376
//
1377
//System.err.println("SnmpAdapter:registerValue> is called for " +
1378
// Utils.name2string(name) + " with IP Address *" + ipAddress + "*");
1379
if (nameExists (name)) {
1380        System.err.println("SNMPAdapter:registerValue> Could not register object with Name "
1381          + Utils.name2string(name) + " because it already exists!");
1382        throw new SnmpApplicationError(ExceptionMessages.snmp_register_error);
1383    }
1384    else
1385        if (rootObjectExists(ipAddress, name) == false) {
1386            System.err.println("SNMPAdapter:registerValue> Could not find parent for this object.");
1387            throw new SnmpApplicationError(ExceptionMessages.snmp_superior_error);
1388        }
1389        else {
1390            ObjectData objData = new ObjectData (name, ipAddress, value);
1391            this.linkedList.add(objData);
1392            //System.err.println("Registered object with Name " + Utils.name2string(name) + " and IP Address " + ipAddress);
1393
}
1394    }
1395    //
1396
// IDL:coach.ist/coachEmfServices/SnmpAdapter/SnmpTrapDaemon/unregister:1.0
1397
//
1398
/**
1399     ** Implementation of the ::coachEmfServices::SnmpAdapter::SnmpTrapDaemon::unregister operation.
1400     **/

1401    public void
1402    unregister(org.omg.CosNaming.NameComponent JavaDoc[] name)
1403    throws ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError JavaDoc
1404    {
1405        //
1406
// DONE : implement
1407
//
1408

1409    ObjectData objData = null;
1410
1411    if ((objData = findObjectWithName(name)) != null) {
1412        this.linkedList.remove(objData);
1413        System.err.println("SnmpAdapter:unregister>Unregistered object with name " + Utils.name2string(name));
1414    }
1415    else {
1416        System.err.println("SnmpAdapter:unregister>Could not unregister object with name " + Utils.name2string(name));
1417        throw new SnmpApplicationError(ExceptionMessages.snmp_unregister_error);
1418    }
1419
1420    }
1421}
1422
Popular Tags