1 karl 1.67 //%2005////////////////////////////////////////////////////////////////////////
|
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 mike 1.18 //
12 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
13 chip 1.21 // of this software and associated documentation files (the "Software"), to
14 // deal in the Software without restriction, including without limitation the
15 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
16 mike 1.18 // sell copies of the Software, and to permit persons to whom the Software is
17 // furnished to do so, subject to the following conditions:
|
18 kumpf 1.44 //
|
19 chip 1.21 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
20 mike 1.18 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
21 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
22 chip 1.21 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
23 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
25 mike 1.18 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 //==============================================================================
29 //
30 // Author: Mike Brasher (mbrasher@bmc.com)
31 //
|
32 kumpf 1.35 // Modified By: Karl Schopmeyer(k.schopmeyer@attglobal.net)
33 // Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
|
34 kumpf 1.46 // Carol Ann Krug Graves, Hewlett-Packard Company
|
35 david.dillard 1.65 // (carolann_graves@hp.com)
36 // David Dillard, VERITAS Software Corp.
37 // (david.dillard@veritas.com)
|
38 mike 1.18 //
39 //%/////////////////////////////////////////////////////////////////////////////
40
|
41 kumpf 1.34 #include "CIMClassRep.h"
|
42 mike 1.18 #include "DeclContext.h"
|
43 kumpf 1.47 #include "Resolver.h"
|
44 mike 1.18 #include "Indentor.h"
45 #include "CIMName.h"
46 #include "CIMQualifierNames.h"
|
47 kumpf 1.37 #include "CIMScope.h"
|
48 mike 1.18 #include "XmlWriter.h"
|
49 kumpf 1.42 #include "MofWriter.h"
|
50 karl 1.30 #include <Pegasus/Common/Tracer.h>
|
51 humberto 1.57 #include <Pegasus/Common/MessageLoader.h> //l10n
|
52 r.kieninger 1.71 #include "CIMNameUnchecked.h"
|
53 mike 1.70 #include "StrLit.h"
|
54 mike 1.18
55 PEGASUS_NAMESPACE_BEGIN
|
56 karl 1.29 PEGASUS_USING_STD;
|
57 mike 1.18
58 CIMClassRep::CIMClassRep(
|
59 kumpf 1.49 const CIMName& className,
60 const CIMName& superClassName)
|
61 mike 1.20 :
|
62 kumpf 1.49 CIMObjectRep(CIMObjectPath(String(), CIMNamespaceName(), className)),
|
63 mike 1.20 _superClassName(superClassName)
|
64 mike 1.18 {
65 }
66
67 CIMClassRep::~CIMClassRep()
68 {
69 }
70
71 Boolean CIMClassRep::isAssociation() const
72 {
|
73 kumpf 1.55 Uint32 index = findQualifier(CIMQualifierNames::ASSOCIATION);
|
74 mike 1.18
|
75 kumpf 1.55 if (index == PEG_NOT_FOUND)
|
76 mike 1.18 return false;
77
78 Boolean flag;
79
|
80 kumpf 1.55 const CIMValue& value = getQualifier(index).getValue();
|
81 mike 1.18
|
82 kumpf 1.48 if (value.getType() != CIMTYPE_BOOLEAN)
|
83 mike 1.18 return false;
84
85 value.get(flag);
86 return flag;
87 }
88
89 Boolean CIMClassRep::isAbstract() const
90 {
|
91 kumpf 1.55 Uint32 index = findQualifier(CIMQualifierNames::ABSTRACT);
|
92 mike 1.18
|
93 kumpf 1.55 if (index == PEG_NOT_FOUND)
|
94 mike 1.18 return false;
95
96 Boolean flag;
|
97 kumpf 1.55 const CIMValue& value = getQualifier(index).getValue();
|
98 mike 1.18
|
99 kumpf 1.48 if (value.getType() != CIMTYPE_BOOLEAN)
|
100 mike 1.18 return false;
101
102 value.get(flag);
103 return flag;
104 }
|
105 kumpf 1.49 void CIMClassRep::setSuperClassName(const CIMName& superClassName)
|
106 mike 1.18 {
107 _superClassName = superClassName;
108 }
109
110 void CIMClassRep::addProperty(const CIMProperty& x)
111 {
|
112 kumpf 1.50 if (x.isUninitialized())
|
113 kumpf 1.54 throw UninitializedObjectException();
|
114 mike 1.18
115 // Reject addition of duplicate property name:
116
|
117 humberto 1.57 if (findProperty(x.getName()) != PEG_NOT_FOUND){
118 //l10n
119 //throw AlreadyExistsException
120 //("property \"" + x.getName().getString () + "\"");
121 MessageLoaderParms parms("Common.CIMClassRep.PROPERTY",
122 "property \"$0\"",
123 x.getName().getString());
124 throw AlreadyExistsException(parms);
125
126 }
|
127 mike 1.18
|
128 kumpf 1.59 // Reject addition of a reference property without a referenceClassName
129
130 if ((x.getType() == CIMTYPE_REFERENCE) &&
131 (x.getReferenceClassName().isNull()))
132 {
133 throw TypeMismatchException();
134 }
135
|
136 mike 1.18 // Add the property:
137
138 _properties.append(x);
139 }
140
141 void CIMClassRep::addMethod(const CIMMethod& x)
142 {
|
143 kumpf 1.50 if (x.isUninitialized())
|
144 kumpf 1.54 throw UninitializedObjectException();
|
145 mike 1.18
146 // Reject duplicate method names:
147
|
148 humberto 1.57 if (findMethod(x.getName()) != PEG_NOT_FOUND){
149 //l10n
150 //throw AlreadyExistsException
151 //("method \"" + x.getName().getString() + "\"");
152 MessageLoaderParms parms("Common.CIMClassRep.METHOD",
153 "method \"$0\"",
154 x.getName().getString());
155 throw AlreadyExistsException(parms);
156
157 }
|
158 mike 1.18
159 // Add the method:
160
161 _methods.append(x);
162 }
163
|
164 kumpf 1.49 Uint32 CIMClassRep::findMethod(const CIMName& name) const
|
165 mike 1.18 {
166 for (Uint32 i = 0, n = _methods.size(); i < n; i++)
167 {
|
168 kumpf 1.49 if (name.equal(_methods[i].getName()))
|
169 mike 1.18 return i;
170 }
171
172 return PEG_NOT_FOUND;
173 }
|
174 mike 1.20
|
175 kumpf 1.55 CIMMethod CIMClassRep::getMethod(Uint32 index)
|
176 mike 1.18 {
|
177 kumpf 1.55 if (index >= _methods.size())
|
178 kumpf 1.54 throw IndexOutOfBoundsException();
|
179 mike 1.18
|
180 kumpf 1.55 return _methods[index];
|
181 mike 1.18 }
182
183 Uint32 CIMClassRep::getMethodCount() const
184 {
185 return _methods.size();
186 }
|
187 mike 1.20
|
188 kumpf 1.55 void CIMClassRep::removeMethod(Uint32 index)
|
189 mike 1.18 {
|
190 kumpf 1.55 if (index >= _methods.size())
|
191 kumpf 1.54 throw IndexOutOfBoundsException();
|
192 mike 1.18
|
193 kumpf 1.55 _methods.remove(index);
|
194 mike 1.18 }
195
196 void CIMClassRep::resolve(
197 DeclContext* context,
|
198 kumpf 1.49 const CIMNamespaceName& nameSpace)
|
199 mike 1.18 {
|
200 karl 1.30 PEG_METHOD_ENTER(TRC_OBJECTRESOLUTION, "CIMClassRep::resolve()");
|
201 mike 1.18 #if 0
202 if (_resolved)
|
203 chip 1.23 throw ClassAlreadyResolved(_reference.getClassName());
|
204 mike 1.18 #endif
205 if (!context)
206 throw NullPointer();
207
|
208 kumpf 1.32 PEG_TRACE_STRING(TRC_OBJECTRESOLUTION, Tracer::LEVEL3,
209 String("CIMClassRep::resolve class = ") +
|
210 kumpf 1.56 _reference.getClassName().getString() + ", superclass = " +
211 _superClassName.getString());
|
212 karl 1.30
|
213 kumpf 1.49 if (!_superClassName.isNull())
|
214 karl 1.29 {
215 //cout << "KSTEST Class Resolve with Super class " << getClassName()
216 //<< " superClass " << _superClassName << endl;
217 //----------------------------------------------------------------------
218 // First check to see if the super-class really exists and the subclassing legal:
219 //----------------------------------------------------------------------
220 CIMConstClass superClass
221 = context->lookupClass(nameSpace, _superClassName);
222
|
223 kumpf 1.50 if (superClass.isUninitialized())
|
224 kumpf 1.56 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_SUPERCLASS,
|
225 humberto 1.57 _superClassName.getString());
226
|
227 karl 1.29
|
228 mike 1.18 #if 0
|
229 karl 1.29 if (!superClass._rep->_resolved)
230 throw ClassNotResolved(_superClassName);
|
231 mike 1.18 #endif
|
232 karl 1.29 // If subclass is abstract but superclass not, throw CIM Exception
233
234 /* ATTN:KS-24 Mar 2002 P1 - Test this and confirm that rule is correct
235 if isAbstract() && !superclass.isAbstract()
236 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_SUPERCLASS,_superClassName);
237 */
|
238 karl 1.31 /*if(superclass.isTrueQualifier(CIMQualifierNames::TERMINAL)
239 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_SUPERCLASS,_superClassName);
240 */
|
241 karl 1.29 //----------------------------------------------------------------------
242 // Iterate all the properties of *this* class. Resolve each one and
243 // set the class-origin:
244 //----------------------------------------------------------------------
245
|
246 kumpf 1.54 Boolean isAssociationClass = isAssociation();
247
|
248 karl 1.29 for (Uint32 i = 0, n = _properties.size(); i < n; i++)
249 {
250 CIMProperty& property = _properties[i];
|
251 kumpf 1.54
|
252 a.dunfey 1.63 if(!isAssociationClass &&
253 property.getValue().getType() == CIMTYPE_REFERENCE)
|
254 a.dunfey 1.62 {
|
255 humberto 1.57 //l10n
256 //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_PARAMETER,
257 //"Non-assocation class contains reference property");
258 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_INVALID_PARAMETER,
259 MessageLoaderParms("Common.CIMClassRep.NON_ASSOCIATION_CLASS_CONTAINS_REFERENCE_PROPERTY",
260 "Non-assocation class contains reference property"));
261
|
262 a.dunfey 1.63
|
263 a.dunfey 1.62 }
264
|
265 kumpf 1.54
|
266 kumpf 1.55 Uint32 index = superClass.findProperty(property.getName());
|
267 karl 1.29
|
268 kumpf 1.55 if (index == PEG_NOT_FOUND)
|
269 karl 1.29 {
|
270 kumpf 1.47 Resolver::resolveProperty (property, context,
271 nameSpace, false, true);
|
272 kumpf 1.66 if (property.getClassOrigin().isNull())
273 {
274 property.setClassOrigin(getClassName());
275 }
|
276 a.dunfey 1.68 property.setPropagated(false);
|
277 karl 1.29 }
278 else
|
279 karl 1.28 {
|
280 karl 1.29 CIMConstProperty superClassProperty =
|
281 kumpf 1.55 superClass.getProperty(index);
|
282 kumpf 1.47 Resolver::resolveProperty (property, context,
283 nameSpace, false, superClassProperty, true);
|
284 kumpf 1.66 if (property.getClassOrigin().isNull())
285 {
286 property.setClassOrigin(
287 superClassProperty.getClassOrigin());
288 }
|
289 karl 1.28 }
|
290 karl 1.29 }
291
292 //----------------------------------------------------------------------
293 // Now prepend all properties inherited from the super-class (that
294 // are not overriden by this sub-class).
295 //----------------------------------------------------------------------
296
297 // Iterate super-class properties:
298
299 for (Uint32 i = 0, m = 0, n = superClass.getPropertyCount(); i < n; i++)
|
300 karl 1.28 {
|
301 karl 1.29 CIMConstProperty superClassProperty = superClass.getProperty(i);
302
303 // Find the property in *this* class; if not found, then clone and
304 // insert it (setting the propagated flag). Otherwise, change
305 // the class-origin and propagated flag accordingly.
306
|
307 kumpf 1.55 Uint32 index = PEG_NOT_FOUND;
|
308 karl 1.29 /* ATTN: KS move to simpler version of the find
309 for (Uint32 j = m, n = _properties.size(); j < n; j++)
|
310 karl 1.28 {
|
311 karl 1.29 if (CIMName::equal(_properties[j].getName(),
312 superClassProperty.getName()))
|
313 karl 1.28 {
|
314 kumpf 1.55 index = j;
|
315 karl 1.29 break;
316 }
317 }
318 */
|
319 kumpf 1.55 index = findProperty(superClassProperty.getName());
|
320 karl 1.29
321 // If property exists in super class but not in this one, then
322 // clone and insert it. Otherwise, the properties class
323 // origin was set above.
324
|
325 kumpf 1.51 CIMProperty superproperty = superClassProperty.clone();
|
326 karl 1.29
|
327 kumpf 1.55 if (index == PEG_NOT_FOUND)
|
328 karl 1.29 {
329 superproperty.setPropagated(true);
330 _properties.insert(m++, superproperty);
331 }
332 else
333 {
334 // Property Qualifiers must propagate if allowed
335 // If property exists in the superclass and in the subclass,
336 // then, enumerate the qualifiers of the superclass's property.
337 // If a qualifier is defined on the superclass's property
338 // but not on the subclass's, then add it to the subclass's
339 // property's qualifier list.
|
340 kumpf 1.55 CIMProperty subproperty = _properties[index];
|
341 karl 1.29 for (Uint32 i = 0, n = superproperty.getQualifierCount();
342 i < n; i++)
343 {
|
344 kumpf 1.55 Uint32 index = PEG_NOT_FOUND;
|
345 karl 1.29 CIMQualifier superClassQualifier =
346 superproperty.getQualifier(i);
|
347 kumpf 1.49 const CIMName name = superClassQualifier.getName();
|
348 karl 1.29 /* ATTN KS This is replacement find function.
349 if((Uint32 j = subproperty.findQualifier(q.getName()) == PEG_NOT_FOUND)
|
350 karl 1.28 {
|
351 karl 1.29 subproperty.addQualifier(superClassQualifier);
352
|
353 karl 1.28 }
|
354 karl 1.29 */
355 for (Uint32 j = 0, m = subproperty.getQualifierCount();
356 j < m;
357 j++)
358 {
359 CIMConstQualifier q = subproperty.getQualifier(j);
|
360 kumpf 1.49 if (name.equal(q.getName()))
|
361 karl 1.29 {
|
362 kumpf 1.55 index = j;
|
363 karl 1.29 break;
364 }
365 } // end comparison of subclass property's qualifiers
|
366 kumpf 1.55 if (index == PEG_NOT_FOUND)
|
367 karl 1.29 {
368 subproperty.addQualifier(superClassQualifier);
369 }
370 /*
|
371 kumpf 1.55 if ((index = subproperty.findQualifier(name)) == PEG_NOT_FOUND)
|
372 karl 1.29 {
373 subproperty.addQualifier(superClassQualifier);
374 }
375 */
376 } // end iteration over superclass property's qualifiers
377 }
378 }
379
380 //----------------------------------------------------------------------
381 // Iterate all the methods of *this* class. Resolve each one and
382 // set the class-origin:
383 //----------------------------------------------------------------------
384
385 for (Uint32 i = 0, n = _methods.size(); i < n; i++)
386 {
387 CIMMethod& method = _methods[i];
|
388 kumpf 1.55 Uint32 index = superClass.findMethod(method.getName());
|
389 karl 1.29
|
390 kumpf 1.55 if (index == PEG_NOT_FOUND)
|
391 karl 1.29 {
|
392 kumpf 1.47 Resolver::resolveMethod (method, context,
393 nameSpace);
|
394 karl 1.29 }
395 else
396 {
|
397 kumpf 1.55 CIMConstMethod superClassMethod = superClass.getMethod(index);
|
398 kumpf 1.47 Resolver::resolveMethod (method, context,
399 nameSpace, superClassMethod);
|
400 karl 1.29 }
401 }
402
403 //----------------------------------------------------------------------
404 // Now prepend all methods inherited from the super-class (that
405 // are not overriden by this sub-class).
406 //----------------------------------------------------------------------
407
408 for (Uint32 i = 0, m = 0, n = superClass.getMethodCount(); i < n; i++)
409 {
410 CIMConstMethod superClassMethod = superClass.getMethod(i);
411
412 // Find the method in *this* class; if not found, then clone and
413 // insert it (setting the propagated flag). Otherwise, change
414 // the class-origin and propagated flag accordingly.
415
|
416 kumpf 1.55 Uint32 index = PEG_NOT_FOUND;
|
417 karl 1.29 /********************** KS move to simpler version
418 for (Uint32 j = m, n = _methods.size(); j < n; j++)
419 {
420 if (CIMName::equal(_methods[j].getName(),
421 superClassMethod.getName()))
|
422 karl 1.28 {
|
423 kumpf 1.55 index = j;
|
424 karl 1.29 break;
|
425 karl 1.28 }
|
426 karl 1.29 }
427
428 // If method exists in super class but not in this one, then
429 // clone and insert it. Otherwise, the method's class origin
430 // has already been set above.
431
|
432 kumpf 1.55 if (index == PEG_NOT_FOUND)
|
433 karl 1.29 {
434 CIMMethod method = superClassMethod.clone();
435 method.setPropagated(true);
436 _methods.insert(m++, method);
437 }
438 */
|
439 kumpf 1.55 if((index = findMethod(superClassMethod.getName())) == PEG_NOT_FOUND)
|
440 karl 1.28 {
|
441 karl 1.29 CIMMethod method = superClassMethod.clone();
442 method.setPropagated(true);
443 _methods.insert(m++, method);
|
444 karl 1.28 }
445 }
|
446 karl 1.29
447 //----------------------------------------------------------------------
448 // Validate the qualifiers of this class:
449 //----------------------------------------------------------------------
450 //cout << "KSTEST Class Qualifiers resolve for class" << getClassName() << endl;
451 _qualifiers.resolve(
452 context,
453 nameSpace,
454 isAssociation() ? CIMScope::ASSOCIATION : CIMScope::CLASS,
455 false,
456 superClass._rep->_qualifiers,
457 true);
|
458 mike 1.18 }
|
459 karl 1.29 else // No SuperClass exsts
|
460 mike 1.18 {
|
461 karl 1.28 //----------------------------------------------------------------------
462 // Resolve each property:
463 //----------------------------------------------------------------------
|
464 karl 1.29 //cout << "KSTEST Class Resolve, No Super class " << getClassName() << endl;
465
|
466 karl 1.28 for (Uint32 i = 0, n = _properties.size(); i < n; i++)
|
467 kumpf 1.66 {
|
468 kumpf 1.47 Resolver::resolveProperty (_properties[i], context,
469 nameSpace, false, true);
|
470 kumpf 1.66 _properties[i].setClassOrigin(getClassName());
|
471 a.dunfey 1.68 _properties[i].setPropagated(false);
|
472 kumpf 1.66 }
|
473 karl 1.28
474 //----------------------------------------------------------------------
475 // Resolve each method:
476 //----------------------------------------------------------------------
477
478 for (Uint32 i = 0, n = _methods.size(); i < n; i++)
|
479 kumpf 1.47 Resolver::resolveMethod (_methods[i], context, nameSpace);
|
480 karl 1.28
481 //----------------------------------------------------------------------
482 // Resolve the qualifiers:
483 //----------------------------------------------------------------------
484
485 CIMQualifierList dummy;
486
487 _qualifiers.resolve(
488 context,
489 nameSpace,
490 isAssociation() ? CIMScope::ASSOCIATION : CIMScope::CLASS,
491 false,
492 dummy,
493 true);
|
494 mike 1.18 }
495
496 // _resolved = true;
497 }
498
|
499 karl 1.61 CIMInstance CIMClassRep::buildInstance(Boolean includeQualifiers,
|
500 karl 1.60 Boolean includeClassOrigin,
501 const CIMPropertyList& propertyList) const
502 {
503
504 // Create the new instance
505 CIMInstance newInstance(_reference.getClassName());
506
507 // Copy qualifiers if required
508 if (includeQualifiers)
509 {
510 for (Uint32 i = 0 ; i < getQualifierCount() ; i++)
511 {
512 newInstance.addQualifier(getQualifier(i).clone());
513 }
514 }
515
516 // Copy Properties
517 for (Uint32 i = 0 ; i < _properties.size() ; i++)
518 {
519 CIMConstProperty p = getProperty(i);
520 CIMName name = p.getName();
521 karl 1.60 Array<CIMName> pl = propertyList.getPropertyNameArray();
522 if (propertyList.isNull() || Contains(pl, name))
523 {
524 CIMProperty p = getProperty(i).clone();
525 if (!includeQualifiers && p.getQualifierCount() != 0)
526 {
527 for (Uint32 j = 0 ; j < getQualifierCount() ; j++)
528 {
529 p.removeQualifier(i - 1);
530 }
531 }
532 if (!includeClassOrigin)
533 {
534 p.setClassOrigin(CIMName());
535 }
536 newInstance.addProperty(p);
537
538 // Delete class origin attribute if required
539 }
540 }
541
542 karl 1.60 return(newInstance);
543 }
544
|
545 mike 1.69 void CIMClassRep::toXml(Buffer& out) const
|
546 mike 1.18 {
547 // Class opening element:
548
|
549 mike 1.70 out << STRLIT("<CLASS ");
550 out << STRLIT(" NAME=\"") << _reference.getClassName() << STRLIT("\" ");
|
551 mike 1.18
|
552 kumpf 1.49 if (!_superClassName.isNull())
|
553 mike 1.70 out << STRLIT(" SUPERCLASS=\"") << _superClassName << STRLIT("\" ");
|
554 mike 1.18
|
555 mike 1.70 out << STRLIT(">\n");
|
556 mike 1.18
557 // Qualifiers:
558
559 _qualifiers.toXml(out);
560
561 // Parameters:
562
563 for (Uint32 i = 0, n = _properties.size(); i < n; i++)
|
564 kumpf 1.41 XmlWriter::appendPropertyElement(out, _properties[i]);
|
565 mike 1.18
566 // Methods:
567
568 for (Uint32 i = 0, n = _methods.size(); i < n; i++)
|
569 kumpf 1.41 XmlWriter::appendMethodElement(out, _methods[i]);
|
570 mike 1.18
571 // Class closing element:
572
|
573 mike 1.70 out << STRLIT("</CLASS>\n");
|
574 mike 1.18 }
|
575 mike 1.19 /** toMof prepares an 8-bit string with the MOF for the class.
576 The BNF for this is:
577 <pre>
578 classDeclaration = [ qualifierList ]
579 CLASS className [ alias ] [ superClass ]
580 "{" *classFeature "}" ";"
|
581 chip 1.21
|
582 mike 1.19 superClass = :" className
583
584 classFeature = propertyDeclaration | methodDeclaration
585
586 */
587
|
588 mike 1.69 void CIMClassRep::toMof(Buffer& out) const
|
589 mike 1.19 {
590 // Get and format the class qualifiers
|
591 mike 1.70 out << STRLIT("\n// Class ") << _reference.getClassName();
|
592 mike 1.19 if (_qualifiers.getCount())
|
593 mike 1.70 out.append('\n');
594 out.append('\n');
|
595 mike 1.19 _qualifiers.toMof(out);
596
597 // Separate qualifiers from Class Name
|
598 mike 1.70 out.append('\n');
|
599 mike 1.19
600 // output class statement
|
601 mike 1.70 out << STRLIT("class ") << _reference.getClassName();
|
602 mike 1.19
|
603 kumpf 1.49 if (!_superClassName.isNull())
|
604 mike 1.70 out << STRLIT(" : ") << _superClassName;
|
605 chip 1.21
|
606 mike 1.70 out << STRLIT("\n{");
|
607 mike 1.19
608 // format the Properties:
609 for (Uint32 i = 0, n = _properties.size(); i < n; i++)
610 {
|
611 kumpf 1.51 // Generate MOF if this property not propagated
|
612 mike 1.19 // Note that the test is required only because
613 // there is an error in getclass that does not
614 // test the localOnly flag.
615 if (!_properties[i].getPropagated())
|
616 kumpf 1.42 MofWriter::appendPropertyElement(out, _properties[i]);
|
617 mike 1.19 }
618
619 // Format the Methods: for non-propagated methods
620 for (Uint32 i = 0, n = _methods.size(); i < n; i++)
621 {
622 if (!_methods[i].getPropagated())
|
623 kumpf 1.42 MofWriter::appendMethodElement(out, _methods[i]);
|
624 mike 1.19 }
625
626 // Class closing element:
|
627 mike 1.70 out << STRLIT("\n};\n");
|
628 mike 1.19 }
629
|
630 mike 1.18
631 CIMClassRep::CIMClassRep()
632 {
633 }
634
635 CIMClassRep::CIMClassRep(const CIMClassRep& x) :
|
636 mike 1.20 CIMObjectRep(x),
637 _superClassName(x._superClassName)
|
638 mike 1.18 {
|
639 kumpf 1.45 _methods.reserveCapacity(x._methods.size());
|
640 mike 1.18
641 for (Uint32 i = 0, n = x._methods.size(); i < n; i++)
642 _methods.append(x._methods[i].clone());
643 }
644
|
645 kumpf 1.36 Boolean CIMClassRep::identical(const CIMObjectRep* x) const
|
646 mike 1.18 {
|
647 mike 1.20 if (!CIMObjectRep::identical(x))
|
648 mike 1.18 return false;
649
|
650 kumpf 1.36 const CIMClassRep* tmprep = dynamic_cast<const CIMClassRep*>(x);
651 if (!tmprep)
652 return false;
653
|
654 kumpf 1.56 if (!_superClassName.equal (tmprep->_superClassName))
|
655 mike 1.18 return false;
656
|
657 mike 1.20 //
658 // Check methods:
659 //
|
660 mike 1.18
661 {
662 const Array<CIMMethod>& tmp1 = _methods;
|
663 kumpf 1.36 const Array<CIMMethod>& tmp2 = tmprep->_methods;
|
664 mike 1.18
665 if (tmp1.size() != tmp2.size())
666 return false;
667
668 for (Uint32 i = 0, n = tmp1.size(); i < n; i++)
669 {
670 if (!tmp1[i].identical(tmp2[i]))
671 return false;
672
|
673 kumpf 1.56 if (!tmp1[i].getClassOrigin().equal (tmp2[i].getClassOrigin()))
|
674 mike 1.18 return false;
675
676 if (tmp1[i].getPropagated() != tmp2[i].getPropagated())
677 return false;
678 }
679 }
680
|
681 kumpf 1.36 if (_resolved != tmprep->_resolved)
|
682 mike 1.18 return false;
683
684 return true;
685 }
686
|
687 kumpf 1.49 void CIMClassRep::getKeyNames(Array<CIMName>& keyNames) const
|
688 mike 1.18 {
689 keyNames.clear();
690
691 for (Uint32 i = 0, n = getPropertyCount(); i < n; i++)
692 {
693 CIMConstProperty property = getProperty(i);
694
|
695 kumpf 1.55 Uint32 index;
|
696 r.kieninger 1.71 if ((index = property.findQualifier(
697 CIMNameUnchecked("key"))) != PEG_NOT_FOUND)
|
698 kumpf 1.51 {
699 CIMValue value;
|
700 kumpf 1.55 value = property.getQualifier (index).getValue ();
|
701 kumpf 1.51 if (!value.isNull ())
702 {
703 Boolean isKey;
704 value.get (isKey);
705 if (isKey)
706 keyNames.append(property.getName());
707 }
708 }
|
709 mike 1.18 }
710 }
711
712 Boolean CIMClassRep::hasKeys() const
713 {
714 for (Uint32 i = 0, n = getPropertyCount(); i < n; i++)
715 {
716 CIMConstProperty property = getProperty(i);
717
|
718 kumpf 1.55 Uint32 index;
|
719 r.kieninger 1.71 if ((index = property.findQualifier(
720 CIMNameUnchecked("key"))) != PEG_NOT_FOUND)
|
721 kumpf 1.51 {
722 CIMValue value;
|
723 kumpf 1.55 value = property.getQualifier (index).getValue ();
|
724 kumpf 1.51 if (!value.isNull ())
725 {
726 Boolean isKey;
727 value.get (isKey);
728 if (isKey)
729 return true;
730 }
731 }
|
732 mike 1.18 }
733
734 return false;
735 }
736
737 PEGASUS_NAMESPACE_END
738
|