(file) Return to CIMRepository.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Repository

   1 mike  1.48 //%/////////////////////////////////////////////////////////////////////////////
   2            //
   3 kumpf 1.72 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
   4            // The Open Group, Tivoli Systems
   5 mike  1.48 //
   6            // Permission is hereby granted, free of charge, to any person obtaining a copy
   7            // of this software and associated documentation files (the "Software"), to
   8            // deal in the Software without restriction, including without limitation the
   9            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  10            // sell copies of the Software, and to permit persons to whom the Software is
  11            // furnished to do so, subject to the following conditions:
  12 kumpf 1.72 // 
  13 mike  1.48 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
  14            // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
  15            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
  16            // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  17            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  19            // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  20            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21            //
  22            //==============================================================================
  23            //
  24            // Author: Mike Brasher (mbrasher@bmc.com)
  25            //
  26 mike  1.51 // Modified By: Jenny Yu, Hewlett-Packard Company (jenny_yu@hp.com)
  27            //              Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
  28            //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
  29 kumpf 1.70 //              Carol Ann Krug Graves, Hewlett-Packard Company
  30            //                  (carolann_graves@hp.com)
  31 karl  1.86 //              Karl Schopmeyer(k.schopmeyer@opengroup.org) - extend ref function.
  32 mike  1.48 //
  33            //%/////////////////////////////////////////////////////////////////////////////
  34            
  35 mike  1.51 #include <Pegasus/Common/Config.h>
  36 mike  1.48 #include <cctype>
  37            #include <cstdio>
  38            #include <fstream>
  39            #include <Pegasus/Common/Pair.h>
  40            #include <Pegasus/Common/Destroyer.h>
  41            #include <Pegasus/Common/FileSystem.h>
  42 kumpf 1.82 #include <Pegasus/Common/InternalException.h>
  43 mike  1.48 #include <Pegasus/Common/XmlReader.h>
  44            #include <Pegasus/Common/XmlWriter.h>
  45            #include <Pegasus/Common/DeclContext.h>
  46 kumpf 1.76 #include <Pegasus/Common/Resolver.h>
  47 mike  1.48 #include <Pegasus/Common/System.h>
  48 kumpf 1.52 #include <Pegasus/Common/Tracer.h>
  49 kumpf 1.63 #include <Pegasus/Common/PegasusVersion.h>
  50 humberto 1.88 #include <Pegasus/Common/MessageLoader.h> //l10n
  51 kumpf    1.63 
  52 mike     1.48 #include "CIMRepository.h"
  53               #include "RepositoryDeclContext.h"
  54               #include "InstanceIndexFile.h"
  55 mike     1.53 #include "InstanceDataFile.h"
  56 mike     1.48 #include "AssocInstTable.h"
  57               #include "AssocClassTable.h"
  58               
  59               #define INDENT_XML_FILES
  60               
  61               PEGASUS_USING_STD;
  62               
  63               PEGASUS_NAMESPACE_BEGIN
  64               
  65 mike     1.53 static const Uint32 _MAX_FREE_COUNT = 16;
  66               
  67 mike     1.48 ////////////////////////////////////////////////////////////////////////////////
  68               //
  69               // _LoadObject()
  70               //
  71 mike     1.51 //      Loads objects (classes and qualifiers) from disk to
  72               //      memory objects.
  73 mike     1.48 //
  74               ////////////////////////////////////////////////////////////////////////////////
  75               
  76               template<class Object>
  77               void _LoadObject(
  78                   const String& path,
  79                   Object& object)
  80               {
  81 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_LoadObject");
  82               
  83 mike     1.48     // Get the real path of the file:
  84               
  85                   String realPath;
  86               
  87                   if (!FileSystem::existsNoCase(path, realPath))
  88 kumpf    1.61     { 
  89 kumpf    1.75         String traceString = path + " does not exist.";
  90 kumpf    1.61         PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4, traceString);
  91 kumpf    1.58         PEG_METHOD_EXIT();
  92 mike     1.51         throw CannotOpenFile(path);
  93 kumpf    1.58     }
  94 mike     1.48 
  95 kumpf    1.61     PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4, "realpath = " + realPath);
  96               
  97 mike     1.48     // Load file into memory:
  98               
  99                   Array<Sint8> data;
 100                   FileSystem::loadFileToMemory(data, realPath);
 101                   data.append('\0');
 102               
 103                   XmlParser parser((char*)data.getData());
 104               
 105                   XmlReader::getObject(parser, object);
 106 kumpf    1.58 
 107                   PEG_METHOD_EXIT();
 108 mike     1.48 }
 109               
 110               ////////////////////////////////////////////////////////////////////////////////
 111               //
 112               // _SaveObject()
 113               //
 114 mike     1.51 //      Saves objects (classes and qualifiers) from memory to
 115               //      disk files.
 116 mike     1.48 //
 117               ////////////////////////////////////////////////////////////////////////////////
 118               
 119 kumpf    1.66 void _SaveObject(const String& path, Array<Sint8>& objectXml)
 120 mike     1.48 {
 121 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_SaveObject");
 122               
 123 kumpf    1.84     PEGASUS_STD(ofstream) os(path.getCString() PEGASUS_IOS_BINARY);
 124 mike     1.48 
 125                   if (!os)
 126 kumpf    1.58     {
 127                       PEG_METHOD_EXIT();
 128 mike     1.51         throw CannotOpenFile(path);
 129 kumpf    1.58     }
 130 mike     1.48 
 131               #ifdef INDENT_XML_FILES
 132 kumpf    1.66     objectXml.append('\0');
 133                   XmlWriter::indentedPrint(os, objectXml.getData(), 2);
 134 mike     1.48 #else
 135 kumpf    1.66     os.write((char*)objectXml.getData(), objectXml.size());
 136 mike     1.48 #endif
 137 kumpf    1.58 
 138                   PEG_METHOD_EXIT();
 139 mike     1.48 }
 140               
 141               static String _MakeAssocInstPath(
 142 kumpf    1.85     const CIMNamespaceName& nameSpace,
 143 mike     1.48     const String& repositoryRoot)
 144               {
 145 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_MakeAssocInstPath");
 146               
 147 kumpf    1.73     String tmp = namespaceNameToDirName(nameSpace);
 148 kumpf    1.64     String returnString(repositoryRoot);
 149                   returnString.append('/');
 150                   returnString.append(tmp);
 151                   returnString.append("/instances/associations");
 152               
 153 kumpf    1.58     PEG_METHOD_EXIT();
 154 kumpf    1.64     return returnString;
 155 mike     1.48 }
 156               
 157               static String _MakeAssocClassPath(
 158 kumpf    1.85     const CIMNamespaceName& nameSpace,
 159 mike     1.48     const String& repositoryRoot)
 160               {
 161 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_MakeAssocClassPath");
 162               
 163 kumpf    1.73     String tmp = namespaceNameToDirName(nameSpace);
 164 kumpf    1.64     String returnString(repositoryRoot);
 165                   returnString.append('/');
 166                   returnString.append(tmp);
 167                   returnString.append("/classes/associations");
 168               
 169 kumpf    1.58     PEG_METHOD_EXIT();
 170 kumpf    1.64     return returnString;
 171 mike     1.48 }
 172               
 173               ////////////////////////////////////////////////////////////////////////////////
 174               //
 175               // CIMRepository
 176               //
 177               //     The following are not implemented:
 178               //
 179               //         CIMRepository::execQuery()
 180               //         CIMRepository::referencesNames()
 181               //         CIMRepository::invokeMethod()
 182               //
 183               //     Note that invokeMethod() will not never implemented since it is not
 184               //     meaningful for a repository.
 185               //
 186               //     ATTN: make operations on files non-case-sensitive.
 187               //
 188               ////////////////////////////////////////////////////////////////////////////////
 189               
 190               CIMRepository::CIMRepository(const String& repositoryRoot)
 191 mike     1.51    : _repositoryRoot(repositoryRoot), _nameSpaceManager(repositoryRoot),
 192 kumpf    1.56      _lock(), _resolveInstance(true)
 193 mike     1.48 {
 194 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::CIMRepository");
 195               
 196 mike     1.48     _context = new RepositoryDeclContext(this);
 197 mike     1.51     _isDefaultInstanceProvider = (ConfigManager::getInstance()->getCurrentValue(
 198                       "repositoryIsDefaultInstanceProvider") == "true");
 199 kumpf    1.58 
 200                   PEG_METHOD_EXIT();
 201 mike     1.48 }
 202               
 203               CIMRepository::~CIMRepository()
 204               {
 205 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::~CIMRepository");
 206               
 207 mike     1.48     delete _context;
 208 kumpf    1.58 
 209                   PEG_METHOD_EXIT();
 210 mike     1.48 }
 211               
 212 mike     1.51 
 213               void CIMRepository::read_lock(void) throw(IPCException)
 214               {
 215 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::read_lock");
 216               
 217 mike     1.51    _lock.wait_read(pegasus_thread_self());
 218 kumpf    1.58 
 219                   PEG_METHOD_EXIT();
 220 mike     1.51 }
 221               
 222               void CIMRepository::read_unlock(void)
 223               {
 224 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::read_unlock");
 225               
 226 mike     1.51    _lock.unlock_read(pegasus_thread_self());
 227 kumpf    1.58 
 228                   PEG_METHOD_EXIT();
 229 mike     1.51 }
 230               
 231               void CIMRepository::write_lock(void) throw(IPCException)
 232               {
 233 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::write_lock");
 234               
 235 mike     1.51    _lock.wait_write(pegasus_thread_self());
 236 kumpf    1.58 
 237                   PEG_METHOD_EXIT();
 238 mike     1.51 }
 239               
 240               void CIMRepository::write_unlock(void)
 241               {
 242 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::write_unlock");
 243               
 244 mike     1.51    _lock.unlock_write(pegasus_thread_self());
 245 kumpf    1.58 
 246                   PEG_METHOD_EXIT();
 247 mike     1.51 }
 248               
 249 mike     1.48 CIMClass CIMRepository::getClass(
 250 kumpf    1.85     const CIMNamespaceName& nameSpace,
 251                   const CIMName& className,
 252 mike     1.48     Boolean localOnly,
 253                   Boolean includeQualifiers,
 254                   Boolean includeClassOrigin,
 255 mike     1.51     const CIMPropertyList& propertyList)
 256 mike     1.48 {
 257 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::getClass");
 258               
 259 kumpf    1.61     PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4, "nameSpace = " + 
 260 kumpf    1.85                      nameSpace.getString() + ", className = " + 
 261                                    className.getString());
 262 kumpf    1.61 
 263 mike     1.48     // ATTN: localOnly, includeQualifiers, and includeClassOrigin are ignored
 264                   // for now.
 265               
 266                   String classFilePath;
 267                   classFilePath = _nameSpaceManager.getClassFilePath(nameSpace, className);
 268               
 269                   CIMClass cimClass;
 270 mike     1.51 
 271                   try
 272                   {
 273                       _LoadObject(classFilePath, cimClass);
 274                   }
 275 kumpf    1.79     catch (Exception& e)
 276 mike     1.51     {
 277 kumpf    1.58         PEG_METHOD_EXIT();
 278 kumpf    1.85         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, className.getString());
 279 mike     1.51     }
 280 mike     1.48 
 281 kumpf    1.58     PEG_METHOD_EXIT();
 282 mike     1.48     return cimClass;
 283               }
 284               
 285               Boolean CIMRepository::_getInstanceIndex(
 286 kumpf    1.85     const CIMNamespaceName& nameSpace,
 287 kumpf    1.68     const CIMObjectPath& instanceName,
 288 kumpf    1.85     CIMName& className,
 289 mike     1.53     Uint32& index,
 290 mike     1.51     Uint32& size,
 291 mike     1.48     Boolean searchSuperClasses) const
 292               {
 293 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_getInstanceIndex");
 294               
 295 mike     1.53     //
 296                   // Get all descendent classes of this class:
 297                   //
 298 mike     1.51 
 299 mike     1.48     className = instanceName.getClassName();
 300               
 301 kumpf    1.85     Array<CIMName> classNames;
 302 mike     1.48     _nameSpaceManager.getSubClassNames(nameSpace, className, true, classNames);
 303                   classNames.prepend(className);
 304               
 305 mike     1.53     //
 306                   // Get all superclasses of this one:
 307                   //
 308 mike     1.48 
 309                   if (searchSuperClasses)
 310 mike     1.51         _nameSpaceManager.getSuperClassNames(nameSpace, className, classNames);
 311 mike     1.48 
 312 mike     1.53     //
 313                   // Get instance names from each qualifying instance file for the class:
 314                   //
 315 mike     1.48 
 316                   for (Uint32 i = 0; i < classNames.size(); i++)
 317                   {
 318 kumpf    1.68         CIMObjectPath tmpInstanceName = instanceName;
 319 mike     1.51         tmpInstanceName.setClassName(classNames[i]);
 320 mike     1.48 
 321 mike     1.53 	//
 322                       // Lookup index of instance:
 323               	//
 324 mike     1.48 
 325 mike     1.53         String path = _getInstanceIndexFilePath(nameSpace, classNames[i]);
 326 mike     1.48 
 327 mike     1.53         if (InstanceIndexFile::lookupEntry(path, tmpInstanceName, index, size))
 328 mike     1.51         {
 329                           className = classNames[i];
 330 kumpf    1.58             PEG_METHOD_EXIT();
 331 mike     1.51             return true;
 332                       }
 333 mike     1.48     }
 334               
 335 kumpf    1.58     PEG_METHOD_EXIT();
 336 mike     1.48     return false;
 337               }
 338               
 339               CIMInstance CIMRepository::getInstance(
 340 kumpf    1.85     const CIMNamespaceName& nameSpace,
 341 kumpf    1.68     const CIMObjectPath& instanceName,
 342 mike     1.48     Boolean localOnly,
 343                   Boolean includeQualifiers,
 344                   Boolean includeClassOrigin,
 345 mike     1.55     const CIMPropertyList& propertyList)
 346 mike     1.48 {
 347 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::getInstance");
 348               
 349 mike     1.53     //
 350                   // Get the index for this instance:
 351                   //
 352 mike     1.48 
 353 kumpf    1.85     CIMName className;
 354 mike     1.48     Uint32 index;
 355 mike     1.51     Uint32 size;
 356               
 357 mike     1.53     if (!_getInstanceIndex(nameSpace, instanceName, className, index, size))
 358 mike     1.48     {
 359 kumpf    1.52 	PEG_METHOD_EXIT();
 360 mike     1.51         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString());
 361 mike     1.48     }
 362               
 363 mike     1.53     //
 364                   // Load the instance from file:
 365                   //
 366 mike     1.48 
 367 mike     1.53     String path = _getInstanceDataFilePath(nameSpace, className);
 368 mike     1.48     CIMInstance cimInstance;
 369 mike     1.53 
 370 mike     1.51     if (!_loadInstance(path, cimInstance, index, size))
 371                   {
 372 kumpf    1.52 	PEG_METHOD_EXIT();
 373 mike     1.51         throw CannotOpenFile(path);
 374                   }
 375               
 376 mike     1.54     //
 377                   // Resolve the instance (if requested):
 378                   //
 379               
 380                   if (_resolveInstance)
 381                   {
 382               	CIMConstClass cimClass;
 383 kumpf    1.76 	Resolver::resolveInstance (cimInstance, _context, nameSpace, cimClass, 
 384                           true);
 385 mike     1.54     }
 386               
 387 kumpf    1.52     PEG_METHOD_EXIT();
 388 mike     1.48     return cimInstance;
 389               }
 390               
 391               void CIMRepository::deleteClass(
 392 kumpf    1.85     const CIMNamespaceName& nameSpace,
 393                   const CIMName& className)
 394 mike     1.48 {
 395 kumpf    1.61     PEG_METHOD_ENTER(TRC_REPOSITORY,"CIMRepository::deleteClass");
 396 kumpf    1.58 
 397 mike     1.53     //
 398                   // Get the class and check to see if it is an association class:
 399                   //
 400 mike     1.51 
 401 mike     1.48     CIMClass cimClass = getClass(nameSpace, className, false);
 402                   Boolean isAssociation = cimClass.isAssociation();
 403               
 404 mike     1.53     //
 405                   // Disallow deletion if class has instances:
 406                   //
 407 mike     1.48 
 408 mike     1.53     String indexFilePath = _getInstanceIndexFilePath(nameSpace, className);
 409 kumpf    1.61     PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4, 
 410                                    "instance indexFilePath = " + indexFilePath);
 411 mike     1.53 
 412                   String dataFilePath = _getInstanceDataFilePath(nameSpace, className);
 413 kumpf    1.61     PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4, 
 414                                    "instance dataFilePath = " + dataFilePath);
 415 mike     1.48 
 416 mike     1.53     if (InstanceIndexFile::hasNonFreeEntries(indexFilePath))
 417 kumpf    1.58     {
 418                       PEG_METHOD_EXIT();
 419 kumpf    1.85         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_CLASS_HAS_INSTANCES, 
 420                           className.getString());
 421 kumpf    1.58     }
 422 mike     1.48 
 423 mike     1.53     //
 424                   // Delete the class. The NameSpaceManager::deleteClass() method throws
 425                   // and exception if the class has sublclasses.
 426                   //
 427 kumpf    1.58     try
 428                   {
 429                       _nameSpaceManager.deleteClass(nameSpace, className);
 430                   }
 431                   catch (CIMException& e)
 432                   {
 433                       PEG_METHOD_EXIT();
 434                       throw e;
 435                   }
 436 mike     1.48 
 437 mike     1.53     FileSystem::removeFileNoCase(indexFilePath);
 438 kumpf    1.61 
 439 mike     1.53     FileSystem::removeFileNoCase(dataFilePath);
 440               
 441                   //
 442                   // Kill off empty instance files:
 443                   //
 444               
 445                   //
 446                   // Remove association:
 447                   //
 448 mike     1.48 
 449                   if (isAssociation)
 450                   {
 451 mike     1.51         String assocFileName = _MakeAssocClassPath(nameSpace, _repositoryRoot);
 452 mike     1.48 
 453 mike     1.51         if (FileSystem::exists(assocFileName))
 454                           AssocClassTable::deleteAssociation(assocFileName, className);
 455 mike     1.48     }
 456 kumpf    1.61     
 457 kumpf    1.58     PEG_METHOD_EXIT();
 458 mike     1.48 }
 459               
 460 mike     1.53 void _CompactInstanceRepository(
 461                   const String& indexFilePath, 
 462                   const String& dataFilePath)
 463               {
 464 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_CompactInstanceRepository");
 465               
 466 mike     1.53     //
 467                   // Compact the data file first:
 468                   //
 469               
 470                   Array<Uint32> freeFlags;
 471                   Array<Uint32> indices;
 472                   Array<Uint32> sizes;
 473 kumpf    1.68     Array<CIMObjectPath> instanceNames;
 474 mike     1.53 
 475                   if (!InstanceIndexFile::enumerateEntries(
 476               	indexFilePath, freeFlags, indices, sizes, instanceNames, true))
 477                   {
 478 kumpf    1.58         PEG_METHOD_EXIT();
 479 humberto 1.88         //l10n 
 480                       //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "compact failed");
 481                       throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
 482                       		MessageLoaderParms("Repository.CIMRepository.COMPACT_FAILED","compact failed"));										            
 483                       //l10n end
 484                       
 485 mike     1.53     }
 486               
 487                   if (!InstanceDataFile::compact(dataFilePath, freeFlags, indices, sizes))
 488 kumpf    1.58     {
 489                       PEG_METHOD_EXIT();
 490 humberto 1.88         //l10n
 491                       //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "compact failed");
 492                       throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.COMPACT_FAILED",
 493                       										                  "compact failed"));
 494                       //l10n end
 495 kumpf    1.58     }
 496 mike     1.53 
 497                   //
 498                   // Now compact the index file:
 499                   //
 500               
 501                   if (!InstanceIndexFile::compact(indexFilePath))
 502 kumpf    1.58     {
 503                       PEG_METHOD_EXIT();
 504 humberto 1.88         //l10n
 505                       //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "compact failed");
 506                       throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.COMPACT_FAILED",
 507                       										                  "compact failed"));
 508                       //l10n end
 509 kumpf    1.58     }
 510               
 511                   PEG_METHOD_EXIT();
 512 mike     1.53 }
 513               
 514 mike     1.48 void CIMRepository::deleteInstance(
 515 kumpf    1.85     const CIMNamespaceName& nameSpace,
 516 kumpf    1.68     const CIMObjectPath& instanceName)
 517 mike     1.48 {
 518 mike     1.53     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::deleteInstance");
 519 mike     1.51 
 520                   String errMessage;
 521               
 522 mike     1.53     //
 523                   // Get paths of index and data files:
 524                   //
 525               
 526                   String indexFilePath = _getInstanceIndexFilePath(
 527                       nameSpace, instanceName.getClassName());
 528 mike     1.48 
 529 mike     1.53     String dataFilePath = _getInstanceDataFilePath(
 530 mike     1.51         nameSpace, instanceName.getClassName());
 531 mike     1.48 
 532 mike     1.53     //
 533                   // Attempt rollback (if there are no rollback files, this will have no 
 534                   // effect). This code is here to rollback uncommitted changes left over 
 535                   // from last time an instance-oriented function was called.
 536                   //
 537               
 538                   if (!InstanceIndexFile::rollbackTransaction(indexFilePath))
 539                   {
 540                       PEG_METHOD_EXIT();
 541 humberto 1.88         //l10n
 542                       //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "rollback failed");
 543                       throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.ROLLBACK_FAILED",
 544                       														  "rollback failed"));														  
 545                       //l10n end
 546 mike     1.53     }
 547               
 548                   if (!InstanceDataFile::rollbackTransaction(dataFilePath))
 549                   {
 550                       PEG_METHOD_EXIT();
 551 humberto 1.88         //l10n
 552                       //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "rollback failed");
 553                       throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.ROLLBACK_FAILED",
 554                       														  "rollback failed"));
 555                       //l10n end
 556 mike     1.53     }
 557               
 558                   //
 559                   // Lookup instance from the index file (raise error if not found).
 560                   //
 561               
 562 mike     1.48     Uint32 index;
 563 mike     1.51     Uint32 size;
 564 mike     1.48 
 565 mike     1.53     if (!InstanceIndexFile::lookupEntry(
 566               	indexFilePath, instanceName, index, size))
 567 kumpf    1.52     {
 568                       PEG_METHOD_EXIT();
 569 mike     1.51         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString());
 570 kumpf    1.52     }
 571 mike     1.48 
 572 mike     1.53     //
 573                   // Begin the transaction (any return prior to commit will cause
 574                   // a rollback next time an instance-oriented routine is invoked).
 575                   //
 576               
 577                   if (!InstanceIndexFile::beginTransaction(indexFilePath))
 578                   {
 579                       PEG_METHOD_EXIT();
 580 humberto 1.88         //l10n
 581                       //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "begin failed");
 582                       throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.BEGIN_FAILED",
 583                       														  "begin failed"));
 584                       //l10n end
 585 mike     1.53     }
 586 mike     1.48 
 587 mike     1.53     if (!InstanceDataFile::beginTransaction(dataFilePath))
 588 mike     1.48     {
 589 kumpf    1.52         PEG_METHOD_EXIT();
 590 humberto 1.88         //l10n
 591                       //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "begin failed");
 592                       throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.BEGIN_FAILED",
 593                       														  "begin failed"));
 594                       //l10n end
 595 mike     1.48     }
 596               
 597 mike     1.53     //
 598                   // Remove entry from index file.
 599                   //
 600 mike     1.48 
 601 mike     1.53     Uint32 freeCount;
 602 mike     1.48 
 603 mike     1.53     if (!InstanceIndexFile::deleteEntry(indexFilePath, instanceName, freeCount))
 604 mike     1.48     {
 605 humberto 1.88     	//l10n
 606                       //errMessage.append("Failed to delete instance: ");
 607                       //errMessage.append(instanceName.toString());
 608                       PEG_METHOD_EXIT();
 609                       //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
 610                       throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.FAILED_TO_DELETE_INSTANCE",
 611                       														  "Failed to delete instance: $0", 
 612                       														  instanceName.toString()));
 613                       //l10n end
 614 mike     1.48     }
 615               
 616 mike     1.53     //
 617                   // Commit the transaction:
 618                   //
 619 mike     1.51 
 620 mike     1.53     if (!InstanceIndexFile::commitTransaction(indexFilePath))
 621                   {
 622                       PEG_METHOD_EXIT();
 623 humberto 1.88         //l10n
 624                       //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "commit failed");
 625                       throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.COMMIT_FAILED",
 626                       														  "commit failed"));
 627                       //l10n end
 628 mike     1.53     }
 629               
 630                   if (!InstanceDataFile::commitTransaction(dataFilePath))
 631 mike     1.48     {
 632 kumpf    1.52         PEG_METHOD_EXIT();
 633 humberto 1.88         //l10n
 634                       //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "commit failed");
 635                       throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.COMMIT_FAILED",
 636                       														  "commit failed"));
 637                       //l10n end
 638 mike     1.48     }
 639               
 640 mike     1.53     //
 641                   // Compact the index and data files if the free count max was
 642                   // reached.
 643                   //
 644               
 645                   if (freeCount == _MAX_FREE_COUNT)
 646               	_CompactInstanceRepository(indexFilePath, dataFilePath);
 647               
 648                   //
 649                   // Delete from assocation table (if an assocation).
 650                   //
 651 mike     1.48 
 652                   String assocFileName = _MakeAssocInstPath(nameSpace, _repositoryRoot);
 653               
 654                   if (FileSystem::exists(assocFileName))
 655 mike     1.51         AssocInstTable::deleteAssociation(assocFileName, instanceName);
 656 kumpf    1.52 
 657                   PEG_METHOD_EXIT();
 658 mike     1.48 }
 659               
 660               void CIMRepository::_createAssocClassEntries(
 661 kumpf    1.85     const CIMNamespaceName& nameSpace,
 662 mike     1.48     const CIMConstClass& assocClass)
 663               {
 664 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_createAssocClassEntries");
 665               
 666 mike     1.48     // Open input file:
 667               
 668 mike     1.51 
 669 mike     1.48     String assocFileName = _MakeAssocClassPath(nameSpace, _repositoryRoot);
 670                   ofstream os;
 671               
 672                   if (!OpenAppend(os, assocFileName))
 673 kumpf    1.58     {
 674                       PEG_METHOD_EXIT();
 675 mike     1.51         throw CannotOpenFile(assocFileName);
 676 kumpf    1.58     }
 677 mike     1.48 
 678                   // Get the association's class name:
 679               
 680 kumpf    1.85     CIMName assocClassName = assocClass.getClassName();
 681 mike     1.48 
 682                   // For each property:
 683               
 684                   Uint32 n = assocClass.getPropertyCount();
 685               
 686                   for (Uint32 i = 0; i < n; i++)
 687                   {
 688 mike     1.51         CIMConstProperty fromProp = assocClass.getProperty(i);
 689 mike     1.48 
 690 kumpf    1.78         if (fromProp.getType() == CIMTYPE_REFERENCE)
 691 mike     1.51         {
 692                           for (Uint32 j = 0; j < n; j++)
 693                           {
 694                               CIMConstProperty toProp = assocClass.getProperty(j);
 695               
 696 kumpf    1.78                 if (toProp.getType() == CIMTYPE_REFERENCE &&
 697 kumpf    1.85                     (!fromProp.getName().equal (toProp.getName())))
 698 mike     1.51                 {
 699 kumpf    1.85                     CIMName fromClassName = fromProp.getReferenceClassName();
 700                                   CIMName fromPropertyName = fromProp.getName();
 701                                   CIMName toClassName = toProp.getReferenceClassName();
 702                                   CIMName toPropertyName = toProp.getName();
 703 mike     1.51 
 704                                   AssocClassTable::append(
 705                                       os,
 706                                       assocClassName,
 707                                       fromClassName,
 708                                       fromPropertyName,
 709                                       toClassName,
 710                                       toPropertyName);
 711                               }
 712                           }
 713                       }
 714 mike     1.48     }
 715 kumpf    1.58 
 716                   PEG_METHOD_EXIT();
 717 mike     1.48 }
 718               
 719               void CIMRepository::createClass(
 720 kumpf    1.85     const CIMNamespaceName& nameSpace,
 721 mike     1.48     const CIMClass& newClass)
 722               {
 723 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::createClass");
 724               
 725 mike     1.48     // -- Resolve the class:
 726 mike     1.51         CIMClass cimClass(newClass);
 727                       
 728 kumpf    1.76     Resolver::resolveClass (cimClass, _context, nameSpace);
 729 mike     1.48 
 730                   // -- If an association, populate associations file:
 731               
 732                   if (cimClass.isAssociation())
 733 mike     1.51         _createAssocClassEntries(nameSpace, cimClass);
 734 mike     1.48 
 735                   // -- Create namespace manager entry:
 736               
 737                   String classFilePath;
 738               
 739                   _nameSpaceManager.createClass(nameSpace, cimClass.getClassName(),
 740 mike     1.51         cimClass.getSuperClassName(), classFilePath);
 741 mike     1.48 
 742                   // -- Create the class file:
 743               
 744 kumpf    1.66     Array<Sint8> classXml;
 745                   XmlWriter::appendClassElement(classXml, cimClass);
 746                   _SaveObject(classFilePath, classXml);
 747 kumpf    1.58 
 748                   PEG_METHOD_EXIT();
 749 mike     1.48 }
 750               
 751               /*------------------------------------------------------------------------------
 752               
 753                   This routine does the following:
 754               
 755 mike     1.51         1.  Creates two entries in the association file for each relationship
 756                           formed by this new assocation instance. A binary association
 757                           (one with two references) ties two instances together. Suppose
 758                           there are two instances: I1 and I2. Then two entries are created:
 759               
 760                               I2 -> I1
 761                               I1 -> I2
 762               
 763                           For a ternary relationship, six entries will be created. Suppose
 764                           there are three instances: I1, I2, and I3:
 765               
 766                               I1 -> I2
 767                               I1 -> I3
 768                               I2 -> I1
 769                               I2 -> I3
 770                               I3 -> I1
 771                               I3 -> I2
 772               
 773                           So for an N-ary relationship, there will be 2*N entries created.
 774               
 775                       2.  Verifies that the association instance refers to real objects.
 776 mike     1.51             (note that an association reference may refer to either an instance
 777                           or a class). Throws an exception if one of the references does not
 778                           refer to a valid object.
 779 mike     1.48 
 780               ------------------------------------------------------------------------------*/
 781               
 782               void CIMRepository::_createAssocInstEntries(
 783 kumpf    1.85     const CIMNamespaceName& nameSpace,
 784 mike     1.48     const CIMConstClass& cimClass,
 785                   const CIMInstance& cimInstance,
 786 kumpf    1.68     const CIMObjectPath& instanceName)
 787 mike     1.48 {
 788 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_createAssocInstEntries");
 789               
 790 mike     1.48     // Open input file:
 791               
 792                   String assocFileName = _MakeAssocInstPath(nameSpace, _repositoryRoot);
 793                   ofstream os;
 794               
 795                   if (!OpenAppend(os, assocFileName))
 796 kumpf    1.58     {
 797                       PEG_METHOD_EXIT();
 798 mike     1.51         throw CannotOpenFile(assocFileName);
 799 kumpf    1.58     }
 800 mike     1.48 
 801                   // Get the association's instance name and class name:
 802               
 803                   String assocInstanceName = instanceName.toString();
 804 kumpf    1.85     CIMName assocClassName = instanceName.getClassName();
 805 mike     1.48 
 806                   // For each property:
 807               
 808                   for (Uint32 i = 0, n = cimInstance.getPropertyCount(); i < n; i++)
 809                   {
 810 mike     1.51         CIMConstProperty fromProp = cimInstance.getProperty(i);
 811 mike     1.48 
 812 mike     1.51         // If a reference property:
 813 mike     1.48 
 814 kumpf    1.78         if (fromProp.getType() == CIMTYPE_REFERENCE)
 815 mike     1.51         {
 816                           // For each property:
 817               
 818                           for (Uint32 j = 0, n = cimInstance.getPropertyCount(); j < n; j++)
 819                           {
 820                               CIMConstProperty toProp = cimInstance.getProperty(j);
 821               
 822                               // If a reference property and not the same property:
 823               
 824 kumpf    1.78                 if (toProp.getType() == CIMTYPE_REFERENCE &&
 825 kumpf    1.85                     (!fromProp.getName().equal (toProp.getName())))
 826 mike     1.51                 {
 827 kumpf    1.68                     CIMObjectPath fromRef;
 828 mike     1.51                     fromProp.getValue().get(fromRef);
 829               
 830 kumpf    1.68                     CIMObjectPath toRef;
 831 mike     1.51                     toProp.getValue().get(toRef);
 832               
 833                                   String fromObjectName = fromRef.toString();
 834 kumpf    1.85                     CIMName fromClassName = fromRef.getClassName();
 835                                   CIMName fromPropertyName = fromProp.getName();
 836 mike     1.51                     String toObjectName = toRef.toString();
 837 kumpf    1.85                     CIMName toClassName = toRef.getClassName();
 838                                   CIMName toPropertyName = toProp.getName();
 839 mike     1.51 
 840                                   AssocInstTable::append(
 841                                       os,
 842                                       assocInstanceName,
 843                                       assocClassName,
 844                                       fromObjectName,
 845                                       fromClassName,
 846                                       fromPropertyName,
 847                                       toObjectName,
 848                                       toClassName,
 849                                       toPropertyName);
 850                               }
 851                           }
 852                       }
 853 mike     1.48     }
 854 kumpf    1.58 
 855                   PEG_METHOD_EXIT();
 856 mike     1.48 }
 857               
 858 kumpf    1.68 CIMObjectPath CIMRepository::createInstance(
 859 kumpf    1.85     const CIMNamespaceName& nameSpace,
 860 mike     1.48     const CIMInstance& newInstance)
 861               {
 862 kumpf    1.61     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::createInstance");
 863 mike     1.51 
 864                   String errMessage;
 865               
 866 mike     1.53     //
 867                   // Get paths to data and index files:
 868                   //
 869               
 870                   String dataFilePath = _getInstanceDataFilePath(
 871               	nameSpace, newInstance.getClassName());
 872               
 873                   String indexFilePath = _getInstanceIndexFilePath(
 874                       nameSpace, newInstance.getClassName());
 875               
 876                   //
 877                   // Attempt rollback (if there are no rollback files, this will have no 
 878                   // effect). This code is here to rollback uncommitted changes left over 
 879                   // from last time an instance-oriented function was called.
 880                   //
 881               
 882                   if (!InstanceIndexFile::rollbackTransaction(indexFilePath))
 883                   {
 884                       PEG_METHOD_EXIT();
 885 humberto 1.88         //l10n
 886                       //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "rollback failed");
 887                       throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.ROLLBACK_FAILED",
 888                       														  "rollback failed"));														  
 889                       //l10n end
 890 mike     1.53     }
 891               
 892                   if (!InstanceDataFile::rollbackTransaction(dataFilePath))
 893                   {
 894                       PEG_METHOD_EXIT();
 895 humberto 1.88         //l10n
 896                       //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "rollback failed");
 897                       throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.ROLLBACK_FAILED",
 898                       														  "rollback failed"));														  
 899                       //l10n end
 900 mike     1.53     }
 901               
 902                   //
 903 mike     1.54     // Resolve the instance. Looks up class and fills out properties but
 904                   // not the qualifiers.
 905 mike     1.53     //
 906               
 907 mike     1.51     CIMInstance cimInstance(newInstance);
 908 mike     1.48     CIMConstClass cimClass;
 909 kumpf    1.76     Resolver::resolveInstance (cimInstance, _context, nameSpace, cimClass, 
 910                       false);
 911 kumpf    1.81     CIMObjectPath instanceName = cimInstance.buildPath(cimClass);
 912 mike     1.48 
 913 mike     1.53     //
 914                   // Make sure the class has keys (otherwise it will be impossible to
 915                   // create the instance).
 916                   //
 917 mike     1.48 
 918                   if (!cimClass.hasKeys())
 919                   {
 920 humberto 1.88     	//l10n
 921                       //errMessage = "class has no keys: " + 
 922                           //cimClass.getClassName().getString();
 923                       PEG_METHOD_EXIT();
 924                       throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.CLASS_HAS_NO_KEYS",
 925                   															  "class has no keys: $0", 
 926                   															  cimClass.getClassName().getString()));
 927                       //l10n end
 928 mike     1.48     }
 929               
 930 mike     1.53     //
 931                   // Be sure instance does not already exist:
 932                   //
 933 mike     1.48 
 934 kumpf    1.85     CIMName className;
 935 mike     1.48     Uint32 dummyIndex;
 936 mike     1.51     Uint32 dummySize;
 937 mike     1.48 
 938 mike     1.53     if (_getInstanceIndex(nameSpace, instanceName, className, dummyIndex, 
 939                       dummySize, true))
 940 mike     1.48     {
 941 kumpf    1.52         PEG_METHOD_EXIT();
 942 mike     1.51         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_ALREADY_EXISTS, 
 943                           instanceName.toString());
 944 mike     1.48     }
 945               
 946 mike     1.53     //
 947                   // Create association entries if an association instance.
 948                   //
 949 mike     1.48 
 950                   if (cimClass.isAssociation())
 951 mike     1.53         _createAssocInstEntries(nameSpace, cimClass, cimInstance, instanceName);
 952               
 953                   //
 954                   // Begin the transaction (any return prior to commit will cause
 955                   // a rollback next time an instance-oriented routine is invoked).
 956                   //
 957               
 958                   if (!InstanceIndexFile::beginTransaction(indexFilePath))
 959 mike     1.48     {
 960 mike     1.53         PEG_METHOD_EXIT();
 961 humberto 1.88         //l10n
 962                       //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "begin failed");
 963                       throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.BEGIN_FAILED",
 964                       														  "begin failed"));														  
 965                       //l10n end
 966 mike     1.48     }
 967               
 968 mike     1.53     if (!InstanceDataFile::beginTransaction(dataFilePath))
 969                   {
 970                       PEG_METHOD_EXIT();
 971 humberto 1.88         //l10n
 972                       //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "begin failed");
 973                       throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.BEGIN_FAILED",
 974                       														  "begin failed"));														  
 975                       //l10n end
 976 mike     1.53     }
 977 mike     1.48 
 978 mike     1.53     //
 979                   // Save instance to file:
 980                   //
 981 mike     1.51 
 982                   Uint32 index;
 983                   Uint32 size;
 984 mike     1.53 
 985 mike     1.51     {
 986 mike     1.53 	Array<Sint8> data;
 987 kumpf    1.66 	XmlWriter::appendInstanceElement(data, cimInstance);
 988 mike     1.53 	size = data.size();
 989               
 990               	if (!InstanceDataFile::appendInstance(dataFilePath, data, index))
 991               	{
 992 humberto 1.88 		//l10n
 993               	    //errMessage.append("Failed to create instance: ");
 994               	    //errMessage.append(instanceName.toString());
 995 mike     1.53 	    PEG_METHOD_EXIT();
 996 humberto 1.88 	    //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
 997               	    throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.FAILED_TO_CREATE_INSTANCE",
 998                   															  "Failed to create instance: $0", 
 999                   															  instanceName.toString()));
1000               	    //l10n end
1001 mike     1.53 	}
1002                   }
1003               
1004                   //
1005                   // Create entry in index file:
1006                   //
1007               
1008                   if (!InstanceIndexFile::createEntry(
1009               	indexFilePath, instanceName, index, size))
1010                   {
1011 humberto 1.88     	//l10n
1012                       //errMessage.append("Failed to create instance: ");
1013                       //errMessage.append(instanceName.toString());
1014                       PEG_METHOD_EXIT();
1015                       //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
1016                       throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.FAILED_TO_CREATE_INSTANCE",
1017                   															  "Failed to create instance: $0", 
1018                   															  instanceName.toString()));
1019               	    //l10n end
1020 mike     1.51     }
1021 mike     1.48 
1022 mike     1.53     //
1023                   // Commit the changes:
1024                   //
1025 mike     1.48 
1026 mike     1.53     if (!InstanceIndexFile::commitTransaction(indexFilePath))
1027 mike     1.51     {
1028 kumpf    1.52         PEG_METHOD_EXIT();
1029 humberto 1.88         //l10n
1030                       //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "commit failed");
1031                       throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.COMMIT_FAILED",
1032                       														  "commit failed"));
1033                       //l10n end
1034 mike     1.51     }
1035 mike     1.48 
1036 mike     1.53     if (!InstanceDataFile::commitTransaction(dataFilePath))
1037 mike     1.51     {
1038 kumpf    1.52         PEG_METHOD_EXIT();
1039 humberto 1.88         //l10n
1040                       //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "commit failed");
1041                       throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.COMMIT_FAILED",
1042                       														  "commit failed"));
1043                       //l10n end
1044 mike     1.51     }
1045 mike     1.53 
1046 kumpf    1.76     Resolver::resolveInstance (cimInstance, _context, nameSpace, cimClass, 
1047                       true);
1048 mike     1.54 
1049 kumpf    1.52     PEG_METHOD_EXIT();
1050 mike     1.53     return instanceName;
1051 mike     1.48 }
1052               
1053               void CIMRepository::modifyClass(
1054 kumpf    1.85     const CIMNamespaceName& nameSpace,
1055 mike     1.48     const CIMClass& modifiedClass)
1056               {
1057 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::modifyClass");
1058               
1059 mike     1.53     //
1060                   // Resolve the class:
1061                   //
1062 mike     1.51 
1063 mike     1.53     CIMClass cimClass(modifiedClass);
1064 kumpf    1.76     Resolver::resolveClass (cimClass, _context, nameSpace);
1065 mike     1.48 
1066 mike     1.53     //
1067                   // Check to see if it is okay to modify this class:
1068                   //
1069 mike     1.48 
1070                   String classFilePath;
1071               
1072                   _nameSpaceManager.checkModify(nameSpace, cimClass.getClassName(),
1073 mike     1.51         cimClass.getSuperClassName(), classFilePath);
1074 mike     1.48 
1075 mike     1.53     //
1076                   // ATTN: KS
1077                   // Disallow modification of classes which have instances (that are
1078                   // in the repository). And we have no idea whether the class has
1079                   // instances in other repositories or in providers. We should do
1080                   // an enumerate instance names at a higher level (above the repository).
1081                   //
1082               
1083                   //
1084                   // Delete the old file containing the class:
1085                   //
1086 mike     1.48 
1087                   if (!FileSystem::removeFileNoCase(classFilePath))
1088                   {
1089 kumpf    1.58         PEG_METHOD_EXIT();
1090 humberto 1.88         //l10n
1091                       String str = "CIMRepository::modifyClass()";
1092                       //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
1093                           //"failed to remove file in CIMRepository::modifyClass()");
1094                       throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.FAILED_TO_REMOVE_FILE",
1095                       														  "failed to remove file in $0", str));
1096                       //l10n end
1097 mike     1.48     }
1098               
1099 mike     1.53     //
1100                   // Create new class file:
1101                   //
1102 mike     1.48 
1103 kumpf    1.66     Array<Sint8> classXml;
1104                   XmlWriter::appendClassElement(classXml, cimClass);
1105                   _SaveObject(classFilePath, classXml);
1106 kumpf    1.58 
1107                   PEG_METHOD_EXIT();
1108 mike     1.48 }
1109               
1110               void CIMRepository::modifyInstance(
1111 kumpf    1.85     const CIMNamespaceName& nameSpace,
1112 kumpf    1.70     const CIMInstance& modifiedInstance,
1113 mike     1.51     Boolean includeQualifiers,
1114                   const CIMPropertyList& propertyList)
1115 mike     1.48 {
1116 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::modifyInstance");
1117               
1118 mike     1.53     //
1119                   // Get paths of index and data files:
1120                   //
1121 mike     1.51 
1122 kumpf    1.70     const CIMInstance& instance = modifiedInstance;
1123 mike     1.53 
1124                   String indexFilePath = _getInstanceIndexFilePath(
1125                       nameSpace, instance.getClassName());
1126               
1127                   String dataFilePath = _getInstanceDataFilePath(
1128                       nameSpace, instance.getClassName());
1129               
1130                   //
1131                   // First attempt rollback:
1132                   //
1133               
1134                   if (!InstanceIndexFile::rollbackTransaction(indexFilePath))
1135 kumpf    1.58     {
1136                       PEG_METHOD_EXIT();
1137 humberto 1.88         //l10n
1138                       //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "rollback failed");
1139                       throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.ROLLBACK_FAILED",
1140                       														  "rollback failed"));														  
1141                       //l10n end
1142 kumpf    1.58     }
1143 mike     1.53 
1144                   if (!InstanceDataFile::rollbackTransaction(dataFilePath))
1145 kumpf    1.58     {
1146                       PEG_METHOD_EXIT();
1147 humberto 1.88         //l10n
1148                       //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "rollback failed");
1149                       throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,MessageLoaderParms("Repository.CIMRepository.ROLLBACK_FAILED",
1150                       														  "rollback failed"));														  
1151                       //l10n end
1152 kumpf    1.58     }
1153 mike     1.53 
1154                   //
1155                   // Begin the transaction:
1156                   //
1157               
1158                   if (!InstanceIndexFile::beginTransaction(indexFilePath))
1159 kumpf    1.58     {
1160                       PEG_METHOD_EXIT();
1161 humberto 1.88         //l10n
1162                       //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "begin failed");
1163                       throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.BEGIN_FAILED",
1164                       														  "begin failed"));														  
1165                       //l10n end
1166 kumpf    1.58     }
1167 mike     1.53 
1168                   if (!InstanceDataFile::beginTransaction(dataFilePath))
1169 kumpf    1.61     { 
1170 kumpf    1.58         PEG_METHOD_EXIT();
1171 humberto 1.88         //l10n
1172                       //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "begin failed");
1173                       throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.BEGIN_FAILED",
1174                       														  "begin failed"));														  
1175                       //l10n end
1176 kumpf    1.58     }
1177 mike     1.53 
1178                   //
1179                   // Do this:
1180                   //
1181 mike     1.51 
1182                   String errMessage;
1183 mike     1.53     CIMInstance cimInstance;   // The instance that replaces the original
1184 mike     1.51 
1185                   if (propertyList.isNull())
1186                   {
1187                       //
1188                       // Replace all the properties in the instance
1189                       //
1190                       if (includeQualifiers)
1191                       {
1192                           //
1193                           // Replace the entire instance with the given instance
1194                           // (this is the default behavior)
1195                           //
1196 kumpf    1.70             cimInstance = modifiedInstance;
1197 mike     1.51         }
1198                       else
1199                       {
1200                           //
1201                           // Replace all the properties in the instance, but keep the
1202                           // original qualifiers on the instance and on the properties
1203                           //
1204               
1205 mike     1.55 	    _resolveInstance = false;
1206               
1207                           cimInstance = getInstance(
1208               		nameSpace,
1209 kumpf    1.70                 modifiedInstance.getPath (), 
1210 mike     1.55 		false, 
1211               		true, 
1212               		true);
1213               
1214               	    _resolveInstance = true;
1215 mike     1.54 
1216 mike     1.51             CIMInstance newInstance(
1217 kumpf    1.70                 modifiedInstance.getPath ().getClassName());
1218 mike     1.54 
1219 kumpf    1.70             CIMInstance givenInstance = modifiedInstance;
1220 mike     1.51 
1221                           //
1222                           // Copy over the original instance qualifiers
1223                           //
1224 mike     1.54 
1225                           for (Uint32 i = 0; i < cimInstance.getQualifierCount(); i++)
1226 mike     1.51             {
1227                               newInstance.addQualifier(cimInstance.getQualifier(i));
1228                           }
1229               
1230                           //
1231                           // Loop through the properties replacing each property in the
1232                           // original with a new value, but keeping the original qualifiers
1233                           //
1234                           for (Uint32 i=0; i<givenInstance.getPropertyCount(); i++)
1235                           {
1236                               // Copy the given property value (not qualifiers)
1237                               CIMProperty givenProperty = givenInstance.getProperty(i);
1238                               CIMProperty newProperty(
1239                                   givenProperty.getName(),
1240                                   givenProperty.getValue(),
1241                                   givenProperty.getArraySize(),
1242                                   givenProperty.getReferenceClassName(),
1243                                   givenProperty.getClassOrigin(),
1244                                   givenProperty.getPropagated());
1245               
1246                               // Copy the original property qualifiers
1247 mike     1.51                 Uint32 origPos =
1248                                   cimInstance.findProperty(newProperty.getName());
1249                               if (origPos != PEG_NOT_FOUND)
1250                               {
1251                                   CIMProperty origProperty = cimInstance.getProperty(origPos);
1252                                   for (Uint32 j=0; j<origProperty.getQualifierCount(); j++)
1253                                   {
1254                                       newProperty.addQualifier(origProperty.getQualifier(i));
1255                                   }
1256                               }
1257               
1258                               // Add the newly constructed property to the new instance
1259                               newInstance.addProperty(newProperty);
1260                           }
1261               
1262                           // Use the newly merged instance to replace the original instance
1263                           cimInstance = newInstance;
1264                       }
1265                   }
1266                   else
1267                   {
1268 mike     1.51         //
1269                       // Replace only the properties specified in the given instance
1270                       //
1271               
1272 mike     1.55 	_resolveInstance = false;
1273               
1274 mike     1.51         cimInstance = getInstance(nameSpace,
1275 kumpf    1.70             modifiedInstance.getPath (), false, true, true);
1276 mike     1.55 
1277               	_resolveInstance = true;
1278               
1279 kumpf    1.70         CIMInstance givenInstance = modifiedInstance;
1280 mike     1.51 
1281                       // NOTE: Instance qualifiers are not changed when a property list
1282                       // is specified.  Property qualifiers are replaced with the
1283                       // corresponding property values.
1284               
1285                       //
1286                       // Loop through the propertyList replacing each property in the original
1287                       //
1288 mike     1.53 
1289 kumpf    1.74         for (Uint32 i=0; i<propertyList.size(); i++)
1290 mike     1.51         {
1291 kumpf    1.74             Uint32 origPropPos = cimInstance.findProperty(propertyList[i]);
1292 mike     1.51             if (origPropPos != PEG_NOT_FOUND)
1293                           {
1294                               // Case: Property set in original
1295                               CIMProperty origProperty =
1296                                   cimInstance.getProperty(origPropPos);
1297               
1298                               // Get the given property value
1299                               Uint32 givenPropPos =
1300 kumpf    1.74                     givenInstance.findProperty(propertyList[i]);
1301 mike     1.51                 if (givenPropPos != PEG_NOT_FOUND)
1302                               {
1303                                   // Case: Property set in original and given
1304                                   CIMProperty givenProperty =
1305                                       givenInstance.getProperty(givenPropPos);
1306               
1307                                   // Copy over the property from the given to the original
1308                                   if (includeQualifiers)
1309                                   {
1310                                       // Case: Total property replacement
1311                                       cimInstance.removeProperty(origPropPos);
1312                                       cimInstance.addProperty(givenProperty);
1313                                   }
1314                                   else
1315                                   {
1316                                       // Case: Replace only the property value (not quals)
1317                                       origProperty.setValue(givenProperty.getValue());
1318                                       cimInstance.removeProperty(origPropPos);
1319                                       cimInstance.addProperty(origProperty);
1320                                   }
1321                               }
1322 mike     1.51                 else
1323                               {
1324                                   // Case: Property set in original and not in given
1325                                   // Just remove the property (set to null)
1326                                   cimInstance.removeProperty(origPropPos);
1327                               }
1328                           }
1329                           else
1330                           {
1331                               // Case: Property not set in original
1332               
1333                               // Get the given property value
1334                               Uint32 givenPropPos =
1335 kumpf    1.74                     givenInstance.findProperty(propertyList[i]);
1336 mike     1.51                 if (givenPropPos != PEG_NOT_FOUND)
1337                               {
1338                                   // Case: Property set in given and not in original
1339                                   CIMProperty givenProperty =
1340                                       givenInstance.getProperty(givenPropPos);
1341               
1342                                   // Copy over the property from the given to the original
1343                                   if (includeQualifiers)
1344                                   {
1345                                       // Case: Total property copy
1346                                       cimInstance.addProperty(givenProperty);
1347                                   }
1348                                   else
1349                                   {
1350                                       // Case: Copy only the property value (not qualifiers)
1351                                       CIMProperty newProperty(
1352                                           givenProperty.getName(),
1353                                           givenProperty.getValue(),
1354                                           givenProperty.getArraySize(),
1355                                           givenProperty.getReferenceClassName(),
1356                                           givenProperty.getClassOrigin(),
1357 mike     1.51                             givenProperty.getPropagated());
1358                                       cimInstance.addProperty(newProperty);
1359                                   }
1360                               }
1361                               else
1362                               {
1363                                   // Case: Property not set in original or in given
1364               
1365                                   // Nothing to do; just make sure the property name is valid
1366                                   // ATTN: This is not the most efficient solution
1367                                   CIMClass cimClass = getClass(
1368                                       nameSpace, cimInstance.getClassName(), false);
1369 kumpf    1.74                     if (cimClass.findProperty(propertyList[i]) == PEG_NOT_FOUND)
1370 mike     1.51                     {
1371                                       // ATTN: This exception may be returned by setProperty
1372 kumpf    1.58                         PEG_METHOD_EXIT();
1373 mike     1.51                         throw PEGASUS_CIM_EXCEPTION(
1374                                           CIM_ERR_NO_SUCH_PROPERTY, "modifyInstance()");
1375                                   }
1376                               }
1377                           }
1378                       }
1379                   }
1380               
1381 mike     1.53     //
1382 mike     1.54     // Resolve the instance (do not propagate qualifiers from class since
1383                   // this will bloat the instance).
1384 mike     1.53     //
1385 mike     1.48 
1386                   CIMConstClass cimClass;
1387 kumpf    1.76     Resolver::resolveInstance (cimInstance, _context, nameSpace, cimClass, 
1388                       false);
1389 mike     1.48 
1390 kumpf    1.81     CIMObjectPath instanceName = cimInstance.buildPath(cimClass);
1391 mike     1.51 
1392 mike     1.53     //
1393                   // Disallow operation if the instance name was changed:
1394                   //
1395 mike     1.51 
1396 kumpf    1.70     if (instanceName != modifiedInstance.getPath ())
1397 mike     1.51     {
1398 kumpf    1.58         PEG_METHOD_EXIT();
1399 humberto 1.88         //l10n
1400                       //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
1401                           //"Attempted to modify a key property");
1402                       throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.ATTEMPT_TO_MODIFY_KEY_PROPERTY",
1403                       														  "Attempted to modify a key property"));
1404                       //l10n end
1405 mike     1.51     }
1406               
1407                   Uint32 oldSize;
1408                   Uint32 oldIndex;
1409                   Uint32 newSize;
1410                   Uint32 newIndex;
1411 mike     1.48 
1412 mike     1.53     if (!InstanceIndexFile::lookupEntry(
1413               	indexFilePath, instanceName, oldIndex, oldSize))
1414 mike     1.51     {
1415 kumpf    1.58         PEG_METHOD_EXIT();
1416 mike     1.51         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString());
1417                   }
1418 mike     1.48 
1419 mike     1.53     //
1420                   // Modify the data file:
1421                   //
1422               
1423                   {
1424               	Array<Sint8> out;
1425 kumpf    1.66 	XmlWriter::appendInstanceElement(out, cimInstance);
1426 mike     1.48 
1427 mike     1.53 	newSize = out.size();
1428 mike     1.48 
1429 mike     1.53 	if (!InstanceDataFile::appendInstance(dataFilePath, out, newIndex))
1430               	{
1431 humberto 1.88 		//l10n
1432               	    //errMessage.append("Failed to modify instance ");
1433               	    //errMessage.append(instanceName.toString());
1434 kumpf    1.58             PEG_METHOD_EXIT();
1435 humberto 1.88 	    //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
1436               	    throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.FAILED_TO_MODIFY_INSTANCE",
1437               																  "Failed to modify instance $0",
1438               																  instanceName.toString()));
1439               	    //l10n end
1440 mike     1.53 	}
1441 mike     1.48     }
1442               
1443 mike     1.53     //
1444                   // Modify the index file:
1445                   //
1446               
1447                   Uint32 freeCount;
1448 mike     1.51 
1449 mike     1.53     if (!InstanceIndexFile::modifyEntry(indexFilePath, instanceName, newIndex,
1450                       newSize, freeCount))
1451 mike     1.51     {
1452 humberto 1.88         //l10n
1453               	    //errMessage.append("Failed to modify instance ");
1454               	    //errMessage.append(instanceName.toString());
1455                           PEG_METHOD_EXIT();
1456               	    //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
1457               	    throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.FAILED_TO_MODIFY_INSTANCE",
1458               																  "Failed to modify instance $0",
1459               																  instanceName.toString()));
1460               	    //l10n end
1461 mike     1.51     }
1462               
1463 mike     1.53     //
1464                   // Commit the transaction:
1465                   //
1466               
1467                   if (!InstanceIndexFile::commitTransaction(indexFilePath))
1468 kumpf    1.58     {
1469                       PEG_METHOD_EXIT();
1470 humberto 1.88         //l10n
1471                       //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "commit failed");
1472                       throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.COMMIT_FAILED",
1473                       														  "commit failed"));
1474                       //l10n end
1475 kumpf    1.58     }
1476 mike     1.53 
1477                   if (!InstanceDataFile::commitTransaction(dataFilePath))
1478 kumpf    1.58     {
1479                       PEG_METHOD_EXIT();
1480 humberto 1.88         //l10n
1481                       //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "commit failed");
1482                       throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,MessageLoaderParms("Repository.CIMRepository.COMMIT_FAILED",
1483                       														  "commit failed"));
1484                       //l10n end
1485 kumpf    1.58     }
1486 mike     1.48 
1487 mike     1.53     //
1488                   // Compact the index and data files if the free count max was
1489                   // reached.
1490                   //
1491               
1492                   if (freeCount == _MAX_FREE_COUNT)
1493               	_CompactInstanceRepository(indexFilePath, dataFilePath);
1494 mike     1.54 
1495                   //
1496                   // Resolve the instance:
1497                   //
1498               
1499 kumpf    1.76     Resolver::resolveInstance (cimInstance, _context, nameSpace, cimClass, 
1500                       true);
1501 kumpf    1.58 
1502                   PEG_METHOD_EXIT();
1503 mike     1.48 }
1504               
1505               Array<CIMClass> CIMRepository::enumerateClasses(
1506 kumpf    1.85     const CIMNamespaceName& nameSpace,
1507                   const CIMName& className,
1508 mike     1.48     Boolean deepInheritance,
1509                   Boolean localOnly,
1510                   Boolean includeQualifiers,
1511                   Boolean includeClassOrigin)
1512               {
1513 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::enumerateClasses");
1514 mike     1.51 
1515 kumpf    1.85     Array<CIMName> classNames;
1516 mike     1.48 
1517                   _nameSpaceManager.getSubClassNames(
1518 mike     1.51         nameSpace, className, deepInheritance, classNames);
1519 mike     1.48 
1520                   Array<CIMClass> result;
1521               
1522                   for (Uint32 i = 0; i < classNames.size(); i++)
1523                   {
1524 mike     1.51         result.append(getClass(nameSpace, classNames[i], localOnly,
1525                           includeQualifiers, includeClassOrigin));
1526 mike     1.48     }
1527               
1528 kumpf    1.58     PEG_METHOD_EXIT();
1529 mike     1.48     return result;
1530               }
1531               
1532 kumpf    1.85 Array<CIMName> CIMRepository::enumerateClassNames(
1533                   const CIMNamespaceName& nameSpace,
1534                   const CIMName& className,
1535 mike     1.48     Boolean deepInheritance)
1536               {
1537 kumpf    1.59     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::enumerateClassNames");
1538 kumpf    1.58 
1539 kumpf    1.85     Array<CIMName> classNames;
1540 mike     1.48 
1541                   _nameSpaceManager.getSubClassNames(
1542 mike     1.51         nameSpace, className, deepInheritance, classNames);
1543 mike     1.48 
1544 kumpf    1.58     PEG_METHOD_EXIT();
1545 mike     1.48     return classNames;
1546               }
1547               
1548 mike     1.53 Boolean CIMRepository::_loadAllInstances(
1549 kumpf    1.85     const CIMNamespaceName& nameSpace,
1550                   const CIMName& className,
1551 kumpf    1.70     Array<CIMInstance>& namedInstances)
1552 mike     1.53 {
1553 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_loadAllInstances");
1554               
1555 kumpf    1.68     Array<CIMObjectPath> instanceNames;
1556 mike     1.53     Array<Sint8> data;
1557                   Array<Uint32> indices;
1558                   Array<Uint32> sizes;
1559               
1560                   //
1561                   // Form the name of the instance index file
1562                   //
1563               
1564                   String indexFilePath = _getInstanceIndexFilePath(nameSpace, className);
1565               
1566                   //
1567                   // Form the name of the instance file
1568                   //
1569               
1570                   String dataFilePath = _getInstanceDataFilePath(nameSpace, className);
1571               
1572                   //
1573                   // Enumerate the index file:
1574                   //
1575               
1576                   Array<Uint32> freeFlags;
1577 mike     1.53 
1578                   if (!InstanceIndexFile::enumerateEntries(
1579                       indexFilePath, freeFlags, indices, sizes, instanceNames, true))
1580                   {
1581 kumpf    1.58         PEG_METHOD_EXIT();
1582 mike     1.53         return false;
1583                   }
1584               
1585                   //
1586                   // Form the array of instances result:
1587                   //
1588               
1589                   if (instanceNames.size() > 0)
1590                   {
1591               	//
1592               	// Load all instances from the data file:
1593               	//
1594               
1595                       if (!InstanceDataFile::loadAllInstances(dataFilePath, data))
1596 kumpf    1.58         {
1597                           PEG_METHOD_EXIT();
1598 mike     1.53             return false;
1599 kumpf    1.58         }
1600 mike     1.53  
1601                       //
1602                       // for each instance loaded, call XML parser to parse the XML
1603                       // data and create a CIMInstance object.
1604                       //
1605               
1606                       CIMInstance tmpInstance;
1607               
1608                       Uint32 bufferSize = data.size();
1609                       char* buffer = (char*)data.getData();
1610               
1611                       for (Uint32 i = 0; i < instanceNames.size(); i++)
1612                       {
1613               	    if (!freeFlags[i])
1614               	    {
1615               		XmlParser parser(&(buffer[indices[i]]));
1616               
1617               		XmlReader::getObject(parser, tmpInstance);
1618               
1619 kumpf    1.76 		Resolver::resolveInstance (tmpInstance, _context, nameSpace, 
1620                                   true);
1621 kumpf    1.70                 tmpInstance.setPath (instanceNames[i]);
1622 mike     1.54 
1623 kumpf    1.70 		namedInstances.append (tmpInstance);
1624 mike     1.53 	    }
1625                       }
1626                   }
1627               
1628 kumpf    1.58     PEG_METHOD_EXIT();
1629 mike     1.53     return true;
1630               }
1631               
1632 kumpf    1.70 Array<CIMInstance> CIMRepository::enumerateInstances(
1633 kumpf    1.85     const CIMNamespaceName& nameSpace,
1634                   const CIMName& className,
1635 mike     1.48     Boolean deepInheritance,
1636                   Boolean localOnly,
1637                   Boolean includeQualifiers,
1638                   Boolean includeClassOrigin,
1639 mike     1.51     const CIMPropertyList& propertyList)
1640 mike     1.48 {
1641 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::enumerateInstances");
1642 karl     1.69     //
1643                   // Get all descendent classes of this class:
1644                   //
1645               
1646 kumpf    1.85     Array<CIMName> classNames;
1647 karl     1.69     _nameSpaceManager.getSubClassNames(nameSpace, className, true, classNames);
1648                   classNames.prepend(className);
1649               
1650                   //
1651                   // Get all instances for this class and all its descendent classes
1652                   //
1653 kumpf    1.58 
1654 kumpf    1.70     Array<CIMInstance> namedInstances;
1655 karl     1.69     
1656                   for (Uint32 i = 0; i < classNames.size(); i++)
1657 karl     1.65     {
1658 karl     1.69         if (!_loadAllInstances(nameSpace, classNames[i], namedInstances))
1659                       {
1660 humberto 1.88         	//l10n
1661                           //String errMessage = "Failed to load instances in class ";
1662                           //errMessage.append(classNames[i].getString ());
1663 karl     1.69             PEG_METHOD_EXIT();
1664 humberto 1.88             //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
1665                           throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.FAILED_TO_LOAD_INSTANCES",
1666                       															  "Failed to load instances in class $0",
1667                       															  classNames[i].getString()));
1668                           //10n end
1669 karl     1.69         }
1670 karl     1.65     }
1671 karl     1.69     
1672 karl     1.65     PEG_METHOD_EXIT();
1673                   return namedInstances;
1674 karl     1.69 }
1675 karl     1.65 
1676 kumpf    1.70 Array<CIMInstance> CIMRepository::enumerateInstancesForClass(
1677 kumpf    1.85     const CIMNamespaceName& nameSpace,
1678                   const CIMName& className,
1679 karl     1.69     Boolean deepInheritance,
1680                   Boolean localOnly,
1681                   Boolean includeQualifiers,
1682                   Boolean includeClassOrigin,
1683                   Boolean includeInheritance,
1684                   const CIMPropertyList& propertyList)
1685               {
1686                   PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::enumerateInstances");
1687 mike     1.53     //
1688                   // Get all descendent classes of this class:
1689                   //
1690 mike     1.48 
1691 kumpf    1.85     Array<CIMName> classNames;
1692 karl     1.69     // If includeInheritance is true, get all subclasses.
1693                   // ATTN: P3 KS Look at whether the subclassNames requires an empty array.
1694                   if(includeInheritance)
1695                   {
1696               	try
1697               	{
1698               	    _nameSpaceManager.getSubClassNames(nameSpace, className, true, classNames);
1699               	}
1700               	catch(CIMException& e)
1701               	{
1702               	    PEG_METHOD_EXIT();
1703               	    throw e;
1704               	}
1705                   }
1706 mike     1.48     classNames.prepend(className);
1707               
1708 mike     1.53     //
1709                   // Get all instances for this class and all its descendent classes
1710                   //
1711 mike     1.48 
1712 kumpf    1.70     Array<CIMInstance> namedInstances;
1713 karl     1.69     
1714 mike     1.48     for (Uint32 i = 0; i < classNames.size(); i++)
1715                   {
1716 mike     1.51         if (!_loadAllInstances(nameSpace, classNames[i], namedInstances))
1717                       {
1718 humberto 1.88         	//l10n
1719                           //String errMessage = "Failed to load instances in class ";
1720                           //errMessage.append(classNames[i].getString());
1721 kumpf    1.58             PEG_METHOD_EXIT();
1722 humberto 1.88             //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
1723                           throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.FAILED_TO_LOAD_INSTANCES",
1724                       															  "Failed to load instances in class $0",
1725                       															  classNames[i].getString()));
1726                           //l10n end
1727 mike     1.51         }
1728 mike     1.48     }
1729 karl     1.69     
1730 kumpf    1.58     PEG_METHOD_EXIT();
1731 mike     1.51     return namedInstances;
1732 mike     1.48 }
1733 kumpf    1.68 Array<CIMObjectPath> CIMRepository::enumerateInstanceNames(
1734 kumpf    1.85     const CIMNamespaceName& nameSpace,
1735                   const CIMName& className)
1736 mike     1.48 {
1737 kumpf    1.61     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::enumerateInstanceNames");
1738 mike     1.51 
1739 karl     1.65     //
1740 karl     1.69     // Get names of descendent classes:
1741 karl     1.65     //
1742 kumpf    1.85     Array<CIMName> classNames;
1743 karl     1.69 
1744                   try
1745                   {
1746               	_nameSpaceManager.getSubClassNames(nameSpace, className, true, classNames);
1747                   }
1748                   catch(CIMException& e)
1749                   {
1750               	PEG_METHOD_EXIT();
1751               	throw e;
1752                   }
1753                   classNames.prepend(className);
1754 karl     1.65 
1755                   //
1756 karl     1.69     // Get instance names from each qualifying instance file for the class:
1757 karl     1.65     //
1758 karl     1.69     Array<CIMObjectPath> instanceNames;
1759                   Array<Uint32> indices;
1760                   Array<Uint32> sizes;
1761 karl     1.65 
1762 karl     1.69     for (Uint32 i = 0; i < classNames.size(); i++)
1763                   {
1764               	//
1765                       // Form the name of the class index file:
1766               	//
1767               
1768                       String indexFilePath = _getInstanceIndexFilePath(
1769               	    nameSpace, classNames[i]);
1770               
1771               	//
1772                       // Get all instances for that class:
1773               	//
1774               
1775               	Array<Uint32> freeFlags;
1776 karl     1.65 
1777 karl     1.69 	if (!InstanceIndexFile::enumerateEntries(
1778               	    indexFilePath, freeFlags, indices, sizes, instanceNames, false))
1779                       {
1780 humberto 1.88         	//l10n
1781                           //String errMessage = "Failed to load instance names in class ";
1782               	    		//errMessage.append(classNames[i].getString());
1783 karl     1.69             PEG_METHOD_EXIT();
1784 humberto 1.88             //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
1785                           throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.FAILED_TO_LOAD_INSTANCE_NAMES",
1786                       															  "Failed to load instance names in class $0",
1787                       															  classNames[i].getString()));
1788                           //l10n end
1789 karl     1.69         }
1790 karl     1.65     }
1791               
1792 karl     1.69     PEG_METHOD_EXIT();
1793                   return instanceNames;
1794               }
1795               
1796               Array<CIMObjectPath> CIMRepository::enumerateInstanceNamesForClass(
1797 kumpf    1.85     const CIMNamespaceName& nameSpace,
1798                   const CIMName& className,
1799 karl     1.69     Boolean includeInheritance)
1800               {
1801                   PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::enumerateInstanceNames");
1802               
1803 mike     1.53     //
1804                   // Get names of descendent classes:
1805                   //
1806 kumpf    1.85     Array<CIMName> classNames;
1807 karl     1.69 
1808                   // If includeInheritance is true, get all subclasses.
1809                   if(includeInheritance)
1810 mday     1.57     {
1811 karl     1.69 	try
1812               	{
1813               	    _nameSpaceManager.getSubClassNames(nameSpace, className, true, classNames);
1814               	}
1815               	catch(CIMException& e)
1816               	{
1817               	    PEG_METHOD_EXIT();
1818               	    throw e;
1819               	}
1820 mday     1.57     }
1821 mike     1.48     classNames.prepend(className);
1822               
1823 mike     1.53     //
1824                   // Get instance names from each qualifying instance file for the class:
1825                   //
1826 kumpf    1.68     Array<CIMObjectPath> instanceNames;
1827 mike     1.48     Array<Uint32> indices;
1828 mike     1.51     Array<Uint32> sizes;
1829 mike     1.48 
1830                   for (Uint32 i = 0; i < classNames.size(); i++)
1831                   {
1832 mike     1.53 	//
1833                       // Form the name of the class index file:
1834               	//
1835 mike     1.48 
1836 mike     1.53         String indexFilePath = _getInstanceIndexFilePath(
1837               	    nameSpace, classNames[i]);
1838 mike     1.48 
1839 mike     1.53 	//
1840 mike     1.51         // Get all instances for that class:
1841 mike     1.53 	//
1842               
1843               	Array<Uint32> freeFlags;
1844 mike     1.48 
1845 mike     1.53 	if (!InstanceIndexFile::enumerateEntries(
1846               	    indexFilePath, freeFlags, indices, sizes, instanceNames, false))
1847 mike     1.51         {
1848 humberto 1.88         	//l10n
1849                           //String errMessage = "Failed to load instance names in class ";
1850               	    		//errMessage.append(classNames[i].getString());
1851 kumpf    1.52             PEG_METHOD_EXIT();
1852 humberto 1.88             //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
1853                           throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.FAILED_TO_LOAD_INSTANCE_NAMES",
1854                       															  "Failed to load instance names in class $0",
1855                       															  classNames[i].getString()));
1856                           //l10n end
1857 mike     1.51         }
1858 mike     1.48     }
1859 mike     1.53 
1860 kumpf    1.52     PEG_METHOD_EXIT();
1861 mike     1.48     return instanceNames;
1862               }
1863 karl     1.69 
1864 mike     1.48 
1865               Array<CIMInstance> CIMRepository::execQuery(
1866                   const String& queryLanguage,
1867                   const String& query)
1868               {
1869 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::execQuery");
1870               
1871                   PEG_METHOD_EXIT();
1872 mike     1.48     throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED, "execQuery()");
1873               
1874 kumpf    1.58     PEG_METHOD_EXIT();
1875 mike     1.48     return Array<CIMInstance>();
1876               }
1877               
1878 kumpf    1.71 Array<CIMObject> CIMRepository::associators(
1879 kumpf    1.85     const CIMNamespaceName& nameSpace,
1880 kumpf    1.68     const CIMObjectPath& objectName,
1881 kumpf    1.85     const CIMName& assocClass,
1882                   const CIMName& resultClass,
1883 mike     1.48     const String& role,
1884                   const String& resultRole,
1885                   Boolean includeQualifiers,
1886                   Boolean includeClassOrigin,
1887 mike     1.51     const CIMPropertyList& propertyList)
1888 mike     1.48 {
1889 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::associators");
1890               
1891 kumpf    1.68     Array<CIMObjectPath> names = associatorNames(
1892 mike     1.51         nameSpace,
1893                       objectName,
1894                       assocClass,
1895                       resultClass,
1896                       role,
1897                       resultRole);
1898 mike     1.48 
1899 kumpf    1.71     Array<CIMObject> result;
1900 mike     1.48 
1901                   for (Uint32 i = 0, n = names.size(); i < n; i++)
1902                   {
1903 kumpf    1.85         CIMNamespaceName tmpNameSpace = names[i].getNameSpace();
1904 mike     1.48 
1905 kumpf    1.85         if (tmpNameSpace.isNull())
1906 mike     1.51             tmpNameSpace = nameSpace;
1907 mike     1.48 
1908 kumpf    1.80         //
1909                       //  ATTN-CAKG-P2-20020726:  The following condition does not correctly
1910                       //  distinguish instanceNames from classNames in every case
1911                       //  The instanceName of a singleton instance of a keyless class also
1912                       //  has no key bindings
1913                       //
1914                       if (names[i].getKeyBindings ().size () == 0)
1915 mike     1.51         {
1916 kumpf    1.68             CIMObjectPath tmpRef = names[i];
1917 mike     1.51             tmpRef.setHost(String());
1918                           tmpRef.setNameSpace(String());
1919               
1920                           CIMClass cimClass = getClass(
1921                               tmpNameSpace,
1922                               tmpRef.getClassName(),
1923                               false,
1924                               includeQualifiers,
1925                               includeClassOrigin,
1926                               propertyList);
1927               
1928                           CIMObject cimObject(cimClass);
1929 kumpf    1.71             cimObject.setPath (names[i]);
1930                           result.append(cimObject);
1931 mike     1.51         }
1932                       else
1933                       {
1934 kumpf    1.68             CIMObjectPath tmpRef = names[i];
1935 mike     1.51             tmpRef.setHost(String());
1936                           tmpRef.setNameSpace(String());
1937               
1938                           CIMInstance cimInstance = getInstance(
1939                               tmpNameSpace,
1940                               tmpRef,
1941                               false,
1942                               includeQualifiers,
1943                               includeClassOrigin,
1944                               propertyList);
1945               
1946                           CIMObject cimObject(cimInstance);
1947 kumpf    1.71             cimObject.setPath (names[i]);
1948                           result.append(cimObject);
1949 mike     1.51         }
1950 mike     1.48     }
1951               
1952 kumpf    1.58     PEG_METHOD_EXIT();
1953 mike     1.48     return result;
1954               }
1955               
1956 kumpf    1.68 Array<CIMObjectPath> CIMRepository::associatorNames(
1957 kumpf    1.85     const CIMNamespaceName& nameSpace,
1958 kumpf    1.68     const CIMObjectPath& objectName,
1959 kumpf    1.85     const CIMName& assocClass,
1960                   const CIMName& resultClass,
1961 mike     1.48     const String& role,
1962                   const String& resultRole)
1963               {
1964 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::associatorNames");
1965 mike     1.51 
1966 mike     1.48     Array<String> associatorNames;
1967               
1968 kumpf    1.80     //
1969                   //  ATTN-CAKG-P2-20020726:  The following condition does not correctly
1970                   //  distinguish instanceNames from classNames in every case
1971                   //  The instanceName of a singleton instance of a keyless class also
1972                   //  has no key bindings
1973                   //
1974                   if (objectName.getKeyBindings ().size () == 0)
1975 mike     1.48     {
1976 mike     1.51         String assocFileName = _MakeAssocClassPath(nameSpace, _repositoryRoot);
1977 mike     1.48 
1978 mike     1.51         AssocClassTable::getAssociatorNames(
1979                           assocFileName,
1980 karl     1.86             objectName.getClassName(),
1981 mike     1.51             assocClass,
1982                           resultClass,
1983                           role,
1984                           resultRole,
1985                           associatorNames);
1986 mike     1.48     }
1987                   else
1988                   {
1989 mike     1.51         String assocFileName = _MakeAssocInstPath(nameSpace, _repositoryRoot);
1990 mike     1.48 
1991 mike     1.51         AssocInstTable::getAssociatorNames(
1992                           assocFileName,
1993                           objectName,
1994                           assocClass,
1995                           resultClass,
1996                           role,
1997                           resultRole,
1998                           associatorNames);
1999 mike     1.48     }
2000               
2001 kumpf    1.68     Array<CIMObjectPath> result;
2002 mike     1.48 
2003                   for (Uint32 i = 0, n = associatorNames.size(); i < n; i++)
2004                   {
2005 kumpf    1.68         CIMObjectPath r = associatorNames[i];
2006 mike     1.48 
2007                       if (r.getHost().size() == 0)
2008                           r.setHost(System::getHostName());
2009               
2010 kumpf    1.79         if (r.getNameSpace().isNull())
2011 mike     1.48             r.setNameSpace(nameSpace);
2012               
2013 mike     1.51         result.append(r);
2014 mike     1.48     }
2015               
2016 kumpf    1.58     PEG_METHOD_EXIT();
2017 mike     1.48     return result;
2018               }
2019               
2020 kumpf    1.71 Array<CIMObject> CIMRepository::references(
2021 kumpf    1.85     const CIMNamespaceName& nameSpace,
2022 kumpf    1.68     const CIMObjectPath& objectName,
2023 kumpf    1.85     const CIMName& resultClass,
2024 mike     1.48     const String& role,
2025                   Boolean includeQualifiers,
2026                   Boolean includeClassOrigin,
2027 mike     1.51     const CIMPropertyList& propertyList)
2028 mike     1.48 {
2029 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::references");
2030               
2031 kumpf    1.68     Array<CIMObjectPath> names = referenceNames(
2032 mike     1.51         nameSpace,
2033                       objectName,
2034                       resultClass,
2035                       role);
2036 mike     1.48 
2037 kumpf    1.71     Array<CIMObject> result;
2038 mike     1.48 
2039                   for (Uint32 i = 0, n = names.size(); i < n; i++)
2040                   {
2041 kumpf    1.85         CIMNamespaceName tmpNameSpace = names[i].getNameSpace();
2042 mike     1.48 
2043 kumpf    1.85         if (tmpNameSpace.isNull())
2044 mike     1.51             tmpNameSpace = nameSpace;
2045 mike     1.48 
2046 mike     1.51         // ATTN: getInstance() should this be able to handle instance names
2047                       // with host names and namespaces?
2048 mike     1.48 
2049 kumpf    1.68         CIMObjectPath tmpRef = names[i];
2050 mike     1.51         tmpRef.setHost(String());
2051                       tmpRef.setNameSpace(String());
2052               
2053 kumpf    1.80         //
2054                       //  ATTN-CAKG-P2-20020726:  The following condition does not correctly
2055                       //  distinguish instanceNames from classNames in every case
2056                       //  The instanceName of a singleton instance of a keyless class also
2057                       //  has no key bindings
2058                       //
2059                       if (objectName.getKeyBindings ().size () == 0)
2060 mike     1.51         {
2061                           CIMClass cimClass = getClass(
2062                               tmpNameSpace,
2063                               tmpRef.getClassName(),
2064                               false,
2065                               includeQualifiers,
2066                               includeClassOrigin,
2067                               propertyList);
2068               
2069 kumpf    1.71             CIMObject cimObject = CIMObject (cimClass);
2070                           cimObject.setPath (names[i]);
2071                           result.append (cimObject);
2072 mike     1.51         }
2073                       else
2074                       {
2075                           CIMInstance instance = getInstance(
2076                               tmpNameSpace,
2077                               tmpRef,
2078                               false,
2079                               includeQualifiers,
2080                               includeClassOrigin,
2081                               propertyList);
2082 mike     1.48 
2083 kumpf    1.71             CIMObject cimObject = CIMObject (instance);
2084                           cimObject.setPath (names[i]);
2085                           result.append (cimObject);
2086 mike     1.51         }
2087 mike     1.48     }
2088               
2089 kumpf    1.58     PEG_METHOD_EXIT();
2090 mike     1.48     return result;
2091               }
2092               
2093 karl     1.86 
2094 kumpf    1.68 Array<CIMObjectPath> CIMRepository::referenceNames(
2095 kumpf    1.85     const CIMNamespaceName& nameSpace,
2096 kumpf    1.68     const CIMObjectPath& objectName,
2097 kumpf    1.85     const CIMName& resultClass,
2098 mike     1.48     const String& role)
2099               {
2100 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::referenceNames");
2101               
2102 mike     1.48     Array<String> tmpReferenceNames;
2103               
2104 karl     1.86     CIMName className = objectName.getClassName();
2105 karl     1.87 
2106 karl     1.86     Array<CIMName> classList;
2107                   _nameSpaceManager.getSuperClassNames(nameSpace, className, classList);
2108                   classList.prepend(className);
2109               
2110                   // ATTN: KS 20030428 - Apparently getSuperClassNames returning toplevel twice.
2111               
2112 kumpf    1.80     //  ATTN-CAKG-P2-20020726:  The following condition does not correctly
2113                   //  distinguish instanceNames from classNames in every case
2114                   //  The instanceName of a singleton instance of a keyless class also
2115                   //  has no key bindings
2116                   //
2117                   if (objectName.getKeyBindings ().size () == 0)
2118 mike     1.48     {
2119 mike     1.51         String assocFileName = _MakeAssocClassPath(nameSpace, _repositoryRoot);
2120 mike     1.48 
2121 mike     1.51         if (!AssocClassTable::getReferenceNames(
2122                           assocFileName,
2123 karl     1.86             classList,
2124 mike     1.51             resultClass,
2125                           role,
2126                           tmpReferenceNames))
2127                       {
2128                           // Ignore error! It's okay not to have references.
2129                       }
2130 mike     1.48     }
2131                   else
2132                   {
2133 mike     1.51         String assocFileName = _MakeAssocInstPath(nameSpace, _repositoryRoot);
2134 mike     1.48 
2135 mike     1.51         if (!AssocInstTable::getReferenceNames(
2136                           assocFileName,
2137                           objectName,
2138                           resultClass,
2139                           role,
2140                           tmpReferenceNames))
2141                       {
2142                           // Ignore error! It's okay not to have references.
2143                       }
2144 mike     1.48     }
2145               
2146 kumpf    1.68     Array<CIMObjectPath> result;
2147 mike     1.48 
2148                   for (Uint32 i = 0, n = tmpReferenceNames.size(); i < n; i++)
2149                   {
2150 kumpf    1.68         CIMObjectPath r = tmpReferenceNames[i];
2151 mike     1.48 
2152                       if (r.getHost().size() == 0)
2153                           r.setHost(System::getHostName());
2154               
2155 kumpf    1.79         if (r.getNameSpace().isNull())
2156 mike     1.48             r.setNameSpace(nameSpace);
2157               
2158 mike     1.51         result.append(r);
2159 mike     1.48     }
2160               
2161 kumpf    1.58     PEG_METHOD_EXIT();
2162 mike     1.48     return result;
2163               }
2164 karl     1.86 
2165               Array<CIMName> CIMRepository::referencedClassNames(
2166                   const CIMNamespaceName& nameSpace,
2167                   const CIMName& className,
2168                   const CIMName& resultClass,
2169                   const String& role)
2170               {
2171                   PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::referencedClassNames");
2172                   Array<String> referenceNames;
2173               
2174                   Array<CIMName> referencedNames;
2175               
2176                   Array<CIMName> classList;
2177                   _nameSpaceManager.getSuperClassNames(nameSpace, className, classList);
2178                   classList.prepend(className);
2179               
2180                   // ATTN: KS 20030428 - Apparently getSuperClassNames returning toplevel twice.
2181               
2182                       String assocFileName = _MakeAssocClassPath(nameSpace, _repositoryRoot);
2183               
2184                       if (!AssocClassTable::getReferencedClassNames(
2185 karl     1.86             assocFileName,
2186                           classList,
2187                           resultClass,
2188                           role,
2189                           referencedNames))
2190                       {
2191                           // Ignore error! It's okay not to have references.
2192                       }
2193                   // ATTN: KS 030301 Probably need a test here to clip off anything above the class names
2194 karl     1.87     PEG_METHOD_EXIT();
2195                   
2196                   return referencedNames;
2197 karl     1.86  }
2198 mike     1.48 
2199               CIMValue CIMRepository::getProperty(
2200 kumpf    1.85     const CIMNamespaceName& nameSpace,
2201 kumpf    1.68     const CIMObjectPath& instanceName,
2202 kumpf    1.85     const CIMName& propertyName)
2203 mike     1.48 {
2204 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::getProperty");
2205               
2206 mike     1.53     //
2207                   // Get the index for this instance:
2208                   //
2209 mike     1.48 
2210 kumpf    1.85     CIMName className;
2211 mike     1.48     Uint32 index;
2212 mike     1.51     Uint32 size;
2213 mike     1.48 
2214 mike     1.53     if (!_getInstanceIndex(nameSpace, instanceName, className, index, size))
2215 kumpf    1.58     {
2216                       PEG_METHOD_EXIT();
2217 mike     1.51         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString());
2218 kumpf    1.58     }
2219 mike     1.48 
2220 mike     1.53     //
2221                   // Load the instance into memory:
2222                   //
2223 mike     1.48 
2224 mike     1.53     String path = _getInstanceDataFilePath(nameSpace, className);
2225 mike     1.48     CIMInstance cimInstance;
2226 mike     1.53 
2227 mike     1.51     if (!_loadInstance(path, cimInstance, index, size))
2228                   {
2229 kumpf    1.58         PEG_METHOD_EXIT();
2230 mike     1.51         throw CannotOpenFile(path);
2231                   }
2232 mike     1.48 
2233 mike     1.53     //
2234                   // Grab the property from the instance:
2235                   //
2236 mike     1.48 
2237                   Uint32 pos = cimInstance.findProperty(propertyName);
2238               
2239 mike     1.51     // ATTN: This breaks if the property is simply null
2240 kumpf    1.77     if (pos == PEG_NOT_FOUND)
2241 kumpf    1.58     {
2242                       PEG_METHOD_EXIT();
2243 mike     1.51         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NO_SUCH_PROPERTY, "getProperty()");
2244 kumpf    1.58     }
2245 mike     1.48 
2246                   CIMProperty prop = cimInstance.getProperty(pos);
2247               
2248 mike     1.53     //
2249                   // Return the value:
2250                   //
2251 mike     1.48 
2252 kumpf    1.58     PEG_METHOD_EXIT();
2253 mike     1.48     return prop.getValue();
2254               }
2255               
2256               void CIMRepository::setProperty(
2257 kumpf    1.85     const CIMNamespaceName& nameSpace,
2258 kumpf    1.68     const CIMObjectPath& instanceName,
2259 kumpf    1.85     const CIMName& propertyName,
2260 mike     1.48     const CIMValue& newValue)
2261               {
2262 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::setProperty");
2263               
2264 mike     1.51     //
2265                   // Create the instance to pass to modifyInstance()
2266                   //
2267 mike     1.53 
2268 mike     1.51     CIMInstance instance(instanceName.getClassName());
2269                   instance.addProperty(CIMProperty(propertyName, newValue));
2270 kumpf    1.70     instance.setPath (instanceName);
2271 mike     1.51 
2272                   //
2273                   // Create the propertyList to pass to modifyInstance()
2274                   //
2275 mike     1.53 
2276 kumpf    1.79     Array<CIMName> propertyListArray;
2277 mike     1.51     propertyListArray.append(propertyName);
2278                   CIMPropertyList propertyList(propertyListArray);
2279               
2280                   //
2281                   // Modify the instance to set the value of the given property
2282                   //
2283 kumpf    1.70     modifyInstance(nameSpace, instance, false, propertyList);
2284 kumpf    1.58 
2285                   PEG_METHOD_EXIT();
2286 mike     1.48 }
2287               
2288               CIMQualifierDecl CIMRepository::getQualifier(
2289 kumpf    1.85     const CIMNamespaceName& nameSpace,
2290                   const CIMName& qualifierName)
2291 mike     1.48 {
2292 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::getQualifier");
2293               
2294 mike     1.53     //
2295                   // Get path of qualifier file:
2296                   //
2297 mike     1.48 
2298                   String qualifierFilePath = _nameSpaceManager.getQualifierFilePath(
2299 mike     1.51         nameSpace, qualifierName);
2300 mike     1.48 
2301 mike     1.53     //
2302                   // Load qualifier:
2303                   //
2304 mike     1.48 
2305                   CIMQualifierDecl qualifierDecl;
2306               
2307                   try
2308                   {
2309 mike     1.51         _LoadObject(qualifierFilePath, qualifierDecl);
2310 mike     1.48     }
2311                   catch (CannotOpenFile&)
2312                   {
2313 kumpf    1.58         PEG_METHOD_EXIT();
2314 kumpf    1.85         throw PEGASUS_CIM_EXCEPTION
2315                           (CIM_ERR_NOT_FOUND, qualifierName.getString());
2316 mike     1.48     }
2317               
2318 kumpf    1.58     PEG_METHOD_EXIT();
2319 mike     1.48     return qualifierDecl;
2320               }
2321               
2322               void CIMRepository::setQualifier(
2323 kumpf    1.85     const CIMNamespaceName& nameSpace,
2324 mike     1.48     const CIMQualifierDecl& qualifierDecl)
2325               {
2326 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::setQualifier");
2327               
2328 mike     1.48     // -- Get path of qualifier file:
2329               
2330                   String qualifierFilePath = _nameSpaceManager.getQualifierFilePath(
2331 mike     1.51         nameSpace, qualifierDecl.getName());
2332 mike     1.48 
2333 kumpf    1.75     // -- If qualifier already exists, throw exception:
2334 mike     1.48 
2335                   if (FileSystem::existsNoCase(qualifierFilePath))
2336 mike     1.53     {
2337 kumpf    1.58         PEG_METHOD_EXIT();
2338 mike     1.53         throw PEGASUS_CIM_EXCEPTION(
2339 kumpf    1.85 	    CIM_ERR_ALREADY_EXISTS, qualifierDecl.getName().getString());
2340 mike     1.53     }
2341 mike     1.48 
2342                   // -- Save qualifier:
2343               
2344 kumpf    1.66     Array<Sint8> qualifierDeclXml;
2345 kumpf    1.67     XmlWriter::appendQualifierDeclElement(qualifierDeclXml, qualifierDecl);
2346 kumpf    1.66     _SaveObject(qualifierFilePath, qualifierDeclXml);
2347 kumpf    1.58 
2348                   PEG_METHOD_EXIT();
2349 mike     1.48 }
2350               
2351               void CIMRepository::deleteQualifier(
2352 kumpf    1.85     const CIMNamespaceName& nameSpace,
2353                   const CIMName& qualifierName)
2354 mike     1.48 {
2355 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::deleteQualifier");
2356               
2357 mike     1.48     // -- Get path of qualifier file:
2358               
2359                   String qualifierFilePath = _nameSpaceManager.getQualifierFilePath(
2360 mike     1.51         nameSpace, qualifierName);
2361 mike     1.48 
2362                   // -- Delete qualifier:
2363               
2364                   if (!FileSystem::removeFileNoCase(qualifierFilePath))
2365 kumpf    1.58     {
2366                       PEG_METHOD_EXIT();
2367 kumpf    1.85         throw PEGASUS_CIM_EXCEPTION
2368                           (CIM_ERR_NOT_FOUND, qualifierName.getString());
2369 kumpf    1.58     }
2370               
2371                   PEG_METHOD_EXIT();
2372 mike     1.48 }
2373               
2374               Array<CIMQualifierDecl> CIMRepository::enumerateQualifiers(
2375 kumpf    1.85     const CIMNamespaceName& nameSpace)
2376 mike     1.48 {
2377 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::enumerateQualifiers");
2378               
2379 mike     1.48     String qualifiersRoot = _nameSpaceManager.getQualifiersRoot(nameSpace);
2380               
2381                   Array<String> qualifierNames;
2382               
2383                   if (!FileSystem::getDirectoryContents(qualifiersRoot, qualifierNames))
2384                   {
2385 kumpf    1.58         PEG_METHOD_EXIT();
2386 humberto 1.88         //l10n
2387                       String str ="enumerateQualifiers()";
2388                       //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
2389                           //"enumerateQualifiers(): internal error");
2390                       throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms("Repository.CIMRepository.INTERNAL_ERROR",
2391                       														  "$0: internal error",
2392                       														  str));
2393                       //l10n end
2394 mike     1.48     }
2395               
2396                   Array<CIMQualifierDecl> qualifiers;
2397               
2398                   for (Uint32 i = 0; i < qualifierNames.size(); i++)
2399                   {
2400 mike     1.51         CIMQualifierDecl qualifier = getQualifier(nameSpace, qualifierNames[i]);
2401                       qualifiers.append(qualifier);
2402 mike     1.48     }
2403               
2404 kumpf    1.58     PEG_METHOD_EXIT();
2405 mike     1.48     return qualifiers;
2406               }
2407               
2408 kumpf    1.85 void CIMRepository::createNameSpace(const CIMNamespaceName& nameSpace)
2409 mike     1.48 {
2410 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::createNameSpace");
2411               
2412 mike     1.48     _nameSpaceManager.createNameSpace(nameSpace);
2413 kumpf    1.58 
2414                   PEG_METHOD_EXIT();
2415 mike     1.48 }
2416               
2417 kumpf    1.85 Array<CIMNamespaceName> CIMRepository::enumerateNameSpaces() const
2418 mike     1.48 {
2419 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::enumerateNameSpaces");
2420               
2421 kumpf    1.85     Array<CIMNamespaceName> nameSpaceNames;
2422 mike     1.48     _nameSpaceManager.getNameSpaceNames(nameSpaceNames);
2423 kumpf    1.58 
2424                   PEG_METHOD_EXIT();
2425 mike     1.48     return nameSpaceNames;
2426               }
2427               
2428 kumpf    1.85 void CIMRepository::deleteNameSpace(const CIMNamespaceName& nameSpace)
2429 mike     1.48 {
2430 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::deleteNameSpace");
2431               
2432 mike     1.48     _nameSpaceManager.deleteNameSpace(nameSpace);
2433 kumpf    1.58 
2434                   PEG_METHOD_EXIT();
2435 mike     1.48 }
2436               
2437 mike     1.51 //----------------------------------------------------------------------
2438               //
2439 mike     1.53 // _getInstanceIndexFilePath()
2440 mike     1.51 //
2441               //      returns the file path of the instance index file. 
2442               //
2443               //----------------------------------------------------------------------
2444               
2445 mike     1.53 String CIMRepository::_getInstanceIndexFilePath(
2446 kumpf    1.85     const CIMNamespaceName& nameSpace,
2447                   const CIMName& className) const
2448 mike     1.48 {
2449 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_getInstanceIndexFilePath");
2450               
2451 mike     1.53     String tmp = _nameSpaceManager.getInstanceDataFileBase(
2452               	nameSpace, className);
2453               
2454 mike     1.48     tmp.append(".idx");
2455 kumpf    1.58 
2456                   PEG_METHOD_EXIT();
2457 mike     1.48     return tmp;
2458               }
2459               
2460 mike     1.51 //----------------------------------------------------------------------
2461               //
2462 mike     1.53 // _getInstanceDataFilePath()
2463 mike     1.51 //
2464               //      returns the file path of the instance file. 
2465               //
2466               //----------------------------------------------------------------------
2467               
2468 mike     1.53 String CIMRepository::_getInstanceDataFilePath(
2469 kumpf    1.85     const CIMNamespaceName& nameSpace,
2470                   const CIMName& className) const
2471 mike     1.48 {
2472 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_getInstanceDataFilePath");
2473               
2474 mike     1.53     String tmp = _nameSpaceManager.getInstanceDataFileBase(
2475               	nameSpace, className);
2476 mike     1.51     tmp.append(".instances");
2477 kumpf    1.61   
2478 kumpf    1.58     PEG_METHOD_EXIT();
2479 mike     1.48     return tmp;
2480 mike     1.51 }
2481               
2482               Boolean CIMRepository::_loadInstance(
2483                   const String& path,
2484                   CIMInstance& object,
2485                   Uint32 index,
2486                   Uint32 size)
2487               {
2488 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_loadInstance");
2489               
2490 mike     1.51     //
2491 mike     1.53     // Load instance (in XML) from instance file into memory:
2492 mike     1.51     //
2493               
2494 mike     1.53     Array<Sint8> data;
2495 mike     1.51 
2496 mike     1.53     if (!InstanceDataFile::loadInstance(path, index, size, data))
2497 kumpf    1.58     {
2498                       PEG_METHOD_EXIT();
2499 mike     1.51         return false;
2500 kumpf    1.58     }
2501 mike     1.51 
2502                   //
2503 mike     1.53     // Convert XML into an actual object:
2504 mike     1.51     //
2505               
2506 mike     1.53     XmlParser parser((char*)data.getData());
2507                   XmlReader::getObject(parser, object);
2508 mike     1.51 
2509 kumpf    1.58     PEG_METHOD_EXIT();
2510 mike     1.51     return true;
2511 mike     1.48 }
2512               
2513 bob      1.49 void CIMRepository::setDeclContext(RepositoryDeclContext *context)
2514               {
2515 kumpf    1.58     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::setDeclContext");
2516               
2517                   _context = context;
2518               
2519                   PEG_METHOD_EXIT();
2520 kumpf    1.73 }
2521               
2522 kumpf    1.85 String namespaceNameToDirName(const CIMNamespaceName& namespaceName)
2523 kumpf    1.73 {
2524 kumpf    1.85     String dirName = namespaceName.getString();
2525 kumpf    1.73 
2526                   for (int i=0; i<dirName.size(); i++)
2527                   {
2528                       if (dirName[i] == '/')
2529                       {
2530                           dirName[i] = '#';
2531                       }
2532                   }
2533               
2534                   return dirName;
2535               }
2536               
2537               String dirNameToNamespaceName(const String& dirName)
2538               {
2539                   String namespaceName = dirName;
2540               
2541                   for (int i=0; i<namespaceName.size(); i++)
2542                   {
2543                       if (namespaceName[i] == '#')
2544                       {
2545                           namespaceName[i] = '/';
2546 kumpf    1.73         }
2547                   }
2548               
2549                   return namespaceName;
2550 bob      1.49 }
2551               
2552 mike     1.48 PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2