1 marek 1.1 //%2004////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development
4 // Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
16 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
17 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
18 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
19 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 marek 1.1 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 //
24 //==============================================================================
25 // Author: Mike Brasher (mbrasher@bmc.com)
26 // Marek Szermutzky (MSzermutzky@de.ibm.com) PEP#139 Stage2
27 //
28 // Modified By: Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com)
29 // Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
30 // Nag Boranna, Hewlett-Packard Company (nagaraja_boranna@hp.com)
31 // Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
32 // Carol Ann Krug Graves, Hewlett-Packard Company
33 // (carolann_graves@hp.com)
34 // Jair Santos, Hewlett-Packard Company (jair.santos@hp.com)
35 //
36 //%/////////////////////////////////////////////////////////////////////////////
37
38 #include "CIMManagedClient.h"
39
40 PEGASUS_NAMESPACE_BEGIN
41
42 // class constructor
43 marek 1.1 CIMManagedClient::CIMManagedClient()
44 {
45 // *shrugs*
46 // using this constructor doesn't seem to clever
47 // remind, if you use it, don't forget to set the ConnectionManager via setConnectionManager()
48 setPegasusDefaultPort();
49 _cccm = 0;
50 }
51
52 CIMManagedClient::CIMManagedClient(CIMClientConnectionManager* cccm)
53 {
54 CDEBUG("Using given CIMClientConnectionManager*");
55 setPegasusDefaultPort();
56 _cccm = cccm;
57 }
58
59 void CIMManagedClient::setConnectionManager(CIMClientConnectionManager* cccm)
60 {
61 // if (_cccm != 0) delete _cccm;
62 _cccm = cccm;
63 }
64 marek 1.1
65 CIMClientConnectionManager* CIMManagedClient::getConnectionManager(void)
66 {
67 return _cccm;
68 }
69
70 CIMManagedClient::~CIMManagedClient()
71 {
72 // ubs, we shouldn't delete the ClientConnectionManager,
73 // as we don't know what it is anyway
74 // if (_cccm != 0) delete _cccm;
75 }
76
77 // l10n start
78 void CIMManagedClient::setRequestAcceptLanguages(const String& host, const String& port, AcceptLanguages& langs)
79 {
80 CIMClientRep * _rep;
81 _rep = getTargetCIMOM(host, port, CIMNamespaceName());
82 _rep->setRequestAcceptLanguages(langs);
83 }
84
85 marek 1.1 AcceptLanguages CIMManagedClient::getRequestAcceptLanguages(const String& host, const String& port) const
86 {
87 CIMClientRep * _rep;
88 _rep = getTargetCIMOM(host, port, CIMNamespaceName());
89 return _rep->getRequestAcceptLanguages();
90 }
91
92 void CIMManagedClient::setRequestContentLanguages(const String& host, const String& port, ContentLanguages& langs)
93 {
94 CIMClientRep * _rep;
95 _rep = getTargetCIMOM(host, port, CIMNamespaceName());
96 _rep->setRequestContentLanguages(langs);
97 }
98
99 ContentLanguages CIMManagedClient::getRequestContentLanguages(const String& host, const String& port) const
100 {
101 CIMClientRep * _rep;
102 _rep = getTargetCIMOM(host, port, CIMNamespaceName());
103 return _rep->getRequestContentLanguages();
104 }
105
106 marek 1.1 ContentLanguages CIMManagedClient::getResponseContentLanguages(const String& host, const String& port) const
107 {
108 CIMClientRep * _rep;
109 _rep = getTargetCIMOM(host, port, CIMNamespaceName());
110 return _rep->getResponseContentLanguages();
111 }
112
113 void CIMManagedClient::setRequestDefaultLanguages(const String& host, const String& port)
114 {
115 CIMClientRep * _rep;
116 _rep = getTargetCIMOM(host, port, CIMNamespaceName());
117 _rep->setRequestDefaultLanguages();
118 }
119 // l10n end
120
121 Array<CIMObjectPath> CIMManagedClient::enumerateInstanceNames(
122 const String& host,
123 const String& port,
124 const CIMNamespaceName& nameSpace,
125 const CIMName& className)
126 {
127 marek 1.1 // test if host and namespace are provided
128 hasHostandNameSpace(host, nameSpace);
129 CIMClientRep * _rep;
130 _rep = getTargetCIMOM(host, port, nameSpace);
131 Array<CIMObjectPath> returnedInstanceNames = _rep->enumerateInstanceNames(nameSpace, className);
132 for (Uint32 i = 0; i < returnedInstanceNames.size(); i++)
133 {
134 returnedInstanceNames[i].setHost(_getHostwithPort(host, port));
135 returnedInstanceNames[i].setNameSpace(nameSpace);
136 }
137 return returnedInstanceNames;
138 }
139
140 Array<CIMInstance> CIMManagedClient::enumerateInstances(
141 const String& host,
142 const String& port,
143 const CIMNamespaceName& nameSpace,
144 const CIMName& className,
145 Boolean deepInheritance,
146 Boolean localOnly,
147 Boolean includeQualifiers,
148 marek 1.1 Boolean includeClassOrigin,
149 const CIMPropertyList& propertyList
150 )
151 {
152 // test if host and namespace are provided
153 hasHostandNameSpace(host, nameSpace);
154 CIMClientRep * _rep;
155 _rep = getTargetCIMOM(host, port, nameSpace);
156
157 Array<CIMInstance> returnedNamedInstances = _rep->enumerateInstances(
158 nameSpace,
159 className,
160 deepInheritance,
161 localOnly,
162 includeQualifiers,
163 includeClassOrigin,
164 propertyList);
165
166 // adding host, port and namespace to every Instance to make sure object path is
167 // full specified
168 for (Uint32 i = 0; i < returnedNamedInstances.size(); i++)
169 marek 1.1 {
170 CIMObjectPath chgObjectPath = CIMObjectPath(returnedNamedInstances[i].getPath());
171
172 chgObjectPath.setHost(_getHostwithPort(host, port));
173 chgObjectPath.setNameSpace(nameSpace);
174
175 returnedNamedInstances[i].setPath(chgObjectPath);
176 }
177 return returnedNamedInstances;
178 }
179
180 Array<CIMObject> CIMManagedClient::execQuery(
181 const String& host,
182 const String& port,
183 const CIMNamespaceName& nameSpace,
184 const String& queryLanguage,
185 const String& query
186 )
187 {
188 // test if host and namespace are provided
189 hasHostandNameSpace(host, nameSpace);
190 marek 1.1 CIMClientRep * _rep;
191 _rep = getTargetCIMOM(host, port, nameSpace);
192 Array<CIMObject> returnedCimObjects = _rep->execQuery(
193 nameSpace,
194 queryLanguage,
195 query);
196 // check if all objects contain a full specified object path
197 for (Uint32 i = 0; i < returnedCimObjects.size(); i++)
198 {
199 CIMObjectPath chgObjectPath = CIMObjectPath(returnedCimObjects[i].getPath());
200 // if there is no cimom and no namespace specified, set the current as default
201 // if there is no namespace, but a cimom specified, add the current namespace
202 // if there is no cimom, but a namespace specified, add the current cimom
203 // if there are both cimom and namespace specified, do nothing
204 // thus, only do something if either cimom or namespace is missing
205
206 // test for empty cimom
207 if (chgObjectPath.getHost() == String::EMPTY)
208 {
209 chgObjectPath.setHost(_getHostwithPort(host, port));
210 }
211 marek 1.1 // test for empty namespace
212 if (chgObjectPath.getNameSpace().isNull())
213 {
214 chgObjectPath.setNameSpace(nameSpace);
215 }
216 returnedCimObjects[i].setPath(chgObjectPath);
217 }
218 return returnedCimObjects;
219 }
220
221
222 Array<CIMClass> CIMManagedClient::enumerateClasses(
223 const String& host,
224 const String& port,
225 const CIMNamespaceName& nameSpace,
226 const CIMName& className,
227 Boolean deepInheritance,
228 Boolean localOnly,
229 Boolean includeQualifiers,
230 Boolean includeClassOrigin
231 )
232 marek 1.1 {
233 // test if host and namespace are provided
234 hasHostandNameSpace(host, nameSpace);
235 CIMClientRep * _rep;
236 _rep = getTargetCIMOM(host, port, nameSpace);
237
238 Array<CIMClass> returnedCimClasses = _rep->enumerateClasses(
239 nameSpace,
240 className,
241 deepInheritance,
242 localOnly,
243 includeQualifiers,
244 includeClassOrigin);
245
246 // adding host, port and namespace to every Instance to make sure object path is
247 // full specified
248 for (Uint32 i = 0; i < returnedCimClasses.size(); i++)
249 {
250 CIMObjectPath chgObjectPath = CIMObjectPath(returnedCimClasses[i].getPath());
251
252 chgObjectPath.setHost(_getHostwithPort(host,port));
253 marek 1.1 chgObjectPath.setNameSpace(nameSpace);
254
255 returnedCimClasses[i].setPath(chgObjectPath);
256 }
257 return returnedCimClasses;
258 }
259
260 Array<CIMName> CIMManagedClient::enumerateClassNames(
261 const String& host,
262 const String& port,
263 const CIMNamespaceName& nameSpace,
264 const CIMName& className,
265 Boolean deepInheritance
266 )
267 {
268 // test if host and namespace are provided
269 hasHostandNameSpace(host, nameSpace);
270 CIMClientRep * _rep;
271 _rep = getTargetCIMOM(host, port, nameSpace);
272 return _rep->enumerateClassNames(
273 nameSpace,
274 marek 1.1 className,
275 deepInheritance);
276 }
277
278 CIMClass CIMManagedClient::getClass(
279 const String& host,
280 const String& port,
281 const CIMNamespaceName& nameSpace,
282 const CIMName& className,
283 Boolean localOnly,
284 Boolean includeQualifiers,
285 Boolean includeClassOrigin,
286 const CIMPropertyList& propertyList
287 )
288 {
289 // test if host and namespace are provided
290 hasHostandNameSpace(host, nameSpace);
291 CIMClientRep * _rep;
292 _rep = getTargetCIMOM(host, port, nameSpace);
293 CIMClass returnedCimClass = _rep->getClass(
294 nameSpace,
295 marek 1.1 className,
296 localOnly,
297 includeQualifiers,
298 includeClassOrigin,
299 propertyList);
300
301 CIMObjectPath chgObjectPath = CIMObjectPath(returnedCimClass.getPath());
302
303 chgObjectPath.setHost(_getHostwithPort(host, port));
304 chgObjectPath.setNameSpace(nameSpace);
305
306 returnedCimClass.setPath(chgObjectPath);
307 return returnedCimClass;
308 }
309
310 void CIMManagedClient::createClass(
311 const String& host,
312 const String& port,
313 const CIMNamespaceName& nameSpace,
314 const CIMClass& newClass
315 )
316 marek 1.1 {
317 // test if host and namespace are provided
318 hasHostandNameSpace(host, nameSpace);
319 CIMClientRep * _rep;
320 _rep = getTargetCIMOM(host, port, nameSpace);
321 _rep->createClass(
322 nameSpace,
323 newClass);
324 }
325
326 void CIMManagedClient::deleteClass(
327 const String& host,
328 const String& port,
329 const CIMNamespaceName& nameSpace,
330 const CIMName& className
331 )
332 {
333 // test if host and namespace are provided
334 hasHostandNameSpace(host, nameSpace);
335 CIMClientRep * _rep;
336 _rep = getTargetCIMOM(host, port, nameSpace);
337 marek 1.1 _rep->deleteClass(
338 nameSpace,
339 className);
340 }
341
342 void CIMManagedClient::deleteQualifier(
343 const String& host,
344 const String& port,
345 const CIMNamespaceName& nameSpace,
346 const CIMName& qualifierName
347 )
348 {
349 // test if host and namespace are provided
350 hasHostandNameSpace(host, nameSpace);
351 CIMClientRep * _rep;
352 _rep = getTargetCIMOM(host, port, nameSpace);
353 _rep->deleteQualifier(
354 nameSpace,
355 qualifierName);
356 }
357
358 marek 1.1 CIMQualifierDecl CIMManagedClient::getQualifier(
359 const String& host,
360 const String& port,
361 const CIMNamespaceName& nameSpace,
362 const CIMName& qualifierName
363 )
364 {
365 // test if host and namespace are provided
366 hasHostandNameSpace(host, nameSpace);
367 CIMClientRep * _rep;
368 _rep = getTargetCIMOM(host, port, nameSpace);
369 return _rep->getQualifier(
370 nameSpace,
371 qualifierName);
372 }
373
374 Array<CIMQualifierDecl> CIMManagedClient::enumerateQualifiers(
375 const String& host,
376 const String& port,
377 const CIMNamespaceName& nameSpace
378 )
379 marek 1.1 {
380 // test if host and namespace are provided
381 hasHostandNameSpace(host, nameSpace);
382 CIMClientRep * _rep;
383 _rep = getTargetCIMOM(host, port, nameSpace);
384 return _rep->enumerateQualifiers(
385 nameSpace);
386 }
387
388
389 void CIMManagedClient::modifyClass(
390 const String& host,
391 const String& port,
392 const CIMNamespaceName& nameSpace,
393 const CIMClass& modifiedClass
394 )
395 {
396 // test if host and namespace are provided
397 hasHostandNameSpace(host, nameSpace);
398 CIMClientRep * _rep;
399 _rep = getTargetCIMOM(host, port, nameSpace);
400 marek 1.1 _rep->modifyClass(
401 nameSpace,
402 modifiedClass);
403 }
404
405 void CIMManagedClient::setQualifier(
406 const String& host,
407 const String& port,
408 const CIMNamespaceName& nameSpace,
409 const CIMQualifierDecl& qualifierDeclaration
410 )
411 {
412 // test if host and namespace are provided
413 hasHostandNameSpace(host, nameSpace);
414 CIMClientRep * _rep;
415 _rep = getTargetCIMOM(host, port, nameSpace);
416 _rep->setQualifier(
417 nameSpace,
418 qualifierDeclaration);
419 }
420
421 marek 1.1 CIMValue CIMManagedClient::getProperty(
422 const CIMObjectPath& instanceName,
423 const CIMName& propertyName
424 )
425 {
426 hasHostandNameSpace(instanceName);
427 CIMClientRep * _rep;
428 _rep = getTargetCIMOM(instanceName);
429 return _rep->getProperty(
430 instanceName.getNameSpace(),
431 instanceName,
432 propertyName);
433 }
434
435 void CIMManagedClient::setProperty(
436 const CIMObjectPath& instanceName,
437 const CIMName& propertyName,
438 const CIMValue& newValue
439 )
440 {
441 hasHostandNameSpace(instanceName);
442 marek 1.1 CIMClientRep * _rep;
443 _rep = getTargetCIMOM(instanceName);
444 _rep->setProperty(
445 instanceName.getNameSpace(),
446 instanceName,
447 propertyName,
448 newValue);
449 }
450
451
452 void CIMManagedClient::deleteInstance(
453 const CIMObjectPath& instanceName
454 )
455 {
456 hasHostandNameSpace(instanceName);
457 CIMClientRep * _rep;
458 _rep = getTargetCIMOM(instanceName);
459 _rep->deleteInstance(
460 instanceName.getNameSpace(),
461 instanceName);
462 }
463 marek 1.1
464 CIMObjectPath CIMManagedClient::createInstance(
465 const CIMInstance& newInstance
466 )
467 {
468 hasHostandNameSpace(newInstance);
469 // save name space for later usage
470 CIMNamespaceName reqNameSpace = CIMNamespaceName(newInstance.getPath().getNameSpace());
471 CIMClientRep * _rep;
472 _rep = getTargetCIMOM(newInstance.getPath());
473 CIMObjectPath returnedObjectPath = _rep->createInstance(
474 reqNameSpace,
475 newInstance);
476 // put host and namespace back into object path, so it is definite fully specified
477 returnedObjectPath.setHost(newInstance.getPath().getHost());
478 returnedObjectPath.setNameSpace(reqNameSpace);
479 return returnedObjectPath;
480 }
481
482 CIMInstance CIMManagedClient::getInstance(
483 const CIMObjectPath& instanceName,
484 marek 1.1 Boolean localOnly,
485 Boolean includeQualifiers,
486 Boolean includeClassOrigin,
487 const CIMPropertyList& propertyList
488 )
489 {
490 hasHostandNameSpace(instanceName);
491 CIMNamespaceName reqNameSpace = CIMNamespaceName(instanceName.getNameSpace());
492 CIMClientRep * _rep;
493 _rep = getTargetCIMOM(instanceName);
494 CIMInstance returnedCimInstance = _rep->getInstance(
495 reqNameSpace,
496 instanceName,
497 localOnly,
498 includeQualifiers,
499 includeClassOrigin,
500 propertyList);
501 /*
502 CIMObjectPath chgObjectPath = CIMObjectPath(returnedCimInstance.getPath());
503
504 chgObjectPath.setHost(instanceName.getHost());
505 marek 1.1 chgObjectPath.setNameSpace(reqNameSpace);
506
507 returnedCimInstance.setPath(chgObjectPath);
508 */
509 // changed to take over the entire CIMObjectPath that was given ...
510 returnedCimInstance.setPath(instanceName);
511
512 return returnedCimInstance;
513 }
514
515 void CIMManagedClient::modifyInstance(
516 const CIMInstance& modifiedInstance,
517 Boolean includeQualifiers,
518 const CIMPropertyList& propertyList
519 )
520 {
521 hasHostandNameSpace(modifiedInstance);
522 CIMClientRep * _rep;
523 _rep = getTargetCIMOM(modifiedInstance.getPath());
524 _rep->modifyInstance(
525 modifiedInstance.getPath().getNameSpace(),
526 marek 1.1 modifiedInstance,
527 includeQualifiers,
528 propertyList);
529 }
530
531
532 CIMValue CIMManagedClient::invokeMethod(
533 const CIMObjectPath& instanceName,
534 const CIMName& methodName,
535 const Array<CIMParamValue>& inParameters,
536 Array<CIMParamValue>& outParameters
537 )
538 {
539 hasHostandNameSpace(instanceName);
540 CIMClientRep * _rep;
541 _rep = getTargetCIMOM(instanceName);
542 return _rep->invokeMethod(
543 instanceName.getNameSpace(),
544 instanceName,
545 methodName,
546 inParameters,
547 marek 1.1 outParameters);
548 }
549
550 Array<CIMObjectPath> CIMManagedClient::associatorNames(
551 const CIMObjectPath& objectName,
552 const CIMName& assocClass,
553 const CIMName& resultClass,
554 const String& role,
555 const String& resultRole
556 )
557 {
558 hasHostandNameSpace(objectName);
559 CIMClientRep * _rep;
560 _rep = getTargetCIMOM(objectName);
561 Array<CIMObjectPath> retAssocNames = _rep->associatorNames(
562 objectName.getNameSpace(),
563 objectName,
564 assocClass,
565 resultClass,
566 role,
567 resultRole);
568 marek 1.1
569 for (Uint32 i = 0; i < retAssocNames.size(); i++)
570 {
571 try
572 {
573 // check if all object paths are fully qualified
574 hasHostandNameSpace(retAssocNames[i]);
575 }
576 catch(TypeMismatchException tme)
577 {
578 // should throw nasty exception about missing namespace ....
579 // TODO: prepare exception for this
580 MessageLoaderParms retTypeMismatchMessage = MessageLoaderParms("Client.CIMClientRep.TYPEMISMATCH_PORTMISMATCH",
581 "Returned CIM object path incomplete specified.");
582 throw TypeMismatchException(retTypeMismatchMessage);
583 }
584 }
585 return retAssocNames;
586 }
587
588 Array<CIMObject> CIMManagedClient::associators(
589 marek 1.1 const CIMObjectPath& objectName,
590 const CIMName& assocClass,
591 const CIMName& resultClass,
592 const String& role,
593 const String& resultRole,
594 Boolean includeQualifiers,
595 Boolean includeClassOrigin,
596 const CIMPropertyList& propertyList
597 )
598 {
599 hasHostandNameSpace(objectName);
600 CIMClientRep * _rep;
601 _rep = getTargetCIMOM(objectName);
602 Array<CIMObject> retAssoc = _rep->associators(
603 objectName.getNameSpace(),
604 objectName,
605 assocClass,
606 resultClass,
607 role,
608 resultRole,
609 includeQualifiers,
610 marek 1.1 includeClassOrigin,
611 propertyList);
612 for (Uint32 i = 0; i < retAssoc.size(); i++)
613 {
614 // check if all object paths are fully qualified
615 try
616 {
617 hasHostandNameSpace(retAssoc[i].getPath());
618 }
619 catch(TypeMismatchException tme)
620 {
621 // should throw nasty exception about missing namespace ....
622 // TODO: prepare exception for this
623 MessageLoaderParms retTypeMismatchMessage = MessageLoaderParms("Client.CIMClientRep.TYPEMISMATCH_PORTMISMATCH",
624 "Returned CIM object path incomplete specified.");
625 throw TypeMismatchException(retTypeMismatchMessage);
626 }
627 }
628 return retAssoc;
629 }
630
631 marek 1.1 Array<CIMObject> CIMManagedClient::references(
632 const CIMObjectPath& objectName,
633 const CIMName& resultClass,
634 const String& role,
635 Boolean includeQualifiers,
636 Boolean includeClassOrigin,
637 const CIMPropertyList& propertyList
638 )
639 {
640 hasHostandNameSpace(objectName);
641 CIMClientRep * _rep;
642 _rep = getTargetCIMOM(objectName);
643 Array<CIMObject> retRefer = _rep->references(
644 objectName.getNameSpace(),
645 objectName,
646 resultClass,
647 role,
648 includeQualifiers,
649 includeClassOrigin,
650 propertyList);
651
652 marek 1.1 for (Uint32 i = 0; i < retRefer.size(); i++)
653 {
654 // check if all object paths are fully qualified
655 try
656 {
657 hasHostandNameSpace(retRefer[i].getPath());
658 }
659 catch(TypeMismatchException tme)
660 {
661 // should throw nasty exception about missing namespace ....
662 // TODO: prepare exception for this
663 MessageLoaderParms retTypeMismatchMessage = MessageLoaderParms("Client.CIMClientRep.TYPEMISMATCH_PORTMISMATCH",
664 "Returned CIM object path incomplete specified.");
665 throw TypeMismatchException(retTypeMismatchMessage);
666 }
667 }
668 return retRefer;
669 }
670
671 Array<CIMObjectPath> CIMManagedClient::referenceNames(
672 const CIMObjectPath& objectName,
673 marek 1.1 const CIMName& resultClass,
674 const String& role
675 )
676 {
677 hasHostandNameSpace(objectName);
678 CIMClientRep * _rep;
679 _rep = getTargetCIMOM(objectName);
680 Array<CIMObjectPath> retReferNames = _rep->referenceNames(
681 objectName.getNameSpace(),
682 objectName,
683 resultClass,
684 role);
685 for (Uint32 i = 0; i < retReferNames.size(); i++)
686 {
687 try
688 {
689 // check if all object paths are fully qualified
690 hasHostandNameSpace(retReferNames[i]);
691 }
692 catch(TypeMismatchException tme)
693 {
694 marek 1.1 // should throw nasty exception about missing namespace ....
695 // TODO: prepare exception for this
696 MessageLoaderParms retTypeMismatchMessage = MessageLoaderParms("Client.CIMClientRep.TYPEMISMATCH_PORTMISMATCH",
697 "Returned CIM object path incomplete specified.");
698 throw TypeMismatchException(retTypeMismatchMessage);
699 }
700 }
701 return retReferNames;
702 }
703
704
705
706 void CIMManagedClient::hasHostandNameSpace(const String& _host, const CIMNamespaceName& _nameSpace) throw(TypeMismatchException)
707 {
708 MessageLoaderParms typeMismatchMessage;
709 if (_host == String::EMPTY)
710 {
711 // should throw nasty exception about missing hostname ....
712 // TODO: prepare exception for this
713 typeMismatchMessage = MessageLoaderParms("Client.CIMClientRep.TYPEMISMATCH_PORTMISMATCH",
714 "Failed validation of CIM object path: no host name specified");
715 marek 1.1 throw TypeMismatchException(typeMismatchMessage);
716 }
717 if (_nameSpace.isNull())
718 {
719 // should throw nasty exception about missing namespace ....
720 // TODO: prepare exception for this
721 typeMismatchMessage = MessageLoaderParms("Client.CIMClientRep.TYPEMISMATCH_PORTMISMATCH",
722 "Failed validation of CIM object path: no namespace specified");
723 throw TypeMismatchException(typeMismatchMessage);
724 }
725 CDEBUG("No exception thrown, seems the host and namespace are there.");
726 }
727
728 void CIMManagedClient::hasHostandNameSpace(const CIMObjectPath& inObjectPath) throw(TypeMismatchException)
729 {
730 CDEBUG("hasHostandNameSpace(inObjectPath.getHost(), inObjectPath.getNameSpace())=" << inObjectPath.getHost() << "," << inObjectPath.getNameSpace());
731 hasHostandNameSpace(inObjectPath.getHost(), inObjectPath.getNameSpace());
732 }
733
734 void CIMManagedClient::hasHostandNameSpace(const CIMInstance& inInstance) throw(TypeMismatchException)
735 {
736 marek 1.1 hasHostandNameSpace(inInstance.getPath());
737 }
738
739 CIMClientRep* CIMManagedClient::getTargetCIMOM(const String& _host,const String& _port, const CIMNamespaceName& _nameSpace) const
740 {
741 CIMClientRep * targetCIMOM;
742 if (strtoul((const char*) _port.getCString(), NULL, 0) == 0)
743 {
744 CDEBUG("no port given explicitly, thus we use the default port:" << _pegasusDefaultPort);
745 // no port given explicitly, thus we use the default port of 5988
746 // lets determine if there is a connection for this object path available
747 targetCIMOM = _cccm->getConnection(_host, _pegasusDefaultPort, _nameSpace);
748 } else {
749 // lets determine if there is a connection for this object path available
750 targetCIMOM = _cccm->getConnection(_host, _port, _nameSpace);
751 }
752 // damn, somehow we missed to construct a CIMClientRep for this connection
753 // shouldn't be possible at all, but one never knows everything
754 if (targetCIMOM == 0)
755 {
756 // throw some crazy exception
757 marek 1.1 // TODO: invent exception
758 MessageLoaderParms typeMismatchMessage = MessageLoaderParms("Client.CIMClientRep.TYPEMISMATCH_PORTMISMATCH",
759 "No valid CIMOM connection configured for: ($0:$1) ",
760 _host, _port);
761 throw TypeMismatchException(typeMismatchMessage);
762 }
763 CDEBUG("targetCIMOM=" << targetCIMOM);
764 return targetCIMOM;
765 }
766
767 CIMClientRep* CIMManagedClient::getTargetCIMOM(const CIMObjectPath& inObjectPath) const
768 {
769 String inHost, inPort;
770 CIMNamespaceName inNameSpace;
771 inNameSpace = inObjectPath.getNameSpace();
772
773 // need to create our own Host String object, as we split it in two pieces
774 // thus change it ...
775 inHost = String(inObjectPath.getHost());
776
777 // test if a host is given at all not necessary here
778 marek 1.1 // if there is no we failed to detect that before anyway
779 // wonder how that should possibly happen???
780
781 // splitting the port from hostname
782 int i = inHost.find(":");
783 // only if there is a ":" we should split a port address from hostname string
784 if (i > 0)
785 {
786 inPort = inHost.subString(i+1);
787 inHost.remove(i);
788 } else
789 {
790 // if there is no : , there is no port, we use the default empty port
791 inPort = String::EMPTY;
792 }
793 return getTargetCIMOM(inHost, inPort, inNameSpace);
794 }
795
796
797 void CIMManagedClient::setPegasusDefaultPort()
798 {
799 marek 1.1 _pegasusDefaultPort = String("5988");
800 }
801
802 String CIMManagedClient::_getHostwithPort(const String& host, const String& port)
803 {
804 String hostwithport=String(host);
805 hostwithport.append(":");
806 hostwithport.append(port);
807 return hostwithport;
808 }
809
810 PEGASUS_NAMESPACE_END
|