OW_WQLImpl.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_WQLImpl.hpp"
00036 #include "OW_MutexLock.hpp"
00037 #include "OW_WQLProcessor.hpp"
00038 #include "OW_WQLAst.hpp"
00039 #include "OW_AutoPtr.hpp"
00040 #include "OW_CIMException.hpp"
00041 #include "OW_WQLSelectStatementGen.hpp"
00042 #include "OW_ResultHandlerIFC.hpp"
00043 #include "OW_ServiceIFCNames.hpp"
00044 
00045 namespace OW_NAMESPACE
00046 {
00047 
00048 Mutex WQLImpl::s_classLock;
00049 const char* WQLImpl::s_parserInput = 0;
00050 stmt* WQLImpl::s_statement = 0;
00051 
00052 WQLImpl::~WQLImpl()
00053 {
00054 }
00055 
00056 String
00057 WQLImpl::getName() const
00058 {
00059    return ServiceIFCNames::WQL;
00060 }
00061 
00062 void WQLImpl::evaluate(const String& nameSpace,
00063    CIMInstanceResultHandlerIFC& result,
00064    const String& query, const String& queryLanguage,
00065    const CIMOMHandleIFCRef& hdl)
00066 {
00067    OW_WQL_LOG_DEBUG(Format("nameSpace %1, query %2, queryLanguage %3 .", nameSpace, query, queryLanguage));
00068    MutexLock lock(s_classLock);
00069    // set up the parser's input
00070    s_parserInput = query.c_str();
00071    WQLscanner_init();
00072 #ifdef YYOW_DEBUG
00073    owwqldebug = 1;
00074 #endif
00075    OW_WQL_LOG_DEBUG("Parsing: ");
00076    int owwqlresult = owwqlparse();
00077    if (owwqlresult)
00078    {
00079       OW_THROWCIMMSG(CIMException::INVALID_QUERY, "Parse failed");
00080    }
00081    else
00082    {
00083       OW_WQL_LOG_DEBUG("Parse succeeded");
00084    }
00085    OW_WQL_LOG_DEBUG("Processing: ");
00086    WQLProcessor p(hdl, nameSpace);
00087    AutoPtr<stmt> pAST(WQLImpl::s_statement);
00088    lock.release();
00089    if (pAST.get())
00090    {
00091       pAST->acceptInterface(&p);
00092    }
00093    else
00094    {
00095       OW_WQL_LOG_DEBUG("pAST was NULL!");
00096    }
00097    CIMInstanceArray instances = p.getInstances();
00098    for (size_t i = 0; i < instances.size(); ++i)
00099    {
00100       result.handle(instances[i]);
00101    }
00102 
00103    s_parserInput = 0;
00104 }
00105 
00106 WQLSelectStatement
00107 WQLImpl::createSelectStatement(const String& query)
00108 {
00109    MutexLock lock(s_classLock);
00110    // set up the parser's input
00111    s_parserInput = query.c_str();
00112    WQLscanner_init();
00113 #ifdef YYOW_DEBUG
00114    owwqldebug = 1;
00115 #endif
00116    int owwqlresult = owwqlparse();
00117    if (owwqlresult)
00118    {
00119       OW_THROWCIMMSG(CIMException::INVALID_QUERY, "Parse failed");
00120    }
00121    else
00122    {
00123       OW_WQL_LOG_DEBUG("Parse succeeded");
00124    }
00125    WQLSelectStatementGen p;
00126    AutoPtr<stmt> pAST(WQLImpl::s_statement);
00127    lock.release();
00128    if (pAST.get())
00129    {
00130       pAST->acceptInterface(&p);
00131    }
00132    else
00133    {
00134       OW_WQL_LOG_DEBUG("pAST was NULL!");
00135    }
00136    
00137    s_parserInput = 0;
00138 
00139    return p.getSelectStatement();
00140 }
00141 bool WQLImpl::supportsQueryLanguage(const String& lang)
00142 {
00143    if (lang.equalsIgnoreCase("wql1"))
00144    {
00145       return true;
00146    }
00147    else if (lang.equalsIgnoreCase("wql2"))
00148    {
00149       return true;
00150    }
00151    else if (lang.equalsIgnoreCase("wql"))
00152    {
00153       return true;
00154    }
00155    else
00156    {
00157       return false;
00158    }
00159 }
00160 
00162 void
00163 WQLImpl::init(const ServiceEnvironmentIFCRef& env)
00164 {
00165 }
00166 
00168 void
00169 WQLImpl::shutdown()
00170 {
00171 }
00172 
00173 } // end namespace OW_NAMESPACE
00174 
00175 OW_WQLFACTORY(OpenWBEM::WQLImpl,wqlimpl);
00176 

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