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

   1 karl  1.157 //%2006////////////////////////////////////////////////////////////////////////
   2 mike  1.48  //
   3 karl  1.129 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
   4             // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
   5             // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
   6 karl  1.100 // IBM Corp.; EMC Corporation, The Open Group.
   7 karl  1.129 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
   8             // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
   9 karl  1.132 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
  10             // EMC Corporation; VERITAS Software Corporation; The Open Group.
  11 karl  1.157 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
  12             // EMC Corporation; Symantec Corporation; The Open Group.
  13 mike  1.48  //
  14             // Permission is hereby granted, free of charge, to any person obtaining a copy
  15             // of this software and associated documentation files (the "Software"), to
  16             // deal in the Software without restriction, including without limitation the
  17             // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  18             // sell copies of the Software, and to permit persons to whom the Software is
  19             // furnished to do so, subject to the following conditions:
  20 karl  1.177 //
  21 mike  1.48  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
  22             // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
  23             // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
  24             // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  25             // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  26             // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  27             // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28             // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29             //
  30             //==============================================================================
  31             //
  32             //%/////////////////////////////////////////////////////////////////////////////
  33             
  34 mike  1.51  #include <Pegasus/Common/Config.h>
  35 mike  1.48  #include <cctype>
  36             #include <cstdio>
  37             #include <fstream>
  38             #include <Pegasus/Common/Pair.h>
  39             #include <Pegasus/Common/FileSystem.h>
  40 kumpf 1.82  #include <Pegasus/Common/InternalException.h>
  41 schuur 1.114 
  42 mike   1.48  #include <Pegasus/Common/DeclContext.h>
  43 kumpf  1.76  #include <Pegasus/Common/Resolver.h>
  44 mike   1.48  #include <Pegasus/Common/System.h>
  45 kumpf  1.52  #include <Pegasus/Common/Tracer.h>
  46 kumpf  1.63  #include <Pegasus/Common/PegasusVersion.h>
  47 kumpf  1.169 #include <Pegasus/Common/MessageLoader.h>
  48 chuck  1.109 #include <Pegasus/Common/CommonUTF.h>
  49 mike   1.159 #include <Pegasus/Common/ReadWriteSem.h>
  50 mike   1.182 #include <Pegasus/Common/Dir.h>
  51 kumpf  1.63  
  52 schuur 1.114 #include <Pegasus/Common/XmlStreamer.h>
  53              #include <Pegasus/Common/BinaryStreamer.h>
  54              #include <Pegasus/Common/AutoStreamer.h>
  55              
  56 mike   1.48  #include "CIMRepository.h"
  57              #include "RepositoryDeclContext.h"
  58              #include "InstanceIndexFile.h"
  59 mike   1.53  #include "InstanceDataFile.h"
  60 mike   1.48  #include "AssocInstTable.h"
  61              #include "AssocClassTable.h"
  62 mike   1.151 #include "ObjectCache.h"
  63 mike   1.48  
  64 jim.wunderlich 1.137 #ifdef PEGASUS_ENABLE_COMPRESSED_REPOSITORY
  65 kumpf          1.142 // #define win32
  66 jim.wunderlich 1.136 # include <zlib.h>
  67                      # include <sstream>
  68                      #endif
  69                      
  70 schuur         1.112 #if 0
  71                      #undef PEG_METHOD_ENTER
  72                      #undef PEG_METHOD_EXIT
  73                      #define PEG_METHOD_ENTER(x,y)  cout<<"--- Enter: "<<y<<endl;
  74                      #define PEG_METHOD_EXIT()
  75                      #endif
  76                      
  77 jim.wunderlich 1.138 
  78 mike           1.48  PEGASUS_USING_STD;
  79                      
  80                      PEGASUS_NAMESPACE_BEGIN
  81                      
  82 mike           1.184 class CIMRepositoryRep
  83                      {
  84                      public:
  85                      
  86                          CIMRepositoryRep(const String& repositoryRoot) : 
  87                              _repositoryRoot(repositoryRoot),
  88                              _nameSpaceManager(repositoryRoot),
  89                              _resolveInstance(true)
  90                          {
  91                          }
  92                      
  93                          /**
  94                              Searches for incomplete instance transactions for all classes in all
  95                              namespaces.  Restores instance index and data files to void an
  96                              incomplete operation.  If no incomplete instance transactions are
  97                              outstanding, this method has no effect.
  98                           */
  99                          void _rollbackIncompleteTransactions();
 100                      
 101                          void _createAssocInstEntries(
 102                              const CIMNamespaceName& nameSpace,
 103 mike           1.184         const CIMConstClass& cimClass,
 104                              const CIMInstance& cimInstance,
 105                              const CIMObjectPath& instanceName);
 106                      
 107                          void _createAssocClassEntries(
 108                              const CIMNamespaceName& nameSpace,
 109                              const CIMConstClass& assocClass);
 110                      
 111                          /**
 112                              Checks whether an instance with the specified key values exists in the
 113                              class hierarchy of the specified class.
 114                      
 115                              @param   nameSpace      the namespace of the instance
 116                              @param   instanceName   the name of the instance
 117                      
 118                              @return  true           if the instance is found
 119                                       false          if the instance cannot be found
 120                           */
 121                          Boolean _checkInstanceAlreadyExists(
 122                              const CIMNamespaceName& nameSpace,
 123                              const CIMObjectPath& instanceName) const;
 124 mike           1.184 
 125                          /** Returns the file path of the instance index file.
 126                      
 127                              @param   nameSpace      the namespace of the instance
 128                              @param   className      the name of the class
 129                      
 130                              @return  a string containing the index file path
 131                           */
 132                          String _getInstanceIndexFilePath(
 133                              const CIMNamespaceName& nameSpace,
 134                              const CIMName& className) const;
 135                      
 136                          /** Returns the file path of the instance file.
 137                      
 138                              @param   nameSpace      the namespace of the instance
 139                              @param   className      the name of the class
 140                      
 141                              @return  a string containing the instance file path
 142                           */
 143                          String _getInstanceDataFilePath(
 144                              const CIMNamespaceName& nameSpace,
 145 mike           1.184         const CIMName& className) const;
 146                      
 147                          /** Saves an instance object from memory to disk file.  The byte
 148                              position and the size of the newly inserted instance record are
 149                              returned.  Returns true on success.
 150                      
 151                              @param   path      the file path of the instance file
 152                              @param   object    the CIMInstance object to be saved
 153                              @param   index     the byte positon of the saved instance record
 154                              @param   size      the size of the saved instance record
 155                      
 156                              @return  true      if successful
 157                                       false     if an error occurs in saving the instance to file
 158                           */
 159                          Boolean _saveInstance(
 160                              const String& path,
 161                              const CIMInstance& object,
 162                              Uint32& index,
 163                              Uint32& size);
 164                      
 165                          /** loads an instance object from disk to memory.  The caller passes
 166 mike           1.184         the byte position and the size of the instance record to be loaded.
 167                              Returns true on success.
 168                      
 169                              @param   path      the file path of the instance file
 170                              @param   object    the CIMInstance object to be returned
 171                              @param   index     the byte positon of the instance record
 172                              @param   size      the size of the instance record
 173                              @param   data      the buffer to hold the instance data
 174                      
 175                              @return  true      if successful
 176                                       false     if an error occurs in loading the instance from file
 177                           */
 178                          Boolean _loadInstance(
 179                              const String& path,
 180                              CIMInstance& object,
 181                              Uint32 index,
 182                              Uint32 size);
 183                      
 184                          /** loads all the instance objects from disk to memeory.  Returns true
 185                              on success.
 186                      
 187 mike           1.184         @param   nameSpace      the namespace of the instances to be loaded
 188                              @param   className      the class of the instances to be loaded
 189                              @param   namedInstances an array of CIMInstance objects to which
 190                                                      the loaded instances are appended
 191                      
 192                              @return  true      if successful
 193                                       false     if an error occurs in loading the instances
 194                           */
 195                          Boolean _loadAllInstances(
 196                              const CIMNamespaceName& nameSpace,
 197                              const CIMName& className,
 198                              Array<CIMInstance>& namedInstances);
 199                      
 200                          /** Modifies an instance object saved in the disk file.  The byte position
 201                              and the size of the newly added instance record are returned.  Returns
 202                              true on success.
 203                      
 204                              @param   path      the file path of the instance file
 205                              @param   object    the modified CIMInstance object
 206                              @param   oldIndex  the byte positon of the old instance record
 207                              @param   oldSize   the size of the old instance record
 208 mike           1.184         @param   newIndex  the byte positon of the new instance record
 209                              @param   newSize   the size of the new instance record
 210                      
 211                              @return  true      if successful
 212                                       false     if an error occurs in modifying the instance
 213                           */
 214                          Boolean _modifyInstance(
 215                              const String& path,
 216                              const CIMInstance& object,
 217                              Uint32 oldIndex,
 218                              Uint32 oldSize,
 219                              Uint32& newIndex,
 220                              Uint32& newSize);
 221                      
 222                          String _repositoryRoot;
 223                      
 224                          NameSpaceManager _nameSpaceManager;
 225                      
 226                          /** Used by getInstance(); indicates whether instance should be resolved
 227                              after it is retrieved from the file.
 228                          */
 229 mike           1.184     Boolean _resolveInstance;
 230                      
 231                          // This must be initialized in the constructor using values from the
 232                          // ConfigManager.
 233                          Boolean _isDefaultInstanceProvider;
 234                      
 235                          ObjectStreamer* _streamer;
 236                      
 237                          ReadWriteSem _lock;
 238                      
 239                          RepositoryDeclContext* _context;
 240                      
 241                          CString _lockFile;
 242                      };
 243                      
 244 mike           1.53  static const Uint32 _MAX_FREE_COUNT = 16;
 245                      
 246 kumpf          1.142 #ifdef PEGASUS_ENABLE_COMPRESSED_REPOSITORY
 247 jim.wunderlich 1.136 static int compressMode = 0; // PEP214
 248                      #endif
 249                      
 250 kumpf          1.142 // #define TEST_OUTPUT
 251 jim.wunderlich 1.134 
 252 mike           1.151 //==============================================================================
 253                      //
 254                      // This is the class cache, which caches up PEGASUS_CLASS_CACHE_SIZE classes
 255                      // into memory. To override the default, define PEGASUS_CLASS_CACHE_SIZE in
 256                      // your environment. To supress the cache (and not compile it in at all)
 257                      // define PEGASUS_CLASS_CACHE_SIZE to 0.
 258                      //
 259                      //==============================================================================
 260                      
 261 mike           1.153 #define PEGASUS_QUALIFIER_CACHE_SIZE 80
 262                      
 263 mike           1.151 #if !defined(PEGASUS_CLASS_CACHE_SIZE)
 264                      # define PEGASUS_CLASS_CACHE_SIZE 8
 265                      #endif
 266                      
 267                      #if (PEGASUS_CLASS_CACHE_SIZE != 0)
 268                      # define PEGASUS_USE_CLASS_CACHE
 269                      #endif
 270                      
 271                      #ifdef PEGASUS_USE_CLASS_CACHE
 272                      static ObjectCache<CIMClass> _classCache(PEGASUS_CLASS_CACHE_SIZE);
 273                      #endif /* PEGASUS_USE_CLASS_CACHE */
 274                      
 275 kumpf          1.169 static ObjectCache<CIMQualifierDecl>
 276 mike           1.153     _qualifierCache(PEGASUS_QUALIFIER_CACHE_SIZE);
 277                      
 278 jim.wunderlich 1.136 ////////////////////////////////////////////////////////////////////////////////
 279                      //
 280                      // _LoadFileToMemory()  PEP214
 281                      //
 282 kumpf          1.142 // The gzxxxx functions read both compresed and non-compresed files.
 283                      //
 284 jim.wunderlich 1.136 // There is no conditional flag on reading of files since gzread()
 285                      // (from zlib) is capable of reading compressed and non-compressed
 286                      // files (so it contains the logic that examines the header
 287                      // and magic number). Everything will work properly if the repository
 288 kumpf          1.142 // has some compressed and some non-compressed files.
 289 jim.wunderlich 1.136 //
 290                      //
 291                      ////////////////////////////////////////////////////////////////////////////////
 292                      
 293 mike           1.150 void _LoadFileToMemory(Buffer& data, const String& path)
 294 jim.wunderlich 1.136 {
 295                      
 296 kumpf          1.142 #ifdef PEGASUS_ENABLE_COMPRESSED_REPOSITORY
 297 jim.wunderlich 1.136 
 298                          Uint32 fileSize;
 299                      
 300                          if (!FileSystem::getFileSize(path, fileSize))
 301 kumpf          1.142         throw CannotOpenFile(path);
 302 jim.wunderlich 1.136 
 303                          gzFile fp = gzopen(path.getCString(), "rb");
 304                      
 305                          if (fp == NULL)
 306 kumpf          1.142         throw CannotOpenFile(path);
 307 jim.wunderlich 1.136 
 308                          data.reserveCapacity(fileSize);
 309                          char buffer[4096];
 310                          int n;
 311                      
 312                          while ((n = gzread(fp, buffer, sizeof(buffer))) > 0)
 313                              data.append(buffer, n);
 314                      
 315                          gzclose(fp);
 316                      
 317 kumpf          1.142 #else
 318 jim.wunderlich 1.136 
 319                          FileSystem::loadFileToMemory(data, path);
 320                      
 321 jim.wunderlich 1.137 #endif /* PEGASUS_ENABLE_COMPRESSED_REPOSITORY */
 322 jim.wunderlich 1.136 }
 323                      
 324                      
 325 karl           1.101 //
 326                      //  The following _xx functions are local to the repository implementation
 327                      //
 328 mike           1.48  ////////////////////////////////////////////////////////////////////////////////
 329                      //
 330 kumpf          1.104 //   _containsProperty
 331 karl           1.97  //
 332                      ////////////////////////////////////////////////////////////////////////////////
 333 karl           1.101 
 334                      /** Check to see if the specified property is in the property list
 335 kumpf          1.104     @param property the specified property
 336 karl           1.101     @param propertyList the property list
 337 kumpf          1.104     @return true if the property is in the list otherwise false.
 338 karl           1.101 */
 339 kumpf          1.169 Boolean _containsProperty(
 340                          CIMProperty& property,
 341                          const CIMPropertyList& propertyList)
 342 karl           1.97  {
 343 kumpf          1.104     //  For each property in the propertly list
 344                          for (Uint32 p=0; p<propertyList.size(); p++)
 345                          {
 346                              if (propertyList[p].equal(property.getName()))
 347                                  return true;
 348                          }
 349                          return false;
 350 karl           1.97  }
 351                      
 352 karl           1.98  ////////////////////////////////////////////////////////////////////////////////
 353                      //
 354                      // removeAllQualifiers - Remove all of the qualifiers from a class
 355                      //
 356                      ////////////////////////////////////////////////////////////////////////////////
 357 karl           1.101 
 358                      /* removes all Qualifiers from a CIMClass.  This function removes all
 359                         of the qualifiers from the class, from all of the properties,
 360                         from the methods, and from the parameters attached to the methods.
 361                         @param cimClass reference to the class from which qualifiers are to
 362                         be removed.
 363 kumpf          1.169    NOTE: This would be logical to be moved to CIMClass since it may be
 364                         more general than this usage.
 365 karl           1.101 */
 366 kumpf          1.169 void _removeAllQualifiers(CIMClass& cimClass)
 367 karl           1.98  {
 368 kumpf          1.104     // remove qualifiers of the class
 369                          Uint32 count = 0;
 370 kumpf          1.169     while ((count = cimClass.getQualifierCount()) > 0)
 371 kumpf          1.104         cimClass.removeQualifier(count - 1);
 372                      
 373                          // remove qualifiers from the properties
 374                          for (Uint32 i = 0; i < cimClass.getPropertyCount(); i++)
 375                          {
 376                              CIMProperty p = cimClass.getProperty(i);
 377 kumpf          1.169         count = 0;
 378                              while ((count = p.getQualifierCount()) > 0)
 379 kumpf          1.104             p.removeQualifier(count - 1);
 380                          }
 381 kumpf          1.169 
 382 kumpf          1.104     // remove qualifiers from the methods
 383                          for (Uint32 i = 0; i < cimClass.getMethodCount(); i++)
 384                          {
 385                              CIMMethod m = cimClass.getMethod(i);
 386                              for (Uint32 j = 0 ; j < m.getParameterCount(); j++)
 387                              {
 388                                  CIMParameter p = m.getParameter(j);
 389                                  count = 0;
 390                                  while ((count = p.getQualifierCount()) > 0)
 391                                      p.removeQualifier(count - 1);
 392                              }
 393 kumpf          1.169         count = 0;
 394                              while ((count = m.getQualifierCount()) > 0)
 395 kumpf          1.104             m.removeQualifier(count - 1);
 396                          }
 397 karl           1.98  }
 398                      
 399                      /////////////////////////////////////////////////////////////////////////
 400                      //
 401 karl           1.101 // _removePropagatedQualifiers - Removes all qualifiers from the class
 402 kumpf          1.104 // that are marked propagated
 403 karl           1.98  //
 404                      /////////////////////////////////////////////////////////////////////////
 405 karl           1.101 
 406 kumpf          1.104 /* removes propagatedQualifiers from the defined CIMClass.
 407 karl           1.101    This function removes the qualifiers from the class,
 408                         from each of the properties, from the methods and
 409                         the parameters if the qualifiers are marked propagated.
 410 kumpf          1.169    NOTE: This could be logical to be moved to CIMClass since it may be
 411                         more general than the usage here.
 412 karl           1.101 */
 413 kumpf          1.169 void _removePropagatedQualifiers(CIMClass& cimClass)
 414 karl           1.98  {
 415 kumpf          1.104     Uint32 count = cimClass.getQualifierCount();
 416                          // Remove nonlocal qualifiers from Class
 417                          for (Sint32 i = (count - 1); i >= 0; i--)
 418                          {
 419                              CIMQualifier q = cimClass.getQualifier(i);
 420                              if (q.getPropagated())
 421                              {
 422                                  cimClass.removeQualifier(i);
 423                              }
 424                          }
 425                      
 426                          // remove  non localOnly qualifiers from the properties
 427                          for (Uint32 i = 0; i < cimClass.getPropertyCount(); i++)
 428                          {
 429                              CIMProperty p = cimClass.getProperty(i);
 430                              // loop to search qualifiers for nonlocal parameters
 431                              count = p.getQualifierCount();
 432 a.dunfey       1.156         for (Sint32 j = (count - 1); j >= 0; j--)
 433 kumpf          1.104         {
 434                                  CIMQualifier q = p.getQualifier(j);
 435                                  if (q.getPropagated())
 436                                  {
 437                                      p.removeQualifier(j);
 438                                  }
 439                              }
 440                          }
 441 kumpf          1.169 
 442 kumpf          1.104     // remove non LocalOnly qualifiers from the methods and parameters
 443                          for (Uint32 i = 0; i < cimClass.getMethodCount(); i++)
 444                          {
 445                              CIMMethod m = cimClass.getMethod(i);
 446                              // Remove  nonlocal qualifiers from all parameters
 447                              for (Uint32 j = 0 ; j < m.getParameterCount(); j++)
 448                              {
 449                                  CIMParameter p = m.getParameter(j);
 450                                  count = p.getQualifierCount();
 451 a.dunfey       1.156             for (Sint32 k = (count - 1); k >= 0; k--)
 452 kumpf          1.104             {
 453                                      CIMQualifier q = p.getQualifier(k);
 454                                      if (q.getPropagated())
 455                                      {
 456                                          p.removeQualifier(k);
 457                                      }
 458                                  }
 459                              }
 460                      
 461                              // remove nonlocal qualifiers from the method
 462                              count = m.getQualifierCount();
 463 a.dunfey       1.156         for (Sint32 j = (count - 1); j >= 0; j--)
 464 kumpf          1.104         {
 465                                  CIMQualifier q = m.getQualifier(j);
 466                                  if (q.getPropagated())
 467                                  {
 468                                      m.removeQualifier(j);
 469                                  }
 470                              }
 471                          }
 472 karl           1.98  }
 473 karl           1.97  
 474 karl           1.103 /* remove the properties from an instance based on attributes.
 475 karl           1.101     @param Instance from which properties will be removed.
 476                          @param propertyList PropertyList is used in the removal algorithm
 477                          @param localOnly - Boolean used in the removal.
 478                          NOTE: This could be logical to move to CIMInstance since the
 479                          usage is more general than just in the repository
 480                      */
 481 kumpf          1.169 void _removeProperties(
 482                          CIMInstance& cimInstance,
 483                          const CIMPropertyList& propertyList,
 484                          Boolean localOnly)
 485 karl           1.101 {
 486                          Boolean propertyListNull = propertyList.isNull();
 487                          if ((!propertyListNull) || localOnly)
 488                          {
 489                              // Loop through properties to remove those that do not filter through
 490                              // local only attribute and are not in the property list.
 491                              Uint32 count = cimInstance.getPropertyCount();
 492                              // Work backwards because removal may be cheaper. Sint32 covers count=0
 493                              for (Sint32 i = (count - 1); i >= 0; i--)
 494                              {
 495                                  CIMProperty p = cimInstance.getProperty(i);
 496                      
 497 kumpf          1.169             // if localOnly == true, ignore properties defined in super class
 498 karl           1.101             if (localOnly && (p.getPropagated()))
 499                                  {
 500                                      cimInstance.removeProperty(i);
 501                                      continue;
 502                                  }
 503                      
 504 kumpf          1.169             // propertyList NULL means deliver properties.  PropertyList
 505                                  // empty, none.
 506 karl           1.101             // Test for removal if propertyList not NULL. The empty list option
 507                                  // is covered by fact that property is not in the list.
 508                                  if (!propertyListNull)
 509 kumpf          1.169                 if (!_containsProperty(p, propertyList))
 510 karl           1.101                     cimInstance.removeProperty(i);
 511                              }
 512                          }
 513                      }
 514                      
 515                      /* remove all Qualifiers from a single CIMInstance. Removes
 516                          all of the qualifiers from the instance and from properties
 517                          within the instance.
 518                          @param instance from which parameters are removed.
 519                          NOTE: This could be logical to be moved to CIMInstance since
 520                          the usage may be more general than just in the repository.
 521                      */
 522                      void _removeAllQualifiers(CIMInstance& cimInstance)
 523                      {
 524 kumpf          1.169     // remove qualifiers from the instance
 525                          Uint32 count = 0;
 526                          while ((count = cimInstance.getQualifierCount()) > 0)
 527                              cimInstance.removeQualifier(count - 1);
 528 karl           1.101 
 529 kumpf          1.169     // remove qualifiers from the properties
 530                          for (Uint32 i = 0; i < cimInstance.getPropertyCount(); i++)
 531                          {
 532                              CIMProperty p = cimInstance.getProperty(i);
 533                              count = 0;
 534                              while ((count = p.getQualifierCount()) > 0)
 535                                  p.removeQualifier(count - 1);
 536                          }
 537 karl           1.101 }
 538 kumpf          1.169 
 539 karl           1.101 /* removes all ClassOrigin attributes from a single CIMInstance. Removes
 540                          the classOrigin attribute from each property in the Instance.
 541                         @param Instance from which the ClassOrigin Properties will be removed.
 542                         NOTE: Logical to be moved to CIMInstance since it may be more general
 543                         than just the repositoryl
 544                      */
 545                      void _removeClassOrigins(CIMInstance& cimInstance)
 546                      {
 547 marek          1.174     PEG_TRACE_CSTRING(TRC_REPOSITORY, Tracer::LEVEL4, "Remove Class Origins");
 548 kumpf          1.104 
 549 kumpf          1.169     Uint32 propertyCount = cimInstance.getPropertyCount();
 550                          for (Uint32 i = 0; i < propertyCount ; i++)
 551                              cimInstance.getProperty(i).setClassOrigin(CIMName());
 552 karl           1.101 }
 553                      
 554 karl           1.103 /* Filters the properties, qualifiers, and classorigin out of a single instance.
 555 karl           1.101     Based on the parameters provided for localOnly, includeQualifiers,
 556                          and includeClassOrigin, this function simply filters the properties
 557                          qualifiers, and classOrigins out of a single instance.  This function
 558                          was created to have a single piece of code that processes getinstance
 559                          and enumerateInstances returns.
 560                          @param cimInstance reference to instance to be processed.
 561                          @param localOnly defines if request is for localOnly parameters.
 562                          @param includeQualifiers Boolean defining if qualifiers to be returned.
 563                          @param includeClassOrigin Boolean defining if ClassOrigin attribute to
 564                          be removed from properties.
 565                      */
 566 kumpf          1.169 void _filterInstance(
 567                          CIMInstance& cimInstance,
 568                          const CIMPropertyList& propertyList,
 569                          Boolean localOnly,
 570                          Boolean includeQualifiers,
 571                          Boolean includeClassOrigin)
 572 karl           1.101 {
 573 kumpf          1.164     // Remove properties based on propertyList and localOnly flag
 574 karl           1.101     _removeProperties(cimInstance, propertyList, localOnly);
 575 kumpf          1.164 
 576 karl           1.101     // If includequalifiers false, remove all qualifiers from
 577                          // properties.
 578                      
 579 kumpf          1.169     if (!includeQualifiers)
 580 karl           1.101     {
 581                              _removeAllQualifiers(cimInstance);
 582                          }
 583 kumpf          1.164 
 584 karl           1.103     // if ClassOrigin Flag false, remove classOrigin info from Instance object
 585                          // by setting the classOrigin to Null.
 586 kumpf          1.164 
 587 karl           1.101     if (!includeClassOrigin)
 588                          {
 589                              _removeClassOrigins(cimInstance);
 590                          }
 591                      }
 592 kumpf          1.164 
 593 karl           1.97  ////////////////////////////////////////////////////////////////////////////////
 594                      //
 595 mike           1.48  // _LoadObject()
 596                      //
 597 mike           1.51  //      Loads objects (classes and qualifiers) from disk to
 598                      //      memory objects.
 599 mike           1.48  //
 600                      ////////////////////////////////////////////////////////////////////////////////
 601                      
 602                      template<class Object>
 603                      void _LoadObject(
 604                          const String& path,
 605 schuur         1.114     Object& object,
 606 kumpf          1.169     ObjectStreamer* streamer)
 607 mike           1.48  {
 608 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_LoadObject");
 609                      
 610 mike           1.48      // Get the real path of the file:
 611                      
 612                          String realPath;
 613                      
 614                          if (!FileSystem::existsNoCase(path, realPath))
 615 kumpf          1.104     {
 616 marek          1.187         PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL1,
 617 kumpf          1.175             path + " does not exist.");
 618 kumpf          1.58          PEG_METHOD_EXIT();
 619 mike           1.51          throw CannotOpenFile(path);
 620 kumpf          1.58      }
 621 mike           1.48  
 622 kumpf          1.61      PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4, "realpath = " + realPath);
 623                      
 624 mike           1.48      // Load file into memory:
 625                      
 626 mike           1.150     Buffer data;
 627 jim.wunderlich 1.136 
 628 kumpf          1.175     _LoadFileToMemory(data, realPath);
 629 mike           1.48  
 630 schuur         1.114     streamer->decode(data, 0, object);
 631                      
 632 kumpf          1.58      PEG_METHOD_EXIT();
 633 mike           1.48  }
 634                      
 635                      ////////////////////////////////////////////////////////////////////////////////
 636                      //
 637                      // _SaveObject()
 638                      //
 639 mike           1.51  //      Saves objects (classes and qualifiers) from memory to
 640                      //      disk files.
 641 mike           1.48  //
 642                      ////////////////////////////////////////////////////////////////////////////////
 643                      
 644 kumpf          1.169 void _SaveObject(
 645                          const String& path,
 646                          Buffer& objectXml,
 647                          ObjectStreamer* streamer)
 648 mike           1.48  {
 649 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_SaveObject");
 650 david          1.96  
 651 jim.wunderlich 1.137 #ifdef PEGASUS_ENABLE_COMPRESSED_REPOSITORY
 652 jim.wunderlich 1.136     if (compressMode)            // PEP214
 653 kumpf          1.142     {
 654                              PEGASUS_STD(ostringstream) os;
 655                              streamer->write(os, objectXml);
 656                              string str = os.str();
 657                      
 658                              gzFile fp = gzopen(path.getCString(), "wb");
 659                      
 660                              if (fp == NULL)
 661                                throw CannotOpenFile(path);
 662                      
 663                              const char* ptr = str.data();
 664                              size_t rem = str.size();
 665                              int n;
 666                      
 667                              while (rem > 0 && (n = gzwrite(fp, (char*)ptr, rem)) > 0)
 668                              {
 669                                  ptr += n;
 670                                  rem -= n;
 671                              }
 672 david          1.96  
 673 kumpf          1.142         gzclose(fp);
 674                          }
 675 jim.wunderlich 1.136     else
 676 jim.wunderlich 1.137 #endif /* PEGASUS_ENABLE_COMPRESSED_REPOSITORY */
 677 kumpf          1.142     {
 678                              PEGASUS_STD(ofstream) os(path.getCString() PEGASUS_IOS_BINARY);
 679 jim.wunderlich 1.136 
 680 kumpf          1.142         if (!os)
 681                              {
 682                                  PEG_METHOD_EXIT();
 683                                  throw CannotOpenFile(path);
 684                              }
 685 kumpf          1.58  
 686 kumpf          1.142         streamer->write(os, objectXml);
 687                          }
 688 kumpf          1.58      PEG_METHOD_EXIT();
 689 mike           1.48  }
 690                      
 691                      ////////////////////////////////////////////////////////////////////////////////
 692                      //
 693 kumpf          1.165 // _beginInstanceTransaction()
 694                      //
 695                      //      Creates rollback files to allow an incomplete transaction to be voided.
 696                      //
 697                      ////////////////////////////////////////////////////////////////////////////////
 698                      
 699                      void _beginInstanceTransaction(
 700                          const String& indexFilePath,
 701                          const String& dataFilePath)
 702                      {
 703                          PEG_METHOD_ENTER(TRC_REPOSITORY, "_beginInstanceTransaction");
 704                      
 705                          //
 706                          // Begin the transaction (an incomplete transaction will cause
 707                          // a rollback the next time an instance-oriented routine is invoked).
 708                          //
 709                      
 710                          if (!InstanceIndexFile::beginTransaction(indexFilePath))
 711                          {
 712                              PEG_METHOD_EXIT();
 713                              throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
 714 kumpf          1.165             MessageLoaderParms("Repository.CIMRepository.BEGIN_FAILED",
 715                                      "begin failed"));
 716                          }
 717                      
 718                          if (!InstanceDataFile::beginTransaction(dataFilePath))
 719                          {
 720                              PEG_METHOD_EXIT();
 721                              throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
 722                                  MessageLoaderParms("Repository.CIMRepository.BEGIN_FAILED",
 723                                      "begin failed"));
 724                          }
 725                      
 726                          PEG_METHOD_EXIT();
 727                      }
 728                      
 729                      ////////////////////////////////////////////////////////////////////////////////
 730                      //
 731                      // _commitInstanceTransaction()
 732                      //
 733                      //      Removes the rollback files to complete the transaction.
 734                      //
 735 kumpf          1.165 ////////////////////////////////////////////////////////////////////////////////
 736                      
 737                      void _commitInstanceTransaction(
 738                          const String& indexFilePath,
 739                          const String& dataFilePath)
 740                      {
 741                          PEG_METHOD_ENTER(TRC_REPOSITORY, "_commitInstanceTransaction");
 742                      
 743                          //
 744                          // Commit the transaction by removing the rollback files.
 745                          //
 746                      
 747                          if (!InstanceIndexFile::commitTransaction(indexFilePath))
 748                          {
 749                              PEG_METHOD_EXIT();
 750                              throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
 751                                  MessageLoaderParms("Repository.CIMRepository.COMMIT_FAILED",
 752                                      "commit failed"));
 753                          }
 754                      
 755                          if (!InstanceDataFile::commitTransaction(dataFilePath))
 756 kumpf          1.165     {
 757                              PEG_METHOD_EXIT();
 758                              throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
 759                                  MessageLoaderParms("Repository.CIMRepository.COMMIT_FAILED",
 760                                      "commit failed"));
 761                          }
 762                      
 763                          PEG_METHOD_EXIT();
 764                      }
 765                      
 766                      ////////////////////////////////////////////////////////////////////////////////
 767                      //
 768                      // _rollbackInstanceTransaction()
 769                      //
 770                      //      Restores instance index and data files to void an incomplete operation.
 771                      //      If there are no rollback files, this method has no effect.
 772                      //
 773                      ////////////////////////////////////////////////////////////////////////////////
 774                      
 775 mike           1.182 static String _dirName(const String& path)
 776                      {
 777                          Uint32 n = path.size();
 778                      
 779                          for (Uint32 i = n; i != 0; )
 780                          {
 781                              if (path[--i] == '/')
 782                                  return path.subString(0, i);
 783                          }
 784                      
 785                          return String(".");
 786                      }
 787                      
 788 kumpf          1.165 void _rollbackInstanceTransaction(
 789                          const String& indexFilePath,
 790                          const String& dataFilePath)
 791                      {
 792                          PEG_METHOD_ENTER(TRC_REPOSITORY, "_rollbackInstanceTransaction");
 793                      
 794 mike           1.182     // Avoid rollback logic if directory has no .rollback files.
 795                      
 796                          String path = _dirName(indexFilePath);
 797                          Array<String> rollbackFiles;
 798                      
 799                          if (FileSystem::glob(path, "*.rollback", rollbackFiles))
 800                          {
 801                              if (rollbackFiles.size() == 0)
 802                                  return;
 803                          }
 804                      
 805                          // Proceed to rollback logic.
 806                      
 807 kumpf          1.165     if (!InstanceIndexFile::rollbackTransaction(indexFilePath))
 808                          {
 809                              PEG_METHOD_EXIT();
 810                              throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
 811                                  MessageLoaderParms("Repository.CIMRepository.ROLLBACK_FAILED",
 812                                      "rollback failed"));
 813                          }
 814                      
 815                          if (!InstanceDataFile::rollbackTransaction(dataFilePath))
 816                          {
 817                              PEG_METHOD_EXIT();
 818                              throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
 819                                  MessageLoaderParms(
 820                                      "Repository.CIMRepository.ROLLBACK_FAILED",
 821                                      "rollback failed"));
 822                          }
 823                      
 824                          PEG_METHOD_EXIT();
 825                      }
 826                      
 827                      ////////////////////////////////////////////////////////////////////////////////
 828 kumpf          1.165 //
 829 kumpf          1.168 // InstanceTransactionHandler
 830                      //
 831                      //      This class is used to manage a repository instance transaction.  The
 832                      //      transaction is started when the class is instantiated, committed when
 833                      //      the complete() method is called, and rolled back if the destructor is
 834                      //      called without a prior call to complete().
 835                      //
 836                      //      The appropriate repository write locks must be owned while an
 837                      //      InstanceTransactionHandler instance exists.
 838                      //
 839                      ////////////////////////////////////////////////////////////////////////////////
 840                      
 841                      class InstanceTransactionHandler
 842                      {
 843                      public:
 844                          InstanceTransactionHandler(
 845                              const String& indexFilePath,
 846                              const String& dataFilePath)
 847                          : _indexFilePath(indexFilePath),
 848                            _dataFilePath(dataFilePath),
 849                            _isComplete(false)
 850 kumpf          1.168     {
 851                              _rollbackInstanceTransaction(_indexFilePath, _dataFilePath);
 852                              _beginInstanceTransaction(_indexFilePath, _dataFilePath);
 853                          }
 854                      
 855                          ~InstanceTransactionHandler()
 856                          {
 857                              if (!_isComplete)
 858                              {
 859                                  _rollbackInstanceTransaction(_indexFilePath, _dataFilePath);
 860                              }
 861                          }
 862                      
 863                          void complete()
 864                          {
 865                              _commitInstanceTransaction(_indexFilePath, _dataFilePath);
 866                              _isComplete = true;
 867                          }
 868                      
 869                      private:
 870                          String _indexFilePath;
 871 kumpf          1.168     String _dataFilePath;
 872                          Boolean _isComplete;
 873                      };
 874                      
 875                      ////////////////////////////////////////////////////////////////////////////////
 876                      //
 877                      // CIMRepository::_rollbackIncompleteTransactions()
 878                      //
 879                      //      Searches for incomplete instance transactions for all classes in all
 880                      //      namespaces.  Restores instance index and data files to void an
 881                      //      incomplete operation.  If no incomplete instance transactions are
 882                      //      outstanding, this method has no effect.
 883                      //
 884                      ////////////////////////////////////////////////////////////////////////////////
 885                      
 886 mike           1.182 static Boolean _containsNoCase(const Array<String>& array, const String& str)
 887                      {
 888                          for (Uint32 i = 0; i < array.size(); i++)
 889                          {
 890                              if (String::equalNoCase(array[i], str))
 891                                  return true;
 892                          }
 893                      
 894                          return false;
 895                      }
 896                      
 897 mike           1.184 void CIMRepositoryRep::_rollbackIncompleteTransactions()
 898 kumpf          1.168 {
 899                          PEG_METHOD_ENTER(TRC_REPOSITORY,
 900                              "CIMRepository::_rollbackIncompleteTransactions");
 901                      
 902                          WriteLock lock(_lock);
 903                          AutoFileLock fileLock(_lockFile);
 904                      
 905                          Array<CIMNamespaceName> namespaceNames;
 906                          _nameSpaceManager.getNameSpaceNames(namespaceNames);
 907                      
 908                          for (Uint32 i = 0; i < namespaceNames.size(); i++)
 909                          {
 910 mike           1.182         // Form a list of .rollback files.
 911                      
 912                              Array<String> rollbackFiles;
 913                              FileSystem::glob(
 914                                  _nameSpaceManager.getInstanceDirRoot(namespaceNames[i]),
 915                                  "*.rollback", rollbackFiles);
 916                      
 917                              // Don't bother doing rollback if there are no rollback files.
 918                              // The algorithm below is expensive.
 919                      
 920                              if (rollbackFiles.size() == 0)
 921                                  continue;
 922                      
 923 kumpf          1.168         Array<CIMName> classNames;
 924                              _nameSpaceManager.getSubClassNames(
 925                                  namespaceNames[i], CIMName(), true, classNames);
 926                      
 927                              for (Uint32 j = 0; j < classNames.size(); j++)
 928                              {
 929                                  //
 930                                  // Get paths of index and data files:
 931                                  //
 932                      
 933                                  String indexFilePath = _getInstanceIndexFilePath(
 934                                      namespaceNames[i], classNames[j]);
 935                      
 936                                  String dataFilePath = _getInstanceDataFilePath(
 937                                      namespaceNames[i], classNames[j]);
 938                      
 939 mike           1.182             // Only perform rollback processing if there is a rollback file
 940                                  // for either the data or index file.
 941                      
 942                                  if (_containsNoCase(rollbackFiles, dataFilePath + ".rollback") ||
 943                                      _containsNoCase(rollbackFiles, indexFilePath + ".rollback"))
 944                                  {
 945                                      //
 946                                      // Attempt rollback (if there are no rollback files, this will
 947                                      // have no effect). This code is here to rollback uncommitted
 948                                      // changes left over from last time an instance-oriented 
 949                                      // function
 950                                      // was called.
 951                                      //
 952 kumpf          1.168 
 953 mike           1.182                 _rollbackInstanceTransaction(indexFilePath, dataFilePath);
 954                                  }
 955 kumpf          1.168         }
 956                          }
 957                      
 958                          PEG_METHOD_EXIT();
 959                      }
 960                      
 961                      ////////////////////////////////////////////////////////////////////////////////
 962                      //
 963 mike           1.48  // CIMRepository
 964                      //
 965                      //     The following are not implemented:
 966                      //
 967                      //         CIMRepository::execQuery()
 968                      //         CIMRepository::invokeMethod()
 969                      //
 970                      //     Note that invokeMethod() will not never implemented since it is not
 971                      //     meaningful for a repository.
 972                      //
 973 dmitry.mikulin 1.181 //     Note that if declContext is passed to the CIMRepository constructor,
 974                      //     the repository object will own it and will delete it when appropriate.
 975                      //
 976 mike           1.48  ////////////////////////////////////////////////////////////////////////////////
 977                      
 978 kumpf          1.166 CIMRepository::CIMRepository(
 979                          const String& repositoryRoot,
 980 dmitry.mikulin 1.181     Uint32 mode,
 981                          RepositoryDeclContext* declContext)
 982 jim.wunderlich 1.134 {
 983 mike           1.184     _rep = new CIMRepositoryRep(repositoryRoot);
 984                      
 985 jim.wunderlich 1.134     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::CIMRepository");
 986                      
 987 kumpf          1.166     Boolean binaryMode = mode & CIMRepository::MODE_BIN;
 988 kumpf          1.142 
 989 kumpf          1.166     if (mode == CIMRepository::MODE_DEFAULT)
 990 kumpf          1.142     {
 991 kumpf          1.158         binaryMode = ConfigManager::parseBooleanValue(
 992                                  ConfigManager::getInstance()->getCurrentValue(
 993                                      "enableBinaryRepository"));
 994 schuur         1.114     }
 995                      
 996 jim.wunderlich 1.137 #ifdef PEGASUS_ENABLE_COMPRESSED_REPOSITORY    // PEP214
 997 kumpf          1.166     // FUTURE?? -  compressMode = mode & CIMRepository::MODE_COMPRESSED;
 998 jim.wunderlich 1.136     compressMode=1;
 999                      
1000 kumpf          1.169     char* s = getenv("PEGASUS_ENABLE_COMPRESSED_REPOSITORY");
1001 jim.wunderlich 1.136     if (s && (strcmp(s, "build_non_compressed") == 0))
1002 kumpf          1.142     {
1003                              compressMode =0;
1004                      #ifdef TEST_OUTPUT
1005                              cout << "In Compress mode: build_non_compresed found" << endl;
1006 jim.wunderlich 1.136 #endif /* TEST_OUTPUT */
1007 kumpf          1.142     }
1008                      #endif /* PEGASUS_ENABLE_COMPRESSED_REPOSITORY */
1009 jim.wunderlich 1.136 
1010 kumpf          1.142 #ifdef TEST_OUTPUT
1011                          cout << "repositoryRoot = " << repositoryRoot << endl;
1012 kumpf          1.166     cout << "CIMRepository: binaryMode="  << binaryMode <<
1013                              ", mode=" << mode << endl;
1014 jim.wunderlich 1.136     cout << "CIMRepository: compressMode= " << compressMode << endl;
1015                      #endif /* TEST_OUTPUT */
1016 jim.wunderlich 1.134 
1017 marek          1.183     if (binaryMode)
1018 kumpf          1.169     {
1019                              // BUILD BINARY
1020 mike           1.184         _rep->_streamer = new AutoStreamer(new BinaryStreamer(), BINREP_MARKER);
1021                              ((AutoStreamer*)_rep->_streamer)->addReader(new XmlStreamer(), 0);
1022 kumpf          1.169     }
1023                          else
1024                          {
1025                              // BUILD XML
1026 mike           1.184         _rep->_streamer = new AutoStreamer(new XmlStreamer(),0xff);
1027                              ((AutoStreamer*)_rep->_streamer)->addReader(
1028 kumpf          1.169             new BinaryStreamer(), BINREP_MARKER);
1029 mike           1.184         ((AutoStreamer*)_rep->_streamer)->addReader(new XmlStreamer(), 0);
1030 schuur         1.116     }
1031 schuur         1.114 
1032 dmitry.mikulin 1.181     // If declContext is supplied by the caller, don't allocate it.
1033                          // CIMRepository will take ownership and will be responsible for 
1034                          // deleting it.
1035                          if (declContext)
1036 mike           1.184         _rep->_context = declContext;
1037 dmitry.mikulin 1.181     else
1038 mike           1.184         _rep->_context = new RepositoryDeclContext();
1039                          _rep->_context->setRepository(this);
1040 dmitry.mikulin 1.181 
1041 mike           1.184     _rep->_isDefaultInstanceProvider = ConfigManager::parseBooleanValue(
1042 kumpf          1.158         ConfigManager::getInstance()->getCurrentValue(
1043                                  "repositoryIsDefaultInstanceProvider"));
1044 kumpf          1.58  
1045 mike           1.184     _rep->_lockFile = ConfigManager::getInstance()->getHomedPath(
1046 kumpf          1.160         PEGASUS_REPOSITORY_LOCK_FILE).getCString();
1047                      
1048 mike           1.184     _rep->_rollbackIncompleteTransactions();
1049 kumpf          1.168 
1050 kumpf          1.58      PEG_METHOD_EXIT();
1051 mike           1.48  }
1052                      
1053                      CIMRepository::~CIMRepository()
1054                      {
1055 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::~CIMRepository");
1056                      
1057 mike           1.184     delete _rep->_streamer;
1058                          delete _rep->_context;
1059 kumpf          1.58  
1060 r.kieninger    1.152     AssocClassTable::removeCaches();
1061                      
1062 mike           1.184     delete _rep;
1063                      
1064 kumpf          1.58      PEG_METHOD_EXIT();
1065 mike           1.48  }
1066                      
1067 kumpf          1.104 String _toString(Boolean x)
1068 mike           1.51  {
1069 kumpf          1.104     return(x ? "true" : "false");
1070 mike           1.51  }
1071                      
1072 kumpf          1.104 CIMClass CIMRepository::getClass(
1073                          const CIMNamespaceName& nameSpace,
1074                          const CIMName& className,
1075                          Boolean localOnly,
1076                          Boolean includeQualifiers,
1077                          Boolean includeClassOrigin,
1078                          const CIMPropertyList& propertyList)
1079 mike           1.51  {
1080 kumpf          1.104     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::getClass");
1081 kumpf          1.58  
1082 mike           1.184     ReadLock lock(_rep->_lock);
1083 kumpf          1.104     CIMClass cimClass = _getClass(nameSpace,
1084                                                        className,
1085                                                        localOnly,
1086                                                        includeQualifiers,
1087                                                        includeClassOrigin,
1088                                                        propertyList);
1089 kumpf          1.58  
1090                          PEG_METHOD_EXIT();
1091 kumpf          1.104     return cimClass;
1092 mike           1.51  }
1093                      
1094 kumpf          1.104 CIMClass CIMRepository::_getClass(
1095 kumpf          1.85      const CIMNamespaceName& nameSpace,
1096                          const CIMName& className,
1097 mike           1.48      Boolean localOnly,
1098                          Boolean includeQualifiers,
1099                          Boolean includeClassOrigin,
1100 mike           1.51      const CIMPropertyList& propertyList)
1101 mike           1.48  {
1102 kumpf          1.104     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_getClass");
1103 kumpf          1.58  
1104 kumpf          1.104     PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4, "nameSpace= " +
1105                                           nameSpace.getString() + ", className= " +
1106 karl           1.97                       className.getString() +
1107 kumpf          1.104                      ", localOnly= " + _toString(localOnly) +
1108                                           ", includeQualifiers= " + _toString(includeQualifiers) +
1109                                           ", includeClassOrigin= " + _toString(includeClassOrigin));
1110 mike           1.48      String classFilePath;
1111 mike           1.184     classFilePath = _rep->_nameSpaceManager.getClassFilePath(
1112 kumpf          1.169         nameSpace, className, NameSpaceRead);
1113 kumpf          1.104 
1114                          CIMClass cimClass;
1115 mike           1.51  
1116                          try
1117                          {
1118 mike           1.151 #ifdef PEGASUS_USE_CLASS_CACHE
1119                      
1120                              // Check the cache first:
1121                      
1122                              if (!_classCache.get(classFilePath, cimClass))
1123                              {
1124                                  // Not in cache so load from disk:
1125                      
1126 mike           1.184             _LoadObject(classFilePath, cimClass, _rep->_streamer);
1127 mike           1.151 
1128                                  // Put in cache:
1129                      
1130                                  _classCache.put(classFilePath, cimClass);
1131                              }
1132                      
1133                      #else /* PEGASUS_USE_CLASS_CACHE */
1134                      
1135 schuur         1.114         _LoadObject(classFilePath, cimClass, streamer);
1136 mike           1.151 
1137                      #endif /* PEGASUS_USE_CLASS_CACHE */
1138 mike           1.51      }
1139 kumpf          1.161     catch (Exception&)
1140 mike           1.51      {
1141 kumpf          1.58          PEG_METHOD_EXIT();
1142 kumpf          1.85          throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, className.getString());
1143 mike           1.51      }
1144 mike           1.48  
1145 kumpf          1.104     // Remove properties based on propertylist and localOnly flag (Bug 565)
1146                          Boolean propertyListNull = propertyList.isNull();
1147                      
1148                          // if localOnly OR there is a property list, process properties
1149 karl           1.97      if ((!propertyListNull) || localOnly)
1150                          {
1151 kumpf          1.104         // Loop through properties to remove those that do not filter through
1152                              // local only attribute and are not in the property list.
1153                              Uint32 count = cimClass.getPropertyCount();
1154                              // Work backwards because removal may be cheaper. Sint32 covers count=0
1155                              for (Sint32 i = (count - 1); i >= 0; i--)
1156                              {
1157                                  CIMProperty p = cimClass.getProperty(i);
1158                                  // if localOnly==true, ignore properties defined in super class
1159                                  if (localOnly && (p.getPropagated()))
1160                                  {
1161                                      cimClass.removeProperty(i);
1162                                      continue;
1163                                  }
1164                      
1165 kumpf          1.169             // propertyList NULL means all properties.  PropertyList
1166                                  // empty, none.
1167 kumpf          1.104             // Test for removal if propertyList not NULL. The empty list option
1168                                  // is covered by fact that property is not in the list.
1169                                  if (!propertyListNull)
1170 kumpf          1.169                 if (!_containsProperty(p, propertyList))
1171 kumpf          1.104                     cimClass.removeProperty(i);
1172                              }
1173                          }
1174                      
1175                          // remove methods based on localOnly flag
1176                          if (localOnly)
1177                          {
1178                              Uint32 count = cimClass.getMethodCount();
1179                              // Work backwards because removal may be cheaper.
1180 a.dunfey       1.156         for (Sint32 i = (count - 1); i >= 0; i--)
1181 kumpf          1.104         {
1182                                  CIMMethod m = cimClass.getMethod(i);
1183                      
1184                                  // if localOnly==true, ignore properties defined in super class
1185                                  if (localOnly && (m.getPropagated()))
1186                                      cimClass.removeMethod(i);
1187                              }
1188                      
1189                          }
1190                          // If includequalifiers false, remove all qualifiers from
1191                          // properties, methods and parameters.
1192 kumpf          1.169     if (!includeQualifiers)
1193 kumpf          1.104     {
1194 mike           1.182 
1195 kumpf          1.104         _removeAllQualifiers(cimClass);
1196                          }
1197                          else
1198                          {
1199                              // if includequalifiers and localOnly, remove nonLocal qualifiers
1200                              if (localOnly)
1201                              {
1202                                  _removePropagatedQualifiers(cimClass);
1203                              }
1204                      
1205                          }
1206 kumpf          1.169 
1207 kumpf          1.104     // if ClassOrigin Flag false, remove classOrigin info from class object
1208                          // by setting the property to Null.
1209                          if (!includeClassOrigin)
1210                          {
1211 marek          1.174         PEG_TRACE_CSTRING(TRC_REPOSITORY, Tracer::LEVEL4,
1212 kumpf          1.169             "Remove Class Origins");
1213 kumpf          1.104 
1214                              Uint32 propertyCount = cimClass.getPropertyCount();
1215                              for (Uint32 i = 0; i < propertyCount ; i++)
1216                                  cimClass.getProperty(i).setClassOrigin(CIMName());
1217                      
1218                              Uint32 methodCount =  cimClass.getMethodCount();
1219                              for (Uint32 i=0; i < methodCount ; i++)
1220                                  cimClass.getMethod(i).setClassOrigin(CIMName());
1221                          }
1222 karl           1.97  
1223 kumpf          1.58      PEG_METHOD_EXIT();
1224 mike           1.48      return cimClass;
1225                      }
1226                      
1227 mike           1.184 Boolean CIMRepositoryRep::_checkInstanceAlreadyExists(
1228 kumpf          1.85      const CIMNamespaceName& nameSpace,
1229 kumpf          1.162     const CIMObjectPath& instanceName) const
1230 mike           1.48  {
1231 kumpf          1.162     PEG_METHOD_ENTER(TRC_REPOSITORY,
1232                              "CIMRepository::_checkInstanceAlreadyExists");
1233 kumpf          1.58  
1234 mike           1.53      //
1235 kumpf          1.162     // Get the names of all superclasses and subclasses of this class
1236 mike           1.53      //
1237 mike           1.51  
1238 kumpf          1.85      Array<CIMName> classNames;
1239 kumpf          1.162     CIMName className = instanceName.getClassName();
1240 kumpf          1.94      classNames.append(className);
1241 mike           1.48      _nameSpaceManager.getSubClassNames(nameSpace, className, true, classNames);
1242 kumpf          1.162     _nameSpaceManager.getSuperClassNames(nameSpace, className, classNames);
1243 mike           1.48  
1244 mike           1.53      //
1245 kumpf          1.162     // Search for an instance with the specified key values
1246 mike           1.53      //
1247 mike           1.48  
1248                          for (Uint32 i = 0; i < classNames.size(); i++)
1249                          {
1250 kumpf          1.68          CIMObjectPath tmpInstanceName = instanceName;
1251 mike           1.51          tmpInstanceName.setClassName(classNames[i]);
1252 mike           1.48  
1253 mike           1.53          String path = _getInstanceIndexFilePath(nameSpace, classNames[i]);
1254 mike           1.48  
1255 kumpf          1.162         Uint32 index;
1256                              Uint32 size;
1257 mike           1.53          if (InstanceIndexFile::lookupEntry(path, tmpInstanceName, index, size))
1258 mike           1.51          {
1259 kumpf          1.58              PEG_METHOD_EXIT();
1260 mike           1.51              return true;
1261                              }
1262 mike           1.48      }
1263                      
1264 kumpf          1.58      PEG_METHOD_EXIT();
1265 mike           1.48      return false;
1266                      }
1267                      
1268                      CIMInstance CIMRepository::getInstance(
1269 kumpf          1.85      const CIMNamespaceName& nameSpace,
1270 kumpf          1.68      const CIMObjectPath& instanceName,
1271 mike           1.48      Boolean localOnly,
1272                          Boolean includeQualifiers,
1273                          Boolean includeClassOrigin,
1274 mike           1.55      const CIMPropertyList& propertyList)
1275 mike           1.48  {
1276 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::getInstance");
1277                      
1278 mike           1.184     ReadLock lock(_rep->_lock);
1279 kumpf          1.165 
1280 kumpf          1.169     CIMInstance cimInstance = _getInstance(
1281                              nameSpace,
1282                              instanceName,
1283                              localOnly,
1284                              includeQualifiers,
1285                              includeClassOrigin,
1286                              propertyList);
1287 kumpf          1.104 
1288                          PEG_METHOD_EXIT();
1289                          return cimInstance;
1290                      }
1291                      
1292                      CIMInstance CIMRepository::_getInstance(
1293                          const CIMNamespaceName& nameSpace,
1294                          const CIMObjectPath& instanceName,
1295                          Boolean localOnly,
1296                          Boolean includeQualifiers,
1297                          Boolean includeClassOrigin,
1298                          const CIMPropertyList& propertyList)
1299                      {
1300                          PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_getInstance");
1301                      
1302 mike           1.53      //
1303 r.kieninger    1.125     // Validate namespace
1304                          //
1305                          if ((!instanceName.getNameSpace().isNull()) &&
1306                              (!instanceName.getNameSpace().equal(nameSpace)))
1307                          {
1308                              PEG_METHOD_EXIT();
1309                              throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND,
1310                                                             instanceName.toString());
1311                          }
1312                      
1313 mike           1.184     if (!_rep->_nameSpaceManager.classExists(
1314                              nameSpace, instanceName.getClassName()))
1315 kumpf          1.162     {
1316                              throw PEGASUS_CIM_EXCEPTION(
1317                                  CIM_ERR_INVALID_CLASS, instanceName.getClassName().getString());
1318                          }
1319                      
1320 r.kieninger    1.125     //
1321 kumpf          1.165     // Get paths of index and data files:
1322 mike           1.53      //
1323 mike           1.48  
1324 mike           1.184     String indexFilePath = _rep->_getInstanceIndexFilePath(
1325 kumpf          1.162         nameSpace, instanceName.getClassName());
1326                      
1327 mike           1.184     String dataFilePath = _rep->_getInstanceDataFilePath(
1328 kumpf          1.162         nameSpace, instanceName.getClassName());
1329                      
1330 kumpf          1.165     //
1331                          // Get the index for this instance:
1332                          //
1333                      
1334                          Uint32 index;
1335                          Uint32 size;
1336                      
1337 kumpf          1.162     if (!InstanceIndexFile::lookupEntry(
1338                                  indexFilePath, instanceName, index, size))
1339 mike           1.48      {
1340 kumpf          1.104         PEG_METHOD_EXIT();
1341 mike           1.51          throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString());
1342 mike           1.48      }
1343                      
1344 mike           1.53      //
1345                          // Load the instance from file:
1346                          //
1347 mike           1.48  
1348                          CIMInstance cimInstance;
1349 mike           1.53  
1350 mike           1.184     if (!_rep->_loadInstance(dataFilePath, cimInstance, index, size))
1351 mike           1.51      {
1352 kumpf          1.104         PEG_METHOD_EXIT();
1353 kumpf          1.162         throw CannotOpenFile(dataFilePath);
1354 mike           1.51      }
1355                      
1356 mike           1.54      //
1357                          // Resolve the instance (if requested):
1358                          //
1359                      
1360 mike           1.184     if (_rep->_resolveInstance)
1361 mike           1.54      {
1362 kumpf          1.104         CIMConstClass cimClass;
1363 mike           1.184         Resolver::resolveInstance (
1364                                  cimInstance, _rep->_context, nameSpace, cimClass, true);
1365 mike           1.54      }
1366 kumpf          1.99  
1367 kumpf          1.165     _filterInstance(
1368                              cimInstance,
1369                              propertyList,
1370                              localOnly,
1371                              includeQualifiers,
1372                              includeClassOrigin);
1373 kumpf          1.104 
1374 kumpf          1.52      PEG_METHOD_EXIT();
1375 mike           1.48      return cimInstance;
1376                      }
1377                      
1378                      void CIMRepository::deleteClass(
1379 kumpf          1.85      const CIMNamespaceName& nameSpace,
1380                          const CIMName& className)
1381 mike           1.48  {
1382 kumpf          1.61      PEG_METHOD_ENTER(TRC_REPOSITORY,"CIMRepository::deleteClass");
1383 kumpf          1.58  
1384 mike           1.184     WriteLock lock(_rep->_lock);
1385                          AutoFileLock fileLock(_rep->_lockFile);
1386 kumpf          1.104 
1387 mike           1.53      //
1388                          // Get the class and check to see if it is an association class:
1389                          //
1390 mike           1.51  
1391 kumpf          1.104     CIMClass cimClass = _getClass(
1392                              nameSpace, className, false, true, false, CIMPropertyList());
1393 mike           1.48      Boolean isAssociation = cimClass.isAssociation();
1394                      
1395 mike           1.53      //
1396                          // Delete the class. The NameSpaceManager::deleteClass() method throws
1397 karl           1.97      // an exception if the class has subclasses.
1398 mike           1.53      //
1399 mike           1.151 #ifdef PEGASUS_USE_CLASS_CACHE
1400                      
1401 mike           1.184     _classCache.evict(_rep->_nameSpaceManager.getClassFilePath(
1402 kumpf          1.178         nameSpace, className, NameSpaceRead));
1403 mike           1.151 
1404                      #endif /* PEGASUS_USE_CLASS_CACHE */
1405                      
1406 mike           1.184     _rep->_nameSpaceManager.deleteClass(nameSpace, className);
1407 mike           1.48  
1408 mike           1.53      //
1409 karl           1.97      // Remove associations:
1410 mike           1.53      //
1411 mike           1.48  
1412                          if (isAssociation)
1413                          {
1414 kumpf          1.169         Array<String> assocFileName =
1415 mike           1.184             _rep->_nameSpaceManager.getAssocClassPath(
1416                                      nameSpace,NameSpaceDelete);
1417 mike           1.48  
1418 dmitry.mikulin 1.186         AssocClassTable::deleteAssociation(assocFileName[0], className);
1419 mike           1.48      }
1420 kumpf          1.104 
1421 kumpf          1.58      PEG_METHOD_EXIT();
1422 mike           1.48  }
1423                      
1424 dmitry.mikulin 1.179 // This function needs to be called from within a transaction scope for
1425                      // proper error handling in compacting index and data files. 
1426 mike           1.53  void _CompactInstanceRepository(
1427 kumpf          1.104     const String& indexFilePath,
1428 mike           1.53      const String& dataFilePath)
1429                      {
1430 kumpf          1.169     PEG_METHOD_ENTER(TRC_REPOSITORY,
1431                              "CIMRepository::_CompactInstanceRepository");
1432 kumpf          1.58  
1433 mike           1.53      //
1434                          // Compact the data file first:
1435                          //
1436                      
1437                          Array<Uint32> freeFlags;
1438                          Array<Uint32> indices;
1439                          Array<Uint32> sizes;
1440 kumpf          1.68      Array<CIMObjectPath> instanceNames;
1441 mike           1.53  
1442 kumpf          1.104     if (!InstanceIndexFile::enumerateEntries(
1443                                  indexFilePath, freeFlags, indices, sizes, instanceNames, true))
1444 mike           1.53      {
1445 kumpf          1.58          PEG_METHOD_EXIT();
1446 humberto       1.88          throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
1447 dave.sudlik    1.171             MessageLoaderParms(
1448                                      "Repository.CIMRepository.INDEX_ENUM_ENTRIES_FAILED",
1449                                      "Failed to obtain the entries from the Repository Instance"
1450                                      " Index file."));
1451 mike           1.53      }
1452                      
1453                          if (!InstanceDataFile::compact(dataFilePath, freeFlags, indices, sizes))
1454 kumpf          1.58      {
1455                              PEG_METHOD_EXIT();
1456 kumpf          1.99          throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
1457 dave.sudlik    1.171             MessageLoaderParms(
1458                                      "Repository.CIMRepository.COMPACT_FAILED",
1459                                      "Failed to compact the Repository Instance Data file."));
1460 kumpf          1.58      }
1461 mike           1.53  
1462                          //
1463                          // Now compact the index file:
1464                          //
1465                      
1466                          if (!InstanceIndexFile::compact(indexFilePath))
1467 kumpf          1.58      {
1468                              PEG_METHOD_EXIT();
1469 kumpf          1.99          throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
1470 dave.sudlik    1.171             MessageLoaderParms(
1471                                      "Repository.CIMRepository.INDEX_COMPACT_FAILED",
1472                                      "Failed to compact the Repository Instance Index file."));
1473 kumpf          1.58      }
1474                      
1475                          PEG_METHOD_EXIT();
1476 mike           1.53  }
1477                      
1478 mike           1.48  void CIMRepository::deleteInstance(
1479 kumpf          1.85      const CIMNamespaceName& nameSpace,
1480 kumpf          1.68      const CIMObjectPath& instanceName)
1481 mike           1.48  {
1482 mike           1.53      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::deleteInstance");
1483 mike           1.51  
1484 r.kieninger    1.125     //
1485                          // Validate namespace
1486                          //
1487                          if ((!instanceName.getNameSpace().isNull()) &&
1488                              (!instanceName.getNameSpace().equal(nameSpace)))
1489                          {
1490                              PEG_METHOD_EXIT();
1491 kumpf          1.169         throw PEGASUS_CIM_EXCEPTION(
1492                                  CIM_ERR_NOT_FOUND, instanceName.toString());
1493 r.kieninger    1.125     }
1494                      
1495 mike           1.184     WriteLock lock(_rep->_lock);
1496                          AutoFileLock fileLock(_rep->_lockFile);
1497 kumpf          1.104 
1498 mike           1.51      String errMessage;
1499                      
1500 mike           1.53      //
1501                          // Get paths of index and data files:
1502                          //
1503                      
1504 mike           1.184     String indexFilePath = _rep->_getInstanceIndexFilePath(
1505 mike           1.53          nameSpace, instanceName.getClassName());
1506 mike           1.48  
1507 mike           1.184     String dataFilePath = _rep->_getInstanceDataFilePath(
1508 mike           1.51          nameSpace, instanceName.getClassName());
1509 mike           1.48  
1510 mike           1.53      //
1511 kumpf          1.168     // Perform the operation in a transaction scope to enable rollback on
1512                          // failure.
1513 mike           1.53      //
1514                      
1515 kumpf          1.168     InstanceTransactionHandler transaction(indexFilePath, dataFilePath);
1516 mike           1.53  
1517                          //
1518                          // Lookup instance from the index file (raise error if not found).
1519                          //
1520                      
1521 mike           1.48      Uint32 index;
1522 mike           1.51      Uint32 size;
1523 mike           1.48  
1524 mike           1.53      if (!InstanceIndexFile::lookupEntry(
1525 kumpf          1.104             indexFilePath, instanceName, index, size))
1526 kumpf          1.52      {
1527                              PEG_METHOD_EXIT();
1528 mike           1.51          throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString());
1529 kumpf          1.52      }
1530 mike           1.48  
1531 mike           1.53      //
1532 kumpf          1.165     // Remove entry from index file.
1533 mike           1.53      //
1534                      
1535                          Uint32 freeCount;
1536 mike           1.48  
1537 mike           1.53      if (!InstanceIndexFile::deleteEntry(indexFilePath, instanceName, freeCount))
1538 mike           1.48      {
1539 humberto       1.88          PEG_METHOD_EXIT();
1540 kumpf          1.99          throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
1541                                  MessageLoaderParms(
1542                                      "Repository.CIMRepository.FAILED_TO_DELETE_INSTANCE",
1543 kumpf          1.104                 "Failed to delete instance: $0",
1544 kumpf          1.99                  instanceName.toString()));
1545 mike           1.48      }
1546                      
1547 mike           1.53      //
1548                          // Compact the index and data files if the free count max was
1549                          // reached.
1550                          //
1551                      
1552 dmitry.mikulin 1.179     if (freeCount >= _MAX_FREE_COUNT)
1553                          {
1554 kumpf          1.104         _CompactInstanceRepository(indexFilePath, dataFilePath);
1555 dmitry.mikulin 1.179     }
1556                      
1557                          transaction.complete();
1558 mike           1.53  
1559                          //
1560                          // Delete from assocation table (if an assocation).
1561                          //
1562 mike           1.48  
1563 mike           1.184     String assocFileName = _rep->_nameSpaceManager.getAssocInstPath(nameSpace);
1564 dmitry.mikulin 1.186     AssocInstTable::deleteAssociation(assocFileName, instanceName);
1565 kumpf          1.52  
1566                          PEG_METHOD_EXIT();
1567 mike           1.48  }
1568                      
1569 mike           1.184 void CIMRepositoryRep::_createAssocClassEntries(
1570 kumpf          1.85      const CIMNamespaceName& nameSpace,
1571 mike           1.48      const CIMConstClass& assocClass)
1572                      {
1573 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_createAssocClassEntries");
1574                      
1575 mike           1.48      // Open input file:
1576                      
1577 mike           1.51  
1578 kumpf          1.169     Array<String> assocFileName =
1579                              _nameSpaceManager.getAssocClassPath(nameSpace,NameSpaceWrite);
1580 mike           1.48      ofstream os;
1581                      
1582 schuur         1.112     if (!OpenAppend(os, assocFileName[0]))
1583 kumpf          1.58      {
1584                              PEG_METHOD_EXIT();
1585 schuur         1.112         throw CannotOpenFile(assocFileName[0]);
1586 kumpf          1.58      }
1587 mike           1.48  
1588                          // Get the association's class name:
1589                      
1590 kumpf          1.85      CIMName assocClassName = assocClass.getClassName();
1591 mike           1.48  
1592                          // For each property:
1593                      
1594                          Uint32 n = assocClass.getPropertyCount();
1595                      
1596                          for (Uint32 i = 0; i < n; i++)
1597                          {
1598 mike           1.51          CIMConstProperty fromProp = assocClass.getProperty(i);
1599 mike           1.48  
1600 kumpf          1.78          if (fromProp.getType() == CIMTYPE_REFERENCE)
1601 mike           1.51          {
1602                                  for (Uint32 j = 0; j < n; j++)
1603                                  {
1604                                      CIMConstProperty toProp = assocClass.getProperty(j);
1605                      
1606 kumpf          1.78                  if (toProp.getType() == CIMTYPE_REFERENCE &&
1607 kumpf          1.85                      (!fromProp.getName().equal (toProp.getName())))
1608 mike           1.51                  {
1609 kumpf          1.85                      CIMName fromClassName = fromProp.getReferenceClassName();
1610                                          CIMName fromPropertyName = fromProp.getName();
1611                                          CIMName toClassName = toProp.getReferenceClassName();
1612                                          CIMName toPropertyName = toProp.getName();
1613 mike           1.51  
1614                                          AssocClassTable::append(
1615                                              os,
1616 r.kieninger    1.152                         assocFileName[0],
1617 mike           1.51                          assocClassName,
1618                                              fromClassName,
1619                                              fromPropertyName,
1620                                              toClassName,
1621                                              toPropertyName);
1622                                      }
1623                                  }
1624                              }
1625 mike           1.48      }
1626 kumpf          1.58  
1627                          PEG_METHOD_EXIT();
1628 mike           1.48  }
1629                      
1630                      void CIMRepository::createClass(
1631 kumpf          1.85      const CIMNamespaceName& nameSpace,
1632 chuck          1.110     const CIMClass& newClass,
1633 kumpf          1.155     const ContentLanguageList& contentLangs)
1634 mike           1.48  {
1635 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::createClass");
1636                      
1637 mike           1.184     WriteLock lock(_rep->_lock);
1638                          AutoFileLock fileLock(_rep->_lockFile);
1639 kumpf          1.104     _createClass(nameSpace, newClass);
1640                      
1641                          PEG_METHOD_EXIT();
1642                      }
1643                      
1644                      void CIMRepository::_createClass(
1645                          const CIMNamespaceName& nameSpace,
1646                          const CIMClass& newClass)
1647                      {
1648                          PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_createClass");
1649                      
1650 mike           1.48      // -- Resolve the class:
1651 mike           1.51          CIMClass cimClass(newClass);
1652 kumpf          1.104 
1653 mike           1.184     Resolver::resolveClass (cimClass, _rep->_context, nameSpace);
1654 mike           1.48  
1655                          // -- If an association, populate associations file:
1656                      
1657                          if (cimClass.isAssociation())
1658 mike           1.184         _rep->_createAssocClassEntries(nameSpace, cimClass);
1659 mike           1.48  
1660                          // -- Create namespace manager entry:
1661                      
1662                          String classFilePath;
1663                      
1664 mike           1.184     _rep->_nameSpaceManager.createClass(nameSpace, cimClass.getClassName(),
1665 mike           1.51          cimClass.getSuperClassName(), classFilePath);
1666 mike           1.48  
1667                          // -- Create the class file:
1668                      
1669 mike           1.150     Buffer classXml;
1670 mike           1.184     _rep->_streamer->encode(classXml, cimClass);
1671 schuur         1.114     //XmlWriter::appendClassElement(classXml, cimClass);
1672 mike           1.184     _SaveObject(classFilePath, classXml, _rep->_streamer);
1673 kumpf          1.58  
1674                          PEG_METHOD_EXIT();
1675 mike           1.48  }
1676                      
1677                      /*------------------------------------------------------------------------------
1678                      
1679                          This routine does the following:
1680                      
1681 mike           1.51          1.  Creates two entries in the association file for each relationship
1682                                  formed by this new assocation instance. A binary association
1683                                  (one with two references) ties two instances together. Suppose
1684                                  there are two instances: I1 and I2. Then two entries are created:
1685                      
1686                                      I2 -> I1
1687                                      I1 -> I2
1688                      
1689                                  For a ternary relationship, six entries will be created. Suppose
1690                                  there are three instances: I1, I2, and I3:
1691                      
1692                                      I1 -> I2
1693                                      I1 -> I3
1694                                      I2 -> I1
1695                                      I2 -> I3
1696                                      I3 -> I1
1697                                      I3 -> I2
1698                      
1699                                  So for an N-ary relationship, there will be 2*N entries created.
1700                      
1701                              2.  Verifies that the association instance refers to real objects.
1702 mike           1.51              (note that an association reference may refer to either an instance
1703                                  or a class). Throws an exception if one of the references does not
1704                                  refer to a valid object.
1705 mike           1.48  
1706                      ------------------------------------------------------------------------------*/
1707                      
1708 r.kieninger    1.126 
1709 mike           1.184 void CIMRepositoryRep::_createAssocInstEntries(
1710 kumpf          1.85      const CIMNamespaceName& nameSpace,
1711 mike           1.48      const CIMConstClass& cimClass,
1712                          const CIMInstance& cimInstance,
1713 kumpf          1.68      const CIMObjectPath& instanceName)
1714 mike           1.48  {
1715 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_createAssocInstEntries");
1716                      
1717 mike           1.48      // Open input file:
1718                      
1719 kumpf          1.91      String assocFileName = _nameSpaceManager.getAssocInstPath(nameSpace);
1720 mike           1.48      ofstream os;
1721                      
1722                          if (!OpenAppend(os, assocFileName))
1723 kumpf          1.58      {
1724                              PEG_METHOD_EXIT();
1725 mike           1.51          throw CannotOpenFile(assocFileName);
1726 kumpf          1.58      }
1727 mike           1.48  
1728                          // Get the association's instance name and class name:
1729                      
1730                          String assocInstanceName = instanceName.toString();
1731 kumpf          1.85      CIMName assocClassName = instanceName.getClassName();
1732 mike           1.48  
1733                          // For each property:
1734                      
1735                          for (Uint32 i = 0, n = cimInstance.getPropertyCount(); i < n; i++)
1736                          {
1737 mike           1.51          CIMConstProperty fromProp = cimInstance.getProperty(i);
1738 mike           1.48  
1739 mike           1.51          // If a reference property:
1740 mike           1.48  
1741 kumpf          1.78          if (fromProp.getType() == CIMTYPE_REFERENCE)
1742 mike           1.51          {
1743                                  // For each property:
1744                      
1745 kumpf          1.188             for (Uint32 j = 0, m = cimInstance.getPropertyCount(); j < m; j++)
1746 mike           1.51              {
1747                                      CIMConstProperty toProp = cimInstance.getProperty(j);
1748                      
1749                                      // If a reference property and not the same property:
1750                      
1751 kumpf          1.78                  if (toProp.getType() == CIMTYPE_REFERENCE &&
1752 kumpf          1.85                      (!fromProp.getName().equal (toProp.getName())))
1753 mike           1.51                  {
1754 kumpf          1.68                      CIMObjectPath fromRef;
1755 mike           1.51                      fromProp.getValue().get(fromRef);
1756                      
1757 kumpf          1.68                      CIMObjectPath toRef;
1758 mike           1.51                      toProp.getValue().get(toRef);
1759                      
1760 r.kieninger    1.126 
1761                                          // Fix for bugzilla 667:
1762 kumpf          1.169                     // Strip off the hostname if it is the same as the
1763                                          // local host
1764 r.kieninger    1.126                     if ((fromRef.getHost() != String::EMPTY) &&
1765 marek          1.167                         (System::isLocalHost(fromRef.getHost())))
1766 r.kieninger    1.126                     {
1767 marek          1.174                         PEG_TRACE_CSTRING(TRC_REPOSITORY, Tracer::LEVEL4,
1768 kumpf          1.169                             "_createAssocInstEntries() - Stripping off local "
1769                                                      "hostName from fromRef");
1770 r.kieninger    1.126                        fromRef.setHost(String::EMPTY);
1771                                          }
1772                      
1773                                          // Strip off the namespace when it is the same as the
1774                                          // one this instance is created in.
1775                                          if ((fromRef.getHost() == String::EMPTY) &&
1776                                              (fromRef.getNameSpace() == nameSpace))
1777                                          {
1778 marek          1.174                         PEG_TRACE_CSTRING(TRC_REPOSITORY, Tracer::LEVEL4,
1779 kumpf          1.169                             "_createAssocInstEntries() - Stripping off "
1780                                                      "local nameSpace from fromRef");
1781                                              fromRef.setNameSpace(CIMNamespaceName());
1782 r.kieninger    1.126                     }
1783                      
1784 kumpf          1.169                     // Strip off the hostname if it is the same as the
1785                                          // local host
1786 r.kieninger    1.126                     if ((toRef.getHost() != String::EMPTY) &&
1787 marek          1.167                         (System::isLocalHost(toRef.getHost())))
1788 r.kieninger    1.126                     {
1789 marek          1.174                         PEG_TRACE_CSTRING(TRC_REPOSITORY, Tracer::LEVEL4,
1790 kumpf          1.169                             "_createAssocInstEntries() - Stripping off "
1791                                                      "local hostName from toRef");
1792                                              toRef.setHost(String::EMPTY);
1793 r.kieninger    1.126                     }
1794                      
1795                                          // Strip off the namespace when it is the same as the
1796                                          // one this instance is created in.
1797                                          if ((toRef.getHost() == String::EMPTY) &&
1798                                              (toRef.getNameSpace() == nameSpace))
1799                                          {
1800 marek          1.174                        PEG_TRACE_CSTRING(TRC_REPOSITORY, Tracer::LEVEL4,
1801 kumpf          1.169                            "_createAssocInstEntries() - Stripping off "
1802                                                     "local nameSpace from toRef");
1803 r.kieninger    1.126                        toRef.setNameSpace(CIMNamespaceName());
1804                                          }
1805                      
1806                      
1807 mike           1.51                      String fromObjectName = fromRef.toString();
1808 kumpf          1.85                      CIMName fromClassName = fromRef.getClassName();
1809                                          CIMName fromPropertyName = fromProp.getName();
1810 mike           1.51                      String toObjectName = toRef.toString();
1811 kumpf          1.85                      CIMName toClassName = toRef.getClassName();
1812                                          CIMName toPropertyName = toProp.getName();
1813 mike           1.51  
1814                                          AssocInstTable::append(
1815                                              os,
1816                                              assocInstanceName,
1817                                              assocClassName,
1818                                              fromObjectName,
1819                                              fromClassName,
1820                                              fromPropertyName,
1821                                              toObjectName,
1822                                              toClassName,
1823                                              toPropertyName);
1824                                      }
1825                                  }
1826                              }
1827 mike           1.48      }
1828 kumpf          1.58  
1829                          PEG_METHOD_EXIT();
1830 mike           1.48  }
1831                      
1832 kumpf          1.68  CIMObjectPath CIMRepository::createInstance(
1833 kumpf          1.85      const CIMNamespaceName& nameSpace,
1834 chuck          1.110     const CIMInstance& newInstance,
1835 kumpf          1.155     const ContentLanguageList& contentLangs)
1836 mike           1.48  {
1837 kumpf          1.61      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::createInstance");
1838 mike           1.51  
1839 mike           1.184     WriteLock lock(_rep->_lock);
1840                          AutoFileLock fileLock(_rep->_lockFile);
1841 kumpf          1.104     CIMObjectPath instanceName = _createInstance(nameSpace, newInstance);
1842                      
1843                          PEG_METHOD_EXIT();
1844                          return instanceName;
1845                      }
1846                      
1847                      CIMObjectPath CIMRepository::_createInstance(
1848                          const CIMNamespaceName& nameSpace,
1849                          const CIMInstance& newInstance)
1850                      {
1851                          PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_createInstance");
1852                      
1853 mike           1.51      String errMessage;
1854                      
1855 mike           1.53      //
1856 mike           1.54      // Resolve the instance. Looks up class and fills out properties but
1857                          // not the qualifiers.
1858 mike           1.53      //
1859                      
1860 mike           1.51      CIMInstance cimInstance(newInstance);
1861 mike           1.48      CIMConstClass cimClass;
1862 mike           1.184     Resolver::resolveInstance (cimInstance, _rep->_context, nameSpace, cimClass,
1863 kumpf          1.76          false);
1864 kumpf          1.81      CIMObjectPath instanceName = cimInstance.buildPath(cimClass);
1865 mike           1.48  
1866 mike           1.53      //
1867                          // Make sure the class has keys (otherwise it will be impossible to
1868                          // create the instance).
1869                          //
1870 mike           1.48  
1871                          if (!cimClass.hasKeys())
1872                          {
1873 humberto       1.88          PEG_METHOD_EXIT();
1874 kumpf          1.99          throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
1875                                  MessageLoaderParms("Repository.CIMRepository.CLASS_HAS_NO_KEYS",
1876 kumpf          1.104                 "class has no keys: $0",
1877 kumpf          1.99                  cimClass.getClassName().getString()));
1878 mike           1.48      }
1879                      
1880 mike           1.53      //
1881                          // Be sure instance does not already exist:
1882                          //
1883 mike           1.48  
1884 mike           1.184     if (_rep->_checkInstanceAlreadyExists(nameSpace, instanceName))
1885 mike           1.48      {
1886 kumpf          1.52          PEG_METHOD_EXIT();
1887 kumpf          1.104         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_ALREADY_EXISTS,
1888 mike           1.51              instanceName.toString());
1889 mike           1.48      }
1890                      
1891 mike           1.53      //
1892                          // Create association entries if an association instance.
1893                          //
1894 mike           1.48  
1895                          if (cimClass.isAssociation())
1896 mike           1.184         _rep->_createAssocInstEntries(nameSpace, cimClass, cimInstance, 
1897                                  instanceName);
1898 mike           1.53  
1899                          //
1900 kumpf          1.168     // Get paths to data and index files:
1901                          //
1902                      
1903 mike           1.184     String indexFilePath = _rep->_getInstanceIndexFilePath(
1904 kumpf          1.168         nameSpace, newInstance.getClassName());
1905                      
1906 mike           1.184     String dataFilePath = _rep->_getInstanceDataFilePath(
1907 kumpf          1.168         nameSpace, newInstance.getClassName());
1908                      
1909                          //
1910                          // Perform the operation in a transaction scope to enable rollback on
1911                          // failure.
1912                          //
1913                      
1914                          InstanceTransactionHandler transaction(indexFilePath, dataFilePath);
1915                      
1916                          //
1917 kumpf          1.165     // Save instance to file:
1918 mike           1.53      //
1919                      
1920 mike           1.51      Uint32 index;
1921                          Uint32 size;
1922 mike           1.53  
1923 mike           1.51      {
1924 mike           1.150         Buffer data;
1925 mike           1.184         _rep->_streamer->encode(data, cimInstance);
1926 kumpf          1.172         size = data.size();
1927 kumpf          1.104 
1928                              if (!InstanceDataFile::appendInstance(dataFilePath, data, index))
1929                              {
1930                                  PEG_METHOD_EXIT();
1931                                  throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
1932 kumpf          1.99                  MessageLoaderParms(
1933                                          "Repository.CIMRepository.FAILED_TO_CREATE_INSTANCE",
1934 kumpf          1.104                     "Failed to create instance: $0",
1935 kumpf          1.99                      instanceName.toString()));
1936 kumpf          1.104         }
1937 mike           1.53      }
1938                      
1939                          //
1940                          // Create entry in index file:
1941                          //
1942                      
1943                          if (!InstanceIndexFile::createEntry(
1944 kumpf          1.104             indexFilePath, instanceName, index, size))
1945 mike           1.53      {
1946 humberto       1.88          PEG_METHOD_EXIT();
1947 kumpf          1.99          throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
1948                                  MessageLoaderParms(
1949                                      "Repository.CIMRepository.FAILED_TO_CREATE_INSTANCE",
1950 kumpf          1.104                 "Failed to create instance: $0",
1951 kumpf          1.99                  instanceName.toString()));
1952 mike           1.51      }
1953 mike           1.48  
1954 kumpf          1.168     transaction.complete();
1955 mike           1.53  
1956 mike           1.184     Resolver::resolveInstance (
1957                              cimInstance, _rep->_context, nameSpace, cimClass, true);
1958 mike           1.54  
1959 kumpf          1.52      PEG_METHOD_EXIT();
1960 mike           1.53      return instanceName;
1961 mike           1.48  }
1962                      
1963                      void CIMRepository::modifyClass(
1964 kumpf          1.85      const CIMNamespaceName& nameSpace,
1965 chuck          1.110     const CIMClass& modifiedClass,
1966 kumpf          1.155     const ContentLanguageList& contentLangs)
1967 mike           1.48  {
1968 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::modifyClass");
1969                      
1970 mike           1.184     WriteLock lock(_rep->_lock);
1971                          AutoFileLock fileLock(_rep->_lockFile);
1972 kumpf          1.104     _modifyClass(nameSpace, modifiedClass);
1973                      
1974                          PEG_METHOD_EXIT();
1975                      }
1976                      
1977                      void CIMRepository::_modifyClass(
1978                          const CIMNamespaceName& nameSpace,
1979                          const CIMClass& modifiedClass)
1980                      {
1981                          PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_modifyClass");
1982                      
1983 mike           1.53      //
1984                          // Resolve the class:
1985                          //
1986 mike           1.51  
1987 mike           1.53      CIMClass cimClass(modifiedClass);
1988 mike           1.184     Resolver::resolveClass (cimClass, _rep->_context, nameSpace);
1989 mike           1.48  
1990 mike           1.53      //
1991                          // Check to see if it is okay to modify this class:
1992                          //
1993 mike           1.48  
1994                          String classFilePath;
1995                      
1996 mike           1.184     _rep->_nameSpaceManager.checkModify(nameSpace, cimClass.getClassName(),
1997 mike           1.51          cimClass.getSuperClassName(), classFilePath);
1998 mike           1.48  
1999 mike           1.53      //
2000                          // ATTN: KS
2001                          // Disallow modification of classes which have instances (that are
2002                          // in the repository). And we have no idea whether the class has
2003                          // instances in other repositories or in providers. We should do
2004                          // an enumerate instance names at a higher level (above the repository).
2005                          //
2006 chip           1.118 
2007 mike           1.151 #ifdef PEGASUS_USE_CLASS_CACHE
2008                      
2009                          _classCache.evict(classFilePath);
2010                      
2011                      #endif /* PEGASUS_USE_CLASS_CACHE */
2012 mike           1.53  
2013                          //
2014                          // Delete the old file containing the class:
2015                          //
2016 mike           1.48  
2017                          if (!FileSystem::removeFileNoCase(classFilePath))
2018                          {
2019 kumpf          1.58          PEG_METHOD_EXIT();
2020 humberto       1.88          String str = "CIMRepository::modifyClass()";
2021 kumpf          1.99          throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
2022                                  MessageLoaderParms(
2023                                      "Repository.CIMRepository.FAILED_TO_REMOVE_FILE",
2024                                      "failed to remove file in $0", str));
2025 mike           1.48      }
2026                      
2027 mike           1.53      //
2028                          // Create new class file:
2029                          //
2030 mike           1.48  
2031 mike           1.150     Buffer classXml;
2032 mike           1.184     _rep->_streamer->encode(classXml, cimClass);
2033 schuur         1.114     //XmlWriter::appendClassElement(classXml, cimClass);
2034 mike           1.184     _SaveObject(classFilePath, classXml, _rep->_streamer);
2035 kumpf          1.58  
2036 kumpf          1.169     if (cimClass.isAssociation())
2037                          {
2038                              // Remove from Association
2039                              Array<String> assocFileName =
2040 mike           1.184             _rep->_nameSpaceManager.getAssocClassPath(
2041                                      nameSpace,NameSpaceDelete);
2042 dmitry.mikulin 1.186         if (AssocClassTable::deleteAssociation(
2043                                      assocFileName[0], cimClass.getClassName()))
2044 kumpf          1.169         {
2045                                  // Create the association again.
2046 mike           1.184             _rep->_createAssocClassEntries(nameSpace, cimClass);
2047 kumpf          1.169         }
2048 konrad.r       1.111     }
2049                      
2050 mike           1.151 
2051                          //
2052                          // Cache this class:
2053                          //
2054                      
2055                      #ifdef PEGASUS_USE_CLASS_CACHE
2056                      
2057                          _classCache.put(classFilePath, cimClass);
2058                      
2059                      #endif /* PEGASUS_USE_CLASS_CACHE */
2060                      
2061 kumpf          1.58      PEG_METHOD_EXIT();
2062 mike           1.48  }
2063                      
2064                      void CIMRepository::modifyInstance(
2065 kumpf          1.85      const CIMNamespaceName& nameSpace,
2066 kumpf          1.70      const CIMInstance& modifiedInstance,
2067 mike           1.51      Boolean includeQualifiers,
2068 chuck          1.110     const CIMPropertyList& propertyList,
2069 kumpf          1.155     const ContentLanguageList& contentLangs)
2070 mike           1.48  {
2071 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::modifyInstance");
2072                      
2073 mike           1.184     WriteLock lock(_rep->_lock);
2074                          AutoFileLock fileLock(_rep->_lockFile);
2075 kumpf          1.104 
2076 mike           1.53      //
2077                          // Do this:
2078                          //
2079 mike           1.51  
2080                          String errMessage;
2081 mike           1.53      CIMInstance cimInstance;   // The instance that replaces the original
2082 mike           1.51  
2083                          if (propertyList.isNull())
2084                          {
2085                              //
2086                              // Replace all the properties in the instance
2087                              //
2088                              if (includeQualifiers)
2089                              {
2090                                  //
2091                                  // Replace the entire instance with the given instance
2092                                  // (this is the default behavior)
2093                                  //
2094 kumpf          1.70              cimInstance = modifiedInstance;
2095 mike           1.51          }
2096                              else
2097                              {
2098                                  //
2099                                  // Replace all the properties in the instance, but keep the
2100                                  // original qualifiers on the instance and on the properties
2101                                  //
2102                      
2103 mike           1.184             _rep->_resolveInstance = false;
2104 mike           1.55  
2105 kumpf          1.104             cimInstance = _getInstance(
2106                                      nameSpace,
2107                                      modifiedInstance.getPath (),
2108                                      false,
2109                                      true,
2110                                      true,
2111                                      CIMPropertyList());
2112 mike           1.55  
2113 mike           1.184             _rep->_resolveInstance = true;
2114 mike           1.54  
2115 mike           1.51              CIMInstance newInstance(
2116 kumpf          1.70                  modifiedInstance.getPath ().getClassName());
2117 mike           1.54  
2118 kumpf          1.70              CIMInstance givenInstance = modifiedInstance;
2119 mike           1.51  
2120                                  //
2121                                  // Copy over the original instance qualifiers
2122                                  //
2123 mike           1.54  
2124                                  for (Uint32 i = 0; i < cimInstance.getQualifierCount(); i++)
2125 mike           1.51              {
2126                                      newInstance.addQualifier(cimInstance.getQualifier(i));
2127                                  }
2128                      
2129                                  //
2130                                  // Loop through the properties replacing each property in the
2131                                  // original with a new value, but keeping the original qualifiers
2132                                  //
2133                                  for (Uint32 i=0; i<givenInstance.getPropertyCount(); i++)
2134                                  {
2135                                      // Copy the given property value (not qualifiers)
2136                                      CIMProperty givenProperty = givenInstance.getProperty(i);
2137                                      CIMProperty newProperty(
2138                                          givenProperty.getName(),
2139                                          givenProperty.getValue(),
2140                                          givenProperty.getArraySize(),
2141                                          givenProperty.getReferenceClassName(),
2142                                          givenProperty.getClassOrigin(),
2143                                          givenProperty.getPropagated());
2144                      
2145                                      // Copy the original property qualifiers
2146 mike           1.51                  Uint32 origPos =
2147                                          cimInstance.findProperty(newProperty.getName());
2148                                      if (origPos != PEG_NOT_FOUND)
2149                                      {
2150                                          CIMProperty origProperty = cimInstance.getProperty(origPos);
2151                                          for (Uint32 j=0; j<origProperty.getQualifierCount(); j++)
2152                                          {
2153 r.kieninger    1.133                         newProperty.addQualifier(origProperty.getQualifier(j));
2154 mike           1.51                      }
2155                                      }
2156                      
2157                                      // Add the newly constructed property to the new instance
2158                                      newInstance.addProperty(newProperty);
2159                                  }
2160                      
2161                                  // Use the newly merged instance to replace the original instance
2162                                  cimInstance = newInstance;
2163                              }
2164                          }
2165                          else
2166                          {
2167                              //
2168                              // Replace only the properties specified in the given instance
2169                              //
2170                      
2171 mike           1.184         _rep->_resolveInstance = false;
2172 mike           1.55  
2173 kumpf          1.104         cimInstance = _getInstance(nameSpace,
2174                                  modifiedInstance.getPath (), false, true, true, CIMPropertyList());
2175 mike           1.55  
2176 mike           1.184         _rep->_resolveInstance = true;
2177 mike           1.55  
2178 kumpf          1.70          CIMInstance givenInstance = modifiedInstance;
2179 mike           1.51  
2180                              // NOTE: Instance qualifiers are not changed when a property list
2181                              // is specified.  Property qualifiers are replaced with the
2182                              // corresponding property values.
2183                      
2184                              //
2185                              // Loop through the propertyList replacing each property in the original
2186                              //
2187 mike           1.53  
2188 kumpf          1.74          for (Uint32 i=0; i<propertyList.size(); i++)
2189 mike           1.51          {
2190 kumpf          1.74              Uint32 origPropPos = cimInstance.findProperty(propertyList[i]);
2191 mike           1.51              if (origPropPos != PEG_NOT_FOUND)
2192                                  {
2193                                      // Case: Property set in original
2194                                      CIMProperty origProperty =
2195                                          cimInstance.getProperty(origPropPos);
2196                      
2197                                      // Get the given property value
2198                                      Uint32 givenPropPos =
2199 kumpf          1.74                      givenInstance.findProperty(propertyList[i]);
2200 mike           1.51                  if (givenPropPos != PEG_NOT_FOUND)
2201                                      {
2202                                          // Case: Property set in original and given
2203                                          CIMProperty givenProperty =
2204                                              givenInstance.getProperty(givenPropPos);
2205                      
2206                                          // Copy over the property from the given to the original
2207                                          if (includeQualifiers)
2208                                          {
2209                                              // Case: Total property replacement
2210                                              cimInstance.removeProperty(origPropPos);
2211                                              cimInstance.addProperty(givenProperty);
2212                                          }
2213                                          else
2214                                          {
2215                                              // Case: Replace only the property value (not quals)
2216                                              origProperty.setValue(givenProperty.getValue());
2217                                              cimInstance.removeProperty(origPropPos);
2218                                              cimInstance.addProperty(origProperty);
2219                                          }
2220                                      }
2221 mike           1.51                  else
2222                                      {
2223                                          // Case: Property set in original and not in given
2224                                          // Just remove the property (set to null)
2225                                          cimInstance.removeProperty(origPropPos);
2226                                      }
2227                                  }
2228                                  else
2229                                  {
2230                                      // Case: Property not set in original
2231                      
2232                                      // Get the given property value
2233                                      Uint32 givenPropPos =
2234 kumpf          1.74                      givenInstance.findProperty(propertyList[i]);
2235 mike           1.51                  if (givenPropPos != PEG_NOT_FOUND)
2236                                      {
2237                                          // Case: Property set in given and not in original
2238                                          CIMProperty givenProperty =
2239                                              givenInstance.getProperty(givenPropPos);
2240                      
2241                                          // Copy over the property from the given to the original
2242                                          if (includeQualifiers)
2243                                          {
2244                                              // Case: Total property copy
2245                                              cimInstance.addProperty(givenProperty);
2246                                          }
2247                                          else
2248                                          {
2249                                              // Case: Copy only the property value (not qualifiers)
2250                                              CIMProperty newProperty(
2251                                                  givenProperty.getName(),
2252                                                  givenProperty.getValue(),
2253                                                  givenProperty.getArraySize(),
2254                                                  givenProperty.getReferenceClassName(),
2255                                                  givenProperty.getClassOrigin(),
2256 mike           1.51                              givenProperty.getPropagated());
2257                                              cimInstance.addProperty(newProperty);
2258                                          }
2259                                      }
2260                                      else
2261                                      {
2262                                          // Case: Property not set in original or in given
2263                      
2264                                          // Nothing to do; just make sure the property name is valid
2265                                          // ATTN: This is not the most efficient solution
2266                                          CIMClass cimClass = getClass(
2267                                              nameSpace, cimInstance.getClassName(), false);
2268 kumpf          1.74                      if (cimClass.findProperty(propertyList[i]) == PEG_NOT_FOUND)
2269 mike           1.51                      {
2270                                              // ATTN: This exception may be returned by setProperty
2271 kumpf          1.58                          PEG_METHOD_EXIT();
2272 mike           1.51                          throw PEGASUS_CIM_EXCEPTION(
2273                                                  CIM_ERR_NO_SUCH_PROPERTY, "modifyInstance()");
2274                                          }
2275                                      }
2276                                  }
2277                              }
2278                          }
2279                      
2280 mike           1.53      //
2281 mike           1.54      // Resolve the instance (do not propagate qualifiers from class since
2282                          // this will bloat the instance).
2283 mike           1.53      //
2284 mike           1.48  
2285                          CIMConstClass cimClass;
2286 mike           1.184     Resolver::resolveInstance(
2287                              cimInstance, _rep->_context, nameSpace, cimClass, false);
2288 mike           1.48  
2289 kumpf          1.81      CIMObjectPath instanceName = cimInstance.buildPath(cimClass);
2290 mike           1.51  
2291 mike           1.53      //
2292                          // Disallow operation if the instance name was changed:
2293                          //
2294 mike           1.51  
2295 kumpf          1.165     // For bugzilla 1508. Hostname and namespace are not included
2296 r.kieninger    1.122     // in the comparison here.
2297                          CIMObjectPath modifiedInstancePath = modifiedInstance.getPath();
2298                          modifiedInstancePath.setNameSpace(CIMNamespaceName());
2299                          modifiedInstancePath.setHost(String::EMPTY);
2300                          if (instanceName != modifiedInstancePath)
2301 mike           1.51      {
2302 kumpf          1.58          PEG_METHOD_EXIT();
2303 kumpf          1.99          throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
2304                                  MessageLoaderParms(
2305                                      "Repository.CIMRepository.ATTEMPT_TO_MODIFY_KEY_PROPERTY",
2306                                      "Attempted to modify a key property"));
2307 mike           1.51      }
2308                      
2309 kumpf          1.168     //
2310                          // Get paths of index and data files:
2311                          //
2312                      
2313 mike           1.184     String indexFilePath = _rep->_getInstanceIndexFilePath(
2314 kumpf          1.168         nameSpace, modifiedInstance.getClassName());
2315                      
2316 mike           1.184     String dataFilePath = _rep->_getInstanceDataFilePath(
2317 kumpf          1.168         nameSpace, modifiedInstance.getClassName());
2318                      
2319                          //
2320                          // Look up the specified instance
2321                          //
2322                      
2323 mike           1.51      Uint32 oldSize;
2324                          Uint32 oldIndex;
2325                          Uint32 newSize;
2326                          Uint32 newIndex;
2327 mike           1.48  
2328 mike           1.53      if (!InstanceIndexFile::lookupEntry(
2329 kumpf          1.104             indexFilePath, instanceName, oldIndex, oldSize))
2330 mike           1.51      {
2331 kumpf          1.58          PEG_METHOD_EXIT();
2332 mike           1.51          throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString());
2333                          }
2334 mike           1.48  
2335 mike           1.53      //
2336 kumpf          1.168     // Perform the operation in a transaction scope to enable rollback on
2337                          // failure.
2338                          //
2339                      
2340                          InstanceTransactionHandler transaction(indexFilePath, dataFilePath);
2341                      
2342                          //
2343 mike           1.53      // Modify the data file:
2344                          //
2345                      
2346                          {
2347 mike           1.150         Buffer out;
2348 mike           1.184         _rep->_streamer->encode(out, cimInstance);
2349 schuur         1.114         //XmlWriter::appendInstanceElement(out, cimInstance);
2350 kumpf          1.104 
2351 kumpf          1.172         newSize = out.size();
2352 kumpf          1.104 
2353                              if (!InstanceDataFile::appendInstance(dataFilePath, out, newIndex))
2354                              {
2355                                  PEG_METHOD_EXIT();
2356                                  throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
2357                                      MessageLoaderParms(
2358                                          "Repository.CIMRepository.FAILED_TO_MODIFY_INSTANCE",
2359                                          "Failed to modify instance $0",
2360                                          instanceName.toString()));
2361                              }
2362 mike           1.48      }
2363                      
2364 mike           1.53      //
2365                          // Modify the index file:
2366                          //
2367                      
2368                          Uint32 freeCount;
2369 mike           1.51  
2370 mike           1.53      if (!InstanceIndexFile::modifyEntry(indexFilePath, instanceName, newIndex,
2371                              newSize, freeCount))
2372 mike           1.51      {
2373 kumpf          1.104         PEG_METHOD_EXIT();
2374                              throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
2375                                  MessageLoaderParms(
2376                                      "Repository.CIMRepository.FAILED_TO_MODIFY_INSTANCE",
2377                                      "Failed to modify instance $0",
2378                                      instanceName.toString()));
2379 mike           1.51      }
2380                      
2381 mike           1.53      //
2382                          // Compact the index and data files if the free count max was
2383                          // reached.
2384                          //
2385                      
2386 dmitry.mikulin 1.179     if (freeCount >= _MAX_FREE_COUNT)
2387                          {
2388 kumpf          1.104         _CompactInstanceRepository(indexFilePath, dataFilePath);
2389 dmitry.mikulin 1.179     }
2390                      
2391                          transaction.complete();
2392 mike           1.54  
2393                          //
2394                          // Resolve the instance:
2395                          //
2396                      
2397 mike           1.184     Resolver::resolveInstance (
2398                              cimInstance, _rep->_context, nameSpace, cimClass, true);
2399 kumpf          1.58  
2400                          PEG_METHOD_EXIT();
2401 mike           1.48  }
2402                      
2403                      Array<CIMClass> CIMRepository::enumerateClasses(
2404 kumpf          1.85      const CIMNamespaceName& nameSpace,
2405                          const CIMName& className,
2406 mike           1.48      Boolean deepInheritance,
2407                          Boolean localOnly,
2408                          Boolean includeQualifiers,
2409                          Boolean includeClassOrigin)
2410                      {
2411 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::enumerateClasses");
2412 mike           1.51  
2413 mike           1.184     ReadLock lock(_rep->_lock);
2414 kumpf          1.104 
2415 kumpf          1.85      Array<CIMName> classNames;
2416 mike           1.48  
2417 mike           1.184     _rep->_nameSpaceManager.getSubClassNames(
2418 mike           1.51          nameSpace, className, deepInheritance, classNames);
2419 mike           1.48  
2420                          Array<CIMClass> result;
2421                      
2422                          for (Uint32 i = 0; i < classNames.size(); i++)
2423                          {
2424 kumpf          1.104         result.append(_getClass(nameSpace, classNames[i], localOnly,
2425                                  includeQualifiers, includeClassOrigin, CIMPropertyList()));
2426 mike           1.48      }
2427                      
2428 kumpf          1.58      PEG_METHOD_EXIT();
2429 mike           1.48      return result;
2430                      }
2431                      
2432 kumpf          1.85  Array<CIMName> CIMRepository::enumerateClassNames(
2433                          const CIMNamespaceName& nameSpace,
2434                          const CIMName& className,
2435 mike           1.48      Boolean deepInheritance)
2436                      {
2437 kumpf          1.59      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::enumerateClassNames");
2438 kumpf          1.58  
2439 mike           1.184     ReadLock lock(_rep->_lock);
2440 kumpf          1.104 
2441 kumpf          1.85      Array<CIMName> classNames;
2442 mike           1.48  
2443 mike           1.184     _rep->_nameSpaceManager.getSubClassNames(
2444 schuur         1.112         nameSpace, className, deepInheritance, classNames,true);
2445 mike           1.48  
2446 kumpf          1.58      PEG_METHOD_EXIT();
2447 mike           1.48      return classNames;
2448                      }
2449                      
2450 mike           1.184 Boolean CIMRepositoryRep::_loadAllInstances(
2451 kumpf          1.85      const CIMNamespaceName& nameSpace,
2452                          const CIMName& className,
2453 kumpf          1.70      Array<CIMInstance>& namedInstances)
2454 mike           1.53  {
2455 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_loadAllInstances");
2456                      
2457 kumpf          1.68      Array<CIMObjectPath> instanceNames;
2458 mike           1.150     Buffer data;
2459 mike           1.53      Array<Uint32> indices;
2460                          Array<Uint32> sizes;
2461                      
2462                          //
2463 kumpf          1.165     // Form the names of the instance index and data files
2464 mike           1.53      //
2465                      
2466                          String indexFilePath = _getInstanceIndexFilePath(nameSpace, className);
2467                          String dataFilePath = _getInstanceDataFilePath(nameSpace, className);
2468                      
2469                          //
2470                          // Enumerate the index file:
2471                          //
2472                      
2473                          Array<Uint32> freeFlags;
2474                      
2475                          if (!InstanceIndexFile::enumerateEntries(
2476                              indexFilePath, freeFlags, indices, sizes, instanceNames, true))
2477                          {
2478 kumpf          1.58          PEG_METHOD_EXIT();
2479 mike           1.53          return false;
2480                          }
2481                      
2482                          //
2483                          // Form the array of instances result:
2484                          //
2485                      
2486                          if (instanceNames.size() > 0)
2487                          {
2488 kumpf          1.104         //
2489                              // Load all instances from the data file:
2490                              //
2491 mike           1.53  
2492                              if (!InstanceDataFile::loadAllInstances(dataFilePath, data))
2493 kumpf          1.58          {
2494                                  PEG_METHOD_EXIT();
2495 mike           1.53              return false;
2496 kumpf          1.58          }
2497 kumpf          1.104 
2498 mike           1.53          //
2499                              // for each instance loaded, call XML parser to parse the XML
2500                              // data and create a CIMInstance object.
2501                              //
2502                      
2503                              CIMInstance tmpInstance;
2504                      
2505                              char* buffer = (char*)data.getData();
2506                      
2507                              for (Uint32 i = 0; i < instanceNames.size(); i++)
2508                              {
2509 kumpf          1.104             if (!freeFlags[i])
2510                                  {
2511 a.dunfey       1.170                 Uint32 pos= (Uint32)((&(buffer[indices[i]]))-buffer);
2512 mike           1.184                 _streamer->decode(data, pos, tmpInstance);
2513 kumpf          1.104 
2514 mike           1.184                 Resolver::resolveInstance(
2515                                          tmpInstance, _context, nameSpace, true);
2516 kumpf          1.104                 tmpInstance.setPath (instanceNames[i]);
2517                      
2518                                      namedInstances.append (tmpInstance);
2519                                  }
2520 mike           1.53          }
2521                          }
2522                      
2523 kumpf          1.58      PEG_METHOD_EXIT();
2524 mike           1.53      return true;
2525                      }
2526                      
2527 kumpf          1.163 Array<CIMInstance> CIMRepository::enumerateInstancesForSubtree(
2528 kumpf          1.85      const CIMNamespaceName& nameSpace,
2529                          const CIMName& className,
2530 mike           1.48      Boolean deepInheritance,
2531                          Boolean localOnly,
2532                          Boolean includeQualifiers,
2533                          Boolean includeClassOrigin,
2534 mike           1.51      const CIMPropertyList& propertyList)
2535 mike           1.48  {
2536 kumpf          1.163     PEG_METHOD_ENTER(TRC_REPOSITORY,
2537                              "CIMRepository::enumerateInstancesForSubtree");
2538 kumpf          1.104 
2539 mike           1.184     // It is not necessary to control access to the ReadWriteSem lock here.
2540 kumpf          1.104     // This method calls enumerateInstancesForClass, which does its own
2541                          // access control.
2542                      
2543 karl           1.69      //
2544                          // Get all descendent classes of this class:
2545                          //
2546                      
2547 kumpf          1.85      Array<CIMName> classNames;
2548 kumpf          1.94      classNames.append(className);
2549 mike           1.184     _rep->_nameSpaceManager.getSubClassNames(
2550                              nameSpace, className, true, classNames);
2551 karl           1.69  
2552                          //
2553                          // Get all instances for this class and all its descendent classes
2554                          //
2555 kumpf          1.58  
2556 kumpf          1.70      Array<CIMInstance> namedInstances;
2557 kumpf          1.104 
2558 karl           1.69      for (Uint32 i = 0; i < classNames.size(); i++)
2559 karl           1.65      {
2560 karl           1.101         Array<CIMInstance> localNamedInstances =
2561 kumpf          1.163             enumerateInstancesForClass(nameSpace, classNames[i],
2562                                      false, includeQualifiers, includeClassOrigin, propertyList);
2563                      
2564 karl           1.101         // ATTN: Handles everything but deepInheritance.
2565 kumpf          1.188         for (Uint32 j = 0 ; j < localNamedInstances.size(); j++)
2566 karl           1.101         {
2567 kumpf          1.188             _filterInstance(localNamedInstances[j],
2568 karl           1.101                 propertyList,
2569                                      localOnly,
2570                                      includeQualifiers,
2571                                      includeClassOrigin);
2572                              }
2573                              namedInstances.appendArray(localNamedInstances);
2574 karl           1.65      }
2575 karl           1.98  
2576 karl           1.65      PEG_METHOD_EXIT();
2577                          return namedInstances;
2578 karl           1.69  }
2579 karl           1.65  
2580 kumpf          1.70  Array<CIMInstance> CIMRepository::enumerateInstancesForClass(
2581 kumpf          1.85      const CIMNamespaceName& nameSpace,
2582                          const CIMName& className,
2583 karl           1.69      Boolean localOnly,
2584                          Boolean includeQualifiers,
2585                          Boolean includeClassOrigin,
2586                          const CIMPropertyList& propertyList)
2587                      {
2588 kumpf          1.104     PEG_METHOD_ENTER(TRC_REPOSITORY,
2589 kumpf          1.163         "CIMRepository::enumerateInstancesForClass");
2590 kumpf          1.104 
2591 mike           1.184     ReadLock lock(_rep->_lock);
2592 kumpf          1.104 
2593 mike           1.53      //
2594 kumpf          1.163     // Get all instances for this class
2595 mike           1.53      //
2596 mike           1.48  
2597 kumpf          1.163     Array<CIMInstance> namedInstances;
2598                      
2599 mike           1.184     if (!_rep->_loadAllInstances(nameSpace, className, namedInstances))
2600 karl           1.69      {
2601 kumpf          1.163         PEG_METHOD_EXIT();
2602                              throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
2603                                  MessageLoaderParms(
2604                                      "Repository.CIMRepository.FAILED_TO_LOAD_INSTANCES",
2605                                      "Failed to load instances in class $0",
2606                                      className.getString()));
2607 karl           1.69      }
2608 mike           1.48  
2609 kumpf          1.163     // Do any required filtering of properties, qualifiers, classorigin
2610                          // on the returned instances.
2611                          for (Uint32 i = 0 ; i < namedInstances.size(); i++)
2612                          {
2613                              _filterInstance(namedInstances[i],
2614                                  propertyList,
2615                                  localOnly,
2616                                  includeQualifiers,
2617                                  includeClassOrigin);
2618                          }
2619                      
2620 kumpf          1.58      PEG_METHOD_EXIT();
2621 mike           1.51      return namedInstances;
2622 mike           1.48  }
2623 kumpf          1.104 
2624 kumpf          1.163 Array<CIMObjectPath> CIMRepository::enumerateInstanceNamesForSubtree(
2625 kumpf          1.85      const CIMNamespaceName& nameSpace,
2626                          const CIMName& className)
2627 mike           1.48  {
2628 kumpf          1.163     PEG_METHOD_ENTER(TRC_REPOSITORY,
2629                              "CIMRepository::enumerateInstanceNamesForSubtree");
2630 mike           1.51  
2631 mike           1.184     // It is not necessary to control access to the ReadWriteSem lock here.
2632 kumpf          1.165     // This method calls enumerateInstanceNamesForClass, which does its own
2633                          // access control.
2634 kumpf          1.104 
2635 karl           1.65      //
2636 karl           1.69      // Get names of descendent classes:
2637 karl           1.65      //
2638 kumpf          1.165 
2639 kumpf          1.85      Array<CIMName> classNames;
2640 kumpf          1.94      classNames.append(className);
2641 mike           1.184     _rep->_nameSpaceManager.getSubClassNames(
2642                              nameSpace, className, true, classNames);
2643 karl           1.65  
2644                          //
2645 kumpf          1.165     // Enumerate instance names for each of the subclasses
2646 karl           1.65      //
2647 karl           1.69      Array<CIMObjectPath> instanceNames;
2648 karl           1.65  
2649 karl           1.69      for (Uint32 i = 0; i < classNames.size(); i++)
2650                          {
2651 kumpf          1.165         instanceNames.appendArray(
2652                                  enumerateInstanceNamesForClass(nameSpace, classNames[i]));
2653 karl           1.65      }
2654                      
2655 karl           1.69      PEG_METHOD_EXIT();
2656                          return instanceNames;
2657                      }
2658                      
2659                      Array<CIMObjectPath> CIMRepository::enumerateInstanceNamesForClass(
2660 kumpf          1.85      const CIMNamespaceName& nameSpace,
2661 kumpf          1.163     const CIMName& className)
2662 karl           1.69  {
2663 kumpf          1.104     PEG_METHOD_ENTER(TRC_REPOSITORY,
2664 kumpf          1.163         "CIMRepository::enumerateInstanceNamesForClass");
2665 kumpf          1.104 
2666 mike           1.184     ReadLock lock(_rep->_lock);
2667 karl           1.69  
2668 mike           1.53      //
2669 kumpf          1.163     // Get instance names from the instance index file for the class:
2670 mike           1.53      //
2671 kumpf          1.68      Array<CIMObjectPath> instanceNames;
2672 mike           1.48      Array<Uint32> indices;
2673 mike           1.51      Array<Uint32> sizes;
2674 mike           1.48  
2675 kumpf          1.163     //
2676 kumpf          1.165     // Form the names of the instance index and data files
2677 kumpf          1.163     //
2678 mike           1.48  
2679 mike           1.184     String indexFilePath = _rep->_getInstanceIndexFilePath(nameSpace,className);
2680                          String dataFilePath = _rep->_getInstanceDataFilePath(nameSpace, className);
2681 mike           1.48  
2682 kumpf          1.163     //
2683                          // Get all instances for the class:
2684                          //
2685 mike           1.53  
2686 kumpf          1.163     Array<Uint32> freeFlags;
2687 mike           1.48  
2688 kumpf          1.163     if (!InstanceIndexFile::enumerateEntries(
2689                              indexFilePath, freeFlags, indices, sizes, instanceNames, false))
2690                          {
2691                              PEG_METHOD_EXIT();
2692                              throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
2693                                  MessageLoaderParms(
2694                                      "Repository.CIMRepository.FAILED_TO_LOAD_INSTANCE_NAMES",
2695                                      "Failed to load instance names in class $0",
2696                                      className.getString()));
2697 mike           1.48      }
2698 mike           1.53  
2699 kumpf          1.52      PEG_METHOD_EXIT();
2700 mike           1.48      return instanceNames;
2701                      }
2702 karl           1.69  
2703 mike           1.48  
2704 kumpf          1.71  Array<CIMObject> CIMRepository::associators(
2705 kumpf          1.85      const CIMNamespaceName& nameSpace,
2706 kumpf          1.68      const CIMObjectPath& objectName,
2707 kumpf          1.85      const CIMName& assocClass,
2708                          const CIMName& resultClass,
2709 mike           1.48      const String& role,
2710                          const String& resultRole,
2711                          Boolean includeQualifiers,
2712                          Boolean includeClassOrigin,
2713 mike           1.51      const CIMPropertyList& propertyList)
2714 mike           1.48  {
2715 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::associators");
2716                      
2717 mike           1.184     ReadLock lock(_rep->_lock);
2718 kumpf          1.104 
2719                          Array<CIMObjectPath> names = _associatorNames(
2720 mike           1.51          nameSpace,
2721                              objectName,
2722                              assocClass,
2723                              resultClass,
2724                              role,
2725                              resultRole);
2726 mike           1.48  
2727 kumpf          1.71      Array<CIMObject> result;
2728 mike           1.48  
2729                          for (Uint32 i = 0, n = names.size(); i < n; i++)
2730                          {
2731 kumpf          1.85          CIMNamespaceName tmpNameSpace = names[i].getNameSpace();
2732 mike           1.48  
2733 kumpf          1.85          if (tmpNameSpace.isNull())
2734 mike           1.51              tmpNameSpace = nameSpace;
2735 mike           1.48  
2736 kumpf          1.80          //
2737                              //  ATTN-CAKG-P2-20020726:  The following condition does not correctly
2738                              //  distinguish instanceNames from classNames in every case
2739                              //  The instanceName of a singleton instance of a keyless class also
2740                              //  has no key bindings
2741                              //
2742                              if (names[i].getKeyBindings ().size () == 0)
2743 mike           1.51          {
2744 kumpf          1.68              CIMObjectPath tmpRef = names[i];
2745 mike           1.51              tmpRef.setHost(String());
2746 kumpf          1.95              tmpRef.setNameSpace(CIMNamespaceName());
2747 mike           1.51  
2748 kumpf          1.104             CIMClass cimClass = _getClass(
2749 mike           1.51                  tmpNameSpace,
2750                                      tmpRef.getClassName(),
2751                                      false,
2752                                      includeQualifiers,
2753                                      includeClassOrigin,
2754                                      propertyList);
2755                      
2756                                  CIMObject cimObject(cimClass);
2757 kumpf          1.71              cimObject.setPath (names[i]);
2758                                  result.append(cimObject);
2759 mike           1.51          }
2760                              else
2761                              {
2762 kumpf          1.68              CIMObjectPath tmpRef = names[i];
2763 mike           1.51              tmpRef.setHost(String());
2764 kumpf          1.95              tmpRef.setNameSpace(CIMNamespaceName());
2765 mike           1.51  
2766 kumpf          1.104             CIMInstance cimInstance = _getInstance(
2767 mike           1.51                  tmpNameSpace,
2768                                      tmpRef,
2769                                      false,
2770                                      includeQualifiers,
2771                                      includeClassOrigin,
2772                                      propertyList);
2773                      
2774                                  CIMObject cimObject(cimInstance);
2775 kumpf          1.71              cimObject.setPath (names[i]);
2776                                  result.append(cimObject);
2777 mike           1.51          }
2778 mike           1.48      }
2779                      
2780 kumpf          1.58      PEG_METHOD_EXIT();
2781 mike           1.48      return result;
2782                      }
2783                      
2784 kumpf          1.68  Array<CIMObjectPath> CIMRepository::associatorNames(
2785 kumpf          1.85      const CIMNamespaceName& nameSpace,
2786 kumpf          1.68      const CIMObjectPath& objectName,
2787 kumpf          1.85      const CIMName& assocClass,
2788                          const CIMName& resultClass,
2789 mike           1.48      const String& role,
2790                          const String& resultRole)
2791                      {
2792 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::associatorNames");
2793 mike           1.51  
2794 mike           1.184     ReadLock lock(_rep->_lock);
2795 kumpf          1.104     Array<CIMObjectPath> result = _associatorNames(
2796                              nameSpace, objectName, assocClass, resultClass, role, resultRole);
2797                      
2798                          PEG_METHOD_EXIT();
2799                          return result;
2800                      }
2801                      
2802                      Array<CIMObjectPath> CIMRepository::_associatorNames(
2803                          const CIMNamespaceName& nameSpace,
2804                          const CIMObjectPath& objectName,
2805                          const CIMName& assocClass,
2806                          const CIMName& resultClass,
2807                          const String& role,
2808                          const String& resultRole)
2809                      {
2810                          PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_associatorNames");
2811                      
2812 mike           1.48      Array<String> associatorNames;
2813                      
2814 kumpf          1.93      // The assocClass parameter implies subclasses, so retrieve them
2815                          Array<CIMName> assocClassList;
2816                          if (!assocClass.isNull())
2817                          {
2818 mike           1.184         _rep->_nameSpaceManager.getSubClassNames(
2819 kumpf          1.93              nameSpace, assocClass, true, assocClassList);
2820                              assocClassList.append(assocClass);
2821                          }
2822                      
2823                          // The resultClass parameter implies subclasses, so retrieve them
2824                          Array<CIMName> resultClassList;
2825                          if (!resultClass.isNull())
2826                          {
2827 mike           1.184         _rep->_nameSpaceManager.getSubClassNames(
2828 kumpf          1.93              nameSpace, resultClass, true, resultClassList);
2829                              resultClassList.append(resultClass);
2830                          }
2831                      
2832 kumpf          1.80      //
2833                          //  ATTN-CAKG-P2-20020726:  The following condition does not correctly
2834                          //  distinguish instanceNames from classNames in every case
2835                          //  The instanceName of a singleton instance of a keyless class also
2836                          //  has no key bindings
2837                          //
2838                          if (objectName.getKeyBindings ().size () == 0)
2839 mike           1.48      {
2840 kumpf          1.93          CIMName className = objectName.getClassName();
2841                      
2842                              Array<CIMName> classList;
2843 mike           1.184         _rep->_nameSpaceManager.getSuperClassNames(
2844                                  nameSpace, className, classList);
2845 kumpf          1.93          classList.append(className);
2846                      
2847 kumpf          1.169         Array<String> assocFileName =
2848 mike           1.184             _rep->_nameSpaceManager.getAssocClassPath(nameSpace,NameSpaceRead);
2849 mike           1.48  
2850 kumpf          1.169         for (int i=0,m=assocFileName.size(); i<m; i++)
2851                              {
2852                                  AssocClassTable::getAssociatorNames(
2853                                      assocFileName[i],
2854                                      classList,
2855                                      assocClassList,
2856                                      resultClassList,
2857                                      role,
2858                                      resultRole,
2859                                      associatorNames);
2860                              }
2861 mike           1.48      }
2862 kumpf          1.169     else
2863                          {
2864 mike           1.184         String assocFileName = _rep->_nameSpaceManager.getAssocInstPath(
2865                                  nameSpace);
2866 mike           1.48  
2867 mike           1.51          AssocInstTable::getAssociatorNames(
2868                                  assocFileName,
2869                                  objectName,
2870 kumpf          1.93              assocClassList,
2871                                  resultClassList,
2872 mike           1.51              role,
2873                                  resultRole,
2874                                  associatorNames);
2875 mike           1.48      }
2876                      
2877 kumpf          1.68      Array<CIMObjectPath> result;
2878 mike           1.48  
2879                          for (Uint32 i = 0, n = associatorNames.size(); i < n; i++)
2880                          {
2881 kumpf          1.68          CIMObjectPath r = associatorNames[i];
2882 mike           1.48  
2883                              if (r.getHost().size() == 0)
2884                                  r.setHost(System::getHostName());
2885                      
2886 kumpf          1.79          if (r.getNameSpace().isNull())
2887 mike           1.48              r.setNameSpace(nameSpace);
2888                      
2889 mike           1.51          result.append(r);
2890 mike           1.48      }
2891                      
2892 kumpf          1.58      PEG_METHOD_EXIT();
2893 mike           1.48      return result;
2894                      }
2895                      
2896 kumpf          1.71  Array<CIMObject> CIMRepository::references(
2897 kumpf          1.85      const CIMNamespaceName& nameSpace,
2898 kumpf          1.68      const CIMObjectPath& objectName,
2899 kumpf          1.85      const CIMName& resultClass,
2900 mike           1.48      const String& role,
2901                          Boolean includeQualifiers,
2902                          Boolean includeClassOrigin,
2903 mike           1.51      const CIMPropertyList& propertyList)
2904 mike           1.48  {
2905 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::references");
2906                      
2907 mike           1.184     ReadLock lock(_rep->_lock);
2908 kumpf          1.104 
2909                          Array<CIMObjectPath> names = _referenceNames(
2910 mike           1.51          nameSpace,
2911                              objectName,
2912                              resultClass,
2913                              role);
2914 mike           1.48  
2915 kumpf          1.71      Array<CIMObject> result;
2916 mike           1.48  
2917                          for (Uint32 i = 0, n = names.size(); i < n; i++)
2918                          {
2919 kumpf          1.85          CIMNamespaceName tmpNameSpace = names[i].getNameSpace();
2920 mike           1.48  
2921 kumpf          1.85          if (tmpNameSpace.isNull())
2922 mike           1.51              tmpNameSpace = nameSpace;
2923 mike           1.48  
2924 mike           1.51          // ATTN: getInstance() should this be able to handle instance names
2925                              // with host names and namespaces?
2926 mike           1.48  
2927 kumpf          1.68          CIMObjectPath tmpRef = names[i];
2928 mike           1.51          tmpRef.setHost(String());
2929 kumpf          1.95          tmpRef.setNameSpace(CIMNamespaceName());
2930 mike           1.51  
2931 kumpf          1.80          //
2932                              //  ATTN-CAKG-P2-20020726:  The following condition does not correctly
2933                              //  distinguish instanceNames from classNames in every case
2934                              //  The instanceName of a singleton instance of a keyless class also
2935                              //  has no key bindings
2936                              //
2937                              if (objectName.getKeyBindings ().size () == 0)
2938 mike           1.51          {
2939 kumpf          1.104             CIMClass cimClass = _getClass(
2940 mike           1.51                  tmpNameSpace,
2941                                      tmpRef.getClassName(),
2942                                      false,
2943                                      includeQualifiers,
2944                                      includeClassOrigin,
2945                                      propertyList);
2946                      
2947 kumpf          1.71              CIMObject cimObject = CIMObject (cimClass);
2948                                  cimObject.setPath (names[i]);
2949                                  result.append (cimObject);
2950 mike           1.51          }
2951                              else
2952                              {
2953 kumpf          1.104             CIMInstance instance = _getInstance(
2954 mike           1.51                  tmpNameSpace,
2955                                      tmpRef,
2956                                      false,
2957                                      includeQualifiers,
2958                                      includeClassOrigin,
2959                                      propertyList);
2960 mike           1.48  
2961 kumpf          1.71              CIMObject cimObject = CIMObject (instance);
2962                                  cimObject.setPath (names[i]);
2963                                  result.append (cimObject);
2964 mike           1.51          }
2965 mike           1.48      }
2966                      
2967 kumpf          1.58      PEG_METHOD_EXIT();
2968 mike           1.48      return result;
2969                      }
2970                      
2971 kumpf          1.68  Array<CIMObjectPath> CIMRepository::referenceNames(
2972 kumpf          1.85      const CIMNamespaceName& nameSpace,
2973 kumpf          1.68      const CIMObjectPath& objectName,
2974 kumpf          1.85      const CIMName& resultClass,
2975 mike           1.48      const String& role)
2976                      {
2977 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::referenceNames");
2978                      
2979 mike           1.184     ReadLock lock(_rep->_lock);
2980 kumpf          1.104     Array<CIMObjectPath> result = _referenceNames(
2981                              nameSpace, objectName, resultClass, role);
2982                      
2983                          PEG_METHOD_EXIT();
2984                          return result;
2985                      }
2986                      
2987                      Array<CIMObjectPath> CIMRepository::_referenceNames(
2988                          const CIMNamespaceName& nameSpace,
2989                          const CIMObjectPath& objectName,
2990                          const CIMName& resultClass,
2991                          const String& role)
2992                      {
2993                          PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_referenceNames");
2994                      
2995 mike           1.48      Array<String> tmpReferenceNames;
2996                      
2997 kumpf          1.93      // The resultClass parameter implies subclasses, so retrieve them
2998                          Array<CIMName> resultClassList;
2999 a.dunfey       1.120 
3000 kumpf          1.169     try
3001 kumpf          1.93      {
3002 kumpf          1.169         if (!resultClass.isNull())
3003                              {
3004 mike           1.184             _rep->_nameSpaceManager.getSubClassNames(
3005 kumpf          1.169                 nameSpace, resultClass, true, resultClassList);
3006                                  resultClassList.append(resultClass);
3007                              }
3008 karl           1.86  
3009 kumpf          1.169         //  ATTN-CAKG-P2-20020726:  The following condition does not correctly
3010                              //  distinguish instanceNames from classNames in every case
3011                              //  The instanceName of a singleton instance of a keyless class also
3012                              //  has no key bindings
3013                              //
3014                              if (objectName.getKeyBindings ().size () == 0)
3015                              {
3016                                  CIMName className = objectName.getClassName();
3017 kumpf          1.93  
3018 kumpf          1.169             Array<CIMName> classList;
3019 mike           1.184             _rep->_nameSpaceManager.getSuperClassNames(
3020 kumpf          1.169                 nameSpace, className, classList);
3021                                  classList.append(className);
3022 kumpf          1.93  
3023 kumpf          1.169             Array<String> assocFileName =
3024 mike           1.184                 _rep->_nameSpaceManager.getAssocClassPath(
3025                                          nameSpace,NameSpaceRead);
3026 mike           1.48  
3027 kumpf          1.169             Boolean refs=false;
3028                                  for (int i = 0, m=assocFileName.size(); !refs && i < m; i++)
3029                                  {
3030                                      if (AssocClassTable::getReferenceNames(
3031                                              assocFileName[i],
3032                                              classList,
3033                                              resultClassList,
3034                                              role,
3035                                              tmpReferenceNames))
3036                                      {
3037                                          refs |= true;
3038                                      }
3039                                  }
3040 schuur         1.112 
3041 kumpf          1.169             if (refs == false)
3042                                  {
3043                                      // Ignore error! It's okay not to have references.
3044                                  }
3045 mike           1.51          }
3046 kumpf          1.169         else
3047                              {
3048                                  String assocFileName =
3049 mike           1.184                 _rep->_nameSpaceManager.getAssocInstPath(nameSpace);
3050 schuur         1.112 
3051 kumpf          1.169             if (!AssocInstTable::getReferenceNames(
3052                                      assocFileName,
3053                                      objectName,
3054                                      resultClassList,
3055                                      role,
3056                                      tmpReferenceNames))
3057                                  {
3058                                      // Ignore error! It's okay not to have references.
3059                                  }
3060 mike           1.51          }
3061 mike           1.48      }
3062 kumpf          1.169     catch (const CIMException& exception)
3063 kumpf          1.142     {
3064 kumpf          1.169         if (exception.getCode() == CIM_ERR_INVALID_CLASS)
3065                              {
3066                                  throw PEGASUS_CIM_EXCEPTION(
3067                                      CIM_ERR_INVALID_PARAMETER, exception.getMessage());
3068                              }
3069                              else
3070                              {
3071                                  throw;
3072                              }
3073 kumpf          1.142     }
3074 mike           1.48  
3075 kumpf          1.68      Array<CIMObjectPath> result;
3076 mike           1.48  
3077                          for (Uint32 i = 0, n = tmpReferenceNames.size(); i < n; i++)
3078                          {
3079 kumpf          1.68          CIMObjectPath r = tmpReferenceNames[i];
3080 mike           1.48  
3081                              if (r.getHost().size() == 0)
3082                                  r.setHost(System::getHostName());
3083                      
3084 kumpf          1.79          if (r.getNameSpace().isNull())
3085 mike           1.48              r.setNameSpace(nameSpace);
3086                      
3087 mike           1.51          result.append(r);
3088 mike           1.48      }
3089                      
3090 kumpf          1.58      PEG_METHOD_EXIT();
3091 mike           1.48      return result;
3092                      }
3093                      
3094                      CIMValue CIMRepository::getProperty(
3095 kumpf          1.85      const CIMNamespaceName& nameSpace,
3096 kumpf          1.68      const CIMObjectPath& instanceName,
3097 kumpf          1.85      const CIMName& propertyName)
3098 mike           1.48  {
3099 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::getProperty");
3100                      
3101 mike           1.184     ReadLock lock(_rep->_lock);
3102 kumpf          1.104 
3103 mike           1.53      //
3104 kumpf          1.165     // Retrieve the specified instance
3105 mike           1.53      //
3106 mike           1.48  
3107 kumpf          1.165     CIMInstance cimInstance = _getInstance(
3108                              nameSpace, instanceName, false, true, true, CIMPropertyList());
3109 mike           1.48  
3110 mike           1.53      //
3111 kumpf          1.165     // Get the requested property from the instance
3112 mike           1.53      //
3113 mike           1.48  
3114                          Uint32 pos = cimInstance.findProperty(propertyName);
3115                      
3116 mike           1.51      // ATTN: This breaks if the property is simply null
3117 kumpf          1.77      if (pos == PEG_NOT_FOUND)
3118 kumpf          1.58      {
3119                              PEG_METHOD_EXIT();
3120 kumpf          1.149         throw PEGASUS_CIM_EXCEPTION(
3121                                  CIM_ERR_NO_SUCH_PROPERTY,
3122                                  propertyName.getString());
3123 kumpf          1.58      }
3124 mike           1.48  
3125                          CIMProperty prop = cimInstance.getProperty(pos);
3126                      
3127 mike           1.53      //
3128                          // Return the value:
3129                          //
3130 mike           1.48  
3131 kumpf          1.58      PEG_METHOD_EXIT();
3132 mike           1.48      return prop.getValue();
3133                      }
3134                      
3135                      void CIMRepository::setProperty(
3136 kumpf          1.85      const CIMNamespaceName& nameSpace,
3137 kumpf          1.68      const CIMObjectPath& instanceName,
3138 kumpf          1.85      const CIMName& propertyName,
3139 chuck          1.110     const CIMValue& newValue,
3140 kumpf          1.155     const ContentLanguageList& contentLangs)
3141 mike           1.48  {
3142 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::setProperty");
3143                      
3144 mike           1.184     // It is not necessary to control access to the ReadWriteSem lock here.
3145 kumpf          1.104     // This method calls modifyInstance, which does its own access control.
3146                      
3147 mike           1.51      //
3148                          // Create the instance to pass to modifyInstance()
3149                          //
3150 mike           1.53  
3151 mike           1.51      CIMInstance instance(instanceName.getClassName());
3152                          instance.addProperty(CIMProperty(propertyName, newValue));
3153 kumpf          1.70      instance.setPath (instanceName);
3154 mike           1.51  
3155                          //
3156                          // Create the propertyList to pass to modifyInstance()
3157                          //
3158 mike           1.53  
3159 kumpf          1.79      Array<CIMName> propertyListArray;
3160 mike           1.51      propertyListArray.append(propertyName);
3161                          CIMPropertyList propertyList(propertyListArray);
3162                      
3163                          //
3164                          // Modify the instance to set the value of the given property
3165                          //
3166 kumpf          1.70      modifyInstance(nameSpace, instance, false, propertyList);
3167 kumpf          1.58  
3168                          PEG_METHOD_EXIT();
3169 mike           1.48  }
3170                      
3171                      CIMQualifierDecl CIMRepository::getQualifier(
3172 kumpf          1.85      const CIMNamespaceName& nameSpace,
3173                          const CIMName& qualifierName)
3174 mike           1.48  {
3175 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::getQualifier");
3176                      
3177 mike           1.184     ReadLock lock(_rep->_lock);
3178 kumpf          1.104     CIMQualifierDecl qualifierDecl = _getQualifier(nameSpace, qualifierName);
3179                      
3180                          PEG_METHOD_EXIT();
3181                          return qualifierDecl;
3182                      }
3183                      
3184                      CIMQualifierDecl CIMRepository::_getQualifier(
3185                          const CIMNamespaceName& nameSpace,
3186                          const CIMName& qualifierName)
3187                      {
3188                          PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_getQualifier");
3189                      
3190 mike           1.53      //
3191                          // Get path of qualifier file:
3192                          //
3193 mike           1.48  
3194 mike           1.184     String qualifierFilePath = _rep->_nameSpaceManager.getQualifierFilePath(
3195 schuur         1.112         nameSpace, qualifierName,NameSpaceRead);
3196 mike           1.48  
3197 mike           1.53      //
3198                          // Load qualifier:
3199                          //
3200 mike           1.48  
3201                          CIMQualifierDecl qualifierDecl;
3202                      
3203                          try
3204                          {
3205 mike           1.153         // Check the cache first:
3206                      
3207                              if (!_qualifierCache.get(qualifierFilePath, qualifierDecl))
3208                              {
3209                                  // Not in cache so load from disk:
3210                      
3211 mike           1.184             _LoadObject(qualifierFilePath, qualifierDecl, _rep->_streamer);
3212 mike           1.153 
3213                                  // Put in cache:
3214                      
3215                                  _qualifierCache.put(qualifierFilePath, qualifierDecl);
3216                              }
3217 mike           1.48      }
3218 david.dillard  1.141     catch (const CannotOpenFile&)
3219 mike           1.48      {
3220 kumpf          1.58          PEG_METHOD_EXIT();
3221 kumpf          1.85          throw PEGASUS_CIM_EXCEPTION
3222                                  (CIM_ERR_NOT_FOUND, qualifierName.getString());
3223 mike           1.48      }
3224                      
3225 kumpf          1.58      PEG_METHOD_EXIT();
3226 mike           1.48      return qualifierDecl;
3227                      }
3228                      
3229                      void CIMRepository::setQualifier(
3230 kumpf          1.85      const CIMNamespaceName& nameSpace,
3231 chuck          1.110     const CIMQualifierDecl& qualifierDecl,
3232 kumpf          1.155     const ContentLanguageList& contentLangs)
3233 mike           1.48  {
3234 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::setQualifier");
3235 chuck          1.110 
3236 mike           1.184     WriteLock lock(_rep->_lock);
3237                          AutoFileLock fileLock(_rep->_lockFile);
3238 kumpf          1.104     _setQualifier(nameSpace, qualifierDecl);
3239                      
3240                          PEG_METHOD_EXIT();
3241                      }
3242                      
3243                      void CIMRepository::_setQualifier(
3244                          const CIMNamespaceName& nameSpace,
3245                          const CIMQualifierDecl& qualifierDecl)
3246                      {
3247                          PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_setQualifier");
3248                      
3249 mike           1.48      // -- Get path of qualifier file:
3250                      
3251 mike           1.184     String qualifierFilePath = _rep->_nameSpaceManager.getQualifierFilePath(
3252 schuur         1.112         nameSpace, qualifierDecl.getName(),NameSpaceWrite);
3253 mike           1.48  
3254 kumpf          1.75      // -- If qualifier already exists, throw exception:
3255 mike           1.48  
3256                          if (FileSystem::existsNoCase(qualifierFilePath))
3257 mike           1.53      {
3258 kumpf          1.58          PEG_METHOD_EXIT();
3259 mike           1.53          throw PEGASUS_CIM_EXCEPTION(
3260 a.arora        1.107             CIM_ERR_NOT_SUPPORTED, qualifierDecl.getName().getString());
3261 mike           1.53      }
3262 mike           1.48  
3263                          // -- Save qualifier:
3264                      
3265 mike           1.150     Buffer qualifierDeclXml;
3266 mike           1.184     _rep->_streamer->encode(qualifierDeclXml, qualifierDecl);
3267 jim.wunderlich 1.136      //XmlWriter::appendQualifierDeclElement(qualifierDeclXml, qualifierDecl);
3268 mike           1.184     _SaveObject(qualifierFilePath, qualifierDeclXml, _rep->_streamer);
3269 kumpf          1.58  
3270 mike           1.153     _qualifierCache.put(qualifierFilePath, (CIMQualifierDecl&)qualifierDecl);
3271 jim.wunderlich 1.136 
3272 kumpf          1.58      PEG_METHOD_EXIT();
3273 mike           1.48  }
3274                      
3275                      void CIMRepository::deleteQualifier(
3276 kumpf          1.85      const CIMNamespaceName& nameSpace,
3277                          const CIMName& qualifierName)
3278 mike           1.48  {
3279 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::deleteQualifier");
3280                      
3281 mike           1.184     WriteLock lock(_rep->_lock);
3282                          AutoFileLock fileLock(_rep->_lockFile);
3283 kumpf          1.104 
3284 mike           1.48      // -- Get path of qualifier file:
3285                      
3286 mike           1.184     String qualifierFilePath = _rep->_nameSpaceManager.getQualifierFilePath(
3287 schuur         1.112         nameSpace, qualifierName,NameSpaceDelete);
3288 mike           1.48  
3289                          // -- Delete qualifier:
3290                      
3291                          if (!FileSystem::removeFileNoCase(qualifierFilePath))
3292 kumpf          1.58      {
3293                              PEG_METHOD_EXIT();
3294 kumpf          1.85          throw PEGASUS_CIM_EXCEPTION
3295                                  (CIM_ERR_NOT_FOUND, qualifierName.getString());
3296 kumpf          1.58      }
3297                      
3298 mike           1.153     _qualifierCache.evict(qualifierFilePath);
3299                      
3300 kumpf          1.58      PEG_METHOD_EXIT();
3301 mike           1.48  }
3302                      
3303                      Array<CIMQualifierDecl> CIMRepository::enumerateQualifiers(
3304 kumpf          1.85      const CIMNamespaceName& nameSpace)
3305 mike           1.48  {
3306 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::enumerateQualifiers");
3307                      
3308 mike           1.184     ReadLock lock(_rep->_lock);
3309 kumpf          1.104 
3310 mike           1.184     String qualifiersRoot = _rep->_nameSpaceManager.getQualifiersRoot(
3311                              nameSpace);
3312 mike           1.48  
3313                          Array<String> qualifierNames;
3314                      
3315                          if (!FileSystem::getDirectoryContents(qualifiersRoot, qualifierNames))
3316                          {
3317 kumpf          1.58          PEG_METHOD_EXIT();
3318 humberto       1.88          String str ="enumerateQualifiers()";
3319 kumpf          1.99          throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
3320                                  MessageLoaderParms("Repository.CIMRepository.INTERNAL_ERROR",
3321                                      "$0: internal error",
3322                                      str));
3323 mike           1.48      }
3324                      
3325                          Array<CIMQualifierDecl> qualifiers;
3326                      
3327                          for (Uint32 i = 0; i < qualifierNames.size(); i++)
3328                          {
3329 chuck          1.109 #ifdef PEGASUS_REPOSITORY_ESCAPE_UTF8
3330                          // All chars above 0x7F will be escape.
3331                            CIMQualifierDecl qualifier =
3332                                  _getQualifier(nameSpace, escapeStringDecoder(qualifierNames[i]));
3333 chip           1.118 #else
3334 chuck          1.109       CIMQualifierDecl qualifier =
3335 kumpf          1.104             _getQualifier(nameSpace, qualifierNames[i]);
3336 chuck          1.109 #endif
3337                            qualifiers.append(qualifier);
3338 mike           1.48      }
3339                      
3340 kumpf          1.58      PEG_METHOD_EXIT();
3341 mike           1.48      return qualifiers;
3342                      }
3343                      
3344 schuur         1.112 void CIMRepository::createNameSpace(const CIMNamespaceName& nameSpace,
3345 kumpf          1.169         const NameSpaceAttributes& attributes)
3346 mike           1.48  {
3347 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::createNameSpace");
3348                      
3349 mike           1.184     WriteLock lock(_rep->_lock);
3350                          AutoFileLock fileLock(_rep->_lockFile);
3351                          _rep->_nameSpaceManager.createNameSpace(nameSpace, attributes);
3352 schuur         1.112 
3353                          PEG_METHOD_EXIT();
3354                      }
3355                      
3356                      void CIMRepository::modifyNameSpace(const CIMNamespaceName& nameSpace,
3357 kumpf          1.169         const NameSpaceAttributes& attributes)
3358 schuur         1.112 {
3359                          PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::modifyNameSpace");
3360                      
3361 mike           1.184     WriteLock lock(_rep->_lock);
3362                          AutoFileLock fileLock(_rep->_lockFile);
3363                          _rep->_nameSpaceManager.modifyNameSpace(nameSpace, attributes);
3364 kumpf          1.58  
3365                          PEG_METHOD_EXIT();
3366 mike           1.48  }
3367                      
3368 kumpf          1.85  Array<CIMNamespaceName> CIMRepository::enumerateNameSpaces() const
3369 mike           1.48  {
3370 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::enumerateNameSpaces");
3371                      
3372 mike           1.184     ReadLock lock(const_cast<ReadWriteSem&>(_rep->_lock));
3373 kumpf          1.104 
3374 kumpf          1.85      Array<CIMNamespaceName> nameSpaceNames;
3375 mike           1.184     _rep->_nameSpaceManager.getNameSpaceNames(nameSpaceNames);
3376 kumpf          1.58  
3377                          PEG_METHOD_EXIT();
3378 mike           1.48      return nameSpaceNames;
3379                      }
3380                      
3381 kumpf          1.85  void CIMRepository::deleteNameSpace(const CIMNamespaceName& nameSpace)
3382 mike           1.48  {
3383 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::deleteNameSpace");
3384                      
3385 mike           1.184     WriteLock lock(_rep->_lock);
3386                          AutoFileLock fileLock(_rep->_lockFile);
3387                          _rep->_nameSpaceManager.deleteNameSpace(nameSpace);
3388 kumpf          1.58  
3389                          PEG_METHOD_EXIT();
3390 mike           1.48  }
3391                      
3392 schuur         1.112 Boolean CIMRepository::getNameSpaceAttributes(const CIMNamespaceName& nameSpace,
3393 kumpf          1.169         NameSpaceAttributes& attributes)
3394 schuur         1.112 {
3395                          PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::deleteNameSpace");
3396                      
3397 mike           1.184     ReadLock lock(const_cast<ReadWriteSem&>(_rep->_lock));
3398 schuur         1.112     attributes.clear();
3399                          PEG_METHOD_EXIT();
3400 mike           1.184     return _rep->_nameSpaceManager.getNameSpaceAttributes(
3401                              nameSpace, attributes);
3402 schuur         1.112 }
3403                      
3404 schuur         1.115 Boolean CIMRepository::isRemoteNameSpace(const CIMNamespaceName& nameSpaceName,
3405 kumpf          1.169         String& remoteInfo)
3406 schuur         1.115 {
3407                          PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::isRemoteNamespace");
3408 mike           1.184     ReadLock lock(const_cast<ReadWriteSem&>(_rep->_lock));
3409 schuur         1.115     PEG_METHOD_EXIT();
3410 mike           1.184     return _rep->_nameSpaceManager.isRemoteNameSpace(nameSpaceName, remoteInfo);
3411 schuur         1.115 }
3412                      
3413 mike           1.51  //----------------------------------------------------------------------
3414                      //
3415 mike           1.53  // _getInstanceIndexFilePath()
3416 mike           1.51  //
3417 kumpf          1.104 //      returns the file path of the instance index file.
3418 mike           1.51  //
3419                      //----------------------------------------------------------------------
3420                      
3421 mike           1.184 String CIMRepositoryRep::_getInstanceIndexFilePath(
3422 kumpf          1.85      const CIMNamespaceName& nameSpace,
3423                          const CIMName& className) const
3424 mike           1.48  {
3425 kumpf          1.169     PEG_METHOD_ENTER(TRC_REPOSITORY,
3426                              "CIMRepository::_getInstanceIndexFilePath");
3427 kumpf          1.58  
3428 mike           1.53      String tmp = _nameSpaceManager.getInstanceDataFileBase(
3429 kumpf          1.104         nameSpace, className);
3430 mike           1.53  
3431 mike           1.48      tmp.append(".idx");
3432 kumpf          1.58  
3433                          PEG_METHOD_EXIT();
3434 mike           1.48      return tmp;
3435                      }
3436                      
3437 mike           1.51  //----------------------------------------------------------------------
3438                      //
3439 mike           1.53  // _getInstanceDataFilePath()
3440 mike           1.51  //
3441 kumpf          1.104 //      returns the file path of the instance file.
3442 mike           1.51  //
3443                      //----------------------------------------------------------------------
3444                      
3445 mike           1.184 String CIMRepositoryRep::_getInstanceDataFilePath(
3446 kumpf          1.85      const CIMNamespaceName& nameSpace,
3447                          const CIMName& className) const
3448 mike           1.48  {
3449 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_getInstanceDataFilePath");
3450                      
3451 mike           1.53      String tmp = _nameSpaceManager.getInstanceDataFileBase(
3452 kumpf          1.104         nameSpace, className);
3453 mike           1.51      tmp.append(".instances");
3454 kumpf          1.104 
3455 kumpf          1.58      PEG_METHOD_EXIT();
3456 mike           1.48      return tmp;
3457 mike           1.51  }
3458                      
3459 mike           1.184 Boolean CIMRepositoryRep::_loadInstance(
3460 mike           1.51      const String& path,
3461                          CIMInstance& object,
3462                          Uint32 index,
3463                          Uint32 size)
3464                      {
3465 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_loadInstance");
3466                      
3467 mike           1.51      //
3468 mike           1.53      // Load instance (in XML) from instance file into memory:
3469 mike           1.51      //
3470                      
3471 mike           1.150     Buffer data;
3472 mike           1.51  
3473 mike           1.53      if (!InstanceDataFile::loadInstance(path, index, size, data))
3474 kumpf          1.58      {
3475                              PEG_METHOD_EXIT();
3476 mike           1.51          return false;
3477 kumpf          1.58      }
3478 mike           1.51  
3479                          //
3480 mike           1.53      // Convert XML into an actual object:
3481 mike           1.51      //
3482                      
3483 mike           1.184     _streamer->decode(data, 0, object);
3484 mike           1.51  
3485 kumpf          1.58      PEG_METHOD_EXIT();
3486 mike           1.51      return true;
3487 mike           1.48  }
3488                      
3489 bob            1.49  
3490 dave.sudlik    1.154 #ifdef PEGASUS_DEBUG
3491 kumpf          1.169     void CIMRepository::DisplayCacheStatistics()
3492 dave.sudlik    1.154     {
3493                      #ifdef PEGASUS_USE_CLASS_CACHE
3494                              cout << "Repository Class Cache Statistics:" << endl;
3495                              _classCache.DisplayCacheStatistics();
3496                      #endif
3497                              cout << "Repository Qualifier Cache Statistics:" << endl;
3498                              _qualifierCache.DisplayCacheStatistics();
3499                          }
3500                      #endif
3501                      
3502 mike           1.184 void CIMRepository::getSubClassNames(
3503                          const CIMNamespaceName& nameSpaceName,
3504                          const CIMName& className,
3505                          Boolean deepInheritance,
3506                          Array<CIMName>& subClassNames) const
3507                      {
3508                          ReadLock lock(const_cast<ReadWriteSem&>(_rep->_lock));
3509                          _rep->_nameSpaceManager.getSubClassNames(nameSpaceName,
3510                                                             className,
3511                                                             deepInheritance,
3512                                                             subClassNames);
3513                      }
3514                      
3515                      void CIMRepository::getSuperClassNames(
3516                          const CIMNamespaceName& nameSpaceName,
3517                          const CIMName& className,
3518                          Array<CIMName>& subClassNames) const
3519                      {
3520                          ReadLock lock(const_cast<ReadWriteSem&>(_rep->_lock));
3521                          _rep->_nameSpaceManager.getSuperClassNames(
3522                              nameSpaceName, className, subClassNames);
3523 mike           1.184 }
3524                      
3525                      Boolean CIMRepository::isDefaultInstanceProvider()
3526                      {
3527                          return _rep->_isDefaultInstanceProvider;
3528                      }
3529                      
3530 mike           1.48  PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2