1 mike 1.25 //%/////////////////////////////////////////////////////////////////////////////
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.25 //
23 // Author: Mike Brasher (mbrasher@bmc.com)
24 //
25 // Modified By:
26 //
27 //%/////////////////////////////////////////////////////////////////////////////
28
29 #ifndef Pegasus_CIMClass_h
30 #define Pegasus_CIMClass_h
31
32 #include <Pegasus/Common/Config.h>
33 #include <Pegasus/Common/CIMClassRep.h>
34
35 PEGASUS_NAMESPACE_BEGIN
36
37 class CIMConstClass;
38 class CIMObject;
39
40 /** The CIMClass class is used to represent CIM classes in Pegasus. In CIM,
41 a class object may be a class or an associator. A CIM class must contain a
42 name and may contain methods, properties, and qualifiers. It is a template
43 mike 1.25 for creating a CIM instance. A CIM class represents a collection of CIM
44 instances, all of which support a common type (for example, a set of
45 properties, methods, and associations).
46 */
47
48 class PEGASUS_COMMON_LINKAGE CIMClass
49 {
50 public:
51
52 /** Constructor - Creates an uninitiated a new CIM object
53 reprenting a CIM class. The class object created by this
54 constructor can only be used in an operation such as the
55 copy constructor. It cannot be used to create a class by
56 appending names, properties, etc. since it is unitiated.
57
58 Use one of the other constructors to create an initiated new CIM class
59 object.
60 @exception Throws an exception "unitialized handle" if this
61 unitialized handle is used
62 /REF(HPEGASUS_HANDLES)
63 */
64 mike 1.25 CIMClass() : _rep(0)
65 {
66
67 }
68
69 /** Constructor - Creates a class from a previous class
70 */
71 CIMClass(const CIMClass& x)
72 {
73 Inc(_rep = x._rep);
74 }
75
76 /// Operator = Assigns the CIM Class constructor.
77 CIMClass& operator=(const CIMClass& x)
78 {
79 if (x._rep != _rep)
80 {
81 Dec(_rep);
82 Inc(_rep = x._rep);
83 }
84 return *this;
85 mike 1.25 }
86
87 /** Constructor - Creates a Class from inputs of a classname and
88 SuperClassName
89 @param className String representing name of the class being created
90 @param superClassName String representing name of the SuperClass
91 ATTN: Define what makes up legal name.
92 @return Throws IllegalName if className argument illegal CIM identifier.
93 <pre>
94 CIMClass NewCass("MyClass", "YourClass");
95 </pre>
96
97 */
98 CIMClass(
99 const String& className,
100 const String& superClassName = String())
101 {
102 _rep = new CIMClassRep(className, superClassName);
103 }
104
105 /// Destructor
106 mike 1.25 ~CIMClass()
107 {
108 Dec(_rep);
109 }
110
111 /** isAssociation - Identifies whether or not this CIM class
112 is an association. An association is a relationship between two
113 (or more) classes or instances of two classes. The properties of an
114 association class include pointers, or references, to the two (or
115 more) instances. All CIM classes can be included in one or more
116 associations.
117 @return Boolean True if this CIM class belongs to an association;
118 otherwise, false.
119 */
120 Boolean isAssociation() const
121 {
122 _checkRep();
123 return _rep->isAssociation();
124 }
125
126 /// CIMMethod isAbstract
127 mike 1.25 Boolean isAbstract() const
128 {
129 _checkRep();
130 return _rep->isAbstract();
131 }
132
133 /** getClassName Gets the name of the class
134 ATTN: COMMENT. Why not just get name so we have common method for all.
135 @return Returns string with the class name.
136 */
137 const String& getClassName() const
138 {
139 _checkRep();
140 return _rep->getClassName();
141 }
142
143 /** CIMMethod getSuperClassName - Gets the name of the Parent
144 @return String with parent class name.
145 */
146 const String& getSuperClassName() const
147 {
148 mike 1.25 _checkRep();
149 return _rep->getSuperClassName();
150 }
151
152 /** CIMMethod setSuperClassName - Sets the name of the parent class from
153 the input parameter. \REF{CLASSNAME}. ATTN: Define legal classnames
154 @param String defining parent name.
155 @return Throws IllegalName if superClassName argument not legal CIM
156 identifier
157 @exception throws IllegalName if the name is not correct. See
158 \URL[ClassNames]{DefinitionofTerms.html#CLASSNAME}
159 */
160 void setSuperClassName(const String& superClassName)
161 {
162 _checkRep();
163 _rep->setSuperClassName(superClassName);
164 }
165
166 /** addQualifier - Adds the specified qualifier to the class
167 and increments the qualifier count. It is illegal to add the same
168 qualifier more than one time.
169 mike 1.25 @param qualifier CIMQualifier object representing the qualifier to be
170 added
171 @return Returns handle of the class object
172 @exception Throws AlreadyExists.
173 */
174 CIMClass& addQualifier(const CIMQualifier& qualifier)
175 {
176 _checkRep();
177 _rep->addQualifier(qualifier);
178 return *this;
179 }
180
181 /** findQualifier - Searches for a qualifier with the specified `
182 input name if it exists in the class
183 @param name CIMName of the qualifier
184 to be found @return Position of the qualifier in the Class.
185 @return Returns index of the qualifier found or PEG_NOT_FOUND
186 if not found.
187 */
188 Uint32 findQualifier(const String& name)
189 {
190 mike 1.25 _checkRep();
191 return _rep->findQualifier(name);
192 }
193 ///
194 Uint32 findQualifier(const String& name) const
195 {
196 _checkRep();
197 return _rep->findQualifier(name);
198 }
199 /** existsQualifier - Returns true if the qualifier with the
200 specified name exists in the class
201 @param name String name of the qualifier object being tested.
202 @return True if the qualifier exits. Otherwise false is returned.
203 */
204 Boolean existsQualifier(const String& name)
205 {
206 _checkRep();
207 return _rep->existsQualifier(name);
208 }
209 ///
210 Boolean existsQualifier(const String& name) const
211 mike 1.25 {
212 _checkRep();
213 return _rep->existsQualifier(name);
214 }
215
216 /** getQualifier - Gets the CIMQualifier object defined
217 by the input parameter
218 @param pos defines the position of the qualifier in the class from the
219 findQualifier method
220 @return CIMQualifier object representing the qualifier found.
221 ATTN: what is error return here?
222 */
223 CIMQualifier getQualifier(Uint32 pos)
224 {
225 _checkRep();
226 return _rep->getQualifier(pos);
227 }
228
229 /// getQualifier - ATTN:
230 CIMConstQualifier getQualifier(Uint32 pos) const
231 {
232 mike 1.25 _checkRep();
233 return _rep->getQualifier(pos);
234 }
235
236 /** removeQualifier - Removes the qualifier defined by the
237 index parameter.
238 @param Defines the index of the qualifier to be removed.
239 @return There is no return.
240 @exception Throw OutOfBound exception if the index is outside
241 the range of existing qualifier objects for this class
242 */
243 void removeQualifier(Uint32 pos) const
244 {
245 _checkRep();
246 _rep->removeQualifier(pos);
247 }
248
249 /** getQualifierCount - Returns the number of qualifiers
250 in the class.
251 @return ATTN:
252 */
253 mike 1.25 Uint32 getQualifierCount() const
254 {
255 _checkRep();
256 return _rep->getQualifierCount();
257 }
258
259 /** addProperty - Adds the specified property object to the
260 properties in the CIM class
261 */
262 CIMClass& addProperty(const CIMProperty& x)
263 {
264 _checkRep();
265 _rep->addProperty(x);
266 return *this;
267 }
268
269
270
271 /** CIMMethod findProperty - Finds the property object with the
272 name defined by the input parameter in the class.
273 @param String parameter with the property name.
274 mike 1.25 @return position representing the property object found or
275 PEG_NOT_FOUND if the property is not found.
276 */
277 Uint32 findProperty(const String& name)
278 {
279 _checkRep();
280 return _rep->findProperty(name);
281 }
282
283 Uint32 findProperty(const String& name) const
284 {
285 _checkRep();
286 return _rep->findProperty(name);
287 }
288
289 /** existsPropery - Determines if a property object with the
290 name defined by the input parameter exists in the class.
291 @parm String parameter with the property name.
292 @return True if the property object exists.
293 */
294 Boolean existsProperty(const String& name)
295 mike 1.25 {
296 _checkRep();
297 return _rep->existsProperty(name);
298 }
299 Boolean existsProperty(const String& name) const
300 {
301 _checkRep();
302 return _rep->existsProperty(name);
303 }
304
305 /** getProperty - Returns a property representing the property
306 defined by the input parameter
307 @param position for this property
308 ATTN: Should we not use something like handle for position???
309 @return CIMProperty object
310 ATTN: what is error return?
311 */
312 CIMProperty getProperty(Uint32 pos)
313 {
314 _checkRep();
315 return _rep->getProperty(pos);
316 mike 1.25 }
317
318 /**getProperty Gets a property object from the CIMClass
319 @param pos The index of the property object to get.
320 @return Returns handle of the property object requested
321 @exception Throws OutofBounds if the size field is greather than the
322 bunber of properties in the class.
323 */
324 CIMConstProperty getProperty(Uint32 pos) const
325 {
326 _checkRep();
327 return _rep->getProperty(pos);
328 }
329
330 /** removeProperty - Removes the property represented
331 by the position input parameter from the class
332 @param pos Index to the property to be removed from the
333 findPropety method
334 @exception Throws OutofBounds if index is not a property object
335 */
336 void removeProperty(Uint32 pos)
337 mike 1.25 {
338 _checkRep();
339 _rep->removeProperty(pos);
340 }
341
342 /** getPropertyCount - Gets the count of the number of properties
343 defined in the class.
344 @return count of number of proerties in the class
345 */
346 Uint32 getPropertyCount() const
347 {
348 _checkRep();
349 return _rep->getPropertyCount();
350 }
351
352 /** addMethod - Adds the method object defined by the input
353 parameter to the class and increments the count of the number of
354 methods in the class
355 @param method object representing the method to be added
356 @return Returns the CIMClass object to which the method was added.
357 @exception Throws AlreadyExists if the method already exists and throws
358 mike 1.25 UnitializedHandle if the handle is not initialized
359 */
360 CIMClass& addMethod(const CIMMethod& x)
361 {
362 _checkRep();
363 _rep->addMethod(x);
364 return *this;
365 }
366
367 /** findMethod - Locate the method object defined by the
368 name input
369 @param String representing the name of the method to be found
370 @return Position of the method object in the class to be used in
371 subsequent getmethod, etc. operations
372 */
373 Uint32 findMethod(const String& name)
374 {
375 _checkRep();
376 return _rep->findMethod(name);
377 }
378
379 mike 1.25 Uint32 findMethod(const String& name) const
380 {
381 _checkRep();
382 return _rep->findMethod(name);
383 }
384
385 /** existsMethod - Determine if the method object defined by the
386 name input exists
387 @param String representing the name of the method to be found
388 @return True if the method exists
389 */
390 Boolean existsMethod(const String& name)
391 {
392 _checkRep();
393 return _rep->existsMethod(name);
394 }
395
396 Boolean existsMethod(const String& name) const
397 {
398 _checkRep();
399 return _rep->existsMethod(name);
400 mike 1.25 }
401
402
403 /** getMethod - Gets the method object defined by the
404 input parameter.
405 @param pos Index to the CIMMethod object to get
406 @return Returns handle of the CIMMethod requested
407 @exception Throws OutofBounds if the index represented by pos is greater
408 than the number of methods defined in the class object
409 */
410 CIMMethod getMethod(Uint32 pos)
411 {
412 _checkRep();
413 return _rep->getMethod(pos);
414 }
415
416 /** getMethod Gets the method object defined by the input
417 parameter. This is the const version.
418 */
419
420 CIMConstMethod getMethod(Uint32 pos) const
421 mike 1.25 {
422 _checkRep();
423 return _rep->getMethod(pos);
424 }
425
426 /** removeMethod - Removes the method defined by the
427 index parameter.
428 @param Defines the index of the method to be removed.
429 @return There is no return.
430 @exception Throw OutOfBound exception if the index is outside
431 the range of existing method objects for this class
432 */
433 void removeMethod(Uint32 pos) const
434 {
435 _checkRep();
436 _rep->removeMethod(pos);
437 }
438
439 /** CIMMethod getMethodCount - Count of the number of methods in the class
440 @return integer representing the number of methods in the class object.
441 */
442 mike 1.25 Uint32 getMethodCount() const
443 {
444 _checkRep();
445 return _rep->getMethodCount();
446 }
447
448 /** Resolve - Resolve the class: inherit any properties and
449 qualifiers. Make sure the superClass really exists and is consistent
450 with this class. Also set the propagated flag class-origin for each
451 class feature.
452 ATTN: explain why this here
453 */
454 void resolve(
455 DeclContext* declContext,
456 const String& nameSpace)
457 {
458 _checkRep();
459 _rep->resolve(declContext, nameSpace);
460 }
461
462 /// operator - ATTN:
463 mike 1.25 operator int() const { return _rep != 0; }
464
465 /// CIMMethod toXML
466 void toXml(Array<Sint8>& out) const
467 {
468 _checkRep();
469 _rep->toXml(out);
470 }
471
472 /// CIMMethod print
473 void print(PEGASUS_STD(ostream) &o=PEGASUS_STD(cout)) const
474 {
475 _checkRep();
476 _rep->print(o);
477 }
478
479 /** CIMMethod identical - Compares with another class
480 ATTN: Clarify exactly what identical means
481 @param Class object for the class to be compared
482 @return True if the classes are identical
483 */
484 mike 1.25 Boolean identical(const CIMConstClass& x) const;
485
486 /** Makes a deep copy (clone) of the given object. */
487 CIMClass clone() const
488 {
489 return CIMClass(_rep->clone());
490 }
491
492 /** Get names of all keys of this class. */
493 void getKeyNames(Array<String>& keyNames) const
494 {
495 _checkRep();
496 _rep->getKeyNames(keyNames);
497 }
498
499 Boolean hasKeys() const
500 {
501 _checkRep();
502 return _rep->hasKeys();
503 }
504
505 mike 1.25 private:
506
507 CIMClass(CIMClassRep* rep) : _rep(rep)
508 {
509 }
510
511 void _checkRep() const
512 {
513 if (!_rep)
514 ThrowUnitializedHandle();
515 }
516
517 CIMClassRep* _rep;
518 friend class CIMConstClass;
519 friend class CIMObject;
520 };
521
522 #define PEGASUS_ARRAY_T CIMClass
523 # include "ArrayInter.h"
524 #undef PEGASUS_ARRAY_T
525
526 mike 1.25 /** CIMConstClass - ATTN: define this.
527
528 */
529 class PEGASUS_COMMON_LINKAGE CIMConstClass
530 {
531 public:
532
533 CIMConstClass() : _rep(0)
534 {
535
536 }
537
538 CIMConstClass(const CIMConstClass& x)
539 {
540 Inc(_rep = x._rep);
541 }
542
543 CIMConstClass(const CIMClass& x)
544 {
545 Inc(_rep = x._rep);
546 }
547 mike 1.25
548 CIMConstClass& operator=(const CIMConstClass& x)
549 {
550 if (x._rep != _rep)
551 {
552 Dec(_rep);
553 Inc(_rep = x._rep);
554 }
555 return *this;
556 }
557
558 CIMConstClass& operator=(const CIMClass& x)
559 {
560 if (x._rep != _rep)
561 {
562 Dec(_rep);
563 Inc(_rep = x._rep);
564 }
565 return *this;
566 }
567
568 mike 1.25 // Throws IllegalName if className argument not legal CIM identifier.
569
570 CIMConstClass(
571 const String& className,
572 const String& superClassName = String())
573 {
574 _rep = new CIMClassRep(className, superClassName);
575 }
576
577 ~CIMConstClass()
578 {
579 Dec(_rep);
580 }
581
582 Boolean isAssociation() const
583 {
584 _checkRep();
585 return _rep->isAssociation();
586 }
587
588 Boolean isAbstract() const
589 mike 1.25 {
590 _checkRep();
591 return _rep->isAbstract();
592 }
593
594 const String& getClassName() const
595 {
596 _checkRep();
597 return _rep->getClassName();
598 }
599
600 const String& getSuperClassName() const
601 {
602 _checkRep();
603 return _rep->getSuperClassName();
604 }
605
606 Uint32 findQualifier(const String& name) const
607 {
608 _checkRep();
609 return _rep->findQualifier(name);
610 mike 1.25 }
611
612 CIMConstQualifier getQualifier(Uint32 pos) const
613 {
614 _checkRep();
615 return _rep->getQualifier(pos);
616 }
617
618 Uint32 getQualifierCount() const
619 {
620 _checkRep();
621 return _rep->getQualifierCount();
622 }
623
624 Uint32 findProperty(const String& name) const
625 {
626 _checkRep();
627 return _rep->findProperty(name);
628 }
629
630 CIMConstProperty getProperty(Uint32 pos) const
631 mike 1.25 {
632 _checkRep();
633 return _rep->getProperty(pos);
634 }
635
636 Uint32 getPropertyCount() const
637 {
638 _checkRep();
639 return _rep->getPropertyCount();
640 }
641
642 Uint32 findMethod(const String& name) const
643 {
644 _checkRep();
645 return _rep->findMethod(name);
646 }
647
648 CIMConstMethod getMethod(Uint32 pos) const
649 {
650 _checkRep();
651 return _rep->getMethod(pos);
652 mike 1.25 }
653
654 Uint32 getMethodCount() const
655 {
656 _checkRep();
657 return _rep->getMethodCount();
658 }
659
660 operator int() const { return _rep != 0; }
661
662 void toXml(Array<Sint8>& out) const
663 {
664 _checkRep();
665 _rep->toXml(out);
666 }
667
668 void print(PEGASUS_STD(ostream) &o=PEGASUS_STD(cout)) const
669 {
670 _checkRep();
671 _rep->print(o);
672 }
673 mike 1.25
674 Boolean identical(const CIMConstClass& x) const
675 {
676 x._checkRep();
677 _checkRep();
678 return _rep->identical(x._rep);
679 }
680
681 CIMClass clone() const
682 {
683 return CIMClass(_rep->clone());
684 }
685
686 void getKeyNames(Array<String>& keyNames) const
687 {
688 _checkRep();
689 _rep->getKeyNames(keyNames);
690 }
691
692 Boolean hasKeys() const
693 {
694 mike 1.25 _checkRep();
695 return _rep->hasKeys();
696 }
697
698 private:
699
700 void _checkRep() const
701 {
702 if (!_rep)
703 ThrowUnitializedHandle();
704 }
705
706 CIMClassRep* _rep;
707
708 friend class CIMClassRep;
709 friend class CIMClass;
710 friend class CIMInstanceRep;
711 };
712
713 PEGASUS_NAMESPACE_END
714
715 mike 1.25 #endif /* Pegasus_CIMClass_h */
|