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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2