version 1.63, 2008/02/29 18:55:06
|
version 1.64, 2008/03/05 21:31:45
|
|
|
#include "CIMPropertyRep.h" | #include "CIMPropertyRep.h" |
#include "CIMName.h" | #include "CIMName.h" |
#include "CIMScope.h" | #include "CIMScope.h" |
#include "XmlWriter.h" |
|
#include "MofWriter.h" |
|
#include "DeclContext.h" | #include "DeclContext.h" |
#include "StrLit.h" | #include "StrLit.h" |
| |
|
|
propagateQualifiers); | propagateQualifiers); |
} | } |
| |
static const char* _toString(Boolean x) |
|
{ |
|
return x ? "true" : "false"; |
|
} |
|
|
|
void CIMPropertyRep::toXml(Buffer& out) const |
|
{ |
|
if (_value.isArray()) |
|
{ |
|
out << STRLIT("<PROPERTY.ARRAY NAME=\"") << _name << STRLIT("\" "); |
|
|
|
if (_value.getType() == CIMTYPE_OBJECT) |
|
{ |
|
// If the property array type is CIMObject, then |
|
// encode the property in CIM-XML as a string array with the |
|
// EmbeddedObject attribute (there is not currently a CIM-XML |
|
// "object" datatype) |
|
|
|
Array<CIMObject> a; |
|
_value.get(a); |
|
out << STRLIT(" TYPE=\"string\""); |
|
// If the Embedded Object is an instance, always add the |
|
// EmbeddedObject attribute. |
|
if (a.size() > 0 && a[0].isInstance()) |
|
{ |
|
out << STRLIT(" EmbeddedObject=\"object\""); |
|
out << STRLIT(" EMBEDDEDOBJECT=\"object\""); |
|
} |
|
#ifndef PEGASUS_SNIA_INTEROP_COMPATIBILITY |
|
else |
|
{ |
|
#endif |
|
// Else the Embedded Object is a class, always add the |
|
// EmbeddedObject qualifier. Note that if the macro |
|
// PEGASUS_SNIA_INTEROP_COMPATIBILITY is defined, then |
|
// the EmbeddedObject qualifier will always be added, |
|
// whether it's a class or an instance. |
|
if (_qualifiers.find(CIMName("EmbeddedObject")) == |
|
PEG_NOT_FOUND) |
|
{ |
|
// Note that _qualifiers is not defined as const, and |
|
// neither is add(), but this method toXml() *is* const. |
|
// However, in this case we really do want to add the |
|
// EmbeddedObject qualifier, so we cast away the implied |
|
// const-ness of _qualifiers. |
|
CIMQualifierList * tmpQualifiers = |
|
const_cast<CIMQualifierList *>(&_qualifiers); |
|
tmpQualifiers->add( |
|
CIMQualifier(CIMName("EmbeddedObject"), true)); |
|
} |
|
#ifndef PEGASUS_SNIA_INTEROP_COMPATIBILITY |
|
} |
|
#endif |
|
} |
|
#ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT |
|
else if (_value.getType() == CIMTYPE_INSTANCE) |
|
{ |
|
// If the property array type is CIMInstance, then |
|
// encode the property in CIM-XML as a string array with the |
|
// EmbeddedObject attribute (there is not currently a CIM-XML |
|
// "instance" datatype) |
|
|
|
Array<CIMInstance> a; |
|
_value.get(a); |
|
out << STRLIT(" TYPE=\"string\""); |
|
|
|
// add the EmbeddedObject attribute |
|
if (a.size() > 0) |
|
{ |
|
out << STRLIT(" EmbeddedObject=\"instance\""); |
|
out << STRLIT(" EMBEDDEDOBJECT=\"instance\""); |
|
|
|
// Note that if the macro PEGASUS_SNIA_INTEROP_COMPATIBILITY is |
|
// defined, then the EmbeddedInstance qualifier will be added |
|
#ifdef PEGASUS_SNIA_INTEROP_COMPATIBILITY |
|
if (_qualifiers.find(CIMName("EmbeddedInstance")) == |
|
PEG_NOT_FOUND) |
|
{ |
|
// Note that _qualifiers is not defined as const, and |
|
// neither is add(), but this method toXml() *is* const. |
|
// However, in this case we really do want to add the |
|
// EmbeddedObject qualifier, so we cast away the implied |
|
// const-ness of _qualifiers. |
|
|
|
// For now, we assume that all the embedded instances in |
|
// the array are of the same type |
|
CIMQualifierList * tmpQualifiers = |
|
const_cast<CIMQualifierList *>(&_qualifiers); |
|
tmpQualifiers->add(CIMQualifier( |
|
CIMName("EmbeddedInstance"), |
|
a[0].getClassName().getString())); |
|
} |
|
#endif |
|
} |
|
} |
|
#endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT |
|
else |
|
{ |
|
out << STRLIT(" TYPE=\"") << cimTypeToString(_value.getType ()); |
|
out.append('"'); |
|
} |
|
|
|
if (_arraySize) |
|
{ |
|
char buffer[32]; |
|
sprintf(buffer, "%d", _arraySize); |
|
out << STRLIT(" ARRAYSIZE=\"") << buffer; |
|
out.append('"'); |
|
} |
|
|
|
if (!_classOrigin.isNull()) |
|
{ |
|
out << STRLIT(" CLASSORIGIN=\"") << _classOrigin; |
|
out.append('"'); |
|
} |
|
|
|
if (_propagated != false) |
|
{ |
|
out << STRLIT(" PROPAGATED=\"") << _toString(_propagated); |
|
out.append('"'); |
|
} |
|
|
|
out << STRLIT(">\n"); |
|
|
|
_qualifiers.toXml(out); |
|
|
|
XmlWriter::appendValueElement(out, _value); |
|
|
|
out << STRLIT("</PROPERTY.ARRAY>\n"); |
|
} |
|
else if (_value.getType() == CIMTYPE_REFERENCE) |
|
{ |
|
out << STRLIT("<PROPERTY.REFERENCE"); |
|
|
|
out << STRLIT(" NAME=\"") << _name << STRLIT("\" "); |
|
|
|
if (!_referenceClassName.isNull()) |
|
{ |
|
out << STRLIT(" REFERENCECLASS=\"") << _referenceClassName; |
|
out.append('"'); |
|
} |
|
|
|
if (!_classOrigin.isNull()) |
|
{ |
|
out << STRLIT(" CLASSORIGIN=\"") << _classOrigin; |
|
out.append('"'); |
|
} |
|
|
|
if (_propagated != false) |
|
{ |
|
out << STRLIT(" PROPAGATED=\"") << _toString(_propagated); |
|
out.append('"'); |
|
} |
|
|
|
out << STRLIT(">\n"); |
|
|
|
_qualifiers.toXml(out); |
|
|
|
XmlWriter::appendValueElement(out, _value); |
|
|
|
out << STRLIT("</PROPERTY.REFERENCE>\n"); |
|
} |
|
else |
|
{ |
|
out << STRLIT("<PROPERTY NAME=\"") << _name << STRLIT("\" "); |
|
|
|
if (!_classOrigin.isNull()) |
|
{ |
|
out << STRLIT(" CLASSORIGIN=\"") << _classOrigin; |
|
out.append('"'); |
|
} |
|
|
|
if (_propagated != false) |
|
{ |
|
out << STRLIT(" PROPAGATED=\"") << _toString(_propagated); |
|
out.append('"'); |
|
} |
|
|
|
if (_value.getType() == CIMTYPE_OBJECT) |
|
{ |
|
// If the property type is CIMObject, then |
|
// encode the property in CIM-XML as a string with the |
|
// EmbeddedObject attribute (there is not currently a CIM-XML |
|
// "object" datatype) |
|
|
|
CIMObject a; |
|
_value.get(a); |
|
out << STRLIT(" TYPE=\"string\""); |
|
|
|
// If the Embedded Object is an instance, always add the |
|
// EmbeddedObject attribute. |
|
if (a.isInstance()) |
|
{ |
|
out << STRLIT(" EmbeddedObject=\"object\""); |
|
out << STRLIT(" EMBEDDEDOBJECT=\"object\""); |
|
} |
|
// Else the Embedded Object is a class, always add the |
|
// EmbeddedObject qualifier. |
|
#ifndef PEGASUS_SNIA_INTEROP_COMPATIBILITY |
|
else |
|
{ |
|
#endif |
|
// Note that if the macro PEGASUS_SNIA_INTEROP_COMPATIBILITY |
|
// is defined, then the EmbeddedObject qualifier will always |
|
// be added, whether it's a class or an instance. |
|
if (_qualifiers.find(CIMName("EmbeddedObject")) == |
|
PEG_NOT_FOUND) |
|
{ |
|
// Note that _qualifiers is not defined as const, and |
|
// neither is add(), but this method toXml() *is* const. |
|
// However, in this case we really do want to add the |
|
// EmbeddedObject qualifier, so we cast away the implied |
|
// const-ness of _qualifiers. |
|
CIMQualifierList * tmpQualifiers = |
|
const_cast<CIMQualifierList *>(&_qualifiers); |
|
tmpQualifiers->add( |
|
CIMQualifier(CIMName("EmbeddedObject"), true)); |
|
} |
|
#ifndef PEGASUS_SNIA_INTEROP_COMPATIBILITY |
|
} |
|
#endif |
|
} |
|
#ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT |
|
else if (_value.getType() == CIMTYPE_INSTANCE) |
|
{ |
|
CIMInstance a; |
|
_value.get(a); |
|
out << " TYPE=\"string\""; |
|
out << " EmbeddedObject=\"instance\""; |
|
out << " EMBEDDEDOBJECT=\"instance\""; |
|
|
|
#ifdef PEGASUS_SNIA_INTEROP_COMPATIBILITY |
|
if (_qualifiers.find(CIMName("EmbeddedObject")) == PEG_NOT_FOUND) |
|
{ |
|
// Note that _qualifiers is not defined as const, and neither |
|
// is add(), but this method toXml() *is* const. However, in |
|
// this case we really do want to add the EmbeddedObject |
|
// qualifier, so we cast away the implied const-ness of |
|
// _qualifiers. |
|
CIMQualifierList * tmpQualifiers = |
|
const_cast<CIMQualifierList *>(&_qualifiers); |
|
tmpQualifiers->add( |
|
CIMQualifier(CIMName("EmbeddedInstance"), |
|
a.getClassName.getString())); |
|
} |
|
#endif |
|
} |
|
#endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT |
|
else |
|
{ |
|
out << STRLIT(" TYPE=\"") << cimTypeToString(_value.getType()); |
|
out.append('"'); |
|
} |
|
|
|
out << STRLIT(">\n"); |
|
|
|
_qualifiers.toXml(out); |
|
|
|
XmlWriter::appendValueElement(out, _value); |
|
|
|
out << STRLIT("</PROPERTY>\n"); |
|
} |
|
} |
|
|
|
/** toMof - returns the MOF for the CIM Property Object in the parameter. |
|
The MOF for property declaration in a class and value presentation in |
|
an instance are different. |
|
|
|
The BNF for the property Declaration MOF is: |
|
<pre> |
|
propertyDeclaration = [ qualifierList ] dataType propertyName |
|
[ array ] [ defaultValue ] ";" |
|
|
|
array = "[" [positiveDecimalValue] "]" |
|
|
|
defaultValue = "=" initializer |
|
</pre> |
|
Format with qualifiers on one line and declaration on another. Start |
|
with newline but none at the end. |
|
|
|
Note that instances have a different format that propertyDeclarations: |
|
instanceDeclaration = [ qualifiersList ] INSTANCE OF className | alias |
|
"["valueInitializer "]" ";" |
|
valueInitializer = [ qualifierList ] [ propertyName | referenceName ] "=" |
|
initializer ";" |
|
*/ |
|
void CIMPropertyRep::toMof(Boolean isDeclaration, Buffer& out) const |
|
{ |
|
//Output the qualifier list |
|
if (_qualifiers.getCount()) |
|
out.append('\n'); |
|
_qualifiers.toMof(out); |
|
|
|
// Output the Type and name on a new line |
|
out << '\n'; |
|
if (isDeclaration) |
|
{ |
|
out << cimTypeToString(_value.getType ()); |
|
out.append(' '); |
|
} |
|
out << _name; |
|
|
|
// If array put the Array indicator "[]" and possible size after name. |
|
if (isDeclaration) |
|
{ |
|
if (_value.isArray()) |
|
{ |
|
if (_arraySize) |
|
{ |
|
char buffer[32]; |
|
int n = sprintf(buffer, "[%d]", _arraySize); |
|
out.append(buffer, n); |
|
} |
|
else |
|
out << STRLIT("[]"); |
|
} |
|
} |
|
|
|
// If the property value is not Null, add value after "=" |
|
if (!_value.isNull()) |
|
{ |
|
out << STRLIT(" = "); |
|
if (_value.isArray()) |
|
{ |
|
// Insert any property values |
|
MofWriter::appendValueElement(out, _value); |
|
} |
|
else if (_value.getType() == CIMTYPE_REFERENCE) |
|
{ |
|
MofWriter::appendValueElement(out, _value); |
|
} |
|
else |
|
{ |
|
MofWriter::appendValueElement(out, _value); |
|
} |
|
} |
|
else if (!isDeclaration) |
|
out << STRLIT(" = NULL"); |
|
|
|
// Close the property MOF |
|
out.append(';'); |
|
|
|
} |
|
|
|
Boolean CIMPropertyRep::identical(const CIMPropertyRep* x) const | Boolean CIMPropertyRep::identical(const CIMPropertyRep* x) const |
{ | { |
// If the pointers are the same, the objects must be identical | // If the pointers are the same, the objects must be identical |