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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2