OW_XMLClass.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_XMLCIMFactory.hpp"
00038 #include "OW_XMLClass.hpp"
00039 #include "OW_String.hpp"
00040 #include "OW_CIMClass.hpp"
00041 #include "OW_CIMInstance.hpp"
00042 #include "OW_CIMProperty.hpp"
00043 #include "OW_CIMValue.hpp"
00044 #include "OW_CIMUrl.hpp"
00045 #include "OW_CIMXMLParser.hpp"
00046 #include "OW_CIMObjectPath.hpp"
00047 #include "OW_Format.hpp"
00048 #include "OW_CIMException.hpp"
00049 
00050 namespace OW_NAMESPACE
00051 {
00052 
00053 namespace XMLClass
00054 {
00056 String
00057 getNameSpace(CIMXMLParser& parser)
00058 {
00059    String nameSpace;
00060    bool firstTime = true;
00061    while (parser.tokenIsId(CIMXMLParser::E_NAMESPACE))
00062    {
00063       String pname = parser.mustGetAttribute(CIMXMLParser::A_NAME);
00064       if (pname.empty())
00065       {
00066          //OW_THROWCIM(CIMException::INVALID_PARAMETER);
00067          // can't do this, because some clients send invalid xml, and
00068          // interoperability is more important than spec purity.
00069       }
00070       else if (firstTime)
00071       {
00072          firstTime=false;
00073          nameSpace += pname;
00074       }
00075       else
00076       {
00077          nameSpace += "/" + pname;
00078       }
00079       parser.mustGetNextTag();
00080       parser.mustGetEndTag();
00081    }
00082    return nameSpace;
00083 }
00085 CIMObjectPath
00086 getObjectWithPath(CIMXMLParser& parser, CIMClass& c,
00087    CIMInstance& i)
00088 {
00089    CIMXMLParser::tokenId token = parser.getToken();
00090    parser.mustGetChild(); // pass <VALUE.OBJECTWITHPATH> or <VALUE.OBJECTWITHLOCALPATH>
00091    
00092    if (token == CIMXMLParser::E_VALUE_OBJECTWITHPATH)
00093    {
00094       token = parser.getToken();
00095       
00096       CIMObjectPath tmpcop = XMLCIMFactory::createObjectPath(parser);
00097          
00098       if (token == CIMXMLParser::E_CLASSPATH)
00099       {
00100          parser.mustTokenIsId(CIMXMLParser::E_CLASS);
00101          c = readClass(parser,tmpcop);
00102       }
00103       else if (token==CIMXMLParser::E_INSTANCEPATH)
00104       {
00105          parser.mustTokenIsId(CIMXMLParser::E_INSTANCE);
00106          i = readInstance(parser,tmpcop);
00107          i.setNameSpace(tmpcop.getNameSpace());
00108       }
00109       else
00110       {
00111          OW_THROWCIMMSG(CIMException::FAILED,
00112             Format("Require instance or class in object with path declaration. token = %1, parser = %2", token, parser).c_str());
00113       }
00114       
00115       parser.mustGetEndTag(); // pass </VALUE.OBJECTWITHPATH>
00116       return tmpcop;
00117    }
00118    else if (token==CIMXMLParser::E_VALUE_OBJECTWITHLOCALPATH)
00119    {
00120       token = parser.getToken();
00121       CIMObjectPath tmpcop = XMLCIMFactory::createObjectPath(parser);
00122          
00123       if (token == CIMXMLParser::E_LOCALCLASSPATH)
00124       {
00125          parser.mustTokenIsId(CIMXMLParser::E_CLASS);
00126          c = readClass(parser, tmpcop);
00127       }
00128       else if (token == CIMXMLParser::E_LOCALINSTANCEPATH)
00129       {
00130          parser.mustTokenIsId(CIMXMLParser::E_INSTANCE);
00131          i = readInstance(parser, tmpcop);
00132          i.setNameSpace(tmpcop.getNameSpace());
00133       }
00134       else
00135       {
00136          OW_THROWCIMMSG(CIMException::FAILED,
00137             "Require instance or class in object with path declaration");
00138       }
00139       
00140       parser.mustGetEndTag(); // pass </VALUE.OBJECTWITHLOCALPATH>
00141       return tmpcop;
00142    }
00143    OW_THROWCIMMSG(CIMException::FAILED,
00144       Format("Require instance or class in object with path declaration. token = %1, parser = %2", token, parser).c_str());
00145 }
00147 CIMClass
00148 readClass(CIMXMLParser& childNode, CIMObjectPath& path)
00149 {
00150    CIMClass cimClass = XMLCIMFactory::createClass(childNode);
00151    path.setClassName(cimClass.getName());
00152    return cimClass;
00153 }
00155 CIMInstance
00156 readInstance(CIMXMLParser& childNode, CIMObjectPath& path)
00157 {
00158    CIMInstance cimInstance = XMLCIMFactory::createInstance(childNode);
00159    return cimInstance;
00160 }
00161 
00162 } // end namespace XMLClass
00163 } // end namespace OW_NAMESPACE
00164 

Generated on Thu Feb 9 08:48:18 2006 for openwbem by  doxygen 1.4.6