⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlreader.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//  just a Pegasus internal representation of an embedded object. However,//  this case is used when decoding string representations of embedded objects.        case CIMTYPE_OBJECT:#ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT        case CIMTYPE_INSTANCE:#endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT        {            CIMObject x;            if (*valueString == '\0')            {                return CIMValue(type, false, 0);            }            else            {                // Convert the non-NULL string to a CIMObject (containing                // either a CIMInstance or a CIMClass).                // First we need to create a new "temporary" XmlParser that is                // just the value of the Embedded Object in String                // representation.                AutoArrayPtr<char> tmp_buffer(                    new char[strlen(valueString) + 1]);                strcpy(tmp_buffer.get(), valueString);                XmlParser tmp_parser(tmp_buffer.get());                // The next bit of logic constructs a CIMObject from the                // Embedded Object String.  It is similar to the method                // XmlReader::getValueObjectElement().                CIMInstance cimInstance;                CIMClass cimClass;                if (XmlReader::getInstanceElement(tmp_parser, cimInstance))                {#ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT                    if (type == CIMTYPE_INSTANCE)                        return CIMValue(cimInstance);#endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT                    x = CIMObject(cimInstance);                }                else if (XmlReader::getClassElement(tmp_parser, cimClass))                {                    x = CIMObject(cimClass);                }                else                {#ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT                    if (type == CIMTYPE_OBJECT)                    {                        // change "element" to "embedded object"                        MessageLoaderParms mlParms(                            "Common.XmlReader."                                "EXPECTED_INSTANCE_OR_CLASS_ELEMENT",                            "Expected INSTANCE or CLASS element");                        throw XmlValidationError(lineNumber, mlParms);                    }                    else                    {                        // change "element" to "embedded object"                        MessageLoaderParms mlParms(                            "Common.XmlReader.EXPECTED_INSTANCE_ELEMENT",                            "Expected INSTANCE element");                        throw XmlValidationError(lineNumber, mlParms);                    }#else                    // change "element" to "embedded object"                    MessageLoaderParms mlParms(                        "Common.XmlReader.EXPECTED_INSTANCE_OR_CLASS_ELEMENT",                        "Expected INSTANCE or CLASS element");                    throw XmlValidationError(lineNumber, mlParms);#endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT                }                // Ok, now we can delete the storage for the temporary                // XmlParser.                tmp_buffer.reset();            }            return CIMValue(x);        }        default:            break;    }    MessageLoaderParms mlParms(        "Common.XmlReader.MALFORMED_XML",        "malformed XML");    throw XmlSemanticError(lineNumber, mlParms);    return false;}//------------------------------------------------------------------------------//// skipElement()////------------------------------------------------------------------------------void XmlReader::skipElement(    XmlParser& parser,    XmlEntry& entry){    const char * tag_name = entry.text;    if (entry.type == XmlEntry::EMPTY_TAG)    {        return;    }    while (testStartTagOrEmptyTag(parser, entry))    {        skipElement(parser, entry);    }    if (testContentOrCData(parser, entry))    {        ; // skip    }    expectEndTag(parser, tag_name);    return;}//------------------------------------------------------------------------------//// getValueElement()////     <!ELEMENT VALUE (#PCDATA)>//// Return: false if no value element.////------------------------------------------------------------------------------Boolean XmlReader::getValueElement(    XmlParser& parser,    CIMType type,    CIMValue& value){    // Get VALUE start tag: Return false if no VALUE start Tag    XmlEntry entry;    if (!testStartTagOrEmptyTag(parser, entry, "VALUE"))    {        return false;    }    Boolean empty = entry.type == XmlEntry::EMPTY_TAG;    const char* valueString = "";    if (!empty)    {        if (testContentOrCData(parser, entry))        {            valueString = entry.text;        }        expectEndTag(parser, "VALUE");    }#ifdef PEGASUS_SNIA_INTEROP_TEST    // KS 20021004 - tries to put value in even if empty.    // Think this is general problem with empty value    // Need to check meaning of (#PCDATA) - Does it allow empty.    // Bugzilla tbd    if (!empty)#endif        value = stringToValue(parser.getLine(), valueString,type);    return true;}//------------------------------------------------------------------------------//// getStringValueElement()////     <!ELEMENT VALUE (#PCDATA)>////------------------------------------------------------------------------------Boolean XmlReader::getStringValueElement(    XmlParser& parser,    String& str,    Boolean required){    XmlEntry entry;    if (!testStartTagOrEmptyTag(parser, entry, "VALUE"))    {        if (required)        {            MessageLoaderParms mlParms(                "Common.XmlReader.EXPECTED_VALUE_ELEMENT",                "Expected VALUE element");            throw XmlValidationError(parser.getLine(), mlParms);        }        return false;    }    Boolean empty = entry.type == XmlEntry::EMPTY_TAG;    const char* valueString = "";    if (!empty)    {        if (testContentOrCData(parser, entry))            valueString = entry.text;        expectEndTag(parser, "VALUE");    }    str = String(valueString);    return true;}//----------------------------------------------------------------------------//// getPropertyValue//     Use: Decode property value from SetProperty request and//     GetProperty response.////     PropertyValue is one of://////      <!ELEMENT VALUE.ARRAY (VALUE*)>////      <!ELEMENT VALUE.REFERENCE (CLASSPATH|LOCALCLASSPATH|CLASSNAME|//         <!ELEMENT VALUE.ARRAY (VALUE*)>////         <!ELEMENT VALUE.REFERENCE (CLASSPATH|LOCALCLASSPATH|CLASSNAME|//                           INSTANCEPATH|LOCALINSTANCEPATH|INSTANCENAME)>////         <!ELEMENT VALUE.REFARRAY (VALUE.REFERENCE*)>////----------------------------------------------------------------------------Boolean XmlReader::getPropertyValue(    XmlParser& parser,    CIMValue& cimValue){    // Can not test for value type, so assume String    const CIMType type = CIMTYPE_STRING;    // Test for VALUE element    if (XmlReader::getValueElement(parser, type, cimValue))    {        return true;    }    // Test for VALUE.ARRAY element    if (XmlReader::getValueArrayElement(parser, type, cimValue))    {       return true;    }    // Test for VALUE.REFERENCE element    CIMObjectPath reference;    if (XmlReader::getValueReferenceElement(parser, reference))    {        cimValue.set(reference);        return true;    }    // Test for VALUE.REFARRAY element    if (XmlReader::getValueReferenceArrayElement(parser, cimValue))    {       return true;    }    return false;}//------------------------------------------------------------------------------//// stringArrayToValue()////------------------------------------------------------------------------------template<class T>CIMValue StringArrayToValueAux(    Uint32 lineNumber,    const Array<const char*>& stringArray,    CIMType type,    T*){    Array<T> array;    for (Uint32 i = 0, n = stringArray.size(); i < n; i++)    {        CIMValue value = XmlReader::stringToValue(            lineNumber, stringArray[i], type);        T x;        value.get(x);        array.append(x);    }    return CIMValue(array);}CIMValue XmlReader::stringArrayToValue(    Uint32 lineNumber,    const Array<const char*>& array,    CIMType type){    switch (type)    {        case CIMTYPE_BOOLEAN:            return StringArrayToValueAux(lineNumber, array, type, (Boolean*)0);        case CIMTYPE_STRING:            return StringArrayToValueAux(lineNumber, array, type, (String*)0);        case CIMTYPE_CHAR16:            return StringArrayToValueAux(lineNumber, array, type, (Char16*)0);        case CIMTYPE_UINT8:            return StringArrayToValueAux(lineNumber, array, type, (Uint8*)0);        case CIMTYPE_UINT16:            return StringArrayToValueAux(lineNumber, array, type, (Uint16*)0);        case CIMTYPE_UINT32:            return StringArrayToValueAux(lineNumber, array, type, (Uint32*)0);        case CIMTYPE_UINT64:            return StringArrayToValueAux(lineNumber, array, type, (Uint64*)0);        case CIMTYPE_SINT8:            return StringArrayToValueAux(lineNumber, array, type, (Sint8*)0);        case CIMTYPE_SINT16:            return StringArrayToValueAux(lineNumber, array, type, (Sint16*)0);        case CIMTYPE_SINT32:            return StringArrayToValueAux(lineNumber, array, type, (Sint32*)0);        case CIMTYPE_SINT64:            return StringArrayToValueAux(lineNumber, array, type, (Sint64*)0);        case CIMTYPE_DATETIME:            return StringArrayToValueAux(                lineNumber, array, type, (CIMDateTime*)0);        case CIMTYPE_REAL32:            return StringArrayToValueAux(lineNumber, array, type, (Real32*)0);        case CIMTYPE_REAL64:            return StringArrayToValueAux(lineNumber, array, type, (Real64*)0);//  PEP 194://  Note that "object" (ie. CIMTYPE_OBJECT) is not a real CIM datatype, but//  just a Pegasus internal representation of an embedded object. However,//  this case is used when decoding string representations of embedded objects.        case CIMTYPE_OBJECT:            return StringArrayToValueAux(                lineNumber, array, type, (CIMObject*)0);#ifdef PEGASUS_EMBEDDED_INSTANCE_SUPPORT        case CIMTYPE_INSTANCE:            return StringArrayToValueAux(                lineNumber, array, type, (CIMInstance*)0);#endif // PEGASUS_EMBEDDED_INSTANCE_SUPPORT        default:            break;    }    // Unreachable:    return CIMValue();}//------------------------------------------------------------------------------//// getValueArrayElement()////     <!ELEMENT VALUE.ARRAY (VALUE*)>////  Return: Boolean. Returns false if there is no VALUE.ARRAY start element////------------------------------------------------------------------------------Boolean XmlReader::getValueArrayElement(    XmlParser& parser,    CIMType type,    CIMValue& value){    // Clears any values from the Array. Assumes this is array CIMValue    value.clear();    // Get VALUE.ARRAY open tag:    XmlEntry entry;    Array<const char*> stringArray;    // If no VALUE.ARRAY start tag, return false    if (!testStartTagOrEmptyTag(parser, entry, "VALUE.ARRAY"))        return false;    if (entry.type != XmlEntry::EMPTY_TAG)    {        // For each VALUE element:        while (testStartTagOrEmptyTag(parser, entry, "VALUE"))        {            if (entry.type == XmlEntry::EMPTY_TAG)            {                stringArray.append("");                continue;            }            if (testContentOrCData(parser, entry))                stringArray.append(entry.text);            else                stringArray.append("");            expectEndTag(parser, "VALUE");        }        expectEndTag(parser, "VALUE.ARRAY");    }    value = stringArrayToValue(parser.getLine(), stringArray, type);    return true;}//------------------------------------------------------------------------------//// getFlavor()////     <!ENTITY % QualifierFlavor//         "OVERRIDABLE (true|false) 'true'//         TOSUBCLASS (true|false) 'true'//         TOINSTANCE (true|false)  'false'//         TRANSLATABLE (true|false)  'false'">////------------------------------------------------------------------------------CIMFlavor XmlReader::getFlavor(    XmlEntry& entry,    Uint32 lineNumber,    const char* tagName){    // Get QUALIFIER.OVERRIDABLE    Boolean overridable = getCimBooleanAttribute(        lineNumber, entry, tagName, "OVERRIDABLE", true, false);    // Get QUALIFIER.TOSUBCLASS    Boolean toSubClass = getCimBooleanAttribute(        lineNumber, entry, tagName, "TOSUBCLASS", true, false);    // Get QUALIFIER.TOINSTANCE    Boolean toInstance = getCimBooleanAttribute(        lineNumber, entry, tagName, "TOINSTANCE", false, false);    // Get QUALIFIER.TRANSLATABLE

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -