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 thilo.boehm 1.88 PEG_TRACE((TRC_OBJECTRESOLUTION, Tracer::LEVEL4,
159 "CIMClassRep::resolve class = %s, superclass = %s",
160 (const char*)_reference.getClassName().getString().getCString(),
161 (const char*)_superClassName.getString().getCString()));
|
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 kumpf 1.87 Uint32 index = findProperty(superClassProperty.getName());
|
251 kumpf 1.75
252 // If property exists in super class but not in this one, then
253 // clone and insert it. Otherwise, the properties class
254 // origin was set above.
255
256 CIMProperty superproperty = superClassProperty.clone();
|
257 r.kieninger 1.74
|
258 kumpf 1.75 if (index == PEG_NOT_FOUND)
259 {
260 superproperty.setPropagated(true);
261 _properties.insert(m++, superproperty);
262 }
263 else
264 {
265 // Property Qualifiers must propagate if allowed
266 // If property exists in the superclass and in the subclass,
267 // then, enumerate the qualifiers of the superclass's property.
268 // If a qualifier is defined on the superclass's property
269 // but not on the subclass's, then add it to the subclass's
270 // property's qualifier list.
271 CIMProperty subproperty = _properties[index];
|
272 kumpf 1.87 for (Uint32 j = 0, qc = superproperty.getQualifierCount();
273 j < qc; j++)
|
274 kumpf 1.75 {
275 CIMQualifier superClassQualifier =
|
276 kumpf 1.87 superproperty.getQualifier(j);
|
277 kumpf 1.75 const CIMName name = superClassQualifier.getName();
|
278 kumpf 1.87 if (subproperty.findQualifier(name) == PEG_NOT_FOUND)
|
279 kumpf 1.75 {
280 subproperty.addQualifier(superClassQualifier);
281 }
282 } // end iteration over superclass property's qualifiers
283 }
284 }
285
286 //----------------------------------------------------------------------
287 // Iterate all the methods of *this* class. Resolve each one and
288 // set the class-origin:
289 //----------------------------------------------------------------------
290
291 for (Uint32 i = 0, n = _methods.size(); i < n; i++)
292 {
293 CIMMethod& method = _methods[i];
294 Uint32 index = superClass.findMethod(method.getName());
295
296 if (index == PEG_NOT_FOUND)
297 {
298 Resolver::resolveMethod(method, context, nameSpace);
|
299 r.kieninger 1.80 if (method.getClassOrigin().isNull())
300 {
301 method.setClassOrigin(getClassName());
302 }
303 method.setPropagated(false);
|
304 kumpf 1.75 }
305 else
306 {
307 CIMConstMethod superClassMethod = superClass.getMethod(index);
308 Resolver::resolveMethod(
309 method, context, nameSpace, superClassMethod);
310 }
311 }
312
313 //----------------------------------------------------------------------
314 // Now prepend all methods inherited from the super-class (that
315 // are not overriden by this sub-class).
316 //----------------------------------------------------------------------
317
318 for (Uint32 i = 0, m = 0, n = superClass.getMethodCount(); i < n; i++)
319 {
320 CIMConstMethod superClassMethod = superClass.getMethod(i);
321
322 // Find the method in *this* class; if not found, then clone and
323 // insert it (setting the propagated flag). Otherwise, change
324 // the class-origin and propagated flag accordingly.
325 kumpf 1.75
326 Uint32 index = PEG_NOT_FOUND;
327 /********************** KS move to simpler version
328 for (Uint32 j = m, n = _methods.size(); j < n; j++)
329 {
330 if (_methods[j].getName() == superClassMethod.getName())
331 {
332 index = j;
333 break;
334 }
335 }
336
337 // If method exists in super class but not in this one, then
338 // clone and insert it. Otherwise, the method's class origin
339 // has already been set above.
340
341 if (index == PEG_NOT_FOUND)
342 {
343 CIMMethod method = superClassMethod.clone();
344 method.setPropagated(true);
345 _methods.insert(m++, method);
346 kumpf 1.75 }
347 */
348 if ((index = findMethod(superClassMethod.getName())) ==
349 PEG_NOT_FOUND)
350 {
351 CIMMethod method = superClassMethod.clone();
352 method.setPropagated(true);
353 _methods.insert(m++, method);
354 }
|
355 r.kieninger 1.80
|
356 kumpf 1.75 }
357
358 //----------------------------------------------------------------------
359 // Validate the qualifiers of this class:
360 //----------------------------------------------------------------------
361 _qualifiers.resolve(
362 context,
363 nameSpace,
364 isAssociation() ? CIMScope::ASSOCIATION : CIMScope::CLASS,
365 false,
366 superClass._rep->_qualifiers,
367 true);
368 }
369 else // No SuperClass exsts
370 {
371 //----------------------------------------------------------------------
372 // Resolve each property:
373 //----------------------------------------------------------------------
374
375 for (Uint32 i = 0, n = _properties.size(); i < n; i++)
376 {
377 kumpf 1.75 Resolver::resolveProperty(
378 _properties[i], context, nameSpace, false, true);
379 _properties[i].setClassOrigin(getClassName());
380 _properties[i].setPropagated(false);
381 }
382
383 //----------------------------------------------------------------------
384 // Resolve each method:
385 //----------------------------------------------------------------------
386
387 for (Uint32 i = 0, n = _methods.size(); i < n; i++)
388 {
389 Resolver::resolveMethod (_methods[i], context, nameSpace);
|
390 r.kieninger 1.80 _methods[i].setClassOrigin(getClassName());
391 _methods[i].setPropagated(false);
|
392 kumpf 1.75 }
393
394 //----------------------------------------------------------------------
395 // Resolve the qualifiers:
396 //----------------------------------------------------------------------
397
398 CIMQualifierList dummy;
399
400 _qualifiers.resolve(
401 context,
402 nameSpace,
403 isAssociation() ? CIMScope::ASSOCIATION : CIMScope::CLASS,
404 false,
405 dummy,
406 true);
|
407 mike 1.18 }
408 }
409
|
410 karl 1.61 CIMInstance CIMClassRep::buildInstance(Boolean includeQualifiers,
|
411 karl 1.60 Boolean includeClassOrigin,
412 const CIMPropertyList& propertyList) const
413 {
414
|
415 r.kieninger 1.74 // Create the new instance representation
416 CIMInstanceRep* newInstanceRep = new CIMInstanceRep(
417 CIMObjectPath(String::EMPTY,
418 CIMNamespaceName(),
419 _reference.getClassName()));
|
420 karl 1.60
421 // Copy qualifiers if required
422 if (includeQualifiers)
423 {
424 for (Uint32 i = 0 ; i < getQualifierCount() ; i++)
425 {
|
426 r.kieninger 1.74 newInstanceRep->_qualifiers.add(getQualifier(i).clone());
|
427 karl 1.60 }
428 }
429
|
430 r.kieninger 1.74 newInstanceRep->_properties.reserveCapacity(_properties.size());
431
|
432 karl 1.60 // Copy Properties
433 for (Uint32 i = 0 ; i < _properties.size() ; i++)
434 {
|
435 r.kieninger 1.74 CIMConstProperty cp = getProperty(i);
436 CIMName name = cp.getName();
|
437 karl 1.60 Array<CIMName> pl = propertyList.getPropertyNameArray();
438 if (propertyList.isNull() || Contains(pl, name))
439 {
|
440 r.kieninger 1.74 CIMProperty p;
441
442 if (includeQualifiers)
|
443 karl 1.60 {
|
444 r.kieninger 1.74 p = getProperty(i).clone();
445 }
446 else
447 {
448 p = CIMProperty(cp.getName(),
449 cp.getValue(),
450 cp.getArraySize(),
451 cp.getReferenceClassName(),
452 cp.getClassOrigin());
|
453 karl 1.60 }
|
454 r.kieninger 1.74
455 // Delete class origin attribute if required
|
456 karl 1.60 if (!includeClassOrigin)
457 {
458 p.setClassOrigin(CIMName());
459 }
460
|
461 r.kieninger 1.74 newInstanceRep->_properties.append(p);
|
462 karl 1.60 }
463 }
464
|
465 r.kieninger 1.74 // Create new CIMInstance from CIMInstanceRep
466 CIMInstance newInstance(newInstanceRep);
467
|
468 kumpf 1.76 return newInstance;
|
469 karl 1.60 }
470
|
471 mike 1.18 CIMClassRep::CIMClassRep(const CIMClassRep& x) :
|
472 mike 1.20 CIMObjectRep(x),
473 _superClassName(x._superClassName)
|
474 mike 1.18 {
|
475 kumpf 1.45 _methods.reserveCapacity(x._methods.size());
|
476 mike 1.18
477 for (Uint32 i = 0, n = x._methods.size(); i < n; i++)
|
478 kumpf 1.75 _methods.append(x._methods[i].clone());
|
479 mike 1.18 }
480
|
481 kumpf 1.36 Boolean CIMClassRep::identical(const CIMObjectRep* x) const
|
482 mike 1.18 {
|
483 mike 1.20 if (!CIMObjectRep::identical(x))
|
484 kumpf 1.75 return false;
|
485 mike 1.18
|
486 kumpf 1.36 const CIMClassRep* tmprep = dynamic_cast<const CIMClassRep*>(x);
487 if (!tmprep)
488 return false;
489
|
490 kumpf 1.77 // If the pointers are the same, the objects must be identical
491 if (this == tmprep)
492 {
493 return true;
494 }
495
|
496 kumpf 1.56 if (!_superClassName.equal (tmprep->_superClassName))
|
497 kumpf 1.75 return false;
|
498 mike 1.18
|
499 mike 1.20 //
500 // Check methods:
501 //
|
502 mike 1.18
503 {
|
504 marek 1.79 const MethodSet& tmp1 = _methods;
505 const MethodSet& tmp2 = tmprep->_methods;
|
506 mike 1.18
|
507 kumpf 1.75 if (tmp1.size() != tmp2.size())
508 return false;
|
509 mike 1.18
|
510 kumpf 1.75 for (Uint32 i = 0, n = tmp1.size(); i < n; i++)
511 {
512 if (!tmp1[i].identical(tmp2[i]))
513 return false;
514
515 if (!tmp1[i].getClassOrigin().equal (tmp2[i].getClassOrigin()))
516 return false;
517
518 if (tmp1[i].getPropagated() != tmp2[i].getPropagated())
519 return false;
520 }
|
521 mike 1.18 }
522
523 return true;
524 }
525
|
526 kumpf 1.49 void CIMClassRep::getKeyNames(Array<CIMName>& keyNames) const
|
527 mike 1.18 {
528 keyNames.clear();
529
530 for (Uint32 i = 0, n = getPropertyCount(); i < n; i++)
531 {
|
532 kumpf 1.75 CIMConstProperty property = getProperty(i);
|
533 mike 1.18
|
534 marek 1.79 if (CIMPropertyInternal::isKeyProperty(property))
535 {
536 keyNames.append(property.getName());
|
537 kumpf 1.51 }
|
538 mike 1.18 }
539 }
540
541 Boolean CIMClassRep::hasKeys() const
542 {
543 for (Uint32 i = 0, n = getPropertyCount(); i < n; i++)
544 {
|
545 kumpf 1.75 CIMConstProperty property = getProperty(i);
|
546 marek 1.79 if (CIMPropertyInternal::isKeyProperty(property))
547 {
548 return true;
|
549 kumpf 1.51 }
|
550 mike 1.18 }
551 return false;
552 }
553
554 PEGASUS_NAMESPACE_END
555
|