1 karl 1.52 //%2006////////////////////////////////////////////////////////////////////////
|
2 mike 1.13 //
|
3 karl 1.44 // 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.40 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.44 // 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.46 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.52 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 mike 1.13 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
15 kumpf 1.26 // 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.13 // 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 karl 1.52 //
|
21 kumpf 1.26 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
22 mike 1.13 // 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 kumpf 1.26 // 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.13 // 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 // Author: Mike Brasher (mbrasher@bmc.com)
33 //
|
34 kumpf 1.29 // Modified By: Carol Ann Krug Graves, Hewlett-Packard Company
|
35 david.dillard 1.45 // (carolann_graves@hp.com)
36 // David Dillard, VERITAS Software Corp.
37 // (david.dillard@veritas.com)
|
38 mike 1.13 //
39 //%/////////////////////////////////////////////////////////////////////////////
40
41 #include <cstdio>
|
42 kumpf 1.19 #include "CIMPropertyRep.h"
|
43 mike 1.13 #include "Indentor.h"
44 #include "CIMName.h"
45 #include "CIMScope.h"
|
46 kumpf 1.25 #include "XmlWriter.h"
47 #include "MofWriter.h"
|
48 a.dunfey 1.42 #include "DeclContext.h"
|
49 mike 1.51 #include "StrLit.h"
|
50 mike 1.13
|
51 mike 1.17 PEGASUS_USING_STD;
52
|
53 mike 1.13 PEGASUS_NAMESPACE_BEGIN
54
|
55 chip 1.48 CIMPropertyRep::CIMPropertyRep()
56 {
57 }
58
59 CIMPropertyRep::CIMPropertyRep(
60 const CIMPropertyRep& x,
61 Boolean propagateQualifiers)
62 :
63 Sharable(),
64 _name(x._name),
65 _value(x._value),
66 _arraySize(x._arraySize),
67 _referenceClassName(x._referenceClassName),
68 _classOrigin(x._classOrigin),
69 _propagated(x._propagated)
70 {
71 if (propagateQualifiers)
72 x._qualifiers.cloneTo(_qualifiers);
73 }
74
|
75 mike 1.13 CIMPropertyRep::CIMPropertyRep(
|
76 kumpf 1.30 const CIMName& name,
|
77 mike 1.13 const CIMValue& value,
78 Uint32 arraySize,
|
79 kumpf 1.30 const CIMName& referenceClassName,
80 const CIMName& classOrigin,
|
81 chip 1.48 Boolean propagated)
|
82 mike 1.17 :
|
83 mike 1.13 _name(name), _value(value), _arraySize(arraySize),
84 _referenceClassName(referenceClassName), _classOrigin(classOrigin),
85 _propagated(propagated)
86 {
|
87 chip 1.48 // ensure name is not null
88 if(name.isNull())
89 {
90 throw UninitializedObjectException();
91 }
92
93 if((arraySize != 0) && (!value.isArray() || value.getArraySize() != arraySize))
94 {
|
95 kumpf 1.38 throw TypeMismatchException();
|
96 chip 1.48 }
|
97 mike 1.13
|
98 kumpf 1.49 // A CIM Property may not be of reference array type
99 if (value.isArray() && (value.getType() == CIMTYPE_REFERENCE))
100 {
101 throw TypeMismatchException();
102 }
103
|
104 chip 1.48 // if referenceClassName exists, must be CIMType REFERENCE.
|
105 kumpf 1.30 if (!referenceClassName.isNull())
|
106 mike 1.13 {
|
107 kumpf 1.30 if (_value.getType() != CIMTYPE_REFERENCE)
|
108 chip 1.48 {
|
109 kumpf 1.38 throw TypeMismatchException();
|
110 chip 1.48 }
|
111 kumpf 1.30 }
|
112 kumpf 1.41
113 // Can a property be of reference type with a null referenceClassName?
114 // The DMTF says yes if it is a property of an instance; no if it is a
115 // property of a class. We'll allow it here, but check in the CIMClass
116 // addProperty() method.
|
117 mike 1.13 }
118
119 CIMPropertyRep::~CIMPropertyRep()
120 {
121 }
122
|
123 kumpf 1.30 void CIMPropertyRep::setName(const CIMName& name)
|
124 mike 1.13 {
|
125 chip 1.48 // ensure name is not null
126 if(name.isNull())
127 {
128 throw UninitializedObjectException();
129 }
130
|
131 mike 1.13 _name = name;
132 }
133
|
134 kumpf 1.30 void CIMPropertyRep::setClassOrigin(const CIMName& classOrigin)
|
135 mike 1.13 {
136 _classOrigin = classOrigin;
137 }
138
139 void CIMPropertyRep::resolve(
140 DeclContext* declContext,
|
141 kumpf 1.30 const CIMNamespaceName& nameSpace,
|
142 mike 1.13 Boolean isInstancePart,
|
143 mike 1.17 const CIMConstProperty& inheritedProperty,
144 Boolean propagateQualifiers)
|
145 mike 1.13 {
|
146 kumpf 1.32 PEGASUS_ASSERT(!inheritedProperty.isUninitialized());
|
147 mike 1.13
148 // Check the type:
149
150 if (!inheritedProperty.getValue().typeCompatible(_value))
|
151 dave.sudlik 1.47 {
152 if (!(
153 (inheritedProperty.getValue().getType() == CIMTYPE_OBJECT) &&
154 (_value.getType() == CIMTYPE_STRING) &&
155 (_qualifiers.find(CIMName("EmbeddedObject")) != PEG_NOT_FOUND) &&
156 (inheritedProperty.getValue().isArray() == _value.isArray())
|
157 a.dunfey 1.53 #ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT
158 ) &&
159 !(
160 (inheritedProperty.getValue().getType() == CIMTYPE_INSTANCE) &&
161 (_value.getType() == CIMTYPE_STRING) &&
162 (_qualifiers.find(CIMName("EmbeddedInstance")) != PEG_NOT_FOUND) &&
163 (inheritedProperty.getValue().isArray() == _value.isArray())
164 #endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT
|
165 dave.sudlik 1.47 ))
166 {
167 throw TypeMismatchException();
168 }
169 }
|
170 mike 1.13
171 // Validate the qualifiers of the property (according to
172 // superClass's property with the same name). This method
173 // will throw an exception if the validation fails.
174
|
175 kumpf 1.35 CIMScope scope = CIMScope::PROPERTY;
|
176 mike 1.13
|
177 kumpf 1.29 if (_value.getType() == CIMTYPE_REFERENCE)
|
178 a.dunfey 1.53 scope = CIMScope::REFERENCE;
|
179 mike 1.13
|
180 a.dunfey 1.42 // Test the reference class name against the inherited property
|
181 a.dunfey 1.53 #ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT
182 Boolean isEmbeddedInst = (_value.getType() == CIMTYPE_INSTANCE);
183 if (_value.getType() == CIMTYPE_REFERENCE || isEmbeddedInst)
184 {
185 CIMName inheritedClassName;
186 Array<CIMName> classNames;
187 if(isEmbeddedInst)
|
188 a.dunfey 1.43 {
|
189 a.dunfey 1.53 Uint32 pos = inheritedProperty.findQualifier("EmbeddedInstance");
190 if(pos != PEG_NOT_FOUND)
|
191 a.dunfey 1.43 {
|
192 a.dunfey 1.53 String qualStr;
193 inheritedProperty.getQualifier(pos).getValue().get(qualStr);
194 inheritedClassName = qualStr;
195 }
196
197 if(_value.isArray())
198 {
199 Array<CIMInstance> embeddedInstances;
200 _value.get(embeddedInstances);
201 for(Uint32 i = 0, n = embeddedInstances.size(); i < n; ++i)
|
202 a.dunfey 1.43 {
|
203 a.dunfey 1.53 classNames.append(embeddedInstances[i].getClassName());
|
204 a.dunfey 1.43 }
|
205 a.dunfey 1.53 }
206 else
207 {
208 CIMInstance embeddedInst;
209 _value.get(embeddedInst);
210 classNames.append(embeddedInst.getClassName());
|
211 a.dunfey 1.43 }
212 }
|
213 a.dunfey 1.53 else
|
214 a.dunfey 1.43 {
|
215 a.dunfey 1.53 inheritedClassName = inheritedProperty.getReferenceClassName();
216 classNames.append(_referenceClassName);
|
217 a.dunfey 1.43 }
|
218 a.dunfey 1.42
|
219 a.dunfey 1.53 // This algorithm is friendly to arrays of embedded instances. It
220 // remembers the class names that are found to be subclasses of the
221 // inherited class name retrieved from the inherited property. This
222 // ensures that any branch in the inheritance hierarchy will only be
223 // traversed once. This provides significant optimization given that
224 // most elements of an array of embedded instances will probably be of
225 // very closely related types.
226 Array<CIMName> successTree;
227 successTree.append(inheritedClassName);
228 for(Uint32 i = 0, n = classNames.size(); i < n; ++i)
|
229 a.dunfey 1.43 {
|
230 a.dunfey 1.53 Array<CIMName> traversalHistory;
231 CIMName currentName = classNames[i];
232 Boolean found = false;
233 while(!found && !currentName.isNull())
|
234 a.dunfey 1.43 {
|
235 a.dunfey 1.53 for(Uint32 j = 0, m = successTree.size(); j < m; ++j)
|
236 a.dunfey 1.43 {
|
237 a.dunfey 1.53 if(currentName == successTree[j])
238 {
239 found = true;
240 break;
241 }
|
242 a.dunfey 1.43 }
243
|
244 a.dunfey 1.53 if(!found)
245 {
246 traversalHistory.append(currentName);
247 CIMClass currentClass = declContext->lookupClass(
248 nameSpace, currentName);
249 if(currentClass.isUninitialized())
250 {
251 throw PEGASUS_CIM_EXCEPTION(
252 CIM_ERR_NOT_FOUND, currentName.getString());
253 }
254 currentName = currentClass.getSuperClassName();
255 }
|
256 a.dunfey 1.43 }
|
257 a.dunfey 1.53
258 if(!found)
259 {
260 throw TypeMismatchException();
261 }
262
263 successTree.appendArray(traversalHistory);
|
264 a.dunfey 1.43 }
|
265 kumpf 1.41 }
|
266 a.dunfey 1.53 #endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT
|
267 kumpf 1.41
|
268 mike 1.13 _qualifiers.resolve(
|
269 a.dunfey 1.53 declContext, nameSpace, scope, isInstancePart,
270 inheritedProperty._rep->_qualifiers, propagateQualifiers);
|
271 mike 1.13
272 _classOrigin = inheritedProperty.getClassOrigin();
273 }
274
275 void CIMPropertyRep::resolve(
276 DeclContext* declContext,
|
277 kumpf 1.30 const CIMNamespaceName& nameSpace,
|
278 mike 1.17 Boolean isInstancePart,
|
279 kumpf 1.28 Boolean propagateQualifiers)
|
280 mike 1.13 {
281 CIMQualifierList dummy;
282
|
283 kumpf 1.35 CIMScope scope = CIMScope::PROPERTY;
|
284 mike 1.13
|
285 kumpf 1.29 if (_value.getType() == CIMTYPE_REFERENCE)
|
286 a.dunfey 1.53 scope = CIMScope::REFERENCE;
|
287 mike 1.13
288 _qualifiers.resolve(
|
289 a.dunfey 1.53 declContext,
290 nameSpace,
291 scope,
292 isInstancePart,
293 dummy,
294 propagateQualifiers);
|
295 mike 1.13 }
296
297 static const char* _toString(Boolean x)
298 {
299 return x ? "true" : "false";
300 }
301
|
302 mike 1.50 void CIMPropertyRep::toXml(Buffer& out) const
|
303 mike 1.13 {
304 if (_value.isArray())
305 {
|
306 mike 1.51 out << STRLIT("<PROPERTY.ARRAY NAME=\"") << _name << STRLIT("\" ");
|
307 mike 1.13
|
308 chip 1.48 // If the property array type is CIMObject, then
|
309 dave.sudlik 1.47 // encode the property in CIM-XML as a string array with the EMBEDDEDOBJECT attribute
310 // (there is not currently a CIM-XML "object" datatype)
311 // else
312 // output the real type
313 if (_value.getType() == CIMTYPE_OBJECT)
314 {
315 Array<CIMObject> a;
316 _value.get(a);
|
317 mike 1.51 out << STRLIT(" TYPE=\"string\"");
|
318 dave.sudlik 1.47 // If the Embedded Object is an instance, always add the EMBEDDEDOBJECT attribute.
319 if (a.size() > 0 && a[0].isInstance())
|
320 mike 1.51 out << STRLIT(" EMBEDDEDOBJECT=\"object\"");
|
321 dave.sudlik 1.47 // Else the Embedded Object is a class, always add the EmbeddedObject qualifier.
322 // Note that if the macro PEGASUS_SNIA_INTEROP_COMPATIBILITY is defined, then
323 // the EmbeddedObject qualifier will always be added, whether it's a class or
324 // an instance.
325 #ifndef PEGASUS_SNIA_INTEROP_COMPATIBILITY
326 else
327 {
328 #endif
329 if (_qualifiers.find(CIMName("EmbeddedObject")) == PEG_NOT_FOUND)
330 {
331 // Note that _qualifiers is not defined as const, and neither is add(),
332 // but this method toXml() *is* const. However, in this case we really
333 // do want to add the EmbeddedObject qualifier, so we cast away the
334 // implied const-ness of _qualifiers.
|
335 a.dunfey 1.53 CIMQualifierList * tmpQualifiers =
336 const_cast<CIMQualifierList *>(&_qualifiers);
337 tmpQualifiers->add(
338 CIMQualifier(CIMName("EmbeddedObject"), true));
|
339 dave.sudlik 1.47 }
340 #ifndef PEGASUS_SNIA_INTEROP_COMPATIBILITY
341 }
342 #endif
343 }
|
344 a.dunfey 1.53 #ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT
345 // If the property array type is CIMInstance, then
346 // encode the property in CIM-XML as a string array with the
347 // EMBEDDEDOBJECT attribute (there is not currently a CIM-XML "instance"
348 // datatype)
349 // else
350 // output the real type
351 else if(_value.getType() == CIMTYPE_INSTANCE)
352 {
353 Array<CIMInstance> a;
354 _value.get(a);
355 out << " TYPE=\"string\"";
356 // add the EMBEDDEDOBJECT attribute
357 if (a.size() > 0)
358 {
359 out << " EMBEDDEDOBJECT=\"instance\"";
360 // Note that if the macro PEGASUS_SNIA_INTEROP_COMPATIBILITY is defined,
361 // then the EmbeddedInstance qualifier will be added
362 #ifdef PEGASUS_SNIA_INTEROP_COMPATIBILITY
363 if (_qualifiers.find(CIMName("EmbeddedInstance")) == PEG_NOT_FOUND)
364 {
365 a.dunfey 1.53 // Note that _qualifiers is not defined as const, and neither isadd(),
366 // but this method toXml() *is* const. However, in this case we really
367 // do want to add the EmbeddedObject qualifier, so we cast away the
368 // implied const-ness of _qualifiers.
369
370 // For now, we assume that all the embedded instances in the
371 // array are of the same type
372 CIMQualifierList * tmpQualifiers =
373 const_cast<CIMQualifierList *>(&_qualifiers);
374 tmpQualifiers->add(CIMQualifier(
375 CIMName("EmbeddedInstance"),
376 a[0].getClassName().getString()));
377 }
378 #endif
379 }
380 }
381 #endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT
|
382 dave.sudlik 1.47 else
383 {
|
384 mike 1.51 out << STRLIT(" TYPE=\"") << cimTypeToString(_value.getType ());
385 out.append('"');
|
386 dave.sudlik 1.47 }
|
387 mike 1.13
|
388 dave.sudlik 1.47 if (_arraySize)
|
389 mike 1.13 {
390 char buffer[32];
391 sprintf(buffer, "%d", _arraySize);
|
392 mike 1.51 out << STRLIT(" ARRAYSIZE=\"") << buffer;
393 out.append('"');
|
394 mike 1.13 }
395
|
396 kumpf 1.30 if (!_classOrigin.isNull())
|
397 mike 1.51 {
398 out << STRLIT(" CLASSORIGIN=\"") << _classOrigin;
399 out.append('"');
400 }
|
401 mike 1.13
402 if (_propagated != false)
|
403 mike 1.51 {
404 out << STRLIT(" PROPAGATED=\"") << _toString(_propagated);
405 out.append('"');
406 }
|
407 mike 1.13
|
408 mike 1.51 out << STRLIT(">\n");
|
409 mike 1.13
410 _qualifiers.toXml(out);
411
|
412 kumpf 1.23 XmlWriter::appendValueElement(out, _value);
|
413 mike 1.13
|
414 mike 1.51 out << STRLIT("</PROPERTY.ARRAY>\n");
|
415 mike 1.13 }
|
416 kumpf 1.29 else if (_value.getType() == CIMTYPE_REFERENCE)
|
417 mike 1.13 {
|
418 mike 1.51 out << STRLIT("<PROPERTY.REFERENCE");
|
419 mike 1.13
|
420 mike 1.51 out << STRLIT(" NAME=\"") << _name << STRLIT("\" ");
|
421 mike 1.13
|
422 kumpf 1.41 if (!_referenceClassName.isNull())
423 {
|
424 mike 1.51 out << STRLIT(" REFERENCECLASS=\"") << _referenceClassName;
425 out.append('"');
|
426 kumpf 1.41 }
|
427 mike 1.13
|
428 kumpf 1.30 if (!_classOrigin.isNull())
|
429 mike 1.51 {
430 out << STRLIT(" CLASSORIGIN=\"") << _classOrigin;
431 out.append('"');
432 }
|
433 mike 1.13
434 if (_propagated != false)
|
435 mike 1.51 {
436 out << STRLIT(" PROPAGATED=\"") << _toString(_propagated);
437 out.append('"');
438 }
|
439 mike 1.13
|
440 mike 1.51 out << STRLIT(">\n");
|
441 mike 1.13
442 _qualifiers.toXml(out);
|
443 chip 1.48
|
444 kumpf 1.23 XmlWriter::appendValueElement(out, _value);
|
445 mike 1.13
|
446 mike 1.51 out << STRLIT("</PROPERTY.REFERENCE>\n");
|
447 mike 1.13 }
448 else
449 {
|
450 mike 1.51 out << STRLIT("<PROPERTY NAME=\"") << _name << STRLIT("\" ");
|
451 mike 1.13
|
452 kumpf 1.30 if (!_classOrigin.isNull())
|
453 mike 1.51 {
454 out << STRLIT(" CLASSORIGIN=\"") << _classOrigin;
455 out.append('"');
456 }
|
457 mike 1.13
458 if (_propagated != false)
|
459 mike 1.51 {
460 out << STRLIT(" PROPAGATED=\"") << _toString(_propagated);
461 out.append('"');
462 }
|
463 mike 1.13
|
464 chip 1.48 // If the property type is CIMObject, then
|
465 dave.sudlik 1.47 // encode the property in CIM-XML as a string with the EMBEDDEDOBJECT attribute
466 // (there is not currently a CIM-XML "object" datatype)
467 // else
468 // output the real type
469 if (_value.getType() == CIMTYPE_OBJECT)
470 {
471 CIMObject a;
472 _value.get(a);
|
473 mike 1.51 out << STRLIT(" TYPE=\"string\"");
|
474 dave.sudlik 1.47 // If the Embedded Object is an instance, always add the EMBEDDEDOBJECT attribute.
475 if (a.isInstance())
|
476 mike 1.51 out << STRLIT(" EMBEDDEDOBJECT=\"object\"");
|
477 dave.sudlik 1.47 // Else the Embedded Object is a class, always add the EmbeddedObject qualifier.
478 // Note that if the macro PEGASUS_SNIA_INTEROP_COMPATIBILITY is defined, then
479 // the EmbeddedObject qualifier will always be added, whether it's a class or
480 // an instance.
481 #ifndef PEGASUS_SNIA_INTEROP_COMPATIBILITY
482 else
483 {
484 #endif
485 if (_qualifiers.find(CIMName("EmbeddedObject")) == PEG_NOT_FOUND)
486 {
487 // Note that _qualifiers is not defined as const, and neither is add(),
488 // but this method toXml() *is* const. However, in this case we really
489 // do want to add the EmbeddedObject qualifier, so we cast away the
490 // implied const-ness of _qualifiers.
|
491 a.dunfey 1.53 CIMQualifierList * tmpQualifiers =
492 const_cast<CIMQualifierList *>(&_qualifiers);
493 tmpQualifiers->add(
494 CIMQualifier(CIMName("EmbeddedObject"), true));
|
495 dave.sudlik 1.47 }
496 #ifndef PEGASUS_SNIA_INTEROP_COMPATIBILITY
497 }
498 #endif
499 }
|
500 a.dunfey 1.53 #ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT
501 else if (_value.getType() == CIMTYPE_INSTANCE)
502 {
503 CIMInstance a;
504 _value.get(a);
505 out << " TYPE=\"string\"";
506 out << " EMBEDDEDOBJECT=\"instance\"";
507
508 #ifdef PEGASUS_SNIA_INTEROP_COMPATIBILITY
509 if (_qualifiers.find(CIMName("EmbeddedObject")) == PEG_NOT_FOUND)
510 {
511 // Note that _qualifiers is not defined as const, and neither is add(),
512 // but this method toXml() *is* const. However, in this case we really
513 // do want to add the EmbeddedObject qualifier, so we cast away the
514 // implied const-ness of _qualifiers.
515 CIMQualifierList * tmpQualifiers =
516 const_cast<CIMQualifierList *>(&_qualifiers);
517 tmpQualifiers->add(
518 CIMQualifier(CIMName("EmbeddedInstance"),
519 a.getClassName.getString()));
520 }
521 a.dunfey 1.53 #endif
522 }
523 #endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT
|
524 dave.sudlik 1.47 else
525 {
|
526 mike 1.51 out << STRLIT(" TYPE=\"") << cimTypeToString(_value.getType());
527 out.append('"');
|
528 dave.sudlik 1.47 }
|
529 mike 1.13
|
530 mike 1.51 out << STRLIT(">\n");
|
531 mike 1.13
532 _qualifiers.toXml(out);
|
533 chip 1.48
|
534 kumpf 1.23 XmlWriter::appendValueElement(out, _value);
|
535 mike 1.13
|
536 mike 1.51 out << STRLIT("</PROPERTY>\n");
|
537 mike 1.13 }
538 }
539
|
540 mike 1.14 /** toMof - returns the MOF for the CIM Property Object in the parameter.
|
541 karl 1.54 The MOF for property declaration in a class and value presentation in
542 an instance are different.
543
544 The BNF for the property Declaration MOF is:
|
545 mike 1.14 <pre>
546 propertyDeclaration = [ qualifierList ] dataType propertyName
547 [ array ] [ defaultValue ] ";"
|
548 chip 1.48
|
549 mike 1.14 array = "[" [positiveDecimalValue] "]"
|
550 chip 1.48
|
551 mike 1.14 defaultValue = "=" initializer
552 </pre>
553 Format with qualifiers on one line and declaration on another. Start
554 with newline but none at the end.
|
555 karl 1.54
556 Note that instances have a different format that propertyDeclarations:
557 instanceDeclaration = [ qualifiersList ] INSTANCE OF className | alias
558 "["valueInitializer "]" ";"
559 valueInitializer = [ qualifierList ] [ propertyName | referenceName ] "="
560 initializer ";"
|
561 mike 1.14 */
|
562 karl 1.54 void CIMPropertyRep::toMof(Boolean isDeclaration, Buffer& out) const
|
563 mike 1.14 {
564 //Output the qualifier list
565 if (_qualifiers.getCount())
|
566 mike 1.51 out.append('\n');
|
567 mike 1.14 _qualifiers.toMof(out);
568
569 // Output the Type and name on a new line
|
570 karl 1.54 out << '\n';
571 if (isDeclaration)
572 {
573 out << cimTypeToString(_value.getType ());
574 out.append(' ');
575 }
|
576 mike 1.51 out << _name;
|
577 mike 1.14
578 // If array put the Array indicator "[]" and possible size after name.
|
579 karl 1.54 if (isDeclaration)
|
580 mike 1.14 {
|
581 karl 1.54 if (_value.isArray())
582 {
583 if (_arraySize)
584 {
585 char buffer[32];
586 int n = sprintf(buffer, "[%d]", _arraySize);
587 out.append(buffer, n);
588 }
589 else
590 out << STRLIT("[]");
591 }
|
592 mike 1.14 }
593
594 // If the property value is not Null, add value after "="
595 if (!_value.isNull())
596 {
|
597 mike 1.51 out << STRLIT(" = ");
|
598 mike 1.14 if (_value.isArray())
|
599 chip 1.48 {
|
600 mike 1.14 // Insert any property values
|
601 kumpf 1.25 MofWriter::appendValueElement(out, _value);
|
602 mike 1.14 }
|
603 kumpf 1.29 else if (_value.getType() == CIMTYPE_REFERENCE)
|
604 mike 1.14 {
|
605 kumpf 1.25 MofWriter::appendValueElement(out, _value);
|
606 mike 1.14 }
607 else
|
608 chip 1.48 {
|
609 kumpf 1.25 MofWriter::appendValueElement(out, _value);
|
610 mike 1.14 }
611 }
|
612 karl 1.54 else if (!isDeclaration)
613 out << STRLIT(" = NULL");
614
|
615 mike 1.14 // Close the property MOF
|
616 mike 1.51 out.append(';');
|
617 mike 1.14
618 }
619
|
620 mike 1.13 Boolean CIMPropertyRep::identical(const CIMPropertyRep* x) const
621 {
|
622 kumpf 1.39 if (!_name.equal (x->_name))
|
623 mike 1.13 return false;
624
625 if (_value != x->_value)
626 return false;
627
|
628 kumpf 1.39 if (!_referenceClassName.equal (x->_referenceClassName))
|
629 mike 1.13 return false;
630
631 if (!_qualifiers.identical(x->_qualifiers))
632 return false;
633
|
634 kumpf 1.39 if (!_classOrigin.equal (x->_classOrigin))
|
635 mike 1.13 return false;
636
637 if (_propagated != x->_propagated)
638 return false;
639
640 return true;
641 }
642
643 void CIMPropertyRep::setValue(const CIMValue& value)
644 {
645 // CIMType of value is immutable:
646
647 if (!value.typeCompatible(_value))
|
648 kumpf 1.38 throw TypeMismatchException();
|
649 mike 1.13
650 if (_arraySize && _arraySize != value.getArraySize())
|
651 kumpf 1.38 throw TypeMismatchException();
|
652 mike 1.13
|
653 kumpf 1.49 // A CIM Property may not be of reference array type
654 if (value.isArray() && (value.getType() == CIMTYPE_REFERENCE))
655 {
656 throw TypeMismatchException();
657 }
658
|
659 mike 1.13 _value = value;
660 }
661
662 PEGASUS_NAMESPACE_END
|