//%LICENSE//////////////////////////////////////////////////////////////// // // Licensed to The Open Group (TOG) under one or more contributor license // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with // this work for additional information regarding copyright ownership. // Each contributor licenses this file to you under the OpenPegasus Open // Source License; you may not use this file except in compliance with the // License. // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // ////////////////////////////////////////////////////////////////////////// // //%///////////////////////////////////////////////////////////////////////////// #include #include #include #include PEGASUS_NAMESPACE_BEGIN void SCMOXmlWriter::appendValueSCMOInstanceElement( Buffer& out, const SCMOInstance& scmoInstance) { out << STRLIT("\n"); appendInstanceNameElement(out, scmoInstance); appendInstanceElement(out, scmoInstance); out << STRLIT("\n"); } void SCMOXmlWriter::appendInstanceNameElement( Buffer& out, const SCMOInstance& scmoInstance) { out << STRLIT("\n"); for (Uint32 i = 0, n = scmoInstance.getKeyBindingCount(); i < n; i++) { const char * kbName; const SCMBUnion * kbValue; CIMType kbType; Uint32 kbNameLen; scmoInstance._getKeyBindingDataAtNodeIndex( i, &kbName, kbNameLen, kbType, &kbValue); out << STRLIT("\n"); if (kbType == CIMTYPE_REFERENCE) { /* TODO: NEED RESOLvE the value down to a SCMO.... CIMObjectPath ref = keyBindings[i].getValue(); appendValueReferenceElement(out, ref, true); */ } else { out << STRLIT(""); SCMOXmlWriter::appendSCMBUnion( out, *kbValue, kbType, scmoInstance.inst.base); out << STRLIT("\n"); } out << STRLIT("\n"); } out << STRLIT("\n"); } //------------------------------------------------------------------------------ // // appendInstanceElement() // // // // //------------------------------------------------------------------------------ void SCMOXmlWriter::appendInstanceElement( Buffer& out, const SCMOInstance& scmoInstance) { // Class opening element: out << STRLIT("\n"); // Append Instance Qualifiers: if (scmoInstance.inst.hdr->flags.includeQualifiers) { SCMBClass_Main *classMain=scmoInstance.inst.hdr->theClass->cls.hdr; char* clsbase = scmoInstance.inst.hdr->theClass->cls.base; SCMBQualifier *theArray = (SCMBQualifier*)&(clsbase[classMain->qualifierArray.start]); // need to iterate for (Uint32 i=0, n=classMain->numberOfQualifiers;inumberProperties;iflags.isFiltered && !scmoInstance._isPropertyInFilter(i)) { // Property is filtered, ignore and go to next continue; } else { SCMOXmlWriter::appendPropertyElement(out,scmoInstance,i); } } // Instance closing element: out << STRLIT("\n"); } //------------------------------------------------------------------------------ // // appendQualifierElement() // // // // //------------------------------------------------------------------------------ void SCMOXmlWriter::appendQualifierElement( Buffer& out, const SCMBQualifier& theQualifier, const char* base) { out << STRLIT("\n"); // append the value of the qualifier // TODO: Implement and call appendValueElement //SCMOXmlWriter::appendValueElement(out, theQualifier.value, clsbase); out << STRLIT("\n"); } //------------------------------------------------------------------------------ // // appendPropertyElement() // // // // // // // // // // //------------------------------------------------------------------------------ void SCMOXmlWriter::appendPropertyElement( Buffer& out, const SCMOInstance& scmoInstance, Uint32 pos) { // Get most of the property data from the instance const char* propertyName; Uint32 propertyNameLen; CIMType propertyType; // This is an absolute pointer at a SCMBValue SCMBValue * propertyValue; const char * propertyValueBase; // This is an absolute pointer at a SCMBValue SCMBClassProperty * propertyDef; // This is the absolute pointer at which the class info for the given // instance starts const char* clsbase = scmoInstance.inst.hdr->theClass->cls.base; SCMO_RC rc = scmoInstance.getPropertyAt( pos, &propertyValue, &propertyValueBase, &propertyDef); propertyType = propertyValue->valueType; if (propertyValue->flags.isArray) { out << STRLIT("name.start]), propertyDef->name.length-1); out << STRLIT("\" "); if (propertyType == 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 a; rep->getValue().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\"" " 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 (rep->findQualifier(PEGASUS_QUALIFIERNAME_EMBEDDEDOBJECT) == PEG_NOT_FOUND) { // Note that addQualifiers() cannot be called on a const // CIMQualifierRep.In this case we really do want to add // the EmbeddedObject qualifier, so we cast away the // constness. CIMPropertyRep* tmpRep=const_cast(rep); tmpRep->addQualifier( CIMQualifier(PEGASUS_QUALIFIERNAME_EMBEDDEDOBJECT, true)); } } */ } else if (propertyType == 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 a; rep->getValue().get(a); out << STRLIT(" TYPE=\"string\""); // add the EmbeddedObject attribute if (a.size() > 0) { out << STRLIT(" EmbeddedObject=\"instance\"" " 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 (rep->findQualifier( PEGASUS_QUALIFIERNAME_EMBEDDEDINSTANCE == PEG_NOT_FOUND) { // Note that addQualifiers() cannot be called on a const // CIMQualifierRep.In this case we really do want to add // the EmbeddedInstance qualifier, so we cast away the // constness. // For now, we assume that all the embedded instances in // the array are of the same type CIMPropertyRep* tmpRep=const_cast(rep); tmpRep->addQualifier(CIMQualifier( PEGASUS_QUALIFIERNAME_EMBEDDEDINSTANCE, a[0].getClassName().getString())); } # endif } */ } else { out.append(' '); out << xmlWriterTypeStrings(propertyType); } Uint32 arraySize=propertyValue->valueArraySize; if (0 != arraySize) { out << STRLIT(" ARRAYSIZE=\""); SCMOXmlWriter::append(out, arraySize); out.append('"'); } if (scmoInstance.inst.hdr->flags.includeClassOrigin) { if (propertyDef->originClassName.start != 0) { out << STRLIT(" CLASSORIGIN=\""); out.append( &(clsbase[propertyDef->originClassName.start]), propertyDef->originClassName.length-1); out.append('"'); } } if (propertyDef->flags.propagated) { out << STRLIT(" PROPAGATED=\"true\""); } out << STRLIT(">\n"); // Append Instance Qualifiers: if (scmoInstance.inst.hdr->flags.includeQualifiers) { SCMBQualifier * theArray= (SCMBQualifier*) &(clsbase[propertyDef->qualifierArray.start]); // need to iterate for (Uint32 i=0, n=propertyDef->numberOfQualifiers;i\n"); } else if (propertyType == CIMTYPE_REFERENCE) { /* out << STRLIT("getName() << STRLIT("\" "); if (!rep->getReferenceClassName().isNull()) { out << STRLIT(" REFERENCECLASS=\"") << rep->getReferenceClassName(); out.append('"'); } if (!rep->getClassOrigin().isNull()) { out << STRLIT(" CLASSORIGIN=\"") << rep->getClassOrigin(); out.append('"'); } if (rep->getPropagated()) { out << STRLIT(" PROPAGATED=\"true\""); } out << STRLIT(">\n"); for (Uint32 i = 0, n = rep->getQualifierCount(); i < n; i++) XmlWriter::appendQualifierElement(out, rep->getQualifier(i)); XmlWriter::appendValueElement(out, rep->getValue()); out << STRLIT("\n"); */ } else { out << STRLIT("name.start]), propertyDef->name.length-1); out << STRLIT("\" "); if (scmoInstance.inst.hdr->flags.includeClassOrigin) { if (propertyDef->originClassName.start != 0) { out << STRLIT(" CLASSORIGIN=\""); out.append( &(clsbase[propertyDef->originClassName.start]), propertyDef->originClassName.length-1); out.append('"'); } } if (propertyDef->flags.propagated) { out << STRLIT(" PROPAGATED=\"true\""); } if (propertyType == 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; rep->getValue().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\"" " 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 (rep->findQualifier(PEGASUS_QUALIFIERNAME_EMBEDDEDOBJECT) == PEG_NOT_FOUND) { // Note that addQualifiers() cannot be called on a const // CIMQualifierRep. In this case we really do want to // add the EmbeddedObject qualifier, so we cast away the // constness. CIMPropertyRep* tmpRep=const_cast(rep); tmpRep->addQualifier( CIMQualifier(PEGASUS_QUALIFIERNAME_EMBEDDEDOBJECT, true)); } } */ } else if (propertyType == CIMTYPE_INSTANCE) { /* CIMInstance a; rep->getValue().get(a); out << STRLIT(" TYPE=\"string\"" " EmbeddedObject=\"instance\"" " EMBEDDEDOBJECT=\"instance\""); # ifdef PEGASUS_SNIA_INTEROP_COMPATIBILITY if (rep->findQualifier(PEGASUS_QUALIFIERNAME_EMBEDDEDOBJECT) == PEG_NOT_FOUND) { // Note that addQualifiers() cannot be called on a const // CIMQualifierRep. In this case we really do want to add // the EmbeddedInstance qualifier, so we cast away the // constness. CIMPropertyRep* tmpRep = const_cast(rep); tmpRep->addQualifier(CIMQualifier( PEGASUS_QUALIFIERNAME_EMBEDDEDINSTANCE, a.getClassName().getString())); } # endif */ } else { out.append(' '); out << xmlWriterTypeStrings(propertyType); } out << STRLIT(">\n"); // Append Instance Qualifiers: if (scmoInstance.inst.hdr->flags.includeQualifiers) { SCMBQualifier * theArray= (SCMBQualifier*) &(clsbase[propertyDef->qualifierArray.start]); // need to iterate for (Uint32 i=0, n=propertyDef->numberOfQualifiers;i\n"); } } //------------------------------------------------------------------------------ // // appendValueElement() // // // // // // //------------------------------------------------------------------------------ void SCMOXmlWriter::appendValueElement( Buffer& out, SCMBValue & value, const char * base) { if (value.flags.isNull) { return; } if (value.flags.isArray) { appendSCMBUnionArray( out, value.value, value.valueType, value.valueArraySize, base); } else if (value.valueType == CIMTYPE_REFERENCE) { /* // Has to be separate because it uses VALUE.REFERENCE tag CIMObjectPath v; value.get(v); _xmlWritter_appendValue(out, v); */ } else { out << STRLIT(""); // Call function to write a SCMBUnion + type field appendSCMBUnion(out,value.value, value.valueType,base); out << STRLIT("\n"); } } void SCMOXmlWriter::appendSCMBUnion( Buffer& out, const SCMBUnion & u, const CIMType & valueType, const char * base) { switch (valueType) { case CIMTYPE_BOOLEAN: { SCMOXmlWriter::append(out, u.simple.val.bin); break; } case CIMTYPE_UINT8: { SCMOXmlWriter::append(out, u.simple.val.u8); break; } case CIMTYPE_SINT8: { SCMOXmlWriter::append(out, u.simple.val.s8); break; } case CIMTYPE_UINT16: { SCMOXmlWriter::append(out, u.simple.val.u16); break; } case CIMTYPE_SINT16: { SCMOXmlWriter::append(out, u.simple.val.s16); break; } case CIMTYPE_UINT32: { SCMOXmlWriter::append(out, u.simple.val.u32); break; } case CIMTYPE_SINT32: { SCMOXmlWriter::append(out, u.simple.val.s32); break; } case CIMTYPE_UINT64: { SCMOXmlWriter::append(out, u.simple.val.u64); break; } case CIMTYPE_SINT64: { SCMOXmlWriter::append(out, u.simple.val.s64); break; } case CIMTYPE_REAL32: { SCMOXmlWriter::append(out, u.simple.val.r32); break; } case CIMTYPE_REAL64: { SCMOXmlWriter::append(out, u.simple.val.r64); break; } case CIMTYPE_CHAR16: { SCMOXmlWriter::appendSpecial( out, u.simple.val.c16); break; } case CIMTYPE_STRING: { SCMOXmlWriter::appendSpecial( out, &(base[u.stringValue.start]), u.stringValue.length-1); break; } case CIMTYPE_DATETIME: { // an SCMBDateTime is a CIMDateTimeRep // this should help us to reuse existing optimized Datetime char buffer[26]; _DateTimetoCStr(&(u.dateTimeValue), buffer); // datetime value is formatted with a \0 at end, ignore out.append(buffer,sizeof(buffer)-1); break; } /* case CIMTYPE_OBJECT: { CIMObject v; value.get(v); _xmlWritter_appendValue(out, v); break; } case CIMTYPE_INSTANCE: { CIMInstance v; value.get(v); _xmlWritter_appendValue(out, v); break; } default: PEGASUS_ASSERT(false); */ } } void SCMOXmlWriter::appendSCMBUnionArray( Buffer& out, const SCMBUnion & u, const CIMType & valueType, Uint32 numElements, const char * base) { SCMBUnion* arr = (SCMBUnion*) &(base[u.arrayValue.start]); switch (valueType) { case CIMTYPE_BOOLEAN: { out << STRLIT("\n"); while (numElements--) { out << STRLIT(""); SCMOXmlWriter::append(out, arr->simple.val.bin); arr++; out << STRLIT("\n"); } out << STRLIT("\n"); break; } case CIMTYPE_UINT8: { out << STRLIT("\n"); while (numElements--) { out << STRLIT(""); SCMOXmlWriter::append(out, arr->simple.val.u8); arr++; out << STRLIT("\n"); } out << STRLIT("\n"); break; } case CIMTYPE_SINT8: { out << STRLIT("\n"); while (numElements--) { out << STRLIT(""); SCMOXmlWriter::append(out, arr->simple.val.s8); arr++; out << STRLIT("\n"); } out << STRLIT("\n"); break; } case CIMTYPE_UINT16: { out << STRLIT("\n"); while (numElements--) { out << STRLIT(""); SCMOXmlWriter::append(out, arr->simple.val.u16); arr++; out << STRLIT("\n"); } out << STRLIT("\n"); break; } case CIMTYPE_SINT16: { out << STRLIT("\n"); while (numElements--) { out << STRLIT(""); SCMOXmlWriter::append(out, arr->simple.val.s16); arr++; out << STRLIT("\n"); } out << STRLIT("\n"); break; } case CIMTYPE_UINT32: { out << STRLIT("\n"); while (numElements--) { out << STRLIT(""); SCMOXmlWriter::append(out, arr->simple.val.u32); arr++; out << STRLIT("\n"); } out << STRLIT("\n"); break; } case CIMTYPE_SINT32: { out << STRLIT("\n"); while (numElements--) { out << STRLIT(""); SCMOXmlWriter::append(out, arr->simple.val.s32); arr++; out << STRLIT("\n"); } out << STRLIT("\n"); break; } case CIMTYPE_UINT64: { out << STRLIT("\n"); while (numElements--) { out << STRLIT(""); SCMOXmlWriter::append(out, arr->simple.val.u64); arr++; out << STRLIT("\n"); } out << STRLIT("\n"); break; } case CIMTYPE_SINT64: { out << STRLIT("\n"); while (numElements--) { out << STRLIT(""); SCMOXmlWriter::append(out, arr->simple.val.s64); arr++; out << STRLIT("\n"); } out << STRLIT("\n"); break; } case CIMTYPE_REAL32: { out << STRLIT("\n"); while (numElements--) { out << STRLIT(""); SCMOXmlWriter::append(out, arr->simple.val.r32); arr++; out << STRLIT("\n"); } out << STRLIT("\n"); break; } case CIMTYPE_REAL64: { out << STRLIT("\n"); while (numElements--) { out << STRLIT(""); SCMOXmlWriter::append(out, arr->simple.val.r64); arr++; out << STRLIT("\n"); } out << STRLIT("\n"); break; } case CIMTYPE_CHAR16: { out << STRLIT("\n"); while (numElements--) { out << STRLIT(""); SCMOXmlWriter::append(out, arr->simple.val.bin); SCMOXmlWriter::appendSpecial(out, arr->simple.val.c16); arr++; out << STRLIT("\n"); } out << STRLIT("\n"); break; } case CIMTYPE_STRING: { out << STRLIT("\n"); while (numElements--) { out << STRLIT(""); SCMOXmlWriter::appendSpecial( out, &(base[arr->stringValue.start]), arr->stringValue.length-1); arr++; out << STRLIT("\n"); } out << STRLIT("\n"); break; } case CIMTYPE_DATETIME: { out << STRLIT("\n"); char buffer[26]; while (numElements--) { out << STRLIT(""); // an SCMBDateTime is a CIMDateTimeRep // this should help us to reuse existing optimized Datetime _DateTimetoCStr(&(arr->dateTimeValue), buffer); // datetime value is formatted with a \0 at end, ignore out.append(buffer,sizeof(buffer)-1); arr++; out << STRLIT("\n"); } out << STRLIT("\n"); break; } /* case CIMTYPE_OBJECT: { CIMObject v; value.get(v); _xmlWritter_appendValue(out, v); break; } case CIMTYPE_INSTANCE: { CIMInstance v; value.get(v); _xmlWritter_appendValue(out, v); break; } default: PEGASUS_ASSERT(false); */ } } PEGASUS_NAMESPACE_END