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 "OWBI1_config.h"
00037 #include "OWBI1_CIMClass.hpp"
00038 #include "OWBI1_StringBuffer.hpp"
00039 #include "OW_Assertion.hpp"
00040 #include "OWBI1_CIMQualifier.hpp"
00041 #include "OWBI1_CIMQualifierType.hpp"
00042 #include "OWBI1_CIMProperty.hpp"
00043 #include "OWBI1_CIMMethod.hpp"
00044 #include "OWBI1_CIMInstance.hpp"
00045 #include "OWBI1_CIMUrl.hpp"
00046 #include "OWBI1_CIMValue.hpp"
00047 #include "OWBI1_CIMName.hpp"
00048 #include "OW_BinarySerialization.hpp"
00049 #include "OW_StrictWeakOrdering.hpp"
00050 #include "OWBI1_COWIntrusiveCountableBase.hpp"
00051
00052 #include <algorithm>
00053
00054 namespace OWBI1
00055 {
00056
00057 using namespace OpenWBEM;
00058 using std::istream;
00059 using std::ostream;
00060 using namespace WBEMFlags;
00061
00063 struct CIMClass::CLSData : public COWIntrusiveCountableBase
00064 {
00065 CLSData() :
00066 m_associationFlag(false), m_isKeyed(false){ }
00067 CIMName m_name;
00068 CIMName m_parentClassName;
00069 CIMQualifierArray m_qualifiers;
00070 CIMPropertyArray m_properties;
00071 CIMMethodArray m_methods;
00072 Bool m_associationFlag;
00073 Bool m_isKeyed;
00074 CLSData* clone() const { return new CLSData(*this); }
00075 };
00077 bool operator<(const CIMClass::CLSData& x, const CIMClass::CLSData& y)
00078 {
00079 return StrictWeakOrdering(x.m_name, y.m_name,
00080 x.m_parentClassName, y.m_parentClassName,
00081 x.m_qualifiers, y.m_qualifiers,
00082 x.m_properties, y.m_properties,
00083 x.m_methods, y.m_methods);
00084 }
00086 bool operator==(const CIMClass::CLSData& x, const CIMClass::CLSData& y)
00087 {
00088 return x.m_name == y.m_name &&
00089 x.m_parentClassName == y.m_parentClassName &&
00090 x.m_qualifiers == y.m_qualifiers &&
00091 x.m_properties == y.m_properties &&
00092 x.m_methods == y.m_methods;
00093 }
00095 CIMClass::CIMClass() :
00096 m_pdata(new CLSData)
00097 {
00098 }
00100 CIMClass::CIMClass(CIMNULL_t) :
00101 m_pdata(0)
00102 {
00103 }
00105 CIMClass::CIMClass(const char* name) :
00106 m_pdata(new CLSData)
00107 {
00108 m_pdata->m_name = name;
00109 }
00111 CIMClass::CIMClass(const CIMName& name) :
00112 m_pdata(new CLSData)
00113 {
00114 m_pdata->m_name = name;
00115 }
00116
00118 CIMClass::CIMClass(const CIMClassRepRef& rep)
00119 : m_rep(rep)
00120 {
00121 }
00122
00124 void
00125 CIMClass::setName(const CIMName& name)
00126 {
00127 m_pdata->m_name = name;
00128 }
00130 CIMName
00131 CIMClass::getSuperClass() const
00132 {
00133 return m_pdata->m_parentClassName;
00134 }
00136 CIMClass&
00137 CIMClass::setSuperClass(const CIMName& pname)
00138 {
00139 m_pdata->m_parentClassName = pname;
00140 return *this;
00141 }
00143 bool
00144 CIMClass::isKeyed() const
00145 {
00146 return m_pdata->m_isKeyed;
00147 }
00149 CIMClass&
00150 CIMClass::setIsKeyed(bool isKeyedParm)
00151 {
00152 m_pdata->m_isKeyed = isKeyedParm;
00153 return *this;
00154 }
00156 CIMPropertyArray
00157 CIMClass::getKeys() const
00158 {
00159 CIMPropertyArray v;
00160 for (size_t i = 0; i < m_pdata->m_properties.size(); i++)
00161 {
00162 const CIMProperty& p = m_pdata->m_properties[i];
00163 if (p.isKey())
00164 {
00165 v.append(p);
00166 }
00167 }
00168 return v;
00169 }
00171 CIMQualifier
00172 CIMClass::getQualifier(const CIMName& name) const
00173 {
00174 for (size_t i = 0; i < m_pdata->m_qualifiers.size(); i++)
00175 {
00176 CIMQualifier q = m_pdata->m_qualifiers[i];
00177 if (q.getName() == name)
00178 {
00179 return q;
00180 }
00181 }
00182 return CIMQualifier(CIMNULL);
00183 }
00185 CIMProperty
00186 CIMClass::getProperty(const CIMName& prpName) const
00187 {
00188 return getProperty(prpName, "");
00189 }
00191 CIMProperty
00192 CIMClass::getProperty(const CIMName& name,
00193 const CIMName& originClass) const
00194 {
00195
00196
00197
00198
00199 if (originClass != "")
00200 {
00201 for (size_t i = 0; i < m_pdata->m_properties.size(); i++)
00202 {
00203 CIMProperty cp = m_pdata->m_properties[i];
00204 if (cp.getOriginClass() == originClass && cp.getName() == name)
00205 {
00206 return cp;
00207 }
00208 }
00209 }
00210 else
00211 {
00212 for (size_t i = 0; i < m_pdata->m_properties.size(); i++)
00213 {
00214 CIMProperty cp = m_pdata->m_properties[i];
00215 if (cp.getName() == name)
00216 {
00217 return(cp);
00218 }
00219 }
00220 }
00221 return CIMProperty(CIMNULL);
00222 }
00224 CIMMethod
00225 CIMClass::getMethod(const CIMName& name) const
00226 {
00227 return getMethod(name, "");
00228 }
00230 CIMMethod
00231 CIMClass::getMethod(const CIMName& name,
00232 const CIMName& originClass) const
00233 {
00234
00235
00236
00237
00238 if (originClass != "")
00239 {
00240 int tsize = m_pdata->m_methods.size();
00241 for (int i = 0; i < tsize; i++)
00242 {
00243 CIMMethod q = m_pdata->m_methods[i];
00244 if (q.getOriginClass() == originClass && (q.getName() == name))
00245 {
00246 return q;
00247 }
00248 }
00249 }
00250 else
00251 {
00252 int tsize = m_pdata->m_methods.size();
00253 for (int i = 0; i < tsize; i++)
00254 {
00255 CIMMethod q = m_pdata->m_methods[i];
00256 if (q.getName() == name)
00257 {
00258 return q;
00259 }
00260 }
00261 }
00262 return CIMMethod(CIMNULL);
00263 }
00265 bool
00266 CIMClass::isAssociation() const
00267 {
00268 return m_pdata->m_associationFlag;
00269 }
00271 CIMClass&
00272 CIMClass::setIsAssociation(bool isAssocFlag)
00273 {
00274 m_pdata->m_associationFlag = isAssocFlag;
00275 return *this;
00276 }
00278 CIMQualifierArray
00279 CIMClass::getQualifiers() const
00280 {
00281 return m_pdata->m_qualifiers;
00282 }
00284 CIMPropertyArray
00285 CIMClass::getAllProperties() const
00286 {
00287 return m_pdata->m_properties;
00288 }
00290 CIMName
00291 CIMClass::getKeyClass() const
00292 {
00293 for (size_t i = 0; i < m_pdata->m_properties.size(); i++)
00294 {
00295 CIMProperty p = m_pdata->m_properties[i];
00296 if (p.isKey())
00297 {
00298 return p.getOriginClass();
00299 }
00300 }
00301 return CIMName();
00302 }
00304 CIMPropertyArray
00305 CIMClass::getProperties() const
00306 {
00307 CIMPropertyArray prop;
00308 for (size_t i = 0; i < m_pdata->m_properties.size(); i++)
00309 {
00310 CIMProperty cp = m_pdata->m_properties[i];
00311 if (!cp.hasTrueQualifier(CIMQualifier::CIM_QUAL_OVERRIDE))
00312 {
00313 prop.append(cp);
00314 }
00315 }
00316 return(prop);
00317 }
00319 CIMMethodArray
00320 CIMClass::getAllMethods() const
00321 {
00322 return m_pdata->m_methods;
00323 }
00325 CIMMethodArray
00326 CIMClass::getMethods() const
00327 {
00328 CIMMethodArray meth;
00329 int tsize = m_pdata->m_methods.size();
00330 for (int i = 0; i < tsize; i++)
00331 {
00332 CIMMethod cm = m_pdata->m_methods[i];
00333 if (cm.getQualifier(CIMQualifier::CIM_QUAL_OVERRIDE))
00334 {
00335 meth.append(cm);
00336 }
00337 }
00338 return meth;
00339 }
00341 CIMClass&
00342 CIMClass::addProperty(const CIMProperty& prop)
00343 {
00344 if (prop)
00345 {
00346 m_pdata->m_properties.append(prop);
00347 if (prop.isKey())
00348 {
00349 m_pdata->m_isKeyed = true;
00350 }
00351 }
00352 return *this;
00353 }
00355 int
00356 CIMClass::numberOfProperties() const
00357 {
00358 return m_pdata->m_properties.size();
00359 }
00361 CIMClass&
00362 CIMClass::setProperties(const CIMPropertyArray& props)
00363 {
00364 m_pdata->m_properties = props;
00365 return *this;
00366 }
00368 CIMClass&
00369 CIMClass::setProperty(const CIMProperty& prop)
00370 {
00371 CIMName argName = prop.getName();
00372 for (size_t i = 0; i < m_pdata->m_properties.size(); i++)
00373 {
00374 if (argName == m_pdata->m_properties[i].getName())
00375 {
00376 m_pdata->m_properties[i] = prop;
00377 return *this;
00378 }
00379 }
00380 m_pdata->m_properties.append(prop);
00381 return *this;
00382 }
00384 CIMClass&
00385 CIMClass::setMethod(const CIMMethod& meth)
00386 {
00387 CIMName argName = meth.getName();
00388 for (size_t i = 0; i < m_pdata->m_methods.size(); i++)
00389 {
00390 if (argName == m_pdata->m_methods[i].getName())
00391 {
00392 m_pdata->m_methods[i] = meth;
00393 return *this;
00394 }
00395 }
00396 m_pdata->m_methods.append(meth);
00397 return *this;
00398 }
00400 CIMClass&
00401 CIMClass::addQualifier(const CIMQualifier& qual)
00402 {
00403 if (!qual)
00404 {
00405 return *this;
00406 }
00407
00408
00409
00410 for (size_t i = 0; i < m_pdata->m_qualifiers.size(); i++)
00411 {
00412 if (m_pdata->m_qualifiers[i].equals(qual))
00413 {
00414 m_pdata->m_qualifiers.remove(i);
00415 break;
00416 }
00417 }
00418 if (qual.getName() == CIMQualifier::CIM_QUAL_ASSOCIATION)
00419 {
00420 CIMValue v = qual.getValue();
00421 if (v && v.getType() == CIMDataType::BOOLEAN)
00422 {
00423 Bool b;
00424 qual.getValue().get(b);
00425 m_pdata->m_associationFlag = b;
00426 }
00427 else
00428 {
00429 m_pdata->m_associationFlag = false;
00430 }
00431 }
00432 m_pdata->m_qualifiers.append(qual);
00433 return *this;
00434 }
00436 bool
00437 CIMClass::hasQualifier(const CIMQualifier& qual) const
00438 {
00439 if (qual)
00440 {
00441 for (size_t i = 0; i < m_pdata->m_qualifiers.size(); i++)
00442 {
00443 if (m_pdata->m_qualifiers[i].equals(qual))
00444 {
00445 return true;
00446 }
00447 }
00448 }
00449 return false;
00450 }
00452 int
00453 CIMClass::numberOfQualifiers() const
00454 {
00455 return m_pdata->m_qualifiers.size();
00456 }
00458 bool
00459 CIMClass::removeQualifier(const CIMQualifier& qual)
00460 {
00461 bool cc = false;
00462 if (qual)
00463 {
00464 for (size_t i = 0; i < m_pdata->m_qualifiers.size(); i++)
00465 {
00466 CIMQualifier cq = m_pdata->m_qualifiers[i];
00467 if (cq.equals(qual))
00468 {
00469 m_pdata->m_qualifiers.remove(i);
00470 cc = true;
00471 break;
00472 }
00473 }
00474 }
00475 return cc;
00476 }
00478 bool
00479 CIMClass::removeQualifier(const CIMName& name)
00480 {
00481 bool cc = false;
00482 for (size_t i = 0; i < m_pdata->m_qualifiers.size(); i++)
00483 {
00484 CIMQualifier cq = m_pdata->m_qualifiers[i];
00485 if (cq.getName() == name)
00486 {
00487 m_pdata->m_qualifiers.remove(i);
00488 cc = true;
00489 break;
00490 }
00491 }
00492 return cc;
00493 }
00495 bool
00496 CIMClass::removeProperty(const CIMName& name)
00497 {
00498 bool cc = false;
00499 for (size_t i = 0; i < m_pdata->m_properties.size(); i++)
00500 {
00501 CIMProperty prop = m_pdata->m_properties[i];
00502 if (prop.getName() == name)
00503 {
00504 m_pdata->m_properties.remove(i);
00505 cc = true;
00506 break;
00507 }
00508 }
00509 return cc;
00510 }
00512 CIMClass&
00513 CIMClass::setQualifiers(const CIMQualifierArray& quals)
00514 {
00515 m_pdata->m_qualifiers = quals;
00516 return *this;
00517 }
00519 CIMClass&
00520 CIMClass::setQualifier(const CIMQualifier& qual)
00521 {
00522 if (qual)
00523 {
00524 bool found = false;
00525 for (size_t i = 0; i < m_pdata->m_qualifiers.size(); i++)
00526 {
00527 CIMQualifier cq = m_pdata->m_qualifiers[i];
00528 if (cq.equals(qual))
00529 {
00530 m_pdata->m_qualifiers[i] = qual;
00531 found = true;
00532 break;
00533 }
00534 }
00535 if (!found)
00536 {
00537 m_pdata->m_qualifiers.append(qual);
00538 }
00539 }
00540 return *this;
00541 }
00543 CIMClass&
00544 CIMClass::addMethod(const CIMMethod& meth)
00545 {
00546 if (meth)
00547 {
00548 m_pdata->m_methods.append(meth);
00549 }
00550 return *this;
00551 }
00553 CIMClass&
00554 CIMClass::setMethods(const CIMMethodArray& meths)
00555 {
00556 m_pdata->m_methods = meths;
00557 return *this;
00558 }
00560 CIMInstance
00561 CIMClass::newInstance() const
00562 {
00563 CIMInstance cInstance;
00564 cInstance.syncWithClass(*this);
00565 cInstance.setClassName(m_pdata->m_name);
00566 return cInstance;
00567 }
00569 void
00570 CIMClass::readObject(istream &istrm)
00571 {
00572 CIMName name;
00573 CIMName pcName;
00574 CIMQualifierArray qra;
00575 CIMPropertyArray pra;
00576 CIMMethodArray mra;
00577 Bool isAssocFlag;
00578 Bool isK;
00579
00580 UInt32 version = CIMBase::readSig(istrm, OWBI1_CIMCLASSSIG, OWBI1_CIMCLASSSIG_V, CIMClass::SERIALIZATION_VERSION);
00581 name.readObject(istrm);
00582 pcName.readObject(istrm);
00583 isAssocFlag.readObject(istrm);
00584 isK.readObject(istrm);
00585 BinarySerialization::readArray(istrm, qra);
00586 BinarySerialization::readArray(istrm, pra);
00587 BinarySerialization::readArray(istrm, mra);
00588
00589
00590 if (version == 1)
00591 {
00592 String language;
00593 language.readObject(istrm);
00594 }
00595 if (!m_pdata)
00596 {
00597 m_pdata = new CLSData;
00598 }
00599 m_pdata->m_name = name;
00600 m_pdata->m_parentClassName = pcName;
00601 m_pdata->m_associationFlag = isAssocFlag;
00602 m_pdata->m_isKeyed = isK;
00603 m_pdata->m_qualifiers = qra;
00604 m_pdata->m_properties = pra;
00605 m_pdata->m_methods = mra;
00606 }
00608 void
00609 CIMClass::writeObject(ostream &ostrm) const
00610 {
00611
00612
00613
00614
00615
00616
00617 CIMBase::writeSig(ostrm, OWBI1_CIMCLASSSIG);
00618 m_pdata->m_name.writeObject(ostrm);
00619 m_pdata->m_parentClassName.writeObject(ostrm);
00620 m_pdata->m_associationFlag.writeObject(ostrm);
00621 m_pdata->m_isKeyed.writeObject(ostrm);
00622 BinarySerialization::writeArray(ostrm, m_pdata->m_qualifiers);
00623 BinarySerialization::writeArray(ostrm, m_pdata->m_properties);
00624 BinarySerialization::writeArray(ostrm, m_pdata->m_methods);
00625 }
00627 String
00628 CIMClass::toMOF() const
00629 {
00630 size_t i;
00631 StringBuffer rv;
00632 if (m_pdata->m_qualifiers.size() != 0)
00633 {
00634 rv += "[";
00635 CIMQualifierArray qra = m_pdata->m_qualifiers;
00636
00637
00638
00639
00640 CIMQualifierArray::iterator iter = std::find(
00641 qra.begin(), qra.end(),
00642 CIMQualifier(CIMQualifier::CIM_QUAL_ASSOCIATION));
00643 if (iter != qra.end())
00644 {
00645 if (iter != qra.begin())
00646 {
00647
00648 CIMQualifier tmp = *iter;
00649 qra.erase(iter);
00650 qra.insert(qra.begin(), tmp);
00651 }
00652 }
00653 else
00654 {
00655
00656
00657
00658
00659
00660
00661
00662
00663 }
00664 iter = std::find( qra.begin(), qra.end(),
00665 CIMQualifier(CIMQualifier::CIM_QUAL_INDICATION));
00666 if (iter != qra.end())
00667 {
00668 std::swap(*iter, *qra.begin());
00669 }
00670 for (i = 0; i < qra.size(); i++)
00671 {
00672 if (i > 0)
00673 {
00674 rv += ",\n ";
00675 }
00676 rv += qra[i].toMOF();
00677 }
00678 rv += "]\n";
00679 }
00680 rv += "class ";
00681 rv += getName().toString();
00682 if (m_pdata->m_parentClassName != "")
00683 {
00684 rv += ':';
00685 rv += m_pdata->m_parentClassName.toString();
00686 }
00687 rv += "\n{\n";
00688 for (i = 0; i < m_pdata->m_properties.size(); i++)
00689 {
00690 rv += m_pdata->m_properties[i].toMOF();
00691
00692 }
00693 for (i = 0; i < m_pdata->m_methods.size(); i++)
00694 {
00695 rv += m_pdata->m_methods[i].toMOF();
00696
00697 }
00698 rv += "};\n";
00699 return rv.releaseString();
00700 }
00702 String
00703 CIMClass::toString() const
00704 {
00705 return toMOF();
00706 }
00708 CIMClass::~CIMClass()
00709 {
00710 }
00712 CIMClass::CIMClass(const CIMClass& x)
00713 : CIMElement(x)
00714 , m_pdata(x.m_pdata)
00715 {
00716 }
00718 CIMClass& CIMClass::operator=(const CIMClass& x)
00719 {
00720 m_pdata = x.m_pdata;
00721 return *this;
00722 }
00724 void
00725 CIMClass::setNull()
00726 {
00727 m_pdata = NULL;
00728 }
00730 CIMName
00731 CIMClass::getName() const
00732 {
00733 return m_pdata->m_name;
00734 }
00736 bool operator<(const CIMClass& x, const CIMClass& y)
00737 {
00738 return *x.m_pdata < *y.m_pdata;
00739 }
00740
00742 bool operator==(const CIMClass& x, const CIMClass& y)
00743 {
00744 return *x.m_pdata == *y.m_pdata;
00745 }
00746
00748 bool operator<=(const CIMClass& x, const CIMClass& y)
00749 {
00750 return !(y < x);
00751 }
00752
00754 bool operator>(const CIMClass& x, const CIMClass& y)
00755 {
00756 return y < x;
00757 }
00758
00760 bool operator>=(const CIMClass& x, const CIMClass& y)
00761 {
00762 return !(x < y);
00763 }
00764
00766 bool operator!=(const CIMClass& x, const CIMClass& y)
00767 {
00768 return !(x == y);
00769 }
00770
00771 operator safe_bool () const
00772 {
00773 return m_pdata ? &CIMClass::m_pdata : 0;
00774 }
00775 bool operator!() const
00776 {
00777 return !this->m_pdata;
00778 }
00779
00780 CIMClassRepRef
00781 CIMClass::getRep() const
00782 {
00783 return m_rep;
00784 }
00785
00786 }
00787