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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2