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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2