00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00036 #include "OW_config.h"
00037 #include "OW_CIMInstance.hpp"
00038 #include "OW_StringBuffer.hpp"
00039 #include "OW_CIMDataType.hpp"
00040 #include "OW_String.hpp"
00041 #include "OW_CIMValueCast.hpp"
00042 #include "OW_BinarySerialization.hpp"
00043 #include "OW_NoSuchPropertyException.hpp"
00044 #include "OW_StrictWeakOrdering.hpp"
00045 #include "OW_CIMProperty.hpp"
00046 #include "OW_CIMQualifier.hpp"
00047 #include "OW_CIMName.hpp"
00048 #include "OW_COWIntrusiveCountableBase.hpp"
00049 #include <algorithm> 
00050 
00051 namespace OW_NAMESPACE
00052 {
00053 
00054 using std::ostream;
00055 using std::istream;
00056 using namespace WBEMFlags;
00058 struct CIMInstance::INSTData : public COWIntrusiveCountableBase
00059 {
00060    String m_nameSpace;
00061    CIMName m_owningClassName;
00062    CIMPropertyArray m_keys;
00063    CIMPropertyArray m_properties;
00064    CIMQualifierArray m_qualifiers;
00065    String m_language;
00066    INSTData* clone() const { return new INSTData(*this); }
00067 };
00068 bool operator<(const CIMInstance::INSTData& x, const CIMInstance::INSTData& y)
00069 {
00070    return StrictWeakOrdering(
00071       x.m_nameSpace, y.m_nameSpace,
00072       x.m_owningClassName, y.m_owningClassName,
00073       x.m_properties, y.m_properties,
00074       x.m_keys, y.m_keys,
00075       x.m_qualifiers, y.m_qualifiers);
00076 }
00078 CIMInstance::CIMInstance() :
00079    CIMElement(), m_pdata(new INSTData)
00080 {
00081 }
00083 CIMInstance::CIMInstance(CIMNULL_t) :
00084    CIMElement(), m_pdata(0)
00085 {
00086 }
00088 CIMInstance::CIMInstance(const char* name) :
00089    CIMElement(), m_pdata(new INSTData)
00090 {
00091    m_pdata->m_owningClassName = name;
00092 }
00094 CIMInstance::CIMInstance(const CIMName& name) :
00095    CIMElement(), m_pdata(new INSTData)
00096 {
00097    m_pdata->m_owningClassName = name;
00098 }
00100 CIMInstance::CIMInstance(const CIMInstance& x) :
00101       CIMElement(x), m_pdata(x.m_pdata)
00102 {
00103 }
00105 CIMInstance::~CIMInstance()
00106 {
00107 }
00109 void
00110 CIMInstance::setNull()
00111 {
00112    m_pdata = NULL;
00113 }
00115 CIMInstance& CIMInstance::operator= (const CIMInstance& x)
00116 {
00117    m_pdata = x.m_pdata;
00118    return *this;
00119 }
00121 CIMInstance&
00122 CIMInstance::setKeys(const CIMPropertyArray& keys)
00123 {
00124    m_pdata->m_keys = keys;
00125    return *this;
00126 }
00128 String
00129 CIMInstance::getClassName() const
00130 {
00131    return m_pdata->m_owningClassName.toString();
00132 }
00134 CIMInstance& 
00135 CIMInstance::setNameSpace(const String& ns)
00136 {
00137    m_pdata->m_nameSpace = ns;
00138    return *this;
00139 }
00141 String 
00142 CIMInstance::getNameSpace() const
00143 {
00144    return m_pdata->m_nameSpace;
00145 }
00146 
00148 String
00149 CIMInstance::getLanguage() const
00150 {
00151    return m_pdata->m_language;
00152 }
00154 CIMInstance&
00155 CIMInstance::setLanguage(const String& language)
00156 {
00157    m_pdata->m_language = language;
00158    return *this;
00159 }
00161 CIMInstance&
00162 CIMInstance::setClassName(const CIMName& name)
00163 {
00164    m_pdata->m_owningClassName = name;
00165    return *this;
00166 }
00168 CIMQualifierArray
00169 CIMInstance::getQualifiers() const
00170 {
00171    return m_pdata->m_qualifiers;
00172 }
00174 CIMQualifier
00175 CIMInstance::getQualifier(const CIMName& qualName) const
00176 {
00177    for (size_t i = 0; i < m_pdata->m_qualifiers.size(); i++)
00178    {
00179       CIMQualifier qual = m_pdata->m_qualifiers[i];
00180       if (qual.getName() == qualName)
00181       {
00182          return qual;
00183       }
00184    }
00185    return CIMQualifier(CIMNULL);
00186 }
00188 CIMInstance&
00189 CIMInstance::removeQualifier(const CIMName& qualName)
00190 {
00191    for (size_t i = 0; i < m_pdata->m_qualifiers.size(); i++)
00192    {
00193       if (m_pdata->m_qualifiers[i].getName() == qualName)
00194       {
00195          m_pdata->m_qualifiers.remove(i);
00196          break;
00197       }
00198    }
00199    return *this;
00200 }
00202 CIMInstance&
00203 CIMInstance::setQualifier(const CIMQualifier& qual)
00204 {
00205    if (qual)
00206    {
00207       CIMName qualName = qual.getName();
00208       for (size_t i = 0; i < m_pdata->m_qualifiers.size(); i++)
00209       {
00210          if (m_pdata->m_qualifiers[i].getName() == qualName)
00211          {
00212             m_pdata->m_qualifiers[i] = qual;
00213             return *this;
00214          }
00215       }
00216       m_pdata->m_qualifiers.append(qual);
00217    }
00218    return *this;
00219 }
00221 CIMInstance&
00222 CIMInstance::setQualifiers(const CIMQualifierArray& quals)
00223 {
00224    m_pdata->m_qualifiers = quals;
00225    return *this;
00226 }
00228 CIMPropertyArray
00229 CIMInstance::getProperties(Int32 valueDataType) const
00230 {
00231    if (valueDataType == CIMDataType::INVALID)
00232    {
00233       return m_pdata->m_properties;
00234    }
00235    CIMPropertyArray pra;
00236    for (size_t i = 0; i < m_pdata->m_properties.size(); i++)
00237    {
00238       CIMProperty prop = m_pdata->m_properties[i];
00239       if (prop.getDataType().getType() == valueDataType)
00240       {
00241          pra.append(prop);
00242       }
00243    }
00244    return pra;
00245 }
00247 CIMInstance&
00248 CIMInstance::setProperties(const CIMPropertyArray& props)
00249 {
00250    m_pdata->m_properties = props;
00251    _buildKeys();
00252    return *this;
00253 }
00255 CIMProperty
00256 CIMInstance::getProperty(const CIMName& name,
00257    const CIMName& originClass) const
00258 {
00259    int tsize = m_pdata->m_properties.size();
00260    for (int i = 0; i < tsize; i++)
00261    {
00262       CIMProperty cp = m_pdata->m_properties[i];
00263       if (originClass == cp.getOriginClass()
00264          && name == cp.getName())
00265       {
00266          return(cp);
00267       }
00268    }
00269    return CIMProperty(CIMNULL);
00270 }
00272 CIMProperty
00273 CIMInstance::getProperty(const CIMName& propertyName) const
00274 {
00275    int tsize = m_pdata->m_properties.size();
00276    for (int i = 0; i < tsize; i++)
00277    {
00278       CIMProperty cp = m_pdata->m_properties[i];
00279       if (propertyName == cp.getName())
00280       {
00281          return(cp);
00282       }
00283    }
00284    return CIMProperty(CIMNULL);
00285 }
00287 CIMProperty
00288 CIMInstance::getPropertyT(const CIMName& propertyName) const
00289 {
00290    CIMProperty p = getProperty(propertyName);
00291    if (!p)
00292    {
00293       OW_THROW_ERR(NoSuchPropertyException, propertyName.toString().c_str(), E_INSTANCE_HAS_NO_SUCH_PROPERTY);
00294    }
00295    return p;
00296 }
00298 CIMValue
00299 CIMInstance::getPropertyValue(const CIMName& name) const
00300 {
00301    CIMProperty p = this->getProperty(name);
00302    if (p)
00303    {
00304       return p.getValue();
00305    }
00306    return CIMValue(CIMNULL);
00307 }
00309 bool
00310 CIMInstance::propertyHasValue(const CIMName& name) const
00311 {
00312    CIMProperty p = this->getProperty(name);
00313    if (p)
00314    {
00315       CIMValue v = p.getValue();
00316       if (v)
00317       {
00318          return true;
00319       }
00320       else
00321       {
00322          return false;
00323       }
00324    }
00325    return false;
00326 }
00328 
00329 void
00330 CIMInstance::_buildKeys()
00331 {
00332    m_pdata->m_keys.clear();
00333    int tsize = m_pdata->m_properties.size();
00334    for (int i = 0; i < tsize; i++)
00335    {
00336       CIMProperty cp = m_pdata->m_properties[i];
00337       if (cp.isKey())
00338       {
00339          m_pdata->m_keys.append(cp);
00340       }
00341    }
00342 }
00344 CIMPropertyArray
00345 CIMInstance::getKeyValuePairs() const
00346 {
00347    return m_pdata->m_keys;
00348 }
00350 CIMInstance&
00351 CIMInstance::updatePropertyValues(const CIMPropertyArray& props)
00352 {
00353    int tsize = props.size();
00354    for (int i = 0; i < tsize; i++)
00355    {
00356       updatePropertyValue(props[i]);
00357    }
00358    return *this;
00359 }
00361 CIMInstance&
00362 CIMInstance::updatePropertyValue(const CIMProperty& prop)
00363 {
00364    bool buildTheKeys = false;
00365    if (prop)
00366    {
00367       CIMName name = prop.getName();
00368       int tsize = m_pdata->m_properties.size();
00369       for (int i = 0; i < tsize; i++)
00370       {
00371          CIMProperty cp = m_pdata->m_properties[i];
00372          CIMName rname = cp.getName();
00373          if (rname == name)
00374          {
00375             m_pdata->m_properties[i].setValue(prop.getValue());
00376             if (cp.isKey() || prop.isKey())
00377             {
00378                
00379                
00380                
00381                
00382                buildTheKeys = true;
00383             }
00384             break;
00385          }
00386       }
00387       if (buildTheKeys)
00388       {
00389          _buildKeys();
00390       }
00391    }
00392    return *this;
00393 }
00394 
00396 CIMInstance&
00397 CIMInstance::updatePropertyValue(const CIMName& name, const CIMValue& value)
00398 {
00399    return updatePropertyValue(CIMProperty(name, value));
00400 }
00401 
00403 CIMInstance&
00404 CIMInstance::setProperty(const CIMName& name, const CIMValue& cv)
00405 {
00406    int tsize = m_pdata->m_properties.size();
00407    for (int i = 0; i < tsize; i++)
00408    {
00409       CIMProperty cp = m_pdata->m_properties[i];
00410       CIMName rname = cp.getName();
00411       if (rname == name)
00412       {
00413          m_pdata->m_properties[i].setValue(cv);
00414          if (cp.isKey())
00415          {
00416             _buildKeys();
00417          }
00418          return *this;
00419       }
00420    }
00421    
00422    
00423    
00424    CIMProperty cp(name);
00425    cp.setValue(cv);
00426    if (cv)
00427    {
00428       cp.setDataType(cv.getCIMDataType());
00429    }
00430    else
00431    {
00432       cp.setDataType(CIMDataType::CIMNULL);
00433    }
00434    m_pdata->m_properties.append(cp);
00435    
00436    
00437    
00438    
00439    return *this;
00440 }
00442 CIMInstance&
00443 CIMInstance::setProperty(const CIMProperty& prop)
00444 {
00445    if (prop)
00446    {
00447       CIMName propName = prop.getName();
00448       int tsize = m_pdata->m_properties.size();
00449       for (int i = 0; i < tsize; i++)
00450       {
00451          CIMProperty cp = m_pdata->m_properties[i];
00452          CIMName rname = cp.getName();
00453          if (rname == propName)
00454          {
00455             m_pdata->m_properties[i] = prop;
00456             
00457             
00458             if (cp.isKey() || prop.isKey())
00459             {
00460                _buildKeys();
00461             }
00462             return *this;
00463          }
00464       }
00465       
00466       
00467       
00468       m_pdata->m_properties.append(prop);
00469       if (prop.isKey())
00470       {
00471          _buildKeys();
00472       }
00473    }
00474    return *this;
00475 }
00477 CIMInstance&
00478 CIMInstance::removeProperty(const CIMName& propName)
00479 {
00480    int tsize = m_pdata->m_properties.size();
00481    for (int i = 0; i < tsize; i++)
00482    {
00483       CIMProperty cp = m_pdata->m_properties[i];
00484       if (cp.getName() == propName)
00485       {
00486          m_pdata->m_properties.remove(i);
00487          
00488          if (cp.isKey())
00489          {
00490             _buildKeys();
00491          }
00492          break;
00493       }
00494    }
00495    return *this;
00496 }
00498 CIMInstance
00499 CIMInstance::clone(ELocalOnlyFlag localOnly, EIncludeQualifiersFlag includeQualifiers,
00500    EIncludeClassOriginFlag includeClassOrigin, const StringArray* propertyList) const
00501 {
00502    StringArray lproplist;
00503    bool noprops = false;
00504    if (propertyList)
00505    {
00506       if (propertyList->size() == 0)
00507       {
00508          noprops = true;
00509       }
00510       else
00511       {
00512          lproplist = *propertyList;
00513       }
00514    }
00515    return clone(localOnly, includeQualifiers, includeClassOrigin, lproplist,
00516       noprops);
00517 }
00519 CIMInstance
00520 CIMInstance::clone(ELocalOnlyFlag localOnly, EIncludeQualifiersFlag includeQualifiers,
00521    EIncludeClassOriginFlag includeClassOrigin, const StringArray& propertyList,
00522    bool noProps) const
00523 {
00524    CIMInstance ci;
00525    ci.m_pdata->m_nameSpace = m_pdata->m_nameSpace;
00526    ci.m_pdata->m_owningClassName = m_pdata->m_owningClassName;
00527    ci.m_pdata->m_keys = m_pdata->m_keys;
00528    ci.m_pdata->m_language = m_pdata->m_language;
00529    
00530    
00531    
00532    if (includeQualifiers == E_INCLUDE_QUALIFIERS)
00533    {
00534       CIMQualifierArray qra;
00535       for (size_t i = 0; i < m_pdata->m_qualifiers.size(); i++)
00536       {
00537          CIMQualifier cq = m_pdata->m_qualifiers[i];
00538          if ((localOnly == E_LOCAL_ONLY) && cq.getPropagated())
00539          {
00540             continue;
00541          }
00542          qra.append(cq);
00543       }
00544       ci.m_pdata->m_qualifiers = qra;
00545    }
00546    if (!noProps)
00547    {
00548       CIMPropertyArray props;
00549       for (size_t i = 0; i < m_pdata->m_properties.size(); i++)
00550       {
00551          CIMProperty prop = m_pdata->m_properties[i];
00552          if ((localOnly == E_LOCAL_ONLY) && prop.getPropagated())
00553          {
00554             continue;
00555          }
00556          
00557          
00558          
00559          if (propertyList.size() != 0)
00560          {
00561             CIMName pName = prop.getName();
00562             for (size_t j = 0; j < propertyList.size(); j++)
00563             {
00564                if (pName == propertyList[j])
00565                {
00566                   props.append(prop.clone(includeQualifiers,
00567                      includeClassOrigin));
00568                   break;
00569                }
00570             }
00571          }
00572          else
00573          {
00574             props.append(prop.clone(includeQualifiers,
00575                includeClassOrigin));
00576          }
00577       }
00578       ci.m_pdata->m_properties = props;
00579    }
00580    return ci;
00581 }
00583 CIMInstance
00584 CIMInstance::clone(ELocalOnlyFlag localOnly, EDeepFlag deep, EIncludeQualifiersFlag includeQualifiers,
00585    EIncludeClassOriginFlag includeClassOrigin, const StringArray* propertyList,
00586    const CIMClass& requestedClass, const CIMClass& cimClass) const
00587 {
00588    CIMInstance ci(*this);
00589    ci.syncWithClass(cimClass, E_INCLUDE_QUALIFIERS);
00590    ci = ci.clone(E_NOT_LOCAL_ONLY, includeQualifiers,
00591       includeClassOrigin, propertyList);
00592    
00593    
00594    if (deep != E_DEEP || localOnly != E_NOT_LOCAL_ONLY)
00595    {
00596       CIMPropertyArray props = ci.getProperties();
00597       CIMPropertyArray newprops;
00598       CIMInstance newInst(ci);
00599       CIMName requestedClassName = requestedClass.getName();
00600       for (size_t i = 0; i < props.size(); ++i)
00601       {
00602          CIMProperty p = props[i];
00603          CIMProperty clsp = requestedClass.getProperty(p.getName());
00604          if (clsp)
00605          {
00606             if (clsp.getOriginClass() == requestedClassName)
00607             {
00608                newprops.push_back(p);
00609                continue;
00610             }
00611          }
00612          if (deep == E_DEEP)
00613          {
00614             if (!clsp
00615                || p.getOriginClass() != clsp.getOriginClass())
00616             {
00617                
00618                newprops.push_back(p);
00619                continue;
00620             }
00621          }
00622          if (localOnly == E_NOT_LOCAL_ONLY)
00623          {
00624             if (clsp)
00625             {
00626                
00627                newprops.push_back(p);
00628                continue;
00629             }
00630          }
00631       }
00632       newInst.setProperties(newprops);
00633       newInst.setKeys(ci.getKeyValuePairs());
00634       ci = newInst;
00635    }
00636    return ci;
00637 }
00639 CIMInstance
00640 CIMInstance::filterProperties(const StringArray& propertyList,
00641    EIncludeQualifiersFlag includeQualifiers, EIncludeClassOriginFlag includeClassOrigin,
00642    bool ignorePropertyList) const
00643 {
00644    bool noprops(propertyList.size() == 0 && ignorePropertyList == false);
00645    return clone(E_NOT_LOCAL_ONLY, includeQualifiers, includeClassOrigin, propertyList,
00646       noprops);
00647 }
00649 String
00650 CIMInstance::getName() const
00651 {
00652    return m_pdata->m_owningClassName.toString();
00653 }
00655 CIMInstance&
00656 CIMInstance::syncWithClass(const CIMClass& theClass,
00657    EIncludeQualifiersFlag includeQualifiers)
00658 {
00659    if (!theClass)
00660    {
00661       return *this;
00662    }
00663 
00664 
00665 
00666 
00667 
00668 
00669 
00670 
00671 
00672 
00673 
00674 
00675 
00676 
00677 
00678 
00679 
00680 
00681 
00682 
00683 
00684 
00685 
00686 
00687 
00688 
00689 
00690 
00691 
00692 
00693 
00694 
00695 
00696 
00697 
00698 
00699    CIMName propName;
00700    CIMPropertyArray classProps = theClass.getAllProperties();
00701    CIMPropertyArray instProps = getProperties();
00702    
00703    
00704    size_t i = 0;
00705    while (i < instProps.size())
00706    {
00707       propName = instProps[i].getName();
00708       if (!theClass.getProperty(propName))
00709       {
00710          instProps.remove(i);
00711       }
00712       else
00713       {
00714          ++i;
00715       }
00716    }
00717 
00718    
00719    
00720    for (size_t i = 0; i < classProps.size(); i++)
00721    {
00722       bool found = false;
00723       CIMProperty cprop = classProps[i];
00724       propName = cprop.getName();
00725       for (size_t j = 0; j < instProps.size(); j++)
00726       {
00727          CIMProperty iprop = instProps[j];
00728          if (iprop.getName() == propName)
00729          {
00730             CIMValue cv = iprop.getValue();
00731             iprop = cprop;
00732             if (cv)
00733             {
00734                if (cv.getType() != iprop.getDataType().getType())
00735                {
00736                   
00737                   if (cv.getType() != CIMDataType::EMBEDDEDCLASS && cv.getType() != CIMDataType::EMBEDDEDINSTANCE)
00738                   {
00739                      cv = CIMValueCast::castValueToDataType(cv,
00740                         iprop.getDataType());
00741                   }
00742                }
00743                iprop.setValue(cv);
00744             }
00745             instProps[j] = iprop;
00746             found = true;
00747             break;
00748          }
00749       }
00750       if (!found)
00751       {
00752          instProps.append(classProps[i]);
00753       }
00754    }
00755    setProperties(instProps);
00756    if (!includeQualifiers)
00757    {
00758       for (size_t i = 0; i < m_pdata->m_properties.size(); i++)
00759       {
00760          m_pdata->m_properties[i].clearNonKeyQualifiers();
00761       }
00762    }
00763    return *this;
00764 }
00766 CIMInstance
00767 CIMInstance::createModifiedInstance(
00768    const CIMInstance& previousInstance,
00769    EIncludeQualifiersFlag includeQualifiers,
00770    const StringArray* propertyList,
00771    const CIMClass& theClass) const
00772 {
00773    CIMInstance newInst(*this);
00774    if (!includeQualifiers)
00775    {
00776       newInst.setQualifiers(previousInstance.getQualifiers());
00777    }
00778    if (propertyList)
00779    {
00780       newInst.setProperties(previousInstance.getProperties());
00781       for (StringArray::const_iterator i = propertyList->begin();
00782           i != propertyList->end(); ++i)
00783       {
00784          CIMProperty p = this->getProperty(*i);
00785          if (p)
00786          {
00787             if (!includeQualifiers)
00788             {
00789                CIMProperty cp = theClass.getProperty(*i);
00790                if (cp)
00791                {
00792                   p.setQualifiers(cp.getQualifiers());
00793                }
00794             }
00795             newInst.setProperty(p);
00796          }
00797          else
00798          {
00799             CIMProperty cp = theClass.getProperty(*i);
00800             if (cp)
00801             {
00802                newInst.setProperty(cp);
00803             }
00804             else
00805             {
00806                newInst.removeProperty(*i);
00807             }
00808          }
00809       }
00810    }
00811    return newInst;
00812 }
00814 void
00815 CIMInstance::setName(const CIMName& name)
00816 {
00817    m_pdata->m_owningClassName = name;
00818 }
00820 void
00821 CIMInstance::readObject(istream &istrm)
00822 {
00823    CIMName owningClassName;
00824    CIMPropertyArray properties;
00825    CIMPropertyArray keys;
00826    CIMQualifierArray qualifiers;
00827    String language, nameSpace;
00828 
00829    UInt32 version = CIMBase::readSig(istrm, OW_CIMINSTANCESIG,
00830       OW_CIMINSTANCESIG_V, CIMInstance::SERIALIZATION_VERSION);
00831 
00832    owningClassName.readObject(istrm);
00833    BinarySerialization::readArray(istrm, keys);
00834    BinarySerialization::readArray(istrm, properties);
00835    BinarySerialization::readArray(istrm, qualifiers);
00836    
00837    if (version > 0)
00838    {
00839       language.readObject(istrm);
00840    }
00841    
00842    if (version > 1)
00843    {
00844       nameSpace.readObject(istrm);
00845    }
00846    if (!m_pdata)
00847    {
00848       m_pdata = new INSTData;
00849    }
00850    m_pdata->m_owningClassName = owningClassName;
00851    m_pdata->m_keys = keys;
00852    m_pdata->m_properties = properties;
00853    m_pdata->m_qualifiers = qualifiers;
00854    m_pdata->m_language = language;
00855    m_pdata->m_nameSpace = nameSpace;
00856 }
00858 void
00859 CIMInstance::writeObject(std::ostream &ostrm) const
00860 {
00861    
00862    CIMBase::writeSig(ostrm, OW_CIMINSTANCESIG_V, CIMInstance::SERIALIZATION_VERSION);
00863    m_pdata->m_owningClassName.writeObject(ostrm);
00864    BinarySerialization::writeArray(ostrm, m_pdata->m_keys);
00865    BinarySerialization::writeArray(ostrm, m_pdata->m_properties);
00866    BinarySerialization::writeArray(ostrm, m_pdata->m_qualifiers);
00867    m_pdata->m_language.writeObject(ostrm);
00868    m_pdata->m_nameSpace.writeObject(ostrm);
00869 }
00871 String
00872 CIMInstance::toMOF() const
00873 {
00874    size_t i;
00875    StringBuffer rv;
00876    if (m_pdata->m_qualifiers.size() > 0)
00877    {
00878       rv += "[\n";
00879       for (i = 0; i < m_pdata->m_qualifiers.size(); i++)
00880       {
00881          if (i > 0)
00882          {
00883             rv += ',';
00884          }
00885          rv += m_pdata->m_qualifiers[i].toMOF();
00886       }
00887       rv += "]\n";
00888    }
00889    rv += "INSTANCE OF ";
00890    rv += m_pdata->m_owningClassName.toString();
00891    rv += "\n{\n";
00892    for (i = 0; i < m_pdata->m_properties.size(); i++)
00893    {
00894       
00895       
00896       const CIMProperty& p = m_pdata->m_properties[i];
00897       if (p.hasTrueQualifier(CIMQualifier::CIM_QUAL_INVISIBLE))
00898       {
00899          continue;
00900       }
00901       CIMValue v = p.getValue();
00902       if (v)
00903       {
00904          
00905          CIMQualifierArray qualifiers = p.getQualifiers();
00906          if (qualifiers.size() > 0)
00907          {
00908             rv += "  [";
00909             for (size_t i = 0; i < qualifiers.size(); i++)
00910             {
00911                const CIMQualifier& nq = qualifiers[i];
00912                if (i > 0)
00913                {
00914                   rv += ',';
00915                }
00916                rv += nq.toMOF();
00917             }
00918             rv += "]\n";
00919          }
00920          rv += "  ";
00921          rv += p.getName();
00922          rv += '=';
00923          rv += v.toMOF();
00924          rv += ";\n";
00925       }
00926       else
00927       {
00928          rv += "  ";
00929          rv += p.getName();
00930          rv += "=NULL;\n";
00931       }
00932    }
00933    rv += "};\n";
00934    return rv.releaseString();
00935 }
00937 String
00938 CIMInstance::toString() const
00939 {
00940    size_t i;
00941    StringBuffer temp;
00942    String outVal;
00943    temp += "instance of ";
00944    temp += m_pdata->m_owningClassName.toString() + " {\n";
00945    for (i = 0; i < m_pdata->m_properties.size(); i++)
00946    {
00947       CIMProperty cp = m_pdata->m_properties[i];
00948       if (cp.hasTrueQualifier(CIMQualifier::CIM_QUAL_INVISIBLE))
00949       {
00950          continue;
00951       }
00952 
00953       CIMValue val = cp.getValue();
00954       if (!val)
00955       {
00956          outVal = "null";
00957       }
00958       else
00959       {
00960          outVal = val.toString();
00961       }
00962       temp += cp.getName() + " = " + outVal + ";\n";
00963    }
00964    temp += "}\n";
00965    return temp.releaseString();
00966 }
00968 bool operator<(const CIMInstance& x, const CIMInstance& y)
00969 {
00970    return *x.m_pdata < *y.m_pdata;
00971 }
00973 bool CIMInstance::propertiesAreEqualTo(const CIMInstance& other) const
00974 {
00975    CIMPropertyArray props1(getProperties());
00976    CIMPropertyArray props2(other.getProperties());
00977    if (props1.size() != props2.size())
00978    {
00979       return false;
00980    }
00981    std::sort(props1.begin(), props1.end());
00982    std::sort(props2.begin(), props2.end());
00983    CIMPropertyArray::iterator i1 = props1.begin();
00984    CIMPropertyArray::iterator i2 = props2.begin();
00985    while (i1 != props1.end())
00986    {
00987       CIMProperty p1 = *i1;
00988       CIMProperty p2 = *i2;
00989       if (p1 != p2) 
00990       {
00991          return false;
00992       }
00993       if (p1.getValue() != p2.getValue()) 
00994       {
00995          return false;
00996       }
00997       ++i1;
00998       ++i2;
00999    }
01000    return true;
01001 }
01002 
01003 } 
01004