KickJava   Java API By Example, From Geeks To Geeks.

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


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 JavaDoc;
30
31 //import ist.coach.coachEmfServicesComponents.SnmpObjectData;
32
import ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError JavaDoc;
33 import ist.coach.coachEmfCommon.Utils;
34 import ist.coach.coachEmfCommon.ExceptionMessages;
35
36 import org.omg.CosNaming.NameComponent JavaDoc;
37
38 import java.util.LinkedList JavaDoc;
39 import java.util.ListIterator JavaDoc;
40
41
42 /**
43  * This is the CIDL-based implementation of the
44  * OMG IDL3 CIDL:coach.ist/coachEmfServicesComponents/SnmpAdapterProviderComposition/SnmpAdapterProviderHome_impl/SnmpAdapterProvider_impl/configSeg:1.0 segment type.
45  *
46  * @author OpenCCM CIF_Jimpl Compiler.
47  */

48 public class configSegImpl
49      extends ist.coach.coachEmfServicesComponents.SnmpAdapterProviderComposition.configSeg JavaDoc
50 {
51     // ==================================================================
52
//
53
// Internal states.
54
//
55
// ==================================================================
56

57     // ==================================================================
58
//
59
// Constructors.
60
//
61
// ==================================================================
62

63     public configSegImpl()
64     {
65     }
66     // ==================================================================
67
//
68
// Private Methods.
69
//
70
// ==================================================================
71
private boolean nameExists(NameComponent JavaDoc[] name) {
72
73         ListIterator JavaDoc li = SnmpAdapterProviderImpl.linkedList.listIterator();
74
75         while (li.hasNext()) {
76             SnmpObjectData objData = (SnmpObjectData) li.next();
77             if (objData.getName().equals(name)) {
78                 return true;
79             }
80         }
81         return false;
82      }
83
84      private boolean rootObjectExists(String JavaDoc ipAddress,
85         NameComponent JavaDoc[] name) {
86
87         ListIterator JavaDoc li = SnmpAdapterProviderImpl.linkedList.listIterator();
88
89         while (li.hasNext()) {
90
91             SnmpObjectData objData = (SnmpObjectData)li.next();
92             //System.err.println("Examining object with IPAddress = *" +
93
//objData.getIPAddress() + "* against *" + ipAddress + "*");
94

95             if (objData.getIPAddress().equals(ipAddress) &&
96                 SnmpAdapterProviderImpl.isRootObject(
97                   SnmpAdapterProviderImpl.getObjectClass(objData.getName())) &&
98                   Utils.isChild(name, objData.getName()))
99                     return true;
100         }
101
102         return false;
103     }
104
105     private SnmpObjectData findObjectWithName(NameComponent JavaDoc[] name) {
106
107         String JavaDoc name_str = Utils.name2string(name);
108
109         ListIterator JavaDoc li = SnmpAdapterProviderImpl.linkedList.listIterator();
110
111         SnmpObjectData objData = null;
112
113         while (li.hasNext()) {
114             objData = (SnmpObjectData) li.next();
115             if (Utils.name2string(objData.getName()).equals(name_str)) {
116                 return objData;
117             }
118         }
119         return null;
120      }
121     // ==================================================================
122
//
123
// Methods.
124
//
125
// ==================================================================
126

127     /**
128      * Implementation of the ::coachEmfServices::SnmpAdapter::SnmpTrapDaemon::registerIP operation.
129      */

130     public void
131     registerIP(org.omg.CosNaming.NameComponent JavaDoc[] name, String JavaDoc ipAddress)
132     throws ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError JavaDoc
133     {
134          //
135
// DONE : implement
136
//
137
if (nameExists (name)) {
138         System.err.println("Could not register object with Name " +
139                 Utils.name2string(name) + " because it already exists!");
140         throw new SnmpApplicationError(ExceptionMessages.snmp_register_error);
141
142     }
143     else {
144         SnmpObjectData objData = new SnmpObjectData (name, ipAddress);
145         synchronized(SnmpAdapterProviderImpl.linkedList) {
146           SnmpAdapterProviderImpl.linkedList.add(objData);
147         }
148         //System.err.println("SnmpAdapter> Registered object with Name " +
149
//Utils.name2string(name) + " and IP Address *" + ipAddress + "*");
150
}
151     }
152
153     /**
154      * Implementation of the ::coachEmfServices::SnmpAdapter::SnmpTrapDaemon::registerValue operation.
155      */

156     public void
157     registerValue(org.omg.CosNaming.NameComponent JavaDoc[] name, String JavaDoc ipAddress, org.omg.CORBA.Any JavaDoc value)
158     throws ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError JavaDoc
159     {
160        //
161
// DONE : implement
162
//
163
//System.err.println("SnmpAdapter:registerValue> is called for " +
164
// Utils.name2string(name) + " with IP Address *" + ipAddress + "*");
165
if (nameExists (name)) {
166         System.err.println("SNMPAdapter:registerValue> Could not register object with Name "
167           + Utils.name2string(name) + " because it already exists!");
168         throw new SnmpApplicationError(ExceptionMessages.snmp_register_error);
169     }
170     else
171         if (rootObjectExists(ipAddress, name) == false) {
172             System.err.println("SNMPAdapter:registerValue> Could not find parent for this object.");
173             throw new SnmpApplicationError(ExceptionMessages.snmp_superior_error);
174         }
175         else {
176             SnmpObjectData objData = new SnmpObjectData (name, ipAddress, value);
177             synchronized(SnmpAdapterProviderImpl.linkedList) {
178               SnmpAdapterProviderImpl.linkedList.add(objData);
179             }
180             //System.err.println("Registered object with Name " + Utils.name2string(name) + " and IP Address " + ipAddress);
181
}
182     }
183
184     /**
185      * Implementation of the ::coachEmfServices::SnmpAdapter::SnmpTrapDaemon::unregister operation.
186      */

187     public void
188     unregister(org.omg.CosNaming.NameComponent JavaDoc[] name)
189     throws ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError JavaDoc
190     {
191        //
192
// DONE : implement
193
//
194

195       SnmpObjectData objData = null;
196
197       if ((objData = findObjectWithName(name)) != null) {
198         synchronized(SnmpAdapterProviderImpl.linkedList) {
199           SnmpAdapterProviderImpl.linkedList.remove(objData);
200         }
201         System.err.println("SnmpAdapter:unregister>Unregistered object with name " + Utils.name2string(name));
202       }
203       else {
204         System.err.println("SnmpAdapter:unregister>Could not unregister object with name " + Utils.name2string(name));
205         throw new SnmpApplicationError(ExceptionMessages.snmp_unregister_error);
206       }
207     }
208
209 }
210
Popular Tags