1 karl 1.72 //%2006////////////////////////////////////////////////////////////////////////
|
2 mike 1.18 //
|
3 karl 1.64 // 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 karl 1.58 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.64 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.67 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.72 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 mike 1.18 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
15 chip 1.21 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
18 mike 1.18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
|
20 r.kieninger 1.74 //
|
21 chip 1.21 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
22 mike 1.18 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
24 chip 1.21 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
27 mike 1.18 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 //%/////////////////////////////////////////////////////////////////////////////
33
|
34 kumpf 1.34 #include "CIMClassRep.h"
|
35 mike 1.18 #include "DeclContext.h"
|
36 kumpf 1.47 #include "Resolver.h"
|
37 mike 1.18 #include "CIMName.h"
38 #include "CIMQualifierNames.h"
|
39 kumpf 1.37 #include "CIMScope.h"
|
40 karl 1.30 #include <Pegasus/Common/Tracer.h>
|
41 kumpf 1.76 #include <Pegasus/Common/MessageLoader.h>
|
42 r.kieninger 1.71 #include "CIMNameUnchecked.h"
|
43 mike 1.70 #include "StrLit.h"
|
44 r.kieninger 1.74 #include "CIMInstanceRep.h"
|
45 marek 1.79 #include "CIMPropertyInternal.h"
46 #include "CIMMethodRep.h"
|
47 mike 1.18
48 PEGASUS_NAMESPACE_BEGIN
|
49 karl 1.29 PEGASUS_USING_STD;
|
50 mike 1.18
51 CIMClassRep::CIMClassRep(
|
52 kumpf 1.49 const CIMName& className,
53 const CIMName& superClassName)
|
54 mike 1.20 :
|
55 kumpf 1.49 CIMObjectRep(CIMObjectPath(String(), CIMNamespaceName(), className)),
|
56 mike 1.20 _superClassName(superClassName)
|
57 mike 1.18 {
58 }
59
60 CIMClassRep::~CIMClassRep()
61 {
62 }
63
64 Boolean CIMClassRep::isAssociation() const
65 {
|
66 kumpf 1.55 Uint32 index = findQualifier(CIMQualifierNames::ASSOCIATION);
|
67 mike 1.18
|
68 kumpf 1.55 if (index == PEG_NOT_FOUND)
|
69 kumpf 1.75 return false;
|
70 mike 1.18
71 Boolean flag;
72
|
73 kumpf 1.55 const CIMValue& value = getQualifier(index).getValue();
|
74 mike 1.18
|
75 kumpf 1.48 if (value.getType() != CIMTYPE_BOOLEAN)
|
76 kumpf 1.75 return false;
|
77 mike 1.18
78 value.get(flag);
79 return flag;
80 }
81
82 Boolean CIMClassRep::isAbstract() const
83 {
|
84 kumpf 1.55 Uint32 index = findQualifier(CIMQualifierNames::ABSTRACT);
|
85 mike 1.18
|
86 kumpf 1.55 if (index == PEG_NOT_FOUND)
|
87 kumpf 1.75 return false;
|
88 mike 1.18
89 Boolean flag;
|
90 kumpf 1.55 const CIMValue& value = getQualifier(index).getValue();
|
91 mike 1.18
|
92 kumpf 1.48 if (value.getType() != CIMTYPE_BOOLEAN)
|
93 kumpf 1.75 return false;
|
94 mike 1.18
95 value.get(flag);
96 return flag;
97 }
98
99 void CIMClassRep::addProperty(const CIMProperty& x)
100 {
|
101 kumpf 1.50 if (x.isUninitialized())
|
102 kumpf 1.75 throw UninitializedObjectException();
|
103 mike 1.18
104 // Reject addition of duplicate property name:
105
|
106 kumpf 1.75 if (findProperty(x.getName()) != PEG_NOT_FOUND)
107 {
108 MessageLoaderParms parms(
109 "Common.CIMClassRep.PROPERTY",
110 "property \"$0\"",
111 x.getName().getString());
|
112 humberto 1.57 throw AlreadyExistsException(parms);
113 }
|
114 mike 1.18
|
115 kumpf 1.59 // Reject addition of a reference property without a referenceClassName
116
117 if ((x.getType() == CIMTYPE_REFERENCE) &&
118 (x.getReferenceClassName().isNull()))
119 {
120 throw TypeMismatchException();
121 }
122
|
123 mike 1.18 // Add the property:
124
125 _properties.append(x);
126 }
127
128 void CIMClassRep::addMethod(const CIMMethod& x)
129 {
|
130 kumpf 1.50 if (x.isUninitialized())
|
131 kumpf 1.75 throw UninitializedObjectException();
|
132 mike 1.18
133 // Reject duplicate method names:
134
|
135 kumpf 1.75 if (findMethod(x.getName()) != PEG_NOT_FOUND)
136 {
137 MessageLoaderParms parms(
138 "Common.CIMClassRep.METHOD",
139 "method \"$0\"",
140 x.getName().getString());
|
141 humberto 1.57 throw AlreadyExistsException(parms);
142 }
|
143 mike 1.18
144 // Add the method:
145
146 _methods.append(x);
147 }
148
149 void CIMClassRep::resolve(
150 DeclContext* context,
|
151 kumpf 1.49 const CIMNamespaceName& nameSpace)
|
152 mike 1.18 {
|
153 kumpf 1.75 PEG_METHOD_ENTER(TRC_OBJECTRESOLUTION, "CIMClassRep::resolve()");
|
154 kumpf 1.85
|
155 mike 1.18 if (!context)
|
156 kumpf 1.75 throw NullPointer();
|
157 mike 1.18
|
158 marek 1.86 PEG_TRACE_STRING(TRC_OBJECTRESOLUTION, Tracer::LEVEL4,
|
159 kumpf 1.75 String("CIMClassRep::resolve class = ") +
160 _reference.getClassName().getString() + ", superclass = " +
161 _superClassName.getString());
|
162 karl 1.30
|
163 kumpf 1.49 if (!_superClassName.isNull())
|
164 kumpf 1.75 {
165 //----------------------------------------------------------------------
166 // First check to see if the super-class really exists and the
167 // subclassing legal:
168 //----------------------------------------------------------------------
169 CIMConstClass superClass =
170 context->lookupClass(nameSpace, _superClassName);
171
172 if (superClass.isUninitialized())
173 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_SUPERCLASS,
174 _superClassName.getString());
|
175 r.kieninger 1.74
|
176 kumpf 1.75 // If subclass is abstract but superclass not, throw CIM Exception
|
177 r.kieninger 1.74
|
178 kumpf 1.75 /* ATTN:KS-24 Mar 2002 P1 - Test this and confirm that rule is correct
179 if isAbstract() && !superclass.isAbstract()
180 throw PEGASUS_CIM_EXCEPTION(
181 CIM_ERR_INVALID_SUPERCLASS, _superClassName);
182 */
|
183 kumpf 1.76 /*if (superclass.isTrueQualifier(CIMQualifierNames::TERMINAL)
|
184 kumpf 1.75 throw PEGASUS_CIM_EXCEPTION(
185 CIM_ERR_INVALID_SUPERCLASS, _superClassName);
186 */
187 //----------------------------------------------------------------------
188 // Iterate all the properties of *this* class. Resolve each one and
189 // set the class-origin:
190 //----------------------------------------------------------------------
|
191 r.kieninger 1.74
|
192 kumpf 1.75 Boolean isAssociationClass = isAssociation();
|
193 a.dunfey 1.63
|
194 kumpf 1.75 for (Uint32 i = 0, n = _properties.size(); i < n; i++)
195 {
196 CIMProperty& property = _properties[i];
197
198 if (!isAssociationClass &&
199 property.getValue().getType() == CIMTYPE_REFERENCE)
200 {
201 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_INVALID_PARAMETER,
202 MessageLoaderParms(
203 "Common.CIMClassRep.NON_ASSOCIATION_CLASS_CONTAINS_"
204 "REFERENCE_PROPERTY",
205 "Non-assocation class contains reference property"));
206 }
207
208
209 Uint32 index = superClass.findProperty(property.getName());
210
211 if (index == PEG_NOT_FOUND)
212 {
213 Resolver::resolveProperty(
214 property, context, nameSpace, false, true);
215 kumpf 1.75 if (property.getClassOrigin().isNull())
216 {
217 property.setClassOrigin(getClassName());
218 }
219 property.setPropagated(false);
220 }
221 else
222 {
223 CIMConstProperty superClassProperty =
224 superClass.getProperty(index);
225 Resolver::resolveProperty(property, context,
226 nameSpace, false, superClassProperty, true);
227 if (property.getClassOrigin().isNull())
228 {
229 property.setClassOrigin(
230 superClassProperty.getClassOrigin());
231 }
|
232 a.dunfey 1.62 }
|
233 kumpf 1.75 }
|
234 r.kieninger 1.74
|
235 kumpf 1.75 //----------------------------------------------------------------------
236 // Now prepend all properties inherited from the super-class (that
237 // are not overriden by this sub-class).
238 //----------------------------------------------------------------------
|
239 kumpf 1.54
|
240 kumpf 1.75 // Iterate super-class properties:
|
241 karl 1.29
|
242 kumpf 1.75 for (Uint32 i = 0, m = 0, n = superClass.getPropertyCount(); i < n; i++)
243 {
244 CIMConstProperty superClassProperty = superClass.getProperty(i);
245
246 // Find the property in *this* class; if not found, then clone and
247 // insert it (setting the propagated flag). Otherwise, change
248 // the class-origin and propagated flag accordingly.
249
250 Uint32 index = PEG_NOT_FOUND;
251 /* ATTN: KS move to simpler version of the find
252 for (Uint32 j = m, n = _properties.size(); j < n; j++)
253 {
254 if (_properties[j].getName() == superClassProperty.getName())
|
255 kumpf 1.66 {
|
256 kumpf 1.75 index = j;
257 break;
|
258 kumpf 1.66 }
|
259 kumpf 1.75 }
260 */
261 index = findProperty(superClassProperty.getName());
262
263 // If property exists in super class but not in this one, then
264 // clone and insert it. Otherwise, the properties class
265 // origin was set above.
266
267 CIMProperty superproperty = superClassProperty.clone();
|
268 r.kieninger 1.74
|
269 kumpf 1.75 if (index == PEG_NOT_FOUND)
270 {
271 superproperty.setPropagated(true);
272 _properties.insert(m++, superproperty);
273 }
274 else
275 {
276 // Property Qualifiers must propagate if allowed
277 // If property exists in the superclass and in the subclass,
278 // then, enumerate the qualifiers of the superclass's property.
279 // If a qualifier is defined on the superclass's property
280 // but not on the subclass's, then add it to the subclass's
281 // property's qualifier list.
282 CIMProperty subproperty = _properties[index];
283 for (Uint32 i = 0, n = superproperty.getQualifierCount();
284 i < n; i++)
285 {
286 Uint32 index = PEG_NOT_FOUND;
287 CIMQualifier superClassQualifier =
288 superproperty.getQualifier(i);
289 const CIMName name = superClassQualifier.getName();
290 kumpf 1.75 /* ATTN KS This is replacement find function.
291 if (Uint32 j = subproperty.findQualifier(q.getName()) ==
292 PEG_NOT_FOUND)
293 {
294 subproperty.addQualifier(superClassQualifier);
295 }
296 */
297 for (Uint32 j = 0, m = subproperty.getQualifierCount();
298 j < m;
299 j++)
300 {
301 CIMConstQualifier q = subproperty.getQualifier(j);
302 if (name.equal(q.getName()))
303 {
304 index = j;
305 break;
306 }
307 } // end comparison of subclass property's qualifiers
308 if (index == PEG_NOT_FOUND)
309 {
310 subproperty.addQualifier(superClassQualifier);
311 kumpf 1.75 }
312 /*
313 if ((index = subproperty.findQualifier(name)) ==
314 PEG_NOT_FOUND)
315 {
316 subproperty.addQualifier(superClassQualifier);
317 }
318 */
319 } // end iteration over superclass property's qualifiers
320 }
321 }
322
323 //----------------------------------------------------------------------
324 // Iterate all the methods of *this* class. Resolve each one and
325 // set the class-origin:
326 //----------------------------------------------------------------------
327
328 for (Uint32 i = 0, n = _methods.size(); i < n; i++)
329 {
330 CIMMethod& method = _methods[i];
331 Uint32 index = superClass.findMethod(method.getName());
332 kumpf 1.75
333 if (index == PEG_NOT_FOUND)
334 {
335 Resolver::resolveMethod(method, context, nameSpace);
|
336 r.kieninger 1.80 if (method.getClassOrigin().isNull())
337 {
338 method.setClassOrigin(getClassName());
339 }
340 method.setPropagated(false);
|
341 kumpf 1.75 }
342 else
343 {
344 CIMConstMethod superClassMethod = superClass.getMethod(index);
345 Resolver::resolveMethod(
346 method, context, nameSpace, superClassMethod);
347 }
348 }
349
350 //----------------------------------------------------------------------
351 // Now prepend all methods inherited from the super-class (that
352 // are not overriden by this sub-class).
353 //----------------------------------------------------------------------
354
355 for (Uint32 i = 0, m = 0, n = superClass.getMethodCount(); i < n; i++)
356 {
357 CIMConstMethod superClassMethod = superClass.getMethod(i);
358
359 // Find the method in *this* class; if not found, then clone and
360 // insert it (setting the propagated flag). Otherwise, change
361 // the class-origin and propagated flag accordingly.
362 kumpf 1.75
363 Uint32 index = PEG_NOT_FOUND;
364 /********************** KS move to simpler version
365 for (Uint32 j = m, n = _methods.size(); j < n; j++)
366 {
367 if (_methods[j].getName() == superClassMethod.getName())
368 {
369 index = j;
370 break;
371 }
372 }
373
374 // If method exists in super class but not in this one, then
375 // clone and insert it. Otherwise, the method's class origin
376 // has already been set above.
377
378 if (index == PEG_NOT_FOUND)
379 {
380 CIMMethod method = superClassMethod.clone();
381 method.setPropagated(true);
382 _methods.insert(m++, method);
383 kumpf 1.75 }
384 */
385 if ((index = findMethod(superClassMethod.getName())) ==
386 PEG_NOT_FOUND)
387 {
388 CIMMethod method = superClassMethod.clone();
389 method.setPropagated(true);
390 _methods.insert(m++, method);
391 }
|
392 r.kieninger 1.80
|
393 kumpf 1.75 }
394
395 //----------------------------------------------------------------------
396 // Validate the qualifiers of this class:
397 //----------------------------------------------------------------------
398 _qualifiers.resolve(
399 context,
400 nameSpace,
401 isAssociation() ? CIMScope::ASSOCIATION : CIMScope::CLASS,
402 false,
403 superClass._rep->_qualifiers,
404 true);
405 }
406 else // No SuperClass exsts
407 {
408 //----------------------------------------------------------------------
409 // Resolve each property:
410 //----------------------------------------------------------------------
411
412 for (Uint32 i = 0, n = _properties.size(); i < n; i++)
413 {
414 kumpf 1.75 Resolver::resolveProperty(
415 _properties[i], context, nameSpace, false, true);
416 _properties[i].setClassOrigin(getClassName());
417 _properties[i].setPropagated(false);
418 }
419
420 //----------------------------------------------------------------------
421 // Resolve each method:
422 //----------------------------------------------------------------------
423
424 for (Uint32 i = 0, n = _methods.size(); i < n; i++)
425 {
426 Resolver::resolveMethod (_methods[i], context, nameSpace);
|
427 r.kieninger 1.80 _methods[i].setClassOrigin(getClassName());
428 _methods[i].setPropagated(false);
|
429 kumpf 1.75 }
430
431 //----------------------------------------------------------------------
432 // Resolve the qualifiers:
433 //----------------------------------------------------------------------
434
435 CIMQualifierList dummy;
436
437 _qualifiers.resolve(
438 context,
439 nameSpace,
440 isAssociation() ? CIMScope::ASSOCIATION : CIMScope::CLASS,
441 false,
442 dummy,
443 true);
|
444 mike 1.18 }
445 }
446
|
447 karl 1.61 CIMInstance CIMClassRep::buildInstance(Boolean includeQualifiers,
|
448 karl 1.60 Boolean includeClassOrigin,
449 const CIMPropertyList& propertyList) const
450 {
451
|
452 r.kieninger 1.74 // Create the new instance representation
453 CIMInstanceRep* newInstanceRep = new CIMInstanceRep(
454 CIMObjectPath(String::EMPTY,
455 CIMNamespaceName(),
456 _reference.getClassName()));
|
457 karl 1.60
458 // Copy qualifiers if required
459 if (includeQualifiers)
460 {
461 for (Uint32 i = 0 ; i < getQualifierCount() ; i++)
462 {
|
463 r.kieninger 1.74 newInstanceRep->_qualifiers.add(getQualifier(i).clone());
|
464 karl 1.60 }
465 }
466
|
467 r.kieninger 1.74 newInstanceRep->_properties.reserveCapacity(_properties.size());
468
|
469 karl 1.60 // Copy Properties
470 for (Uint32 i = 0 ; i < _properties.size() ; i++)
471 {
|
472 r.kieninger 1.74 CIMConstProperty cp = getProperty(i);
473 CIMName name = cp.getName();
|
474 karl 1.60 Array<CIMName> pl = propertyList.getPropertyNameArray();
475 if (propertyList.isNull() || Contains(pl, name))
476 {
|
477 r.kieninger 1.74 CIMProperty p;
478
479 if (includeQualifiers)
|
480 karl 1.60 {
|
481 r.kieninger 1.74 p = getProperty(i).clone();
482 }
483 else
484 {
485 p = CIMProperty(cp.getName(),
486 cp.getValue(),
487 cp.getArraySize(),
488 cp.getReferenceClassName(),
489 cp.getClassOrigin());
|
490 karl 1.60 }
|
491 r.kieninger 1.74
492 // Delete class origin attribute if required
|
493 karl 1.60 if (!includeClassOrigin)
494 {
495 p.setClassOrigin(CIMName());
496 }
497
|
498 r.kieninger 1.74 newInstanceRep->_properties.append(p);
|
499 karl 1.60 }
500 }
501
|
502 r.kieninger 1.74 // Create new CIMInstance from CIMInstanceRep
503 CIMInstance newInstance(newInstanceRep);
504
|
505 kumpf 1.76 return newInstance;
|
506 karl 1.60 }
507
|
508 mike 1.18 CIMClassRep::CIMClassRep(const CIMClassRep& x) :
|
509 mike 1.20 CIMObjectRep(x),
510 _superClassName(x._superClassName)
|
511 mike 1.18 {
|
512 kumpf 1.45 _methods.reserveCapacity(x._methods.size());
|
513 mike 1.18
514 for (Uint32 i = 0, n = x._methods.size(); i < n; i++)
|
515 kumpf 1.75 _methods.append(x._methods[i].clone());
|
516 mike 1.18 }
517
|
518 kumpf 1.36 Boolean CIMClassRep::identical(const CIMObjectRep* x) const
|
519 mike 1.18 {
|
520 mike 1.20 if (!CIMObjectRep::identical(x))
|
521 kumpf 1.75 return false;
|
522 mike 1.18
|
523 kumpf 1.36 const CIMClassRep* tmprep = dynamic_cast<const CIMClassRep*>(x);
524 if (!tmprep)
525 return false;
526
|
527 kumpf 1.77 // If the pointers are the same, the objects must be identical
528 if (this == tmprep)
529 {
530 return true;
531 }
532
|
533 kumpf 1.56 if (!_superClassName.equal (tmprep->_superClassName))
|
534 kumpf 1.75 return false;
|
535 mike 1.18
|
536 mike 1.20 //
537 // Check methods:
538 //
|
539 mike 1.18
540 {
|
541 marek 1.79 const MethodSet& tmp1 = _methods;
542 const MethodSet& tmp2 = tmprep->_methods;
|
543 mike 1.18
|
544 kumpf 1.75 if (tmp1.size() != tmp2.size())
545 return false;
|
546 mike 1.18
|
547 kumpf 1.75 for (Uint32 i = 0, n = tmp1.size(); i < n; i++)
548 {
549 if (!tmp1[i].identical(tmp2[i]))
550 return false;
551
552 if (!tmp1[i].getClassOrigin().equal (tmp2[i].getClassOrigin()))
553 return false;
554
555 if (tmp1[i].getPropagated() != tmp2[i].getPropagated())
556 return false;
557 }
|
558 mike 1.18 }
559
560 return true;
561 }
562
|
563 kumpf 1.49 void CIMClassRep::getKeyNames(Array<CIMName>& keyNames) const
|
564 mike 1.18 {
565 keyNames.clear();
566
567 for (Uint32 i = 0, n = getPropertyCount(); i < n; i++)
568 {
|
569 kumpf 1.75 CIMConstProperty property = getProperty(i);
|
570 mike 1.18
|
571 marek 1.79 if (CIMPropertyInternal::isKeyProperty(property))
572 {
573 keyNames.append(property.getName());
|
574 kumpf 1.51 }
|
575 mike 1.18 }
576 }
577
578 Boolean CIMClassRep::hasKeys() const
579 {
580 for (Uint32 i = 0, n = getPropertyCount(); i < n; i++)
581 {
|
582 kumpf 1.75 CIMConstProperty property = getProperty(i);
|
583 marek 1.79 if (CIMPropertyInternal::isKeyProperty(property))
584 {
585 return true;
|
586 kumpf 1.51 }
|
587 mike 1.18 }
588 return false;
589 }
590
591 PEGASUS_NAMESPACE_END
592
|