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 mike 1.18 #if 0
155 if (_resolved)
|
156 kumpf 1.75 throw ClassAlreadyResolved(_reference.getClassName());
|
157 mike 1.18 #endif
158 if (!context)
|
159 kumpf 1.75 throw NullPointer();
|
160 mike 1.18
|
161 kumpf 1.75 PEG_TRACE_STRING(TRC_OBJECTRESOLUTION, Tracer::LEVEL3,
162 String("CIMClassRep::resolve class = ") +
163 _reference.getClassName().getString() + ", superclass = " +
164 _superClassName.getString());
|
165 karl 1.30
|
166 kumpf 1.49 if (!_superClassName.isNull())
|
167 kumpf 1.75 {
168 //----------------------------------------------------------------------
169 // First check to see if the super-class really exists and the
170 // subclassing legal:
171 //----------------------------------------------------------------------
172 CIMConstClass superClass =
173 context->lookupClass(nameSpace, _superClassName);
174
175 if (superClass.isUninitialized())
176 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_SUPERCLASS,
177 _superClassName.getString());
|
178 r.kieninger 1.74
|
179 kumpf 1.75 // If subclass is abstract but superclass not, throw CIM Exception
|
180 r.kieninger 1.74
|
181 kumpf 1.75 /* ATTN:KS-24 Mar 2002 P1 - Test this and confirm that rule is correct
182 if isAbstract() && !superclass.isAbstract()
183 throw PEGASUS_CIM_EXCEPTION(
184 CIM_ERR_INVALID_SUPERCLASS, _superClassName);
185 */
|
186 kumpf 1.76 /*if (superclass.isTrueQualifier(CIMQualifierNames::TERMINAL)
|
187 kumpf 1.75 throw PEGASUS_CIM_EXCEPTION(
188 CIM_ERR_INVALID_SUPERCLASS, _superClassName);
189 */
190 //----------------------------------------------------------------------
191 // Iterate all the properties of *this* class. Resolve each one and
192 // set the class-origin:
193 //----------------------------------------------------------------------
|
194 r.kieninger 1.74
|
195 kumpf 1.75 Boolean isAssociationClass = isAssociation();
|
196 a.dunfey 1.63
|
197 kumpf 1.75 for (Uint32 i = 0, n = _properties.size(); i < n; i++)
198 {
199 CIMProperty& property = _properties[i];
200
201 if (!isAssociationClass &&
202 property.getValue().getType() == CIMTYPE_REFERENCE)
203 {
204 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_INVALID_PARAMETER,
205 MessageLoaderParms(
206 "Common.CIMClassRep.NON_ASSOCIATION_CLASS_CONTAINS_"
207 "REFERENCE_PROPERTY",
208 "Non-assocation class contains reference property"));
209 }
210
211
212 Uint32 index = superClass.findProperty(property.getName());
213
214 if (index == PEG_NOT_FOUND)
215 {
216 Resolver::resolveProperty(
217 property, context, nameSpace, false, true);
218 kumpf 1.75 if (property.getClassOrigin().isNull())
219 {
220 property.setClassOrigin(getClassName());
221 }
222 property.setPropagated(false);
223 }
224 else
225 {
226 CIMConstProperty superClassProperty =
227 superClass.getProperty(index);
228 Resolver::resolveProperty(property, context,
229 nameSpace, false, superClassProperty, true);
230 if (property.getClassOrigin().isNull())
231 {
232 property.setClassOrigin(
233 superClassProperty.getClassOrigin());
234 }
|
235 a.dunfey 1.62 }
|
236 kumpf 1.75 }
|
237 r.kieninger 1.74
|
238 kumpf 1.75 //----------------------------------------------------------------------
239 // Now prepend all properties inherited from the super-class (that
240 // are not overriden by this sub-class).
241 //----------------------------------------------------------------------
|
242 kumpf 1.54
|
243 kumpf 1.75 // Iterate super-class properties:
|
244 karl 1.29
|
245 kumpf 1.75 for (Uint32 i = 0, m = 0, n = superClass.getPropertyCount(); i < n; i++)
246 {
247 CIMConstProperty superClassProperty = superClass.getProperty(i);
248
249 // Find the property in *this* class; if not found, then clone and
250 // insert it (setting the propagated flag). Otherwise, change
251 // the class-origin and propagated flag accordingly.
252
253 Uint32 index = PEG_NOT_FOUND;
254 /* ATTN: KS move to simpler version of the find
255 for (Uint32 j = m, n = _properties.size(); j < n; j++)
256 {
257 if (_properties[j].getName() == superClassProperty.getName())
|
258 kumpf 1.66 {
|
259 kumpf 1.75 index = j;
260 break;
|
261 kumpf 1.66 }
|
262 kumpf 1.75 }
263 */
264 index = findProperty(superClassProperty.getName());
265
266 // If property exists in super class but not in this one, then
267 // clone and insert it. Otherwise, the properties class
268 // origin was set above.
269
270 CIMProperty superproperty = superClassProperty.clone();
|
271 r.kieninger 1.74
|
272 kumpf 1.75 if (index == PEG_NOT_FOUND)
273 {
274 superproperty.setPropagated(true);
275 _properties.insert(m++, superproperty);
276 }
277 else
278 {
279 // Property Qualifiers must propagate if allowed
280 // If property exists in the superclass and in the subclass,
281 // then, enumerate the qualifiers of the superclass's property.
282 // If a qualifier is defined on the superclass's property
283 // but not on the subclass's, then add it to the subclass's
284 // property's qualifier list.
285 CIMProperty subproperty = _properties[index];
286 for (Uint32 i = 0, n = superproperty.getQualifierCount();
287 i < n; i++)
288 {
289 Uint32 index = PEG_NOT_FOUND;
290 CIMQualifier superClassQualifier =
291 superproperty.getQualifier(i);
292 const CIMName name = superClassQualifier.getName();
293 kumpf 1.75 /* ATTN KS This is replacement find function.
294 if (Uint32 j = subproperty.findQualifier(q.getName()) ==
295 PEG_NOT_FOUND)
296 {
297 subproperty.addQualifier(superClassQualifier);
298 }
299 */
300 for (Uint32 j = 0, m = subproperty.getQualifierCount();
301 j < m;
302 j++)
303 {
304 CIMConstQualifier q = subproperty.getQualifier(j);
305 if (name.equal(q.getName()))
306 {
307 index = j;
308 break;
309 }
310 } // end comparison of subclass property's qualifiers
311 if (index == PEG_NOT_FOUND)
312 {
313 subproperty.addQualifier(superClassQualifier);
314 kumpf 1.75 }
315 /*
316 if ((index = subproperty.findQualifier(name)) ==
317 PEG_NOT_FOUND)
318 {
319 subproperty.addQualifier(superClassQualifier);
320 }
321 */
322 } // end iteration over superclass property's qualifiers
323 }
324 }
325
326 //----------------------------------------------------------------------
327 // Iterate all the methods of *this* class. Resolve each one and
328 // set the class-origin:
329 //----------------------------------------------------------------------
330
331 for (Uint32 i = 0, n = _methods.size(); i < n; i++)
332 {
333 CIMMethod& method = _methods[i];
334 Uint32 index = superClass.findMethod(method.getName());
335 kumpf 1.75
336 if (index == PEG_NOT_FOUND)
337 {
338 Resolver::resolveMethod(method, context, nameSpace);
|
339 r.kieninger 1.80 if (method.getClassOrigin().isNull())
340 {
341 method.setClassOrigin(getClassName());
342 }
343 method.setPropagated(false);
|
344 kumpf 1.75 }
345 else
346 {
347 CIMConstMethod superClassMethod = superClass.getMethod(index);
348 Resolver::resolveMethod(
349 method, context, nameSpace, superClassMethod);
350 }
351 }
352
353 //----------------------------------------------------------------------
354 // Now prepend all methods inherited from the super-class (that
355 // are not overriden by this sub-class).
356 //----------------------------------------------------------------------
357
358 for (Uint32 i = 0, m = 0, n = superClass.getMethodCount(); i < n; i++)
359 {
360 CIMConstMethod superClassMethod = superClass.getMethod(i);
361
362 // Find the method in *this* class; if not found, then clone and
363 // insert it (setting the propagated flag). Otherwise, change
364 // the class-origin and propagated flag accordingly.
365 kumpf 1.75
366 Uint32 index = PEG_NOT_FOUND;
367 /********************** KS move to simpler version
368 for (Uint32 j = m, n = _methods.size(); j < n; j++)
369 {
370 if (_methods[j].getName() == superClassMethod.getName())
371 {
372 index = j;
373 break;
374 }
375 }
376
377 // If method exists in super class but not in this one, then
378 // clone and insert it. Otherwise, the method's class origin
379 // has already been set above.
380
381 if (index == PEG_NOT_FOUND)
382 {
383 CIMMethod method = superClassMethod.clone();
384 method.setPropagated(true);
385 _methods.insert(m++, method);
386 kumpf 1.75 }
387 */
388 if ((index = findMethod(superClassMethod.getName())) ==
389 PEG_NOT_FOUND)
390 {
391 CIMMethod method = superClassMethod.clone();
392 method.setPropagated(true);
393 _methods.insert(m++, method);
394 }
|
395 r.kieninger 1.80
|
396 kumpf 1.75 }
397
398 //----------------------------------------------------------------------
399 // Validate the qualifiers of this class:
400 //----------------------------------------------------------------------
401 _qualifiers.resolve(
402 context,
403 nameSpace,
404 isAssociation() ? CIMScope::ASSOCIATION : CIMScope::CLASS,
405 false,
406 superClass._rep->_qualifiers,
407 true);
408 }
409 else // No SuperClass exsts
410 {
411 //----------------------------------------------------------------------
412 // Resolve each property:
413 //----------------------------------------------------------------------
414
415 for (Uint32 i = 0, n = _properties.size(); i < n; i++)
416 {
417 kumpf 1.75 Resolver::resolveProperty(
418 _properties[i], context, nameSpace, false, true);
419 _properties[i].setClassOrigin(getClassName());
420 _properties[i].setPropagated(false);
421 }
422
423 //----------------------------------------------------------------------
424 // Resolve each method:
425 //----------------------------------------------------------------------
426
427 for (Uint32 i = 0, n = _methods.size(); i < n; i++)
428 {
429 Resolver::resolveMethod (_methods[i], context, nameSpace);
|
430 r.kieninger 1.80 _methods[i].setClassOrigin(getClassName());
431 _methods[i].setPropagated(false);
|
432 kumpf 1.75 }
433
434 //----------------------------------------------------------------------
435 // Resolve the qualifiers:
436 //----------------------------------------------------------------------
437
438 CIMQualifierList dummy;
439
440 _qualifiers.resolve(
441 context,
442 nameSpace,
443 isAssociation() ? CIMScope::ASSOCIATION : CIMScope::CLASS,
444 false,
445 dummy,
446 true);
|
447 mike 1.18 }
448
449 // _resolved = true;
450 }
451
|
452 karl 1.61 CIMInstance CIMClassRep::buildInstance(Boolean includeQualifiers,
|
453 karl 1.60 Boolean includeClassOrigin,
454 const CIMPropertyList& propertyList) const
455 {
456
|
457 r.kieninger 1.74 // Create the new instance representation
458 CIMInstanceRep* newInstanceRep = new CIMInstanceRep(
459 CIMObjectPath(String::EMPTY,
460 CIMNamespaceName(),
461 _reference.getClassName()));
|
462 karl 1.60
463 // Copy qualifiers if required
464 if (includeQualifiers)
465 {
466 for (Uint32 i = 0 ; i < getQualifierCount() ; i++)
467 {
|
468 r.kieninger 1.74 newInstanceRep->_qualifiers.add(getQualifier(i).clone());
|
469 karl 1.60 }
470 }
471
|
472 r.kieninger 1.74 newInstanceRep->_properties.reserveCapacity(_properties.size());
473
|
474 karl 1.60 // Copy Properties
475 for (Uint32 i = 0 ; i < _properties.size() ; i++)
476 {
|
477 r.kieninger 1.74 CIMConstProperty cp = getProperty(i);
478 CIMName name = cp.getName();
|
479 karl 1.60 Array<CIMName> pl = propertyList.getPropertyNameArray();
480 if (propertyList.isNull() || Contains(pl, name))
481 {
|
482 r.kieninger 1.74 CIMProperty p;
483
484 if (includeQualifiers)
|
485 karl 1.60 {
|
486 r.kieninger 1.74 p = getProperty(i).clone();
487 }
488 else
489 {
490 p = CIMProperty(cp.getName(),
491 cp.getValue(),
492 cp.getArraySize(),
493 cp.getReferenceClassName(),
494 cp.getClassOrigin());
|
495 karl 1.60 }
|
496 r.kieninger 1.74
497 // Delete class origin attribute if required
|
498 karl 1.60 if (!includeClassOrigin)
499 {
500 p.setClassOrigin(CIMName());
501 }
502
|
503 r.kieninger 1.74 newInstanceRep->_properties.append(p);
|
504 karl 1.60 }
505 }
506
|
507 r.kieninger 1.74 // Create new CIMInstance from CIMInstanceRep
508 CIMInstance newInstance(newInstanceRep);
509
|
510 kumpf 1.76 return newInstance;
|
511 karl 1.60 }
512
|
513 mike 1.18 CIMClassRep::CIMClassRep(const CIMClassRep& x) :
|
514 mike 1.20 CIMObjectRep(x),
515 _superClassName(x._superClassName)
|
516 mike 1.18 {
|
517 kumpf 1.45 _methods.reserveCapacity(x._methods.size());
|
518 mike 1.18
519 for (Uint32 i = 0, n = x._methods.size(); i < n; i++)
|
520 kumpf 1.75 _methods.append(x._methods[i].clone());
|
521 mike 1.18 }
522
|
523 kumpf 1.36 Boolean CIMClassRep::identical(const CIMObjectRep* x) const
|
524 mike 1.18 {
|
525 mike 1.20 if (!CIMObjectRep::identical(x))
|
526 kumpf 1.75 return false;
|
527 mike 1.18
|
528 kumpf 1.36 const CIMClassRep* tmprep = dynamic_cast<const CIMClassRep*>(x);
529 if (!tmprep)
530 return false;
531
|
532 kumpf 1.77 // If the pointers are the same, the objects must be identical
533 if (this == tmprep)
534 {
535 return true;
536 }
537
|
538 kumpf 1.56 if (!_superClassName.equal (tmprep->_superClassName))
|
539 kumpf 1.75 return false;
|
540 mike 1.18
|
541 mike 1.20 //
542 // Check methods:
543 //
|
544 mike 1.18
545 {
|
546 marek 1.79 const MethodSet& tmp1 = _methods;
547 const MethodSet& tmp2 = tmprep->_methods;
|
548 mike 1.18
|
549 kumpf 1.75 if (tmp1.size() != tmp2.size())
550 return false;
|
551 mike 1.18
|
552 kumpf 1.75 for (Uint32 i = 0, n = tmp1.size(); i < n; i++)
553 {
554 if (!tmp1[i].identical(tmp2[i]))
555 return false;
556
557 if (!tmp1[i].getClassOrigin().equal (tmp2[i].getClassOrigin()))
558 return false;
559
560 if (tmp1[i].getPropagated() != tmp2[i].getPropagated())
561 return false;
562 }
|
563 mike 1.18 }
564
|
565 kumpf 1.36 if (_resolved != tmprep->_resolved)
|
566 kumpf 1.75 return false;
|
567 mike 1.18
568 return true;
569 }
570
|
571 kumpf 1.49 void CIMClassRep::getKeyNames(Array<CIMName>& keyNames) const
|
572 mike 1.18 {
573 keyNames.clear();
574
575 for (Uint32 i = 0, n = getPropertyCount(); i < n; i++)
576 {
|
577 kumpf 1.75 CIMConstProperty property = getProperty(i);
|
578 mike 1.18
|
579 marek 1.79 if (CIMPropertyInternal::isKeyProperty(property))
580 {
581 keyNames.append(property.getName());
|
582 kumpf 1.51 }
|
583 mike 1.18 }
584 }
585
586 Boolean CIMClassRep::hasKeys() const
587 {
588 for (Uint32 i = 0, n = getPropertyCount(); i < n; i++)
589 {
|
590 kumpf 1.75 CIMConstProperty property = getProperty(i);
|
591 marek 1.79 if (CIMPropertyInternal::isKeyProperty(property))
592 {
593 return true;
|
594 kumpf 1.51 }
|
595 mike 1.18 }
596 return false;
597 }
598
599 PEGASUS_NAMESPACE_END
600
|