OW_MOFCompiler.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 
00035 #include "OW_MOFCompiler.hpp"
00036 #include "OW_Format.hpp"
00037 #include "OW_MOFParserDecls.hpp"
00038 #include "OW_MOFCIMOMVisitor.hpp"
00039 #include "OW_Assertion.hpp"
00040 #include "OW_ThreadCancelledException.hpp"
00041 #include "OW_MOFGrammar.hpp"
00042 
00043 #include "OW_CIMObjectPath.hpp"
00044 #include "OW_CIMException.hpp"
00045 #include "OW_CIMOMHandleIFC.hpp"
00046 #include "OW_ExceptionIds.hpp"
00047 #include "OW_Enumeration.hpp"
00048 #include "OW_NonRecursiveMutex.hpp"
00049 #include "OW_NonRecursiveMutexLock.hpp"
00050 #include "OW_Logger.hpp"
00051 
00052 #include <assert.h>
00053 #include <cctype>
00054 
00055 // forward declarations of some lex/yacc functions we need to call.
00056 void owmof_delete_buffer(YY_BUFFER_STATE b);
00057 YY_BUFFER_STATE owmof_scan_bytes( const char *bytes, int len );
00058 
00059 namespace OW_NAMESPACE
00060 {
00061 
00062 OW_DEFINE_EXCEPTION_WITH_ID(MOFCompiler)
00063 
00064 namespace MOF
00065 {
00066 
00067 
00068 namespace
00069 {
00070 // since flex/bison aren't re-entrant or thread-safe.
00071 NonRecursiveMutex g_guard;
00072 }
00073 
00074 Compiler::Compiler( const CIMOMHandleIFCRef& ch, const Options& opts, const ParserErrorHandlerIFCRef& mpeh )
00075    : theErrorHandler(mpeh)
00076    , include_stack_ptr(0)
00077    , m_ch(ch)
00078    , m_opts(opts)
00079 {
00080 }
00081 Compiler::~Compiler()
00082 {
00083 }
00084 long Compiler::compile( const String& filename )
00085 {
00086    include_stack_ptr = 0;
00087    theLineInfo = LineInfo(filename,1);
00088    try
00089    {
00090       try
00091       {
00092          size_t i = filename.lastIndexOf(OW_FILENAME_SEPARATOR);
00093          if (i != String::npos)
00094          {
00095             basepath = filename.substring(0,i);
00096          }
00097          else
00098          {
00099             basepath = String();
00100          }
00101          if (filename != "-")
00102          {
00103             owmofin = fopen(filename.c_str(), "r");
00104             if (!owmofin)
00105             {
00106                theErrorHandler->fatalError("Unable to open file", LineInfo(filename, 0));
00107                return 1;
00108             }
00109          }
00110          theErrorHandler->progressMessage("Starting parsing",
00111                LineInfo(filename, 0));
00112          
00113          {
00114             NonRecursiveMutexLock lock(g_guard);
00115             #ifdef YYOW_DEBUG
00116             owmofdebug = 1;
00117             #endif
00118             owmofparse(this);
00119          }
00120 
00121          theErrorHandler->progressMessage("Finished parsing",
00122                theLineInfo);
00123          CIMOMVisitor v(m_ch, m_opts, theErrorHandler);
00124          mofSpecification->Accept(&v);
00125       }
00126       catch (const ParseFatalErrorException&)
00127       {
00128          // error has already been reported.
00129       }
00130       catch (AssertionException& e)
00131       {
00132          theErrorHandler->fatalError(Format( "INTERNAL COMPILER ERROR: %1", e).c_str(), theLineInfo);
00133       }
00134       catch (Exception& e)
00135       {
00136          theErrorHandler->fatalError(Format( "ERROR: %1", e).c_str(), theLineInfo);
00137       }
00138       catch (std::exception& e)
00139       {
00140          theErrorHandler->fatalError(Format( "INTERNAL COMPILER ERROR: %1", e.what() ).c_str(), theLineInfo);
00141       }
00142       catch (ThreadCancelledException&)
00143       {
00144          theErrorHandler->fatalError("INTERNAL COMPILER ERROR: Thread cancelled", theLineInfo);
00145          throw;
00146       }
00147       catch(...)
00148       {
00149          theErrorHandler->fatalError( "INTERNAL COMPILER ERROR: Unknown exception", theLineInfo);
00150       }
00151    }
00152    catch (const ParseFatalErrorException&)
00153    {
00154       // error has already been reported.
00155    }
00156    return theErrorHandler->errorCount();
00157 }
00158 namespace {
00159    struct owmofBufferDeleter
00160    {
00161       owmofBufferDeleter(YY_BUFFER_STATE buf) : m_buf(buf) {}
00162       ~owmofBufferDeleter() {owmof_delete_buffer(m_buf);}
00163       YY_BUFFER_STATE m_buf;
00164    };
00165 }
00166 long Compiler::compileString( const String& mof )
00167 {
00168    include_stack_ptr = 0;
00169    String filename = "string";
00170    theLineInfo = LineInfo(filename,1);
00171    try
00172    {
00173       try
00174       {
00175          NonRecursiveMutexLock lock(g_guard);
00176          
00177             YY_BUFFER_STATE buf = owmof_scan_bytes(mof.c_str(), mof.length());
00178             owmofBufferDeleter deleter(buf);
00179             theErrorHandler->progressMessage("Starting parsing",
00180                   LineInfo(filename, 0));
00181             #ifdef YYOW_DEBUG
00182             owmofdebug = 1;
00183             #endif
00184             owmofparse(this);
00185          
00186          lock.release();
00187 
00188          theErrorHandler->progressMessage("Finished parsing",
00189                theLineInfo);
00190          CIMOMVisitor v(m_ch, m_opts, theErrorHandler);
00191          mofSpecification->Accept(&v);
00192       }
00193       catch (const ParseFatalErrorException&)
00194       {
00195          // error has already been reported.
00196       }
00197       catch (AssertionException& e)
00198       {
00199          theErrorHandler->fatalError(Format( "INTERNAL COMPILER ERROR: %1", e).c_str(), LineInfo("(none)", 0));
00200       }
00201       catch (Exception& e)
00202       {
00203          theErrorHandler->fatalError(Format( "ERROR: %1", e).c_str(), LineInfo("(none)", 0));
00204       }
00205       catch (std::exception& e)
00206       {
00207          theErrorHandler->fatalError(Format( "INTERNAL COMPILER ERROR: %1", e.what() ).c_str(), LineInfo("(none)", 0));
00208       }
00209       catch (ThreadCancelledException&)
00210       {
00211          theErrorHandler->fatalError("INTERNAL COMPILER ERROR: Thread cancelled", theLineInfo);
00212          throw;
00213       }
00214       catch(...)
00215       {
00216          theErrorHandler->fatalError( "INTERNAL COMPILER ERROR: Unknown exception", LineInfo("(none)", 0));
00217       }
00218    }
00219    catch (const ParseFatalErrorException&)
00220    {
00221       // error has already been reported.
00222    }
00223    return theErrorHandler->errorCount();
00224 }
00225 // STATIC
00226 String Compiler::fixParsedString(const String& s)
00227 {
00228    bool inString = false;
00229    StringBuffer unescaped;
00230    for (size_t i = 0; i < s.length(); ++i)
00231    {
00232       if (inString)
00233       {
00234          if (s[i] == '\\')
00235          {
00236             ++i;
00237 
00238             /* this can never happen, unless someone messes up the lexer */
00239             OW_ASSERT(i < s.length());
00240 
00241             switch (s[i])
00242             {
00243                case 'b':
00244                   unescaped += '\b';
00245                   break;
00246                case 't':
00247                   unescaped += '\t';
00248                   break;
00249                case 'n':
00250                   unescaped += '\n';
00251                   break;
00252                case 'f':
00253                   unescaped += '\f';
00254                   break;
00255                case 'r':
00256                   unescaped += '\r';
00257                   break;
00258                case '"':
00259                   unescaped += '"';
00260                   break;
00261                case '\'':
00262                   unescaped += '\'';
00263                   break;
00264                case '\\':
00265                   unescaped += '\\';
00266                   break;
00267                case 'x':
00268                case 'X':
00269                   {
00270                      // The lexer guarantees that there will be from 1-4 hex chars.
00271                      UInt16 hex = 0;
00272                      for (size_t j = 0; j < 4; ++j)
00273                      {
00274                         hex <<= 4;
00275                         char c = s[i+j];
00276                         if (isdigit(c))
00277                         {
00278                            hex |= c - '0';
00279                         }
00280                         else if (isxdigit(c))
00281                         {
00282                            c = toupper(c);
00283                            hex |= c - 'A' + 0xA;
00284                         }
00285                         else
00286                         {
00287                            break;
00288                         }
00289                      }
00290                      if (hex > CHAR_MAX)
00291                      {
00292                         OW_THROW(MOFCompilerException, "Escape sequence larger than supported maximum");
00293                      }
00294                      unescaped += static_cast<char>(hex);
00295                   }
00296                   break;
00297                default:
00298                   // this could never happen unless someone messes up the lexer
00299                   OW_ASSERTMSG(0, "Invalid escape sequence");
00300                   break;
00301             }
00302          }
00303          else if (s[i] == '"')
00304          {
00305             inString = false;
00306          }
00307          else
00308          {
00309             unescaped += s[i];
00310          }
00311       }
00312       else
00313       {
00314          // not in the string
00315          if (s[i] == '"')
00316          {
00317             inString = true;
00318          }
00319       }
00320    }
00321 
00322    return unescaped.releaseString();
00323 }
00324 
00325 class StoreLocalDataHandle : public CIMOMHandleIFC
00326 {
00327 public:
00328    StoreLocalDataHandle(const CIMOMHandleIFCRef& hdl, CIMInstanceArray& instances, CIMClassArray& classes, CIMQualifierTypeArray& qualifierTypes)
00329       : m_realhdl(hdl)
00330       , m_instances(instances)
00331       , m_classes(classes)
00332       , m_qualifierTypes(qualifierTypes)
00333    {
00334    }
00335    virtual CIMObjectPath createInstance(const String &ns, const CIMInstance &instance)
00336    {
00337       m_instances.push_back(instance);
00338       return CIMObjectPath(ns, instance);
00339    }
00340    virtual CIMClass getClass(const String &ns, const String &className,
00341       WBEMFlags:: ELocalOnlyFlag localOnly=WBEMFlags:: E_NOT_LOCAL_ONLY,
00342       WBEMFlags:: EIncludeQualifiersFlag includeQualifiers=WBEMFlags:: E_INCLUDE_QUALIFIERS,
00343       WBEMFlags:: EIncludeClassOriginFlag includeClassOrigin=WBEMFlags:: E_INCLUDE_CLASS_ORIGIN,
00344       const StringArray *propertyList=0)
00345    {
00346       // first get back a class contained in the mof.
00347       for (size_t i = 0; i < m_classes.size(); ++i)
00348       {
00349          if (m_classes[i].getName() == CIMName(className))
00350          {
00351             return m_classes[i];
00352          }
00353       }
00354       // try getting it from the cimom handle
00355       if (m_realhdl)
00356       {
00357          try
00358          {
00359             return m_realhdl->getClass(ns, className, localOnly, includeQualifiers, includeClassOrigin, propertyList);
00360          }
00361          catch (CIMException& e)
00362          {
00363             // ignore it.
00364          }
00365       }
00366 
00367       // just give back an empty class, with just the name set.
00368       return CIMClass(className);
00369    }
00370 
00371    virtual CIMQualifierType getQualifierType(const String &ns, const String &qualifierName)
00372    {
00373       // first get back a qualifier contained in the mof.
00374       for (size_t i = 0; i < m_qualifierTypes.size(); ++i)
00375       {
00376          if (m_qualifierTypes[i].getName() == CIMName(qualifierName))
00377          {
00378             return m_qualifierTypes[i];
00379          }
00380       }
00381       // try getting it from the cimom handle
00382       if (m_realhdl)
00383       {
00384          return m_realhdl->getQualifierType(ns, qualifierName);
00385       }
00386       OW_THROWCIM(CIMException::FAILED);
00387    }
00388 
00389    virtual void setQualifierType(const String &ns, const CIMQualifierType &qualifierType)
00390    {
00391       m_qualifierTypes.push_back(qualifierType);
00392    }
00393 
00394    virtual void createClass(const String &ns, const CIMClass &cimClass)
00395    {
00396       m_classes.push_back(cimClass);
00397    }
00398 
00399 private:
00400    CIMOMHandleIFCRef m_realhdl;
00401    CIMInstanceArray& m_instances;
00402    CIMClassArray& m_classes;
00403    CIMQualifierTypeArray& m_qualifierTypes;
00404 
00405 #define THROW_ERROR_NOT_IMPLEMENTED(name) OW_THROWCIMMSG(CIMException::FAILED, Format("Not implemented: %1", (name)).c_str())
00406 #define THROW_ERROR_NOT_IMPLEMENTED_FUNCNAME() THROW_ERROR_NOT_IMPLEMENTED(OW_LOGGER_PRETTY_FUNCTION)
00407    // all these throw FAILED
00408    virtual void enumClassNames(const String &ns, const String &className, StringResultHandlerIFC &result, WBEMFlags:: EDeepFlag deep=WBEMFlags:: E_DEEP)
00409    {
00410       THROW_ERROR_NOT_IMPLEMENTED_FUNCNAME();
00411    }
00412    virtual void close()
00413    {
00414       THROW_ERROR_NOT_IMPLEMENTED_FUNCNAME();
00415    }
00416    virtual void enumClass(const String &ns, const String &className, CIMClassResultHandlerIFC &result, WBEMFlags:: EDeepFlag deep=WBEMFlags:: E_SHALLOW, WBEMFlags:: ELocalOnlyFlag localOnly=WBEMFlags:: E_NOT_LOCAL_ONLY, WBEMFlags:: EIncludeQualifiersFlag includeQualifiers=WBEMFlags:: E_INCLUDE_QUALIFIERS, WBEMFlags:: EIncludeClassOriginFlag includeClassOrigin=WBEMFlags:: E_INCLUDE_CLASS_ORIGIN)
00417    {
00418       THROW_ERROR_NOT_IMPLEMENTED_FUNCNAME();
00419    }
00420    virtual void enumInstanceNames(const String &ns, const String &className, CIMObjectPathResultHandlerIFC &result)
00421    {
00422       THROW_ERROR_NOT_IMPLEMENTED_FUNCNAME();
00423    }
00424    virtual void enumInstances(const String &ns, const String &className, CIMInstanceResultHandlerIFC &result, WBEMFlags:: EDeepFlag deep=WBEMFlags:: E_DEEP, WBEMFlags:: ELocalOnlyFlag localOnly=WBEMFlags:: E_NOT_LOCAL_ONLY, WBEMFlags:: EIncludeQualifiersFlag includeQualifiers=WBEMFlags:: E_EXCLUDE_QUALIFIERS, WBEMFlags:: EIncludeClassOriginFlag includeClassOrigin=WBEMFlags:: E_EXCLUDE_CLASS_ORIGIN, const StringArray *propertyList=0)
00425    {
00426       THROW_ERROR_NOT_IMPLEMENTED_FUNCNAME();
00427    }
00428    virtual CIMValue invokeMethod(const String &ns, const CIMObjectPath &path, const String &methodName, const CIMParamValueArray &inParams, CIMParamValueArray &outParams)
00429    {
00430       THROW_ERROR_NOT_IMPLEMENTED_FUNCNAME();
00431    }
00432    virtual CIMInstance getInstance(const String &ns, const CIMObjectPath &instanceName, WBEMFlags:: ELocalOnlyFlag localOnly=WBEMFlags:: E_NOT_LOCAL_ONLY, WBEMFlags:: EIncludeQualifiersFlag includeQualifiers=WBEMFlags:: E_EXCLUDE_QUALIFIERS, WBEMFlags:: EIncludeClassOriginFlag includeClassOrigin=WBEMFlags:: E_EXCLUDE_CLASS_ORIGIN, const StringArray *propertyList=0)
00433    {
00434       THROW_ERROR_NOT_IMPLEMENTED_FUNCNAME();
00435    }
00436    virtual void enumQualifierTypes(const String &ns, CIMQualifierTypeResultHandlerIFC &result)
00437    {
00438       THROW_ERROR_NOT_IMPLEMENTED_FUNCNAME();
00439    }
00440    virtual void deleteQualifierType(const String &ns, const String &qualName)
00441    {
00442       THROW_ERROR_NOT_IMPLEMENTED_FUNCNAME();
00443    }
00444    virtual void deleteClass(const String &ns, const String &className)
00445    {
00446       THROW_ERROR_NOT_IMPLEMENTED_FUNCNAME();
00447    }
00448    virtual void modifyInstance(const String &ns, const CIMInstance &modifiedInstance, WBEMFlags:: EIncludeQualifiersFlag includeQualifiers=WBEMFlags:: E_INCLUDE_QUALIFIERS, const StringArray *propertyList=0)
00449    {
00450       THROW_ERROR_NOT_IMPLEMENTED_FUNCNAME();
00451    }
00452    virtual void modifyClass(const String &ns, const CIMClass &cimClass)
00453    {
00454       THROW_ERROR_NOT_IMPLEMENTED_FUNCNAME();
00455    }
00456    virtual void setProperty(const String &ns, const CIMObjectPath &instanceName, const String &propertyName, const CIMValue &newValue)
00457    {
00458       THROW_ERROR_NOT_IMPLEMENTED_FUNCNAME();
00459    }
00460    virtual CIMValue getProperty(const String &ns, const CIMObjectPath &instanceName, const String &propertyName)
00461    {
00462       THROW_ERROR_NOT_IMPLEMENTED_FUNCNAME();
00463    }
00464    virtual void deleteInstance(const String &ns, const CIMObjectPath &path)
00465    {
00466       THROW_ERROR_NOT_IMPLEMENTED_FUNCNAME();
00467    }
00468    virtual void associators(const String &ns, const CIMObjectPath &path, CIMInstanceResultHandlerIFC &result, const String &assocClass=String(), const String &resultClass=String(), const String &role=String(), const String &resultRole=String(), WBEMFlags:: EIncludeQualifiersFlag includeQualifiers=WBEMFlags:: E_EXCLUDE_QUALIFIERS, WBEMFlags:: EIncludeClassOriginFlag includeClassOrigin=WBEMFlags:: E_EXCLUDE_CLASS_ORIGIN, const StringArray *propertyList=0)
00469    {
00470       THROW_ERROR_NOT_IMPLEMENTED_FUNCNAME();
00471    }
00472    virtual void associatorNames(const String &ns, const CIMObjectPath &objectName, CIMObjectPathResultHandlerIFC &result, const String &assocClass=String(), const String &resultClass=String(), const String &role=String(), const String &resultRole=String())
00473    {
00474       THROW_ERROR_NOT_IMPLEMENTED_FUNCNAME();
00475    }
00476    virtual void associatorsClasses(const String &ns, const CIMObjectPath &path, CIMClassResultHandlerIFC &result, const String &assocClass=String(), const String &resultClass=String(), const String &role=String(), const String &resultRole=String(), WBEMFlags:: EIncludeQualifiersFlag includeQualifiers=WBEMFlags:: E_EXCLUDE_QUALIFIERS, WBEMFlags:: EIncludeClassOriginFlag includeClassOrigin=WBEMFlags:: E_EXCLUDE_CLASS_ORIGIN, const StringArray *propertyList=0)
00477    {
00478       THROW_ERROR_NOT_IMPLEMENTED_FUNCNAME();
00479    }
00480    virtual void referenceNames(const String &ns, const CIMObjectPath &path, CIMObjectPathResultHandlerIFC &result, const String &resultClass=String(), const String &role=String())
00481    {
00482       THROW_ERROR_NOT_IMPLEMENTED_FUNCNAME();
00483    }
00484    virtual void references(const String &ns, const CIMObjectPath &path, CIMInstanceResultHandlerIFC &result, const String &resultClass=String(), const String &role=String(), WBEMFlags:: EIncludeQualifiersFlag includeQualifiers=WBEMFlags:: E_EXCLUDE_QUALIFIERS, WBEMFlags:: EIncludeClassOriginFlag includeClassOrigin=WBEMFlags:: E_EXCLUDE_CLASS_ORIGIN, const StringArray *propertyList=0)
00485    {
00486       THROW_ERROR_NOT_IMPLEMENTED_FUNCNAME();
00487    }
00488    virtual void referencesClasses(const String &ns, const CIMObjectPath &path, CIMClassResultHandlerIFC &result, const String &resultClass=String(), const String &role=String(), WBEMFlags:: EIncludeQualifiersFlag includeQualifiers=WBEMFlags:: E_EXCLUDE_QUALIFIERS, WBEMFlags:: EIncludeClassOriginFlag includeClassOrigin=WBEMFlags:: E_EXCLUDE_CLASS_ORIGIN, const StringArray *propertyList=0)
00489    {
00490       THROW_ERROR_NOT_IMPLEMENTED_FUNCNAME();
00491    }
00492    virtual void execQuery(const String &ns, CIMInstanceResultHandlerIFC &result, const String &query, const String &queryLanguage)
00493    {
00494       THROW_ERROR_NOT_IMPLEMENTED_FUNCNAME();
00495    }
00496 };
00497 
00498 class LoggerErrHandler : public ParserErrorHandlerIFC
00499 {
00500 protected:
00501    virtual void doProgressMessage(const char *message, const LineInfo &li)
00502    {
00503       if( logger )
00504       {
00505          OW_LOG_DEBUG(logger, Format("MOF compilation progress: %1: line %2: %3", li.filename, li.lineNum, message));
00506       }
00507       warnings.push_back(message);
00508    }
00509    virtual void doFatalError(const char *error, const LineInfo &li)
00510    {
00511       if( logger )
00512       {
00513          OW_LOG_ERROR(logger, Format("Fatal MOF compilation error: %1: line %2: %3", li.filename, li.lineNum, error));
00514       }
00515       errors.push_back(error);
00516    }
00517    virtual EParserAction doRecoverableError(const char *error, const LineInfo &li)
00518    {
00519       if( logger )
00520       {
00521          OW_LOG_ERROR(logger, Format("MOF compilation error: %1: line %2: %3", li.filename, li.lineNum, error));
00522       }
00523       errors.push_back(error);
00524       return ParserErrorHandlerIFC::E_ABORT_ACTION;
00525    }
00526    LoggerRef logger;
00527 
00528 public:
00529    LoggerErrHandler(const LoggerRef& l):
00530       logger(l)
00531    {
00532    }
00533    StringArray errors;
00534    StringArray warnings;
00535 };
00536 
00537 CIMInstance compileInstanceFromMOF(const String& instMOF, const LoggerRef& logger)
00538 {
00539    CIMInstanceArray cia;
00540    CIMClassArray dummyClasses;
00541    CIMQualifierTypeArray dummyQualifierTypes;
00542    compileMOF(instMOF, CIMOMHandleIFCRef(), "", cia, dummyClasses, dummyQualifierTypes, logger);
00543    if (cia.size() == 1)
00544    {
00545       return cia[0];
00546    }
00547    OW_THROW(MOFCompilerException, "MOF did not contain one instance");
00548 }
00549 
00550 CIMInstanceArray compileInstancesFromMOF(const String& instMOF, const LoggerRef& logger)
00551 {
00552    CIMInstanceArray cia;
00553    CIMClassArray dummyClasses;
00554    CIMQualifierTypeArray dummyQualifierTypes;
00555    compileMOF(instMOF, CIMOMHandleIFCRef(), "", cia, dummyClasses, dummyQualifierTypes, logger);
00556    return cia;
00557 }
00558 
00559 CIMInstanceArray compileInstancesFromMOF(const String& instMOF, const CIMOMHandleIFCRef& realhdl, const String& ns, const LoggerRef& logger)
00560 {
00561    CIMInstanceArray cia;
00562    CIMClassArray dummyClasses;
00563    CIMQualifierTypeArray dummyQualifierTypes;
00564    IntrusiveReference<StoreLocalDataHandle> hdl(new StoreLocalDataHandle(realhdl, cia, dummyClasses, dummyQualifierTypes));
00565    MOF::Compiler::Options opts;
00566    opts.m_namespace = ns;
00567    IntrusiveReference<LoggerErrHandler> errHandler(new LoggerErrHandler(logger));
00568    MOF::Compiler comp(hdl, opts, errHandler);
00569    long errors = comp.compileString(instMOF);
00570    if (errors > 0)
00571    {
00572       // just report the first message, since anything else is too complicated :-{
00573       OW_THROW(MOFCompilerException, errHandler->errors.size() > 0 ? errHandler->errors[0].c_str() : "");
00574    }
00575    return cia;
00576 }
00577 
00578 void compileMOF(const String& mof, const CIMOMHandleIFCRef& realhdl, const String& ns,
00579    CIMInstanceArray& instances, CIMClassArray& classes, CIMQualifierTypeArray& qualifierTypes, const LoggerRef& logger)
00580 {
00581    IntrusiveReference<StoreLocalDataHandle> hdl(new StoreLocalDataHandle(realhdl, instances, classes, qualifierTypes));
00582    MOF::Compiler::Options opts;
00583    opts.m_namespace = ns;
00584    IntrusiveReference<LoggerErrHandler> errHandler(new LoggerErrHandler(logger));
00585    MOF::Compiler comp(hdl, opts, errHandler);
00586    long errors = comp.compileString(mof);
00587    if (errors > 0)
00588    {
00589       // just report the first message, since anything else is too complicated :-{
00590       StringBuffer errorStrs;
00591       for (size_t i = 0; i < errHandler->errors.size(); ++i)
00592       {
00593          if (i > 0)
00594          {
00595             errorStrs += '\n';
00596          }
00597          errorStrs += errHandler->errors[i];
00598       }
00599       OW_THROW(MOFCompilerException, errorStrs.c_str());
00600    }
00601 }
00602 
00603 } // end namespace MOF
00604 } // end namespace OW_NAMESPACE
00605 

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