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 #include "OW_config.h"
00031 #include "OW_InstanceRepository2.hpp"
00032 #include "OW_DataStreams.hpp"
00033 #include "OW_StringBuffer.hpp"
00034 #include "OW_CIMException.hpp"
00035 #include "OW_CIMProperty.hpp"
00036 #include "OW_CIMInstance.hpp"
00037 #include "OW_CIMClass.hpp"
00038 #include "OW_CIMObjectPath.hpp"
00039 #include "OW_CIMValue.hpp"
00040 #include "OW_CIMQualifier.hpp"
00041 #include "OW_CIMFlavor.hpp"
00042 #include "OW_Format.hpp"
00043 #include "OW_CIMValueCast.hpp"
00044 #include "OW_IOException.hpp"
00045
00046 namespace OW_NAMESPACE
00047 {
00048
00049 using namespace WBEMFlags;
00050
00052 InstanceRepository2::~InstanceRepository2()
00053 {
00054 try
00055 {
00056 close();
00057 }
00058 catch (...)
00059 {
00060
00061 }
00062 }
00063
00065 void
00066 InstanceRepository2::close()
00067 {
00068 m_instanceNameLists.close();
00069 m_instances.close();
00070 }
00071
00073 void
00074 InstanceRepository2::open(::DB_ENV* env, ::DB_TXN* txn)
00075 {
00076 m_instanceNameLists.open("instancenamelists", env, txn, dbDatabase::E_DUPLICATES);
00077 m_instances.open("instances", env, txn, dbDatabase::E_NO_DUPLICATES);
00078 }
00079
00081 class UtilKeyArray
00082 {
00083 public:
00084 UtilKeyArray() : m_names(), m_properties() {}
00085 void addElement(const CIMProperty& prop);
00086 String toString(const String& className);
00087 private:
00088 StringArray m_names;
00089 StringArray m_properties;
00090 };
00092 void
00093 UtilKeyArray::addElement(const CIMProperty& prop)
00094 {
00095 String propName = prop.getName().toLowerCase();
00096 for (size_t i = 0; i < m_names.size(); i++)
00097 {
00098 int cc = m_names[i].compareTo(propName);
00099 if (cc == 0)
00100 {
00101 m_properties[i] = prop.getValue().toString();
00102 return;
00103 }
00104 else if (cc > 0)
00105 {
00106 m_names.insert(i, propName);
00107 m_properties.insert(i, prop.getValue().toString());
00108 return;
00109 }
00110 }
00111 m_names.append(propName);
00112 m_properties.append(prop.getValue().toString());
00113 }
00115 String
00116 UtilKeyArray::toString(const String& className)
00117 {
00118 StringBuffer rv(className.toString().toLowerCase());
00119 for (size_t i = 0; i < m_names.size(); i++)
00120 {
00121 char c = (i == 0) ? '.' : ',';
00122 rv += c;
00123 rv += m_names[i];
00124 rv += '=';
00125 rv += m_properties[i];
00126 }
00127 return rv.releaseString();
00128 }
00130 String
00131 InstanceRepository2::makeInstanceKey(const String& ns, const CIMObjectPath& cop,
00132 const CIMClass& theClass)
00133 {
00134 if (!cop)
00135 {
00136 OW_THROWCIMMSG(CIMException::INVALID_PARAMETER, "no object path");
00137 }
00138
00139 StringBuffer rv(makeClassKey(ns, cop.getClassName()));
00140 rv += '/';
00141 CIMPropertyArray kprops = theClass.getKeys();
00142 if (kprops.size() == 0)
00143 {
00144 rv += cop.getClassName();
00145 return rv.releaseString();
00146
00147
00148
00149 }
00150 String oclass = kprops[0].getOriginClass().toLowerCase();
00151 if (oclass.empty())
00152 {
00153 OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
00154 format("No orgin class for key property on class: %1",
00155 theClass.getName()).c_str());
00156 }
00157 rv += oclass;
00158
00159 CIMPropertyArray pra = cop.getKeys();
00160 if (pra.size() == 0)
00161 {
00162 OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
00163 "object path has no keys");
00164 }
00165 for (size_t i = 0; i < pra.size(); i++)
00166 {
00167 if (!pra[i].getValue())
00168 {
00169 OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
00170 "object path has key with missing value");
00171 }
00172 }
00173
00174 if (pra.size() < kprops.size())
00175 {
00176 OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
00177 format("Model path is missing keys: %1", cop.toString()).c_str());
00178 }
00179
00180 if (pra.size() == 1)
00181 {
00182
00183
00184 String pname = pra[0].getName().toLowerCase();
00185 if (!pname.empty() && !pname.equalsIgnoreCase(kprops[0].getName()))
00186 {
00187 OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
00188 format("Property in model path is not a key: %1", pname).c_str());
00189 }
00190 rv += '.';
00191 rv += pname;
00192 rv += '=';
00193 CIMValue cv = CIMValueCast::castValueToDataType(pra[0].getValue(),
00194 kprops[0].getDataType());
00195 if (cv.getType() == CIMDataType::REFERENCE)
00196 {
00197 CIMObjectPath cop(cv.toCIMObjectPath());
00198 if (cop.getNameSpace().empty())
00199 {
00200 cop.setNameSpace(ns);
00201 cv = CIMValue(cop);
00202 }
00203 }
00204 rv += cv.toString();
00205 return rv.releaseString();
00206 }
00207
00208
00209 for (size_t i = 0; i < pra.size(); i++)
00210 {
00211 String pname = pra[i].getName();
00212 size_t j = 0;
00213 for (; j < kprops.size(); j++)
00214 {
00215 if (pname.equalsIgnoreCase(kprops[j].getName()))
00216 {
00217 CIMValue cv = CIMValueCast::castValueToDataType(
00218 pra[i].getValue(), kprops[j].getDataType());
00219 if (cv.getType() == CIMDataType::REFERENCE)
00220 {
00221 CIMObjectPath cop(cv.toCIMObjectPath());
00222 if (cop.getNameSpace().empty())
00223 {
00224 cop.setNameSpace(ns);
00225 cv = CIMValue(cop);
00226 }
00227 }
00228 pra[i].setValue(cv);
00229 break;
00230 }
00231 }
00232 if (j == kprops.size())
00233 {
00234 OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
00235 format("Property in model path is not a key: %1", pname).c_str());
00236 }
00237 }
00238 UtilKeyArray kra;
00239 for (size_t i = 0; i < pra.size(); i++)
00240 {
00241 kra.addElement(pra[i]);
00242 }
00243 return kra.toString(rv.releaseString());
00244 }
00246 String
00247 InstanceRepository2::makeClassKey(const String& ns,
00248 const String& className)
00249 {
00250 String rv(ns);
00251 while (!rv.empty() && rv[0] == '/')
00252 {
00253 rv = rv.substring(1);
00254 }
00255 rv += "/";
00256 rv += className;
00257 return rv.toLowerCase();
00258 }
00260 void
00261 InstanceRepository2::getInstanceNames(const String& ns,
00262 const CIMClass& theClass, CIMObjectPathResultHandlerIFC& result)
00263 {
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287 }
00288
00290 void
00291 InstanceRepository2::getCIMInstances(
00292 const String& ns,
00293 const String& className,
00294 const CIMClass& requestedClass,
00295 const CIMClass& theClass, CIMInstanceResultHandlerIFC& result,
00296 EDeepFlag deep, ELocalOnlyFlag localOnly, EIncludeQualifiersFlag includeQualifiers,
00297 EIncludeClassOriginFlag includeClassOrigin, const StringArray* propertyList)
00298 {
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320 }
00322 CIMInstance
00323 InstanceRepository2::getCIMInstance(
00324 const String& ns,
00325 const CIMObjectPath& instanceName,
00326 const CIMClass& theClass, ELocalOnlyFlag localOnly,
00327 EIncludeQualifiersFlag includeQualifiers, EIncludeClassOriginFlag includeClassOrigin,
00328 const StringArray* propertyList)
00329 {
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351 CIMInstance ci(CIMNULL);
00352 return ci;
00353 }
00354 #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00355
00356 void
00357 InstanceRepository2::deleteInstance(const String& ns, const CIMObjectPath& cop,
00358 const CIMClass& theClass)
00359 {
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375 }
00377 void
00378 InstanceRepository2::createInstance(const String& ns,
00379 const CIMClass& theClass, const CIMInstance& ci_)
00380 {
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404 }
00406
00407 bool
00408 InstanceRepository2::classHasInstances(const CIMObjectPath& classPath)
00409 {
00410 bool cc = false;
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424 return cc;
00425 }
00427 void
00428 InstanceRepository2::modifyInstance(const String& ns,
00429 const CIMObjectPath& cop,
00430 const CIMClass& theClass, const CIMInstance& ci_,
00431 const CIMInstance& oldInst,
00432 EIncludeQualifiersFlag includeQualifiers,
00433 const StringArray* propertyList)
00434 {
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490 }
00491 #endif
00492 #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00493
00494 void InstanceRepository2::_removeDuplicatedQualifiers(CIMInstance& inst,
00495 const CIMClass& theClass)
00496 {
00497 CIMQualifierArray quals(inst.getQualifiers());
00498 CIMQualifierArray newQuals;
00499 for (size_t i = 0; i < quals.size(); ++i)
00500 {
00501 CIMQualifier& iq = quals[i];
00502 CIMQualifier cq = theClass.getQualifier(iq.getName());
00503 if (!cq)
00504 {
00505 newQuals.push_back(iq);
00506 continue;
00507 }
00508 if (iq.getValue() != cq.getValue())
00509 {
00510 newQuals.push_back(iq);
00511 continue;
00512 }
00513 }
00514 inst.setQualifiers(newQuals);
00515 CIMPropertyArray props = inst.getProperties();
00516 for (size_t i = 0; i < props.size(); ++i)
00517 {
00518 CIMProperty& p = props[i];
00519 CIMProperty clsp = theClass.getProperty(p.getName());
00520 CIMQualifierArray quals(p.getQualifiers());
00521 CIMQualifierArray newQuals;
00522 for (size_t j = 0; j < quals.size(); ++j)
00523 {
00524 CIMQualifier& ipq = quals[j];
00525 CIMQualifier cpq = clsp.getQualifier(ipq.getName());
00526 if (!cpq)
00527 {
00528 newQuals.push_back(ipq);
00529 continue;
00530 }
00531 if (ipq.getValue() != cpq.getValue())
00532 {
00533 newQuals.push_back(ipq);
00534 continue;
00535 }
00536 }
00537 p.setQualifiers(newQuals);
00538 }
00539 inst.setProperties(props);
00540 }
00541 #endif // #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00542
00543 }
00544