KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ist > coach > coachEmsMibComponents > IpProtocolMonitorFactoryProviderComposition > IpProtocolMonitorFactoryProviderImpl


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.coachEmsMibComponents.IpProtocolMonitorFactoryProviderComposition;
22
23 import ist.coach.coachEmfCommon.Utils;
24 import ist.coach.coachEmfCommon.CreateController;
25 import ist.coach.coachEmfCommon.CreateBindingInfo;
26 import ist.coach.coachEmfCommon.ExceptionMessages;
27 import ist.coach.coachEmfCommon.CreateErrorInfoTypeImpl;
28 import ist.coach.coachEmfCommon.ApplicationErrorInfoTypeImpl;
29
30 import ist.coach.coachEmsCommon.SnmpUtils;
31 import org.opennms.protocols.snmp.SnmpSMI;
32 import ist.coach.coachEmfServices.SnmpAdapter.DataType;
33 import ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError;
34 import ist.coach.coachEmsCommon.SnmpIdentifiers;
35
36 import intt.itu.itut_x780.UIDType;
37 import intt.itu.itut_x780.CreateError;
38 import intt.itu.itut_x780.ApplicationError;
39 import ist.coach.coachEmsMib.IpRoutingEntryFactory;
40 import ist.coach.coachEmsMib.IpToMACAddressFactory;
41
42 import intt.itu.itut_m3120.conditionalPackages.*;
43 import ist.coach.coachEmfServices.EmfBasicLog.*;
44
45 import org.omg.CosNaming.NameComponent JavaDoc;
46 import ist.coach.coachEmsMibComponents.IpProtocolMonitorMgmt;
47 /**
48  ** Implementation skeleton class for the ::coachEmsMibComponents::IpProtocolMonitorFactoryProvider component.
49  **/

50 public class IpProtocolMonitorFactoryProviderImpl
51      extends ist.coach.coachEmsMibComponents.IpProtocolMonitorFactoryProviderComposition.IpProtocolMonitorFactoryProvider_impl
52 {
53     // ==================================================================
54
//
55
// Internal State.
56
//
57
// ===================================================================
58
/**
59      ** Context reference.
60      **/

61
62         /* Business logic **/
63     intt.itu.itut_q816.ContainmentComponent c_admin = null;
64     intt.itu.itut_q816.Containment c_query = null;
65
66     private static final String JavaDoc FACTORY_CLASS = "LogicalInterfaceFactory";
67     IpProtocolMonitorMgmt facade = null;
68     private BasicLog logSupport;
69     ist.coach.coachEmfServices.SnmpAdapter.SnmpConnector connector = null;
70
71
72     // ==================================================================
73
//
74
// Constructor.
75
//
76
// ===================================================================
77
/**
78      ** The default constructor.
79      **/

80     public
81     IpProtocolMonitorFactoryProviderImpl()
82     {}
83     // ==================================================================
84
//
85
// Internal methods.
86
//
87
// ===================================================================
88
// ==================================================================
89
//
90
// Public methods.
91
//
92
// ===================================================================
93

94     // ==================================================================
95
//
96
// Methods for the OMG IDL Components::EnterpriseComponent local interface.
97
//
98
// ==================================================================
99
//
100
// IDL:omg.org/Components/EnterpriseComponent/configuration_complete:1.0
101
//
102
/**
103      ** Completes the component configuration.
104      **
105      ** @throws org.omg.Components.InvalidConfiguration
106      ** Thrown if the configuration is invalid.
107      **/

108     public void
109     configuration_complete()
110     throws org.omg.Components.InvalidConfiguration
111     {
112         //
113
// DONE : implement !!!
114
//
115

116         if ((facade = get_context().get_connection_facade()) == null)
117             throw new org.omg.Components.InvalidConfiguration();
118
119         if ((c_admin = get_context().get_connection_containment_admin()) == null)
120             throw new org.omg.Components.InvalidConfiguration();
121
122         if ((c_query = get_context().get_connection_containment_query()) == null)
123             throw new org.omg.Components.InvalidConfiguration();
124
125         if ((connector = get_context().get_connection_connector()) == null)
126             throw new org.omg.Components.InvalidConfiguration();
127
128         if ((logSupport = get_context().get_connection_basic_log()) == null)
129             throw new org.omg.Components.InvalidConfiguration();
130
131         System.err.println("IpProtocolMonitorFactoryProviderconfiguration completed...");
132
133
134     }
135
136     // ==================================================================
137
//
138
// Public methods for the CCM_IpProtocolMonitorFactoryProvider local interface.
139
//
140
// ==================================================================
141
//
142
// IDL:coach.ist/coachEmsMib/IpProtocolMonitorFactory/create:1.0
143
//
144
/**
145      ** Implementation of the ::coachEmsMib::IpProtocolMonitorFactory::create operation.
146      **/

147     public org.omg.CosNaming.NameComponent JavaDoc[]
148     create(java.lang.String JavaDoc nameBindingID,
149             org.omg.CosNaming.NameComponent JavaDoc[] superior,
150             String JavaDoc reqID,
151             String JavaDoc [] packageNameList,
152             byte[] mgmtIpAddress,
153             int snmpPort,
154             int supportedSnmpVersions
155     )
156     throws intt.itu.itut_x780.ApplicationError, intt.itu.itut_x780.CreateError
157     {
158         //
159
// DONE : implement
160
//
161

162         String JavaDoc nameBinding_str = "ist.coach.coachEmsMib.NameBindings." +
163             nameBindingID;
164
165         CreateBindingInfo info = CreateController.checkNameBinding(nameBinding_str);
166
167         String JavaDoc objectKind = info.objectKind;
168         short deletePolicy = info.deletePolicy;
169
170         // Check if the parent exists
171
if (! c_query.exists(superior)) {
172                 ApplicationErrorInfoTypeImpl error_code =
173                         new ApplicationErrorInfoTypeImpl();
174                 error_code.error = new UIDType(
175                 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value,
176                 intt.itu.itut_x780.ApplicationErrorConst.objectNotFound.value);
177
178
179                 error_code.details = Utils.name2string(superior) +
180                 ExceptionMessages.parent_object_error;
181
182             throw new ApplicationError(error_code);
183         }
184
185         // The system must have the capability to auto-name objects
186

187         String JavaDoc allocatedId = null;
188         if (reqID == null || reqID.length() == 0) {
189
190             org.omg.CosNaming.NameComponent JavaDoc[][] siblings =
191             c_query.getContained(superior);
192             allocatedId = CreateController.autoCreateId(siblings);
193         }
194         else
195             allocatedId = reqID;
196
197         // Construct the name of the new object
198

199         org.omg.CosNaming.NameComponent JavaDoc[] name = CreateController.createFullName(
200                 superior,
201                 allocatedId,
202                 Utils.name2facade(facade.facade_name()),
203                 objectKind);
204
205         // Decide the conditional packages that are supported.
206
String JavaDoc [] supportedConditionalPackages = packageNameList;
207
208         Utils.pretty_log(logSupport, FACTORY_CLASS, "Factory", (short) LogSeverity._Info,
209           "proceed to create " + Utils.name2string(name));
210
211        // if (packageNameList.length == 0)
212
// System.err.println("No packages are specified. ");
213
/****
214         System.err.println("IpProtocolMonitorFactory> Before invoking the facade " +
215                 Utils.name2facade(facade.facade_name()) + " to create " +
216             Utils.name2string(name) + " port = " + snmpPort);
217 *******/

218             facade.create(
219                     name,
220                 objectKind,
221                 packageNameList,
222                 deletePolicy,
223                 intt.itu.itut_x780.SourceIndicatorType.resourceOperation,
224                 superior,
225                 mgmtIpAddress,
226                 supportedSnmpVersions,
227                 snmpPort);
228
229             c_admin.addName(name, superior);
230             //System.err.println("IpProtocolMonitorFactory>create returns for " +
231
// Utils.name2string(name));
232

233                   // IpRoute Objects must also get created !
234

235         DataType[] routeTable = new DataType[0];
236         try {
237             routeTable = this.connector.getSnmpTable(
238                     SnmpIdentifiers.IP_ROUTE_TABLE_OID,
239                     new String JavaDoc(mgmtIpAddress),
240                     snmpPort,
241                     SnmpIdentifiers.READ_COMMUNITY); // "public"
242
}
243         catch(ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError snmp_ex) {
244             System.err.println("IpProtocolMonitorFactory: create>SnmpApplicationError caught: " +
245                         snmp_ex.reason);
246                 return name;
247         }
248         catch(Exception JavaDoc e) {
249           System.err.println("IpProtocolMonitorFactory: create>Exception caught: " + e.getMessage());
250           e.printStackTrace(System.err);
251         }
252 /*****************************
253         for(int i = 0; i < routeTable.length; i++) {
254             try {
255                 System.err.println("routeTable[" + i + "] = " +
256                     routeTable[i].value.extract_string());
257             }
258             catch(Exception e1) {
259               try {
260                 System.err.println("routeTable[" + i + "] = " +
261                     routeTable[i].value.extract_long());
262               }
263               catch(Exception e2) {
264                 System.err.println("routeTable[" + i + "] can not be read");
265             }
266           }
267         }
268 ****************************/

269         int[] ipRouteDestIndexRows = { 1 };
270             // Experimenting with Linux box proved 8 attributes are supported for ipRoutingEntry
271
int numOfRouteColumns = 8;
272         String JavaDoc [] ipRouteDest = SnmpUtils.getStringColumnData(routeTable,
273             numOfRouteColumns, ipRouteDestIndexRows);
274
275         if (ipRouteDest.length > 0) {
276               IpRoutingEntryFactory ip_address_factory =
277                     get_context().get_connection_ipRoutingEntryFactory();
278
279                 if (ip_address_factory != null) {
280                     for(int i = 0; i < ipRouteDest.length; i ++) {
281                         ip_address_factory.create("IpRoutingEntry_IpProtocolMonitor",
282                                               name,
283                                               new String JavaDoc(),
284                                               new String JavaDoc[0],
285                                               ipRouteDest[i].getBytes(),
286                                               mgmtIpAddress,
287                                               snmpPort,
288                                               supportedSnmpVersions
289                                           );
290
291                     }
292                 }
293         }
294
295             //IpToMACAddress objects must be created!
296

297         //System.err.println("IpProtocolMonitorFactory> Proceeding to create IpToMACAddressObjects...");
298
DataType[] ipToMACTable = new DataType[0];
299         try {
300             ipToMACTable = this.connector.getSnmpTable(
301                     SnmpIdentifiers.IP_MACADDRESS_OID,
302                     new String JavaDoc(mgmtIpAddress),
303                     snmpPort,
304                     SnmpIdentifiers.READ_COMMUNITY); // "public"
305
}
306         catch(ist.coach.coachEmfServices.SnmpAdapter.SnmpApplicationError snmp_ex) {
307             System.err.println("IpProtocolMonitorFactory: create>SnmpApplicationError caught: " +
308                         snmp_ex.reason);
309                 return name;
310         }
311         catch(Exception JavaDoc e) {
312           System.err.println("IpProtocolMonitorFactory: create>Exception caught: " + e.getMessage());
313           e.printStackTrace(System.err);
314         }
315
316         int[] iptoMACAddressIndexRows = { 1 };
317             // Experimenting with Linux box proved 4 attributes are supported for ipToMACAddress
318
int numOfMacColumns = 4;
319         int[] iptoMACAddressIndexes = SnmpUtils.getIntColumnData(ipToMACTable,
320             numOfMacColumns, iptoMACAddressIndexRows);
321
322         int[] ipNetToMediaNetAddressRows = { 3 };
323         String JavaDoc[] ipNetToMediaNetAddress= SnmpUtils.getStringColumnData(ipToMACTable,
324             numOfMacColumns, ipNetToMediaNetAddressRows);
325
326         if (iptoMACAddressIndexes.length > 0 &&
327                 ipNetToMediaNetAddressRows.length == ipNetToMediaNetAddress.length ) {
328
329                 //System.err.println("iptoMACAddresses indexes found....");
330
IpToMACAddressFactory ip_mac_address_factory =
331                     get_context().get_connection_ipToMACAddressFactory();
332
333                 if (ip_mac_address_factory != null) {
334                     for(int i = 0; i < iptoMACAddressIndexes.length; i ++) {
335                         //System.err.println("Ready to create IpTOMACAddress " +
336
// iptoMACAddressIndexes[i] + ", " + ipNetToMediaNetAddress[i]);
337
ip_mac_address_factory.create("IpToMACAddress_IpProtocolMonitor",
338                                               name,
339                                               new String JavaDoc("IpToMACAddress" + (i+1)),
340                                               new String JavaDoc[0],
341                                               iptoMACAddressIndexes[i],
342                                               ipNetToMediaNetAddress[i].getBytes(),
343                                               mgmtIpAddress,
344                                               snmpPort,
345                                               supportedSnmpVersions
346                                           );
347
348                     }
349                 }
350         }
351
352 /**********
353         for(int i = 0; i < ipToMACTable.length; i++) {
354             try {
355                 System.err.println("ipToMACTable[" + i + "] = " +
356                     ipToMACTable[i].value.extract_string());
357             }
358             catch(Exception e1) {
359               try {
360                 System.err.println("ipToMACTable[" + i + "] = " +
361                     ipToMACTable[i].value.extract_long());
362               }
363               catch(Exception e2) {
364                 try {
365                   System.err.println("ipToMACTable[" + i + "] = " +
366                       new String(org.omg.CORBA.OctetSeqHelper.extract(ipToMACTable[i].value)) +
367                           " (byte string)");
368                 }
369                 catch(Exception e3) {
370                   System.err.println("ipToMACTable[" + i + "] can not be read");
371                 }
372             }
373           }
374         }
375 *************/

376                     // ready to return
377

378         Utils.pretty_log(logSupport, FACTORY_CLASS, "Factory", (short) LogSeverity._Info,
379           "successfully created " + Utils.name2string(name));
380         return name;
381
382     }
383     //
384
// IDL:itu.intt/itut_x780/ManagedObjectFactory/create_base:1.0
385
//
386
/**
387      ** Implementation of the ::itut_x780::ManagedObjectFactory::create_base operation.
388      **/

389     public org.omg.CosNaming.NameComponent JavaDoc[]
390     create_base(java.lang.String JavaDoc nameBinding,
391                     org.omg.CosNaming.NameComponent JavaDoc[] superior,
392                     java.lang.String JavaDoc reqId)
393     throws intt.itu.itut_x780.CreateError, intt.itu.itut_x780.ApplicationError
394     {
395         //
396
// TODO : implement
397
//
398
return new NameComponent JavaDoc[0];
399     }
400 }
401
Popular Tags