OW_WQLInstancePropertySource.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2003-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_config.h"
00036 #include "OW_WQLInstancePropertySource.hpp"
00037 #include "OW_CIMProperty.hpp"
00038 #include "OW_CIMClass.hpp"
00039 #include "OW_CIMValue.hpp"
00040 #include "OW_CIMValueCast.hpp"
00041 #include "OW_Bool.hpp"
00042 
00043 namespace OW_NAMESPACE
00044 {
00045 
00047 WQLInstancePropertySource::~WQLInstancePropertySource()
00048 {
00049 }
00051 bool WQLInstancePropertySource::evaluateISA(const String &propertyName, const String &className) const
00052 {
00053    StringArray propNames = propertyName.tokenize(".");
00054    if (propNames.empty())
00055    {
00056       return false;
00057    }
00058    if (propNames[0] == ci.getClassName())
00059    {
00060       propNames.remove(0);
00061    }
00062    return evaluateISAAux(ci, propNames, className);
00063 }
00065 bool WQLInstancePropertySource::getValue(const String &propertyName, WQLOperand &value) const
00066 {
00067    StringArray propNames = propertyName.tokenize(".");
00068    if (propNames.empty())
00069    {
00070       return false;
00071    }
00072    if (propNames[0].equalsIgnoreCase(ci.getClassName()))
00073    {
00074       propNames.remove(0);
00075    }
00076    return getValueAux(ci, propNames, value);
00077 }
00079 bool WQLInstancePropertySource::evaluateISAAux(const CIMInstance& ci, StringArray propNames, const String &className) const
00080 {
00081    if (propNames.empty())
00082    {
00083       return classIsDerivedFrom(ci.getClassName(), className);
00084    }
00085    CIMProperty p = ci.getProperty(propNames[0]);
00086    if (!p)
00087    {
00088       return false;
00089    }
00090    CIMValue v = p.getValue();
00091    switch (v.getType())
00092    {
00093       case CIMDataType::EMBEDDEDINSTANCE:
00094       {
00095          propNames.remove(0);
00096          CIMInstance embed;
00097          v.get(embed);
00098          if (!embed)
00099          {
00100             return false;
00101          }
00102          return evaluateISAAux(embed, propNames, className);
00103       }
00104       default:
00105          return false;
00106    }
00107 }
00109 bool WQLInstancePropertySource::classIsDerivedFrom(const String& cls, const String& className) const
00110 {
00111    CIMName curClassName = cls;
00112    while (curClassName != CIMName())
00113    {
00114       if (curClassName == className)
00115       {
00116          return true;
00117       }
00118       // didn't match, so try the superclass of curClassName
00119       CIMClass cls2 = m_hdl->getClass(m_ns, curClassName.toString());
00120       curClassName = cls2.getSuperClass();
00121    }
00122    return false;
00123 }
00125 bool WQLInstancePropertySource::getValueAux(const CIMInstance& ci, const StringArray& propNames, WQLOperand& value)
00126 {
00127    if (propNames.empty())
00128    {
00129       return false;
00130    }
00131    CIMProperty p = ci.getProperty(propNames[0]);
00132    if (!p)
00133    {
00134       return false;
00135    }
00136    CIMValue v = p.getValue();
00137    switch (v.getType())
00138    {
00139       case CIMDataType::DATETIME:
00140       case CIMDataType::CIMNULL:
00141          value = WQLOperand();
00142          break;
00143       case CIMDataType::UINT8:
00144       case CIMDataType::SINT8:
00145       case CIMDataType::UINT16:
00146       case CIMDataType::SINT16:
00147       case CIMDataType::UINT32:
00148       case CIMDataType::SINT32:
00149       case CIMDataType::UINT64:
00150       case CIMDataType::SINT64:
00151       case CIMDataType::CHAR16:
00152       {
00153          Int64 x;
00154          CIMValueCast::castValueToDataType(v, CIMDataType::SINT64).get(x);
00155          value = WQLOperand(x, WQL_INTEGER_VALUE_TAG);
00156          break;
00157       }
00158       case CIMDataType::STRING:
00159          value = WQLOperand(v.toString(), WQL_STRING_VALUE_TAG);
00160          break;
00161       case CIMDataType::BOOLEAN:
00162       {
00163          Bool b;
00164          v.get(b);
00165          value = WQLOperand(b, WQL_BOOLEAN_VALUE_TAG);
00166          break;
00167       }
00168       case CIMDataType::REAL32:
00169       case CIMDataType::REAL64:
00170       {
00171          Real64 x;
00172          CIMValueCast::castValueToDataType(v, CIMDataType::REAL64).get(x);
00173          value = WQLOperand(x, WQL_DOUBLE_VALUE_TAG);
00174          break;
00175       }
00176       case CIMDataType::REFERENCE:
00177          value = WQLOperand(v.toString(), WQL_STRING_VALUE_TAG);
00178          break;
00179       case CIMDataType::EMBEDDEDCLASS:
00180          value = WQLOperand();
00181          break;
00182       case CIMDataType::EMBEDDEDINSTANCE:
00183       {
00184          CIMInstance embed;
00185          v.get(embed);
00186          if (!embed)
00187          {
00188             return false;
00189          }
00190          StringArray newPropNames(propNames.begin() + 1, propNames.end());
00191          return getValueAux(embed, newPropNames, value);
00192       }
00193       break;
00194       default:
00195          value = WQLOperand();
00196          break;
00197    }
00198    return true;
00199 }
00200 
00201 } // end namespace OW_NAMESPACE
00202 

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