OW_CIMXMLParser.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2001-2004 Vintela, Inc. All rights reserved.
00003 *
00004 * Redistribution and use in source and binary forms, with or without
00005 * modification, are permitted provided that the following conditions are met:
00006 *
00007 *  - Redistributions of source code must retain the above copyright notice,
00008 *    this list of conditions and the following disclaimer.
00009 *
00010 *  - Redistributions in binary form must reproduce the above copyright notice,
00011 *    this list of conditions and the following disclaimer in the documentation
00012 *    and/or other materials provided with the distribution.
00013 *
00014 *  - Neither the name of Vintela, Inc. nor the names of its
00015 *    contributors may be used to endorse or promote products derived from this
00016 *    software without specific prior written permission.
00017 *
00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc. OR THE CONTRIBUTORS
00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 * POSSIBILITY OF SUCH DAMAGE.
00029 *******************************************************************************/
00030 
00036 #include "OW_config.h"
00037 #include "OW_CIMXMLParser.hpp"
00038 #include "OW_CIMException.hpp"
00039 #include "OW_Format.hpp"
00040 #include "OW_Assertion.hpp"
00041 #include "OW_XMLUnescape.hpp"
00042 #include <algorithm> // for std::lower_bound
00043 
00044 namespace OW_NAMESPACE
00045 {
00046 
00048 CIMXMLParser::CIMXMLParser(const String& str)
00049    : XMLPullParser(str)
00050 {
00051 }
00053 CIMXMLParser::CIMXMLParser(std::istream& istr)
00054    : XMLPullParser(istr)
00055 {
00056 }
00058 CIMXMLParser::CIMXMLParser()
00059    : XMLPullParser()
00060 {
00061 }
00062 
00063 // This needs to be sorted alphabetically.
00064 CIMXMLParser::ElemEntry CIMXMLParser::g_elems[] =
00065 {
00066    { "CIM", CIMXMLParser::E_CIM },
00067    { "CLASS", CIMXMLParser::E_CLASS },
00068    { "CLASSNAME", CIMXMLParser::E_CLASSNAME },
00069    { "CLASSPATH", CIMXMLParser::E_CLASSPATH },
00070    { "DECLARATION", CIMXMLParser::E_DECLARATION },
00071    { "DECLGROUP", CIMXMLParser::E_DECLGROUP },
00072    { "DECLGROUP.WITHNAME", CIMXMLParser::E_DECLGROUP_WITHNAME },
00073    { "DECLGROUP.WITHPATH", CIMXMLParser::E_DECLGROUP_WITHPATH },
00074    { "ERROR", CIMXMLParser::E_ERROR },
00075    { "EXPMETHODCALL", CIMXMLParser::E_EXPMETHODCALL },
00076    { "EXPMETHODRESPONSE", CIMXMLParser::E_EXPMETHODRESPONSE },
00077    { "EXPPARAMVALUE", CIMXMLParser::E_EXPPARAMVALUE },
00078    { "HOST", CIMXMLParser::E_HOST },
00079    { "IMETHODCALL", CIMXMLParser::E_IMETHODCALL },
00080    { "IMETHODRESPONSE", CIMXMLParser::E_IMETHODRESPONSE },
00081    { "IMPLICITKEY", CIMXMLParser::E_IMPLICITKEY },
00082    { "INSTANCE", CIMXMLParser::E_INSTANCE },
00083    { "INSTANCENAME", CIMXMLParser::E_INSTANCENAME },
00084    { "INSTANCEPATH", CIMXMLParser::E_INSTANCEPATH },
00085    { "IPARAMVALUE", CIMXMLParser::E_IPARAMVALUE },
00086    { "IRETURNVALUE", CIMXMLParser::E_IRETURNVALUE },
00087    { "KEYBINDING", CIMXMLParser::E_KEYBINDING },
00088    { "KEYVALUE", CIMXMLParser::E_KEYVALUE },
00089    { "LOCALCLASSPATH", CIMXMLParser::E_LOCALCLASSPATH },
00090    { "LOCALINSTANCEPATH", CIMXMLParser::E_LOCALINSTANCEPATH },
00091    { "LOCALNAMESPACEPATH", CIMXMLParser::E_LOCALNAMESPACEPATH },
00092    { "MESSAGE", CIMXMLParser::E_MESSAGE },
00093    { "METHOD", CIMXMLParser::E_METHOD },
00094    { "METHODCALL", CIMXMLParser::E_METHODCALL },
00095    { "METHODRESPONSE", CIMXMLParser::E_METHODRESPONSE },
00096    { "MULTIEXPREQ", CIMXMLParser::E_MULTIEXPREQ },
00097    { "MULTIEXPRSP", CIMXMLParser::E_MULTIEXPRSP },
00098    { "MULTIREQ", CIMXMLParser::E_MULTIREQ },
00099    { "MULTIRSP", CIMXMLParser::E_MULTIRSP },
00100    { "NAMESPACE", CIMXMLParser::E_NAMESPACE },
00101    { "NAMESPACEPATH", CIMXMLParser::E_NAMESPACEPATH },
00102    { "OBJECTPATH", CIMXMLParser::E_OBJECTPATH },
00103    { "PARAMETER", CIMXMLParser::E_PARAMETER },
00104    { "PARAMETER.ARRAY", CIMXMLParser::E_PARAMETER_ARRAY },
00105    { "PARAMETER.REFARRAY", CIMXMLParser::E_PARAMETER_REFARRAY },
00106    { "PARAMETER.REFERENCE", CIMXMLParser::E_PARAMETER_REFERENCE },
00107    { "PARAMVALUE", CIMXMLParser::E_PARAMVALUE },
00108    { "PROPERTY", CIMXMLParser::E_PROPERTY },
00109    { "PROPERTY.ARRAY", CIMXMLParser::E_PROPERTY_ARRAY },
00110    { "PROPERTY.REFERENCE", CIMXMLParser::E_PROPERTY_REFERENCE },
00111    { "QUALIFIER", CIMXMLParser::E_QUALIFIER },
00112    { "QUALIFIER.DECLARATION", CIMXMLParser::E_QUALIFIER_DECLARATION },
00113    { "RETURNVALUE", CIMXMLParser::E_RETURNVALUE },
00114    { "SCOPE", CIMXMLParser::E_SCOPE },
00115    { "SIMPLEEXPREQ", CIMXMLParser::E_SIMPLEEXPREQ },
00116    { "SIMPLEEXPRSP", CIMXMLParser::E_SIMPLEEXPRSP },
00117    { "SIMPLEREQ", CIMXMLParser::E_SIMPLEREQ },
00118    { "SIMPLERSP", CIMXMLParser::E_SIMPLERSP },
00119    { "VALUE", CIMXMLParser::E_VALUE },
00120    { "VALUE.ARRAY", CIMXMLParser::E_VALUE_ARRAY },
00121    { "VALUE.NAMEDINSTANCE", CIMXMLParser::E_VALUE_NAMEDINSTANCE },
00122    { "VALUE.NAMEDOBJECT", CIMXMLParser::E_VALUE_NAMEDOBJECT },
00123    { "VALUE.OBJECT", CIMXMLParser::E_VALUE_OBJECT },
00124    { "VALUE.OBJECTWITHLOCALPATH", CIMXMLParser::E_VALUE_OBJECTWITHLOCALPATH },
00125    { "VALUE.OBJECTWITHPATH", CIMXMLParser::E_VALUE_OBJECTWITHPATH },
00126    { "VALUE.REFARRAY", CIMXMLParser::E_VALUE_REFARRAY },
00127    { "VALUE.REFERENCE", CIMXMLParser::E_VALUE_REFERENCE },
00128    { "garbage", CIMXMLParser::E_UNKNOWN }
00129 };
00130       
00131 CIMXMLParser::ElemEntry* CIMXMLParser::g_elemsEnd = &CIMXMLParser::g_elems[0] +
00132    (sizeof(CIMXMLParser::g_elems)/sizeof(*CIMXMLParser::g_elems)) - 1;
00134 inline bool
00135 CIMXMLParser::elemEntryCompare(const CIMXMLParser::ElemEntry& f1,
00136    const CIMXMLParser::ElemEntry& f2)
00137 {
00138    return (strcmp(f1.name, f2.name) < 0);
00139 }
00141 CIMXMLParser::tokenId
00142 CIMXMLParser::getTokenFromName(const char* name)
00143 {
00144    ElemEntry e = { 0, CIMXMLParser::E_UNKNOWN };
00145    e.name = name;
00146    ElemEntry* i = std::lower_bound(g_elems, g_elemsEnd, e, elemEntryCompare);
00147    if (i == g_elemsEnd || strcmp((*i).name, name) != 0)
00148    {
00149       return CIMXMLParser::E_UNKNOWN;
00150    }
00151    else
00152    {
00153       return i->id;
00154    }
00155 }
00156 
00157 const char* const CIMXMLParser::A_ARRAYSIZE              = "ARRAYSIZE";
00158 const char* const CIMXMLParser::A_ASSOCCLASS          = "ASSOCCLASS";
00159 const char* const CIMXMLParser::A_CLASSNAME              = "CLASSNAME";
00160 const char* const CIMXMLParser::A_CLASSORIGIN            = "CLASSORIGIN";
00161 const char* const CIMXMLParser::A_DEEPINHERITANCE        = "DEEPINHERITANCE";
00162 const char* const CIMXMLParser::A_INCLUDECLASSORIGIN  = "INCLUDECLASSORIGIN";
00163 const char* const CIMXMLParser::A_INCLUDEQUALIFIERS      = "INCLUDEQUALIFIERS";
00164 const char* const CIMXMLParser::A_INSTANCENAME           = "INSTANCENAME";
00165 const char* const CIMXMLParser::A_XML_LANG               = "xml:lang";
00166 const char* const CIMXMLParser::A_LOCALONLY              = "LOCALONLY";
00167 const char* const CIMXMLParser::A_MODIFIEDCLASS       = "MODIFIEDCLASS";
00168 const char* const CIMXMLParser::A_NAME                   = "NAME";
00169 const char* const CIMXMLParser::A_NEWVALUE               = "NEWVALUE";
00170 const char* const CIMXMLParser::A_OBJECTNAME          = "OBJECTNAME";
00171 const char* const CIMXMLParser::A_OVERRIDABLE            = "OVERRIDABLE";
00172 const char* const CIMXMLParser::A_PARAMTYPE                    = "PARAMTYPE";
00173 const char* const CIMXMLParser::A_PROPAGATED             = "PROPAGATED";
00174 const char* const CIMXMLParser::A_PROPERTYLIST           = "PROPERTYLIST";
00175 const char* const CIMXMLParser::A_PROPERTYNAME           = "PROPERTYNAME";
00176 const char* const CIMXMLParser::A_REFERENCECLASS         = "REFERENCECLASS";
00177 const char* const CIMXMLParser::A_RESULTCLASS            = "RESULTCLASS";
00178 const char* const CIMXMLParser::A_RESULTROLE          = "RESULTROLE";
00179 const char* const CIMXMLParser::A_ROLE                   = "ROLE";
00180 const char* const CIMXMLParser::A_SUPERCLASS          = "SUPERCLASS";
00181 const char* const CIMXMLParser::A_TOINSTANCE             = "TOINSTANCE"; // This is a bug in the spec
00182 const char* const CIMXMLParser::A_TOSUBCLASS             = "TOSUBCLASS";
00183 const char* const CIMXMLParser::A_TRANSLATABLE           = "TRANSLATABLE";
00184 const char* const CIMXMLParser::A_TYPE                   = "TYPE";
00185 const char* const CIMXMLParser::A_VALUETYPE              = "VALUETYPE";
00186 const char* const CIMXMLParser::A_CIMVERSION = "CIMVERSION";
00187 const char* const CIMXMLParser::A_DTDVERSION = "DTDVERSION";
00188 const char* const CIMXMLParser::A_ID = "ID";
00189 const char* const CIMXMLParser::A_PROTOCOLVERSION = "PROTOCOLVERSION";
00190 const char* const CIMXMLParser::A_CODE    = "CODE";
00191 const char* const CIMXMLParser::A_DESCRIPTION      = "DESCRIPTION";
00192 const char* const CIMXMLParser::A_ISARRAY = "ISARRAY";
00193 const char* const CIMXMLParser::A_EMBEDDEDOBJECT = "EmbeddedObject";
00194 const char* const CIMXMLParser::AV_CIMVERSION20_VALUE = "2.0";
00195 const char* const CIMXMLParser::AV_CIMVERSION21_VALUE = "2.1";
00196 const char* const CIMXMLParser::AV_CIMVERSION22_VALUE = "2.2";
00197 const char* const CIMXMLParser::AV_DTDVERSION20_VALUE = "2.0";
00198 const char* const CIMXMLParser::AV_DTDVERSION21_VALUE = "2.1";
00199 const char* const CIMXMLParser::AV_PROTOCOLVERSION10_VALUE = "1.0";
00200 const char* const CIMXMLParser::AV_PROTOCOLVERSION11_VALUE = "1.1";
00201 const char* const CIMXMLParser::AV_EMBEDDEDOBJECT_OBJECT_VALUE = "object";
00202 const char* const CIMXMLParser::AV_EMBEDDEDOBJECT_INSTANCE_VALUE = "instance";
00203 const char* const CIMXMLParser::P_ClassName        = "ClassName";
00204 const char* const CIMXMLParser::P_PropertyList     = "PropertyList";
00205 const char* const CIMXMLParser::P_DeepInheritance           = "DeepInheritance";
00206 const char* const CIMXMLParser::P_LocalOnly           = "LocalOnly";
00207 const char* const CIMXMLParser::P_IncludeQualifiers            = "IncludeQualifiers";
00208 const char* const CIMXMLParser::P_IncludeClassOrigin           = "IncludeClassOrigin";
00209 const char* const CIMXMLParser::P_ModifiedClass = "ModifiedClass";
00210 const char* const CIMXMLParser::P_ModifiedInstance = "ModifiedInstance";
00211 const char* const CIMXMLParser::P_InstanceName  = "InstanceName";
00212 const char* const CIMXMLParser::P_PropertyName  = "PropertyName";
00213 const char* const CIMXMLParser::P_NewValue         = "NewValue";
00214 const char* const CIMXMLParser::P_Role          = "Role";
00215 const char* const CIMXMLParser::P_ResultRole    = "ResultRole";
00216 const char* const CIMXMLParser::P_ObjectName    = "ObjectName";
00217 const char* const CIMXMLParser::P_AssocClass    = "AssocClass";
00218 const char* const CIMXMLParser::P_ResultClass      = "ResultClass";
00219 const char* const CIMXMLParser::P_QueryLanguage = "QueryLanguage";
00220 const char* const CIMXMLParser::P_Query = "Query";
00221 const char* const CIMXMLParser::P_QualifierName = "QualifierName";
00222 const char* const CIMXMLParser::P_QualifierDeclaration = "QualifierDeclaration";
00223 
00224 
00226 void
00227 CIMXMLParser::mustGetChildId(CIMXMLParser::tokenId tId)
00228 {
00229    if (!m_good)
00230    {
00231       m_good = false;
00232       OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
00233          "CIMXMLParser has reached EOF");
00234    }
00235    getChild();
00236    if (!m_good || !tokenIsId(tId))
00237    {
00238       m_good = false;
00239       OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
00240          Format("CIMXMLParser::mustGetChild(CIMXMLParser::tokenId tId=%1) failed.  parser = %2",
00241             g_elems[tId].name, *this).c_str());
00242    }
00243 }
00245 void
00246 CIMXMLParser::mustTokenIsId(CIMXMLParser::tokenId tId) const
00247 {
00248    if (!tokenIs(g_elems[tId].name))
00249    {
00250       OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
00251          Format("CIMXMLParser::mustTokenIs(CIMXMLParser::tokenId tId=%1) failed.  parser = %2",
00252             g_elems[tId].name, *this).c_str());
00253    }
00254 }
00256 void
00257 CIMXMLParser::getNextId(CIMXMLParser::tokenId beginTok, bool throwIfError)
00258 {
00259    while (m_good)
00260    {
00261       if (m_curTok.type == XMLToken::START_TAG)
00262       {
00263          if (m_curTok.text.equals(g_elems[beginTok].name))
00264          {
00265             break;
00266          }
00267       }
00268       nextToken();
00269    }
00270    if (!m_good && throwIfError)
00271    {
00272       OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
00273          Format("CIMXMLParser::getNext(CIMXMLParser::tokenId beginTok=%1) failed.  parser = %2",
00274             g_elems[beginTok].name, *this).c_str());
00275    }
00276 }
00277 
00278 } // end namespace OW_NAMESPACE
00279 

Generated on Thu Feb 9 08:47:56 2006 for openwbem by  doxygen 1.4.6