1 mike 1.23 //%/////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to
7 // deal in the Software without restriction, including without limitation the
8 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 // sell copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
13 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
14 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
18 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 //
21 //==============================================================================
22 mike 1.23 //
23 // Author: Mike Brasher (mbrasher@bmc.com)
24 //
25 // Modified By:
26 //
27 //%/////////////////////////////////////////////////////////////////////////////
28
29 /*
30
31 CIMInstance.h File defines the Class used to create, instantiate, and modify
32 CIM Instances
33
34 */
35 #ifndef Pegasus_InstanceDecl_h
36 #define Pegasus_InstanceDecl_h
37
38 #include <Pegasus/Common/Config.h>
39 #include <Pegasus/Common/CIMInstanceRep.h>
40
41 PEGASUS_NAMESPACE_BEGIN
42
43 mike 1.23 ////////////////////////////////////////////////////////////////////////////////
44 //
45 // CIMInstance
46 //
47 ////////////////////////////////////////////////////////////////////////////////
48
49 class CIMConstInstance;
50 class CIMObject;
51
52 /** Class CIMInstance - The CIMInstance class represents the instance of
53 a CIM class in Pegasus. It is used manipulate instances and the
54 characteristics of instances
55 */
56 class PEGASUS_COMMON_LINKAGE CIMInstance
57 {
58 public:
59
60 /** Constructor - Create a CIM Instance object.
61 @return Instance created
62 */
63 CIMInstance() : _rep(0)
64 mike 1.23 {
65
66 }
67
68 /** Constructor - Create a CIMInstance object from another Instance.
69 @param Instance object from which the new instance is created.
70 @return New instance
71 */
72 CIMInstance(const CIMInstance& x)
73 {
74 Inc(_rep = x._rep);
75 }
76
77 /** Constructor. */
78 CIMInstance& operator=(const CIMInstance& x)
79 {
80 if (x._rep != _rep)
81 {
82 Dec(_rep);
83 Inc(_rep = x._rep);
84 }
85 mike 1.23 return *this;
86 }
87
88 /** Constructor - Creates an Instance object with the classname
89 from the input parameters
90 @param - String className to be used with new instance object
91 @return The new instance object
92 @exception Throws IllegalName if className argument not legal CIM
93 identifier. ATTN: Clarify the defintion of legal CIM identifier.
94 */
95 CIMInstance(const String& className)
96 {
97 _rep = new CIMInstanceRep(className);
98 }
99
100 /** Destructor. */
101 ~CIMInstance()
102 {
103 Dec(_rep);
104 }
105
106 mike 1.23 /** getClassName - Returns the class name of the instance
107 @return String with the class name.
108 */
109 const String& getClassName() const
110 {
111 _checkRep();
112 return _rep->getClassName();
113 }
114
115 /** addQualifier - Adds the CIMQualifier object to the instance.
116 Thows an exception of the CIMQualifier already exists in the instance
117 @param CIMQualifier object to add to instance
118 @return ATTN:
119 @exception Throws AlreadyExists.
120 */
121 CIMInstance& addQualifier(const CIMQualifier& qualifier)
122 {
123 _checkRep();
124 _rep->addQualifier(qualifier);
125 return *this;
126 }
127 mike 1.23
128 /** findQualifier - Searches the instance for the qualifier object
129 defined by the input parameter.
130 @param String defining the qualifier object to be found.
131 @return - Position of the qualifier to be used in subsequent
132 operations or PEG_NOT_FOUND if the qualifier is not found.
133 */
134 Uint32 findQualifier(const String& name)
135 {
136 _checkRep();
137 return _rep->findQualifier(name);
138 }
139
140 Uint32 findQualifier(const String& name) const
141 {
142 _checkRep();
143 return _rep->findQualifier(name);
144 }
|
255 mike 1.23 Boolean existsProperty(const String& name) const
256 {
257 _checkRep();
258 return _rep->existsProperty(name);
259 }
260
261 /** getProperty - Gets the CIMproperty object in the CIMInstance defined
262 by the input index parameter.
263 @param Index to the property object in the CIMInstance.
264 The index to qualifier objects is zero-origin and continuous
265 so that incrementing loops can be used to get all qualifier
266 objects in a CIMInstnace.
267 @return CIMProperty object corresponding to the index.
268 @exception Throws the OutOfBounds exception if the index
269 is out of bounds
270
271 ATTN: What is the effect of out of range?
272 */
273 CIMProperty getProperty(Uint32 pos)
274 {
275 _checkRep();
276 mike 1.23 return _rep->getProperty(pos);
277 }
278
279 /** getProperty - Gets the CIMproperty object in the CIMInstance defined
280 by the input index parameter.
281 @param Index to the property object in the CIMInstance.
282 The index to qualifier objects is zero-origin and continuous
283 so that incrementing loops can be used to get all qualifier
284 objects in a CIMInstnace.
285 @return CIMProperty object corresponding to the index.
286 @exception Throws the OutOfBounds exception if the index
287 is out of bounds
288
289 ATTN: What is the effect of out of range?
290 */
291 CIMConstProperty getProperty(Uint32 pos) const
292 {
293 _checkRep();
294 return _rep->getProperty(pos);
295 }
296
297 mike 1.23 /** removeProperty - Removes the property represented
298 by the position input parameter from the instance.
299 @param pos Index to the property to be removed from the
300 instance. Normally this is obtained by getProperty();
301 @exception Throws OutofBounds if index is not a property object
302 */
303 void removeProperty(Uint32 pos)
304 {
305 _checkRep();
306 _rep->removeProperty(pos);
307 }
308
309 /** getPropertyCount - Gets the numbercount of CIMProperty
310 objects defined for this CIMInstance.
311 @return Count of the number of CIMProperty objects in the
312 CIMInstance. Zero indicates that no CIMProperty objects
313 are contained in the CIMInstance
314 @exception Throws the OutOfBounds exception if the index
315 is out of bounds
316
317 */
318 mike 1.23 Uint32 getPropertyCount() const
319 {
320 _checkRep();
321 return _rep->getPropertyCount();
322 }
323
324 /** operator int() - ATTN: */
325 operator int() const { return _rep != 0; }
326
327 /** resolve - ATTN: */
328 void resolve(DeclContext* declContext, const String& nameSpace);
329
330 void resolve(
331 DeclContext* declContext,
332 const String& nameSpace,
333 CIMConstClass& cimClassOut)
334 {
335 _checkRep();
336 _rep->resolve(declContext, nameSpace, cimClassOut);
337 }
338
339 mike 1.23 /** toXml - Creates an XML transformation of the CIMInstance
340 compatiblewith the DMTF CIM Operations over HTTP defintions.
341 @return
342 ATTN: This is incorrect and needs to be corrected.
343 */
344 void toXml(Array<Sint8>& out) const
345 {
346 _checkRep();
347 _rep->toXml(out);
348 }
349
350 /** prints the class in XML format. */
351 void print(PEGASUS_STD(ostream) &o=PEGASUS_STD(cout)) const
352 {
353 _checkRep();
354 _rep->print(o);
355 }
356
357 /** identical - Compares the CIMInstance with another CIMInstance
358 defined by the input parameter for equality of all components.
359 @param CIMInstance to be compared
360 mike 1.23 @return Boolean true if they are identical
361 */
362 Boolean identical(const CIMConstInstance& x) const;
363
364 /** CIMMethod
365
366 */
367 CIMInstance clone() const
368 {
369 return CIMInstance(_rep->clone());
370 }
371
372 /** getInstnaceName - Get the instance name of this instance. The class
373 argument is used to determine which fields are keys. The instance
374 name has this from:
375
376 <PRE>
377 ClassName.key1=value1,...,keyN=valueN
378 </PRE>
379
380 The instance name is in standard form (the class name and key name
381 mike 1.23 is all lowercase; the keys-value pairs appear in sorted order by
382 key name).
383 */
384 CIMReference getInstanceName(const CIMConstClass& cimClass) const
385 {
386 _checkRep();
387 return _rep->getInstanceName(cimClass);
388 }
389
390 private:
391
392 CIMInstance(CIMInstanceRep* rep) : _rep(rep)
393 {
394 }
395
396 void _checkRep() const
397 {
398 if (!_rep)
399 ThrowUnitializedHandle();
400 }
401
402 mike 1.23 CIMInstanceRep* _rep;
403 friend class CIMConstInstance;
404 friend class CIMObject;
405 };
406
407 ////////////////////////////////////////////////////////////////////////////////
408 //
409 // CIMConstInstance
410 //
411 ////////////////////////////////////////////////////////////////////////////////
412
413 class PEGASUS_COMMON_LINKAGE CIMConstInstance
414 {
415 public:
416
417 CIMConstInstance() : _rep(0)
418 {
419
420 }
421
422 CIMConstInstance(const CIMConstInstance& x)
423 mike 1.23 {
424 Inc(_rep = x._rep);
425 }
426
427 CIMConstInstance(const CIMInstance& x)
428 {
429 Inc(_rep = x._rep);
430 }
431
432 CIMConstInstance& operator=(const CIMConstInstance& x)
433 {
434 if (x._rep != _rep)
435 {
436 Dec(_rep);
437 Inc(_rep = x._rep);
438 }
439 return *this;
440 }
441
442 CIMConstInstance& operator=(const CIMInstance& x)
443 {
444 mike 1.23 if (x._rep != _rep)
445 {
446 Dec(_rep);
447 Inc(_rep = x._rep);
448 }
449 return *this;
450 }
451
452 // Throws IllegalName if className argument not legal CIM identifier.
453
454 CIMConstInstance(const String& className)
455 {
456 _rep = new CIMInstanceRep(className);
457 }
458
459 ~CIMConstInstance()
460 {
461 Dec(_rep);
462 }
463
464 const String& getClassName() const
465 mike 1.23 {
466 _checkRep();
467 return _rep->getClassName();
468 }
469
470 Uint32 findQualifier(const String& name) const
471 {
472 _checkRep();
473 return _rep->findQualifier(name);
474 }
475
476 CIMConstQualifier getQualifier(Uint32 pos) const
477 {
478 _checkRep();
479 return _rep->getQualifier(pos);
480 }
481
482 Uint32 getQualifierCount() const
483 {
484 _checkRep();
485 return _rep->getQualifierCount();
486 mike 1.23 }
487
488 Uint32 findProperty(const String& name) const
489 {
490 _checkRep();
491 return _rep->findProperty(name);
492 }
493
494 CIMConstProperty getProperty(Uint32 pos) const
495 {
496 _checkRep();
497 return _rep->getProperty(pos);
498 }
499
500 Uint32 getPropertyCount() const
501 {
502 _checkRep();
503 return _rep->getPropertyCount();
504 }
505
506 operator int() const { return _rep != 0; }
507 mike 1.23
508 void toXml(Array<Sint8>& out) const
509 {
510 _checkRep();
511 _rep->toXml(out);
512 }
513
514 void print(PEGASUS_STD(ostream) &o=PEGASUS_STD(cout)) const
515 {
516 _checkRep();
517 _rep->print(o);
518 }
519
520 Boolean identical(const CIMConstInstance& x) const
521 {
522 x._checkRep();
523 _checkRep();
524 return _rep->identical(x._rep);
525 }
526
527 CIMInstance clone() const
528 mike 1.23 {
529 return CIMInstance(_rep->clone());
530 }
531
532 CIMReference getInstanceName(const CIMConstClass& cimClass) const
533 {
534 _checkRep();
535 return _rep->getInstanceName(cimClass);
536 }
537
538 private:
539
540 void _checkRep() const
541 {
542 if (!_rep)
543 ThrowUnitializedHandle();
544 }
545
546 CIMInstanceRep* _rep;
547 friend class CIMInstance;
548 };
549 mike 1.23
550 #define PEGASUS_ARRAY_T CIMInstance
551 # include "ArrayInter.h"
552 #undef PEGASUS_ARRAY_T
553
554 PEGASUS_NAMESPACE_END
555
556 #endif /* Pegasus_InstanceDecl_h */
557
|