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

   1 karl  1.157 //%2006////////////////////////////////////////////////////////////////////////
   2 mike  1.48  //
   3 karl  1.129 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
   4             // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
   5             // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
   6 karl  1.100 // IBM Corp.; EMC Corporation, The Open Group.
   7 karl  1.129 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
   8             // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
   9 karl  1.132 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
  10             // EMC Corporation; VERITAS Software Corporation; The Open Group.
  11 karl  1.157 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
  12             // EMC Corporation; Symantec Corporation; The Open Group.
  13 mike  1.48  //
  14             // Permission is hereby granted, free of charge, to any person obtaining a copy
  15             // of this software and associated documentation files (the "Software"), to
  16             // deal in the Software without restriction, including without limitation the
  17             // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  18             // sell copies of the Software, and to permit persons to whom the Software is
  19             // furnished to do so, subject to the following conditions:
  20 karl  1.177 //
  21 mike  1.48  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
  22             // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
  23             // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
  24             // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  25             // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  26             // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  27             // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28             // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29             //
  30             //==============================================================================
  31             //
  32             //%/////////////////////////////////////////////////////////////////////////////
  33             
  34 mike  1.51  #include <Pegasus/Common/Config.h>
  35 mike  1.48  #include <cctype>
  36             #include <cstdio>
  37             #include <fstream>
  38 kumpf 1.82  #include <Pegasus/Common/InternalException.h>
  39 schuur 1.114 
  40 mike   1.48  #include <Pegasus/Common/DeclContext.h>
  41 kumpf  1.76  #include <Pegasus/Common/Resolver.h>
  42 mike   1.48  #include <Pegasus/Common/System.h>
  43 kumpf  1.52  #include <Pegasus/Common/Tracer.h>
  44 kumpf  1.63  #include <Pegasus/Common/PegasusVersion.h>
  45 kumpf  1.169 #include <Pegasus/Common/MessageLoader.h>
  46 mike   1.159 #include <Pegasus/Common/ReadWriteSem.h>
  47 kumpf  1.63  
  48 schuur 1.114 #include <Pegasus/Common/XmlStreamer.h>
  49              #include <Pegasus/Common/BinaryStreamer.h>
  50              #include <Pegasus/Common/AutoStreamer.h>
  51              
  52 mike   1.48  #include "CIMRepository.h"
  53              #include "RepositoryDeclContext.h"
  54 mike   1.151 #include "ObjectCache.h"
  55 mike   1.48  
  56 kumpf  1.201 #include "PersistentStore.h"
  57 jim.wunderlich 1.136 
  58 schuur         1.112 #if 0
  59                      #undef PEG_METHOD_ENTER
  60                      #undef PEG_METHOD_EXIT
  61                      #define PEG_METHOD_ENTER(x,y)  cout<<"--- Enter: "<<y<<endl;
  62                      #define PEG_METHOD_EXIT()
  63                      #endif
  64                      
  65 jim.wunderlich 1.138 
  66 mike           1.48  PEGASUS_USING_STD;
  67                      
  68                      PEGASUS_NAMESPACE_BEGIN
  69                      
  70 mike           1.184 class CIMRepositoryRep
  71                      {
  72                      public:
  73                      
  74                          /**
  75                              Checks whether an instance with the specified key values exists in the
  76                              class hierarchy of the specified class.
  77                      
  78                              @param   nameSpace      the namespace of the instance
  79                              @param   instanceName   the name of the instance
  80                      
  81                              @return  true           if the instance is found
  82                                       false          if the instance cannot be found
  83                           */
  84                          Boolean _checkInstanceAlreadyExists(
  85                              const CIMNamespaceName& nameSpace,
  86                              const CIMObjectPath& instanceName) const;
  87                      
  88                          // This must be initialized in the constructor using values from the
  89                          // ConfigManager.
  90                          Boolean _isDefaultInstanceProvider;
  91 mike           1.184 
  92 kumpf          1.189     AutoPtr<ObjectStreamer> _streamer;
  93                      
  94 kumpf          1.201     AutoPtr<PersistentStore> _persistentStore;
  95 kumpf          1.189 
  96 kumpf          1.195     /**
  97                              Indicates whether the class definitions in the persistent store are
  98                              complete (contain propagated elements).
  99                          */
 100                          Boolean _storeCompleteClassDefinitions;
 101                      
 102 kumpf          1.192     NameSpaceManager _nameSpaceManager;
 103 mike           1.184 
 104                          ReadWriteSem _lock;
 105                      
 106                          RepositoryDeclContext* _context;
 107                      
 108                          CString _lockFile;
 109                      };
 110                      
 111 kumpf          1.142 // #define TEST_OUTPUT
 112 jim.wunderlich 1.134 
 113 mike           1.151 //==============================================================================
 114                      //
 115                      // This is the class cache, which caches up PEGASUS_CLASS_CACHE_SIZE classes
 116                      // into memory. To override the default, define PEGASUS_CLASS_CACHE_SIZE in
 117                      // your environment. To supress the cache (and not compile it in at all)
 118                      // define PEGASUS_CLASS_CACHE_SIZE to 0.
 119                      //
 120                      //==============================================================================
 121                      
 122 mike           1.153 #define PEGASUS_QUALIFIER_CACHE_SIZE 80
 123                      
 124 mike           1.151 #if !defined(PEGASUS_CLASS_CACHE_SIZE)
 125 kumpf          1.195 # define PEGASUS_CLASS_CACHE_SIZE 32
 126 mike           1.151 #endif
 127                      
 128                      #if (PEGASUS_CLASS_CACHE_SIZE != 0)
 129                      # define PEGASUS_USE_CLASS_CACHE
 130                      #endif
 131                      
 132                      #ifdef PEGASUS_USE_CLASS_CACHE
 133                      static ObjectCache<CIMClass> _classCache(PEGASUS_CLASS_CACHE_SIZE);
 134                      #endif /* PEGASUS_USE_CLASS_CACHE */
 135                      
 136 kumpf          1.169 static ObjectCache<CIMQualifierDecl>
 137 mike           1.153     _qualifierCache(PEGASUS_QUALIFIER_CACHE_SIZE);
 138                      
 139 kumpf          1.189 static String _getCacheKey(
 140                          const CIMNamespaceName& nameSpace,
 141                          const CIMName& entryName)
 142 jim.wunderlich 1.136 {
 143 kumpf          1.189     return nameSpace.getString() + ":" + entryName.getString();
 144 jim.wunderlich 1.136 }
 145                      
 146                      
 147 karl           1.101 //
 148                      //  The following _xx functions are local to the repository implementation
 149                      //
 150 mike           1.48  ////////////////////////////////////////////////////////////////////////////////
 151                      //
 152 kumpf          1.104 //   _containsProperty
 153 karl           1.97  //
 154                      ////////////////////////////////////////////////////////////////////////////////
 155 karl           1.101 
 156                      /** Check to see if the specified property is in the property list
 157 kumpf          1.104     @param property the specified property
 158 karl           1.101     @param propertyList the property list
 159 kumpf          1.104     @return true if the property is in the list otherwise false.
 160 karl           1.101 */
 161 kumpf          1.189 static Boolean _containsProperty(
 162 kumpf          1.195     const CIMProperty& property,
 163 kumpf          1.169     const CIMPropertyList& propertyList)
 164 karl           1.97  {
 165 kumpf          1.104     //  For each property in the propertly list
 166                          for (Uint32 p=0; p<propertyList.size(); p++)
 167                          {
 168                              if (propertyList[p].equal(property.getName()))
 169                                  return true;
 170                          }
 171                          return false;
 172 karl           1.97  }
 173                      
 174 karl           1.98  ////////////////////////////////////////////////////////////////////////////////
 175                      //
 176                      // removeAllQualifiers - Remove all of the qualifiers from a class
 177                      //
 178                      ////////////////////////////////////////////////////////////////////////////////
 179 karl           1.101 
 180                      /* removes all Qualifiers from a CIMClass.  This function removes all
 181                         of the qualifiers from the class, from all of the properties,
 182                         from the methods, and from the parameters attached to the methods.
 183                         @param cimClass reference to the class from which qualifiers are to
 184                         be removed.
 185 kumpf          1.169    NOTE: This would be logical to be moved to CIMClass since it may be
 186                         more general than this usage.
 187 karl           1.101 */
 188 kumpf          1.189 static void _removeAllQualifiers(CIMClass& cimClass)
 189 karl           1.98  {
 190 kumpf          1.104     // remove qualifiers of the class
 191                          Uint32 count = 0;
 192 kumpf          1.169     while ((count = cimClass.getQualifierCount()) > 0)
 193 kumpf          1.104         cimClass.removeQualifier(count - 1);
 194                      
 195                          // remove qualifiers from the properties
 196                          for (Uint32 i = 0; i < cimClass.getPropertyCount(); i++)
 197                          {
 198                              CIMProperty p = cimClass.getProperty(i);
 199 kumpf          1.169         count = 0;
 200                              while ((count = p.getQualifierCount()) > 0)
 201 kumpf          1.104             p.removeQualifier(count - 1);
 202                          }
 203 kumpf          1.169 
 204 kumpf          1.104     // remove qualifiers from the methods
 205                          for (Uint32 i = 0; i < cimClass.getMethodCount(); i++)
 206                          {
 207                              CIMMethod m = cimClass.getMethod(i);
 208                              for (Uint32 j = 0 ; j < m.getParameterCount(); j++)
 209                              {
 210                                  CIMParameter p = m.getParameter(j);
 211                                  count = 0;
 212                                  while ((count = p.getQualifierCount()) > 0)
 213                                      p.removeQualifier(count - 1);
 214                              }
 215 kumpf          1.169         count = 0;
 216                              while ((count = m.getQualifierCount()) > 0)
 217 kumpf          1.104             m.removeQualifier(count - 1);
 218                          }
 219 karl           1.98  }
 220                      
 221                      /////////////////////////////////////////////////////////////////////////
 222                      //
 223 kumpf          1.195 // _stripPropagatedElements
 224 karl           1.98  //
 225                      /////////////////////////////////////////////////////////////////////////
 226 karl           1.101 
 227 kumpf          1.195 /* Removes propagated elements from the CIMClass, including properties,
 228                         methods, and qualifiers attached to the class, properties, methods, and
 229                         parameters.
 230 karl           1.101 */
 231 kumpf          1.195 static void _stripPropagatedElements(CIMClass& cimClass)
 232 karl           1.98  {
 233 kumpf          1.195     // Remove the propagated qualifiers from the class.
 234                          // Work backwards because removal may be cheaper. Sint32 covers count=0
 235                          for (Sint32 i = cimClass.getQualifierCount() - 1; i >= 0; i--)
 236 kumpf          1.104     {
 237 kumpf          1.195         if (cimClass.getQualifier(i).getPropagated())
 238 kumpf          1.104         {
 239                                  cimClass.removeQualifier(i);
 240                              }
 241                          }
 242                      
 243 kumpf          1.195     // Remove the propagated properties.
 244                          for (Sint32 i = cimClass.getPropertyCount() - 1; i >= 0; i--)
 245 kumpf          1.104     {
 246                              CIMProperty p = cimClass.getProperty(i);
 247 kumpf          1.195         if (p.getPropagated())
 248                              {
 249                                  cimClass.removeProperty(i);
 250                              }
 251                              else
 252 kumpf          1.104         {
 253 kumpf          1.195             // Remove the propagated qualifiers from the property.
 254                                  for (Sint32 j = p.getQualifierCount() - 1; j >= 0; j--)
 255 kumpf          1.104             {
 256 kumpf          1.195                 if (p.getQualifier(j).getPropagated())
 257                                      {
 258                                          p.removeQualifier(j);
 259                                      }
 260 kumpf          1.104             }
 261                              }
 262                          }
 263 kumpf          1.169 
 264 kumpf          1.195     // Remove the propagated methods.
 265                          for (Sint32 i = cimClass.getMethodCount() - 1; i >= 0; i--)
 266 kumpf          1.104     {
 267                              CIMMethod m = cimClass.getMethod(i);
 268 kumpf          1.195         if (m.getPropagated())
 269                              {
 270                                  cimClass.removeMethod(i);
 271                              }
 272                              else
 273 kumpf          1.104         {
 274 kumpf          1.195             // Remove the propagated qualifiers from the method.
 275                                  for (Sint32 j = m.getQualifierCount() - 1; j >= 0; j--)
 276 kumpf          1.104             {
 277 kumpf          1.195                 if (m.getQualifier(j).getPropagated())
 278 kumpf          1.104                 {
 279 kumpf          1.195                     m.removeQualifier(j);
 280 kumpf          1.104                 }
 281                                  }
 282                      
 283 kumpf          1.195             // Remove the propagated qualifiers from the method parameters.
 284                                  for (Sint32 j = m.getParameterCount() - 1; j >= 0; j--)
 285 kumpf          1.104             {
 286 kumpf          1.195                 CIMParameter p = m.getParameter(j);
 287                                      for (Sint32 k = p.getQualifierCount() - 1; k >= 0; k--)
 288                                      {
 289                                          if (p.getQualifier(k).getPropagated())
 290                                          {
 291                                              p.removeQualifier(k);
 292                                          }
 293                                      }
 294 kumpf          1.104             }
 295                              }
 296                          }
 297 karl           1.98  }
 298 karl           1.97  
 299 karl           1.103 /* remove the properties from an instance based on attributes.
 300 karl           1.101     @param Instance from which properties will be removed.
 301                          @param propertyList PropertyList is used in the removal algorithm
 302                          @param localOnly - Boolean used in the removal.
 303                          NOTE: This could be logical to move to CIMInstance since the
 304                          usage is more general than just in the repository
 305                      */
 306 kumpf          1.189 static void _removeProperties(
 307 kumpf          1.169     CIMInstance& cimInstance,
 308                          const CIMPropertyList& propertyList,
 309                          Boolean localOnly)
 310 karl           1.101 {
 311                          Boolean propertyListNull = propertyList.isNull();
 312                          if ((!propertyListNull) || localOnly)
 313                          {
 314                              // Loop through properties to remove those that do not filter through
 315                              // local only attribute and are not in the property list.
 316                              Uint32 count = cimInstance.getPropertyCount();
 317                              // Work backwards because removal may be cheaper. Sint32 covers count=0
 318                              for (Sint32 i = (count - 1); i >= 0; i--)
 319                              {
 320                                  CIMProperty p = cimInstance.getProperty(i);
 321                      
 322 kumpf          1.169             // if localOnly == true, ignore properties defined in super class
 323 karl           1.101             if (localOnly && (p.getPropagated()))
 324                                  {
 325                                      cimInstance.removeProperty(i);
 326                                      continue;
 327                                  }
 328                      
 329 kumpf          1.169             // propertyList NULL means deliver properties.  PropertyList
 330                                  // empty, none.
 331 karl           1.101             // Test for removal if propertyList not NULL. The empty list option
 332                                  // is covered by fact that property is not in the list.
 333                                  if (!propertyListNull)
 334 kumpf          1.169                 if (!_containsProperty(p, propertyList))
 335 karl           1.101                     cimInstance.removeProperty(i);
 336                              }
 337                          }
 338                      }
 339                      
 340                      /* remove all Qualifiers from a single CIMInstance. Removes
 341                          all of the qualifiers from the instance and from properties
 342                          within the instance.
 343                          @param instance from which parameters are removed.
 344                          NOTE: This could be logical to be moved to CIMInstance since
 345                          the usage may be more general than just in the repository.
 346                      */
 347 kumpf          1.189 static void _removeAllQualifiers(CIMInstance& cimInstance)
 348 karl           1.101 {
 349 kumpf          1.169     // remove qualifiers from the instance
 350                          Uint32 count = 0;
 351                          while ((count = cimInstance.getQualifierCount()) > 0)
 352                              cimInstance.removeQualifier(count - 1);
 353 karl           1.101 
 354 kumpf          1.169     // remove qualifiers from the properties
 355                          for (Uint32 i = 0; i < cimInstance.getPropertyCount(); i++)
 356                          {
 357                              CIMProperty p = cimInstance.getProperty(i);
 358                              count = 0;
 359                              while ((count = p.getQualifierCount()) > 0)
 360                                  p.removeQualifier(count - 1);
 361                          }
 362 karl           1.101 }
 363 kumpf          1.169 
 364 karl           1.101 /* removes all ClassOrigin attributes from a single CIMInstance. Removes
 365                          the classOrigin attribute from each property in the Instance.
 366                         @param Instance from which the ClassOrigin Properties will be removed.
 367                         NOTE: Logical to be moved to CIMInstance since it may be more general
 368                         than just the repositoryl
 369                      */
 370 kumpf          1.189 static void _removeClassOrigins(CIMInstance& cimInstance)
 371 karl           1.101 {
 372 marek          1.174     PEG_TRACE_CSTRING(TRC_REPOSITORY, Tracer::LEVEL4, "Remove Class Origins");
 373 kumpf          1.104 
 374 kumpf          1.169     Uint32 propertyCount = cimInstance.getPropertyCount();
 375                          for (Uint32 i = 0; i < propertyCount ; i++)
 376                              cimInstance.getProperty(i).setClassOrigin(CIMName());
 377 karl           1.101 }
 378                      
 379 karl           1.103 /* Filters the properties, qualifiers, and classorigin out of a single instance.
 380 karl           1.101     Based on the parameters provided for localOnly, includeQualifiers,
 381                          and includeClassOrigin, this function simply filters the properties
 382                          qualifiers, and classOrigins out of a single instance.  This function
 383                          was created to have a single piece of code that processes getinstance
 384                          and enumerateInstances returns.
 385                          @param cimInstance reference to instance to be processed.
 386                          @param localOnly defines if request is for localOnly parameters.
 387                          @param includeQualifiers Boolean defining if qualifiers to be returned.
 388                          @param includeClassOrigin Boolean defining if ClassOrigin attribute to
 389                          be removed from properties.
 390                      */
 391 kumpf          1.189 static void _filterInstance(
 392 kumpf          1.169     CIMInstance& cimInstance,
 393                          const CIMPropertyList& propertyList,
 394                          Boolean localOnly,
 395                          Boolean includeQualifiers,
 396                          Boolean includeClassOrigin)
 397 karl           1.101 {
 398 kumpf          1.164     // Remove properties based on propertyList and localOnly flag
 399 karl           1.101     _removeProperties(cimInstance, propertyList, localOnly);
 400 kumpf          1.164 
 401 karl           1.101     // If includequalifiers false, remove all qualifiers from
 402                          // properties.
 403                      
 404 kumpf          1.169     if (!includeQualifiers)
 405 karl           1.101     {
 406                              _removeAllQualifiers(cimInstance);
 407                          }
 408 kumpf          1.164 
 409 karl           1.103     // if ClassOrigin Flag false, remove classOrigin info from Instance object
 410                          // by setting the classOrigin to Null.
 411 kumpf          1.164 
 412 karl           1.101     if (!includeClassOrigin)
 413                          {
 414                              _removeClassOrigins(cimInstance);
 415                          }
 416                      }
 417 kumpf          1.164 
 418 kumpf          1.190 static Array<ClassAssociation> _buildClassAssociationEntries(
 419                          const CIMConstClass& assocClass)
 420                      {
 421                          PEG_METHOD_ENTER(TRC_REPOSITORY, "_buildClassAssociationEntries");
 422                      
 423                          Array<ClassAssociation> classAssocEntries;
 424                      
 425                          // Get the association's class name:
 426                      
 427                          CIMName assocClassName = assocClass.getClassName();
 428                      
 429                          // For each property:
 430                      
 431                          Uint32 n = assocClass.getPropertyCount();
 432                      
 433                          for (Uint32 i = 0; i < n; i++)
 434                          {
 435                              CIMConstProperty fromProp = assocClass.getProperty(i);
 436                      
 437                              if (fromProp.getType() == CIMTYPE_REFERENCE)
 438                              {
 439 kumpf          1.190             for (Uint32 j = 0; j < n; j++)
 440                                  {
 441                                      CIMConstProperty toProp = assocClass.getProperty(j);
 442                      
 443                                      if (toProp.getType() == CIMTYPE_REFERENCE &&
 444                                          (!fromProp.getName().equal(toProp.getName())))
 445                                      {
 446                                          classAssocEntries.append(ClassAssociation(
 447                                              assocClassName,
 448                                              fromProp.getReferenceClassName(),
 449                                              fromProp.getName(),
 450                                              toProp.getReferenceClassName(),
 451                                              toProp.getName()));
 452                                      }
 453                                  }
 454                              }
 455                          }
 456                      
 457                          PEG_METHOD_EXIT();
 458                          return classAssocEntries;
 459                      }
 460 kumpf          1.190 
 461                      /*
 462                          This routine does the following:
 463                      
 464                              1.  Creates two entries in the association file for each relationship
 465                                  formed by this new association instance. A binary association
 466                                  (one with two references) ties two instances together. Suppose
 467                                  there are two instances: I1 and I2. Then two entries are created:
 468                      
 469                                      I2 -> I1
 470                                      I1 -> I2
 471                      
 472                                  For a ternary relationship, six entries will be created. Suppose
 473                                  there are three instances: I1, I2, and I3:
 474                      
 475                                      I1 -> I2
 476                                      I1 -> I3
 477                                      I2 -> I1
 478                                      I2 -> I3
 479                                      I3 -> I1
 480                                      I3 -> I2
 481 kumpf          1.190 
 482                                  So for an N-ary relationship, there will be N! entries created.
 483                      
 484                              2.  Verifies that the association instance refers to real objects.
 485                                  (note that an association reference may refer to either an instance
 486                                  or a class). Throws an exception if one of the references does not
 487                                  refer to a valid object.
 488                      */
 489                      static Array<InstanceAssociation> _buildInstanceAssociationEntries(
 490                          const CIMNamespaceName& nameSpace,
 491                          const CIMConstClass& cimClass,
 492                          const CIMInstance& cimInstance,
 493                          const CIMObjectPath& instanceName)
 494                      {
 495                          PEG_METHOD_ENTER(TRC_REPOSITORY, "_buildInstanceAssociationEntries");
 496                      
 497                          Array<InstanceAssociation> instanceAssocEntries;
 498                      
 499                          // Get the association's instance name and class name:
 500                      
 501                          String assocInstanceName = instanceName.toString();
 502 kumpf          1.190     CIMName assocClassName = instanceName.getClassName();
 503                      
 504                          // For each property:
 505                      
 506                          for (Uint32 i = 0, n = cimInstance.getPropertyCount(); i < n; i++)
 507                          {
 508                              CIMConstProperty fromProp = cimInstance.getProperty(i);
 509                      
 510                              // If a reference property:
 511                      
 512                              if (fromProp.getType() == CIMTYPE_REFERENCE)
 513                              {
 514                                  // For each property:
 515                      
 516                                  for (Uint32 j = 0, m = cimInstance.getPropertyCount(); j < m; j++)
 517                                  {
 518                                      CIMConstProperty toProp = cimInstance.getProperty(j);
 519                      
 520                                      // If a reference property and not the same property:
 521                      
 522                                      if (toProp.getType() == CIMTYPE_REFERENCE &&
 523 kumpf          1.190                     (!fromProp.getName().equal (toProp.getName())))
 524                                      {
 525                                          CIMObjectPath fromRef;
 526                                          fromProp.getValue().get(fromRef);
 527                      
 528                                          CIMObjectPath toRef;
 529                                          toProp.getValue().get(toRef);
 530                      
 531                      
 532                                          // Fix for bugzilla 667:
 533                                          // Strip off the hostname if it is the same as the
 534                                          // local host
 535                                          if ((fromRef.getHost() != String::EMPTY) &&
 536                                              (System::isLocalHost(fromRef.getHost())))
 537                                          {
 538                                              PEG_TRACE_CSTRING(TRC_REPOSITORY, Tracer::LEVEL4,
 539                                                  "Stripping off local hostName from fromRef");
 540                                              fromRef.setHost(String::EMPTY);
 541                                          }
 542                      
 543                                          // Strip off the namespace when it is the same as the
 544 kumpf          1.190                     // one this instance is created in.
 545                                          if ((fromRef.getHost() == String::EMPTY) &&
 546                                              (fromRef.getNameSpace() == nameSpace))
 547                                          {
 548                                              PEG_TRACE_CSTRING(TRC_REPOSITORY, Tracer::LEVEL4,
 549                                                  "Stripping off local nameSpace from fromRef");
 550                                              fromRef.setNameSpace(CIMNamespaceName());
 551                                          }
 552                      
 553                                          // Strip off the hostname if it is the same as the
 554                                          // local host
 555                                          if ((toRef.getHost() != String::EMPTY) &&
 556                                              (System::isLocalHost(toRef.getHost())))
 557                                          {
 558                                              PEG_TRACE_CSTRING(TRC_REPOSITORY, Tracer::LEVEL4,
 559                                                  "Stripping off local hostName from toRef");
 560                                              toRef.setHost(String::EMPTY);
 561                                          }
 562                      
 563                                          // Strip off the namespace when it is the same as the
 564                                          // one this instance is created in.
 565 kumpf          1.190                     if ((toRef.getHost() == String::EMPTY) &&
 566                                              (toRef.getNameSpace() == nameSpace))
 567                                          {
 568                                              PEG_TRACE_CSTRING(TRC_REPOSITORY, Tracer::LEVEL4,
 569                                                  "Stripping off local nameSpace from toRef");
 570                                              toRef.setNameSpace(CIMNamespaceName());
 571                                          }
 572                      
 573                                          instanceAssocEntries.append(InstanceAssociation(
 574                                              assocInstanceName,
 575                                              assocClassName,
 576                                              fromRef.toString(),
 577                                              fromRef.getClassName(),
 578                                              fromProp.getName(),
 579                                              toRef.toString(),
 580                                              toRef.getClassName(),
 581                                              toProp.getName()));
 582                                      }
 583                                  }
 584                              }
 585                          }
 586 kumpf          1.190 
 587                          PEG_METHOD_EXIT();
 588                          return instanceAssocEntries;
 589                      }
 590                      
 591 kumpf          1.189 /**
 592                          Converts an object path to an instance name.  The host name is set to the
 593                          empty string.  The namespace is set to null if it matches the specified
 594                          namespace.  Otherwise, if it is not null, a CIM_ERR_NOT_FOUND exception is
 595                          thrown.
 596 mike           1.48  
 597 kumpf          1.189     This function allows the repository to store instance names with
 598                          consistent contents to facilitate equality tests.  (See Bug 1508.)
 599 david          1.96  
 600 kumpf          1.189 */
 601                      static CIMObjectPath _stripInstanceName(
 602                          const CIMNamespaceName& nameSpace,
 603                          const CIMObjectPath& instanceName)
 604 kumpf          1.165 {
 605 kumpf          1.189     CIMObjectPath normalizedInstanceName = instanceName;
 606                          normalizedInstanceName.setHost(String::EMPTY);
 607 kumpf          1.165 
 608 kumpf          1.189     if (instanceName.getNameSpace() == nameSpace)
 609 kumpf          1.165     {
 610 kumpf          1.189         normalizedInstanceName.setNameSpace(CIMNamespaceName());
 611 kumpf          1.165     }
 612 kumpf          1.189     else if (!instanceName.getNameSpace().isNull())
 613 kumpf          1.165     {
 614 kumpf          1.189         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString());
 615 kumpf          1.165     }
 616                      
 617 kumpf          1.189     return normalizedInstanceName;
 618 kumpf          1.168 }
 619                      
 620                      ////////////////////////////////////////////////////////////////////////////////
 621                      //
 622 mike           1.48  // CIMRepository
 623                      //
 624                      //     The following are not implemented:
 625                      //
 626                      //         CIMRepository::execQuery()
 627                      //         CIMRepository::invokeMethod()
 628                      //
 629                      //     Note that invokeMethod() will not never implemented since it is not
 630                      //     meaningful for a repository.
 631                      //
 632 dmitry.mikulin 1.181 //     Note that if declContext is passed to the CIMRepository constructor,
 633                      //     the repository object will own it and will delete it when appropriate.
 634                      //
 635 mike           1.48  ////////////////////////////////////////////////////////////////////////////////
 636                      
 637 kumpf          1.166 CIMRepository::CIMRepository(
 638                          const String& repositoryRoot,
 639 dmitry.mikulin 1.181     Uint32 mode,
 640                          RepositoryDeclContext* declContext)
 641 jim.wunderlich 1.134 {
 642                          PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::CIMRepository");
 643                      
 644 kumpf          1.166     Boolean binaryMode = mode & CIMRepository::MODE_BIN;
 645 kumpf          1.142 
 646 kumpf          1.166     if (mode == CIMRepository::MODE_DEFAULT)
 647 kumpf          1.142     {
 648 kumpf          1.158         binaryMode = ConfigManager::parseBooleanValue(
 649                                  ConfigManager::getInstance()->getCurrentValue(
 650                                      "enableBinaryRepository"));
 651 schuur         1.114     }
 652                      
 653 kumpf          1.166     // FUTURE?? -  compressMode = mode & CIMRepository::MODE_COMPRESSED;
 654 kumpf          1.189     Boolean compressMode = false;
 655 jim.wunderlich 1.136 
 656 kumpf          1.189 #ifdef PEGASUS_ENABLE_COMPRESSED_REPOSITORY    // PEP214
 657 kumpf          1.196     compressMode = true;
 658 kumpf          1.169     char* s = getenv("PEGASUS_ENABLE_COMPRESSED_REPOSITORY");
 659 jim.wunderlich 1.136     if (s && (strcmp(s, "build_non_compressed") == 0))
 660 kumpf          1.142     {
 661 kumpf          1.189         compressMode = false;
 662 kumpf          1.142 #ifdef TEST_OUTPUT
 663                              cout << "In Compress mode: build_non_compresed found" << endl;
 664 jim.wunderlich 1.136 #endif /* TEST_OUTPUT */
 665 kumpf          1.142     }
 666                      #endif /* PEGASUS_ENABLE_COMPRESSED_REPOSITORY */
 667 jim.wunderlich 1.136 
 668 kumpf          1.142 #ifdef TEST_OUTPUT
 669                          cout << "repositoryRoot = " << repositoryRoot << endl;
 670 kumpf          1.166     cout << "CIMRepository: binaryMode="  << binaryMode <<
 671                              ", mode=" << mode << endl;
 672 jim.wunderlich 1.136     cout << "CIMRepository: compressMode= " << compressMode << endl;
 673                      #endif /* TEST_OUTPUT */
 674 jim.wunderlich 1.134 
 675 kumpf          1.189     _rep = new CIMRepositoryRep();
 676                      
 677 marek          1.183     if (binaryMode)
 678 kumpf          1.169     {
 679                              // BUILD BINARY
 680 kumpf          1.189         _rep->_streamer.reset(
 681                                  new AutoStreamer(new BinaryStreamer(), BINREP_MARKER));
 682                              ((AutoStreamer*)_rep->_streamer.get())->addReader(new XmlStreamer(), 0);
 683 kumpf          1.169     }
 684                          else
 685                          {
 686                              // BUILD XML
 687 kumpf          1.189         _rep->_streamer.reset(new AutoStreamer(new XmlStreamer(), 0xff));
 688                              ((AutoStreamer*)_rep->_streamer.get())->addReader(
 689 kumpf          1.169             new BinaryStreamer(), BINREP_MARKER);
 690 kumpf          1.189         ((AutoStreamer*)_rep->_streamer.get())->addReader(new XmlStreamer(), 0);
 691 schuur         1.116     }
 692 schuur         1.114 
 693 dmitry.mikulin 1.181     // If declContext is supplied by the caller, don't allocate it.
 694                          // CIMRepository will take ownership and will be responsible for 
 695                          // deleting it.
 696                          if (declContext)
 697 mike           1.184         _rep->_context = declContext;
 698 dmitry.mikulin 1.181     else
 699 mike           1.184         _rep->_context = new RepositoryDeclContext();
 700                          _rep->_context->setRepository(this);
 701 dmitry.mikulin 1.181 
 702 mike           1.184     _rep->_isDefaultInstanceProvider = ConfigManager::parseBooleanValue(
 703 kumpf          1.158         ConfigManager::getInstance()->getCurrentValue(
 704                                  "repositoryIsDefaultInstanceProvider"));
 705 kumpf          1.58  
 706 mike           1.184     _rep->_lockFile = ConfigManager::getInstance()->getHomedPath(
 707 kumpf          1.160         PEGASUS_REPOSITORY_LOCK_FILE).getCString();
 708                      
 709 kumpf          1.201     _rep->_persistentStore.reset(PersistentStore::createPersistentStore(
 710 kumpf          1.192         repositoryRoot,
 711                              _rep->_streamer.get(),
 712                              compressMode));
 713                      
 714 kumpf          1.195     _rep->_storeCompleteClassDefinitions =
 715                              _rep->_persistentStore->storeCompleteClassDefinitions();
 716                      
 717 kumpf          1.192     // Initialize the NameSpaceManager
 718                      
 719                          Array<NamespaceDefinition> nameSpaces =
 720                              _rep->_persistentStore->enumerateNameSpaces();
 721                      
 722                          Uint32 i = 0;
 723                          while (i < nameSpaces.size())
 724                          {
 725                              if (nameSpaces[i].parentNameSpace.isNull() ||
 726                                  _rep->_nameSpaceManager.nameSpaceExists(
 727                                      nameSpaces[i].parentNameSpace))
 728                              {
 729                                  // Parent namespace exists; go ahead and initialize this namespace
 730                                  _rep->_nameSpaceManager.initializeNameSpace(
 731                                      nameSpaces[i],
 732                                      _rep->_persistentStore->enumerateClassNames(
 733                                          nameSpaces[i].name));
 734                                  i++;
 735                              }
 736                              else
 737                              {
 738 kumpf          1.192             // If the parent namespace appears later in the list, swap the
 739                                  // entries and repeat this iteration
 740                                  Boolean swapped = false;
 741                                  for (Uint32 j = i + 1; j < nameSpaces.size(); j++)
 742                                  {
 743                                      if (nameSpaces[i].parentNameSpace == nameSpaces[j].name)
 744                                      {
 745                                          NamespaceDefinition tmp = nameSpaces[j];
 746                                          nameSpaces[j] = nameSpaces[i];
 747                                          nameSpaces[i] = tmp;
 748                                          swapped = true;
 749                                          break;
 750                                      }
 751                                  }
 752 kumpf          1.189 
 753 kumpf          1.192             if (!swapped)
 754                                  {
 755                                      PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL1,
 756                                          "Namespace: %s ignored - parent namespace %s not found",
 757                                          (const char*)nameSpaces[i].name.getString().getCString(),
 758                                          (const char*)nameSpaces[i].parentNameSpace.getString().
 759                                              getCString()));
 760                                      nameSpaces.remove(i);
 761                                  }
 762                              }
 763 kumpf          1.189     }
 764                      
 765 kumpf          1.192     if (!_rep->_nameSpaceManager.nameSpaceExists("root"))
 766 kumpf          1.189     {
 767                              // Create a root namespace per ...
 768                              // Specification for CIM Operations over HTTP
 769                              // Version 1.0
 770                              // 2.5 Namespace Manipulation
 771                              //
 772                              // There are no intrinsic methods defined specifically for the
 773                              // purpose of manipulating CIM Namespaces.  However, the
 774                              // modelling of the a CIM Namespace using the class
 775                              // __Namespace, together with the requirement that that
 776                              // root Namespace MUST be supported by all CIM Servers,
 777                              // implies that all Namespace operations can be supported.
 778                      
 779                              createNameSpace("root");
 780                          }
 781 kumpf          1.168 
 782 kumpf          1.58      PEG_METHOD_EXIT();
 783 mike           1.48  }
 784                      
 785                      CIMRepository::~CIMRepository()
 786                      {
 787 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::~CIMRepository");
 788                      
 789 mike           1.184     delete _rep->_context;
 790 kumpf          1.58  
 791 mike           1.184     delete _rep;
 792                      
 793 kumpf          1.58      PEG_METHOD_EXIT();
 794 mike           1.48  }
 795                      
 796 kumpf          1.104 String _toString(Boolean x)
 797 mike           1.51  {
 798 kumpf          1.104     return(x ? "true" : "false");
 799 mike           1.51  }
 800                      
 801 kumpf          1.104 CIMClass CIMRepository::getClass(
 802                          const CIMNamespaceName& nameSpace,
 803                          const CIMName& className,
 804                          Boolean localOnly,
 805                          Boolean includeQualifiers,
 806                          Boolean includeClassOrigin,
 807                          const CIMPropertyList& propertyList)
 808 mike           1.51  {
 809 kumpf          1.104     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::getClass");
 810 kumpf          1.58  
 811 mike           1.184     ReadLock lock(_rep->_lock);
 812 kumpf          1.104     CIMClass cimClass = _getClass(nameSpace,
 813                                                        className,
 814                                                        localOnly,
 815                                                        includeQualifiers,
 816                                                        includeClassOrigin,
 817                                                        propertyList);
 818 kumpf          1.58  
 819                          PEG_METHOD_EXIT();
 820 kumpf          1.104     return cimClass;
 821 mike           1.51  }
 822                      
 823 kumpf          1.104 CIMClass CIMRepository::_getClass(
 824 kumpf          1.85      const CIMNamespaceName& nameSpace,
 825                          const CIMName& className,
 826 mike           1.48      Boolean localOnly,
 827                          Boolean includeQualifiers,
 828                          Boolean includeClassOrigin,
 829 mike           1.51      const CIMPropertyList& propertyList)
 830 mike           1.48  {
 831 kumpf          1.104     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_getClass");
 832 kumpf          1.58  
 833 thilo.boehm    1.193     PEG_TRACE((TRC_REPOSITORY, Tracer::LEVEL4,
 834                                 "nameSpace= %s, className= %s, localOnly= %s"
 835                                 ", includeQualifiers=  %s, includeClassOrigin= %s",
 836                                 (const char*)nameSpace.getString().getCString(),
 837                                 (const char*)className.getString().getCString(),
 838                                 (localOnly?"true":"false"),
 839                                 (includeQualifiers?"true":"false"),
 840                                 (includeClassOrigin?"true":"false")));
 841 kumpf          1.104 
 842                          CIMClass cimClass;
 843 mike           1.51  
 844 mike           1.151 #ifdef PEGASUS_USE_CLASS_CACHE
 845 kumpf          1.189     // Check the cache first:
 846 mike           1.151 
 847 kumpf          1.189     String cacheKey = _getCacheKey(nameSpace, className);
 848 mike           1.151 
 849 kumpf          1.189     if (!_classCache.get(cacheKey, cimClass))
 850                          {
 851                              // Not in cache so load from disk:
 852                      #endif
 853 mike           1.151 
 854 kumpf          1.189         CIMNamespaceName actualNameSpaceName;
 855                              CIMName superClassName;
 856 kumpf          1.192         _rep->_nameSpaceManager.locateClass(
 857 kumpf          1.189             nameSpace, className, actualNameSpaceName, superClassName);
 858 mike           1.151 
 859 kumpf          1.189         cimClass = _rep->_persistentStore->getClass(
 860                                  actualNameSpaceName, className, superClassName);
 861 mike           1.151 
 862 kumpf          1.189 #ifdef PEGASUS_USE_CLASS_CACHE
 863                              // Put in cache:
 864 mike           1.151 
 865 kumpf          1.189         _classCache.put(cacheKey, cimClass);
 866 mike           1.51      }
 867 kumpf          1.189 #endif
 868 mike           1.48  
 869 kumpf          1.195     if (_rep->_storeCompleteClassDefinitions)
 870                          {
 871                              if (localOnly)
 872                              {
 873                                  _stripPropagatedElements(cimClass);
 874                              }
 875                          }
 876                          else if (!localOnly)
 877                          {
 878                              // Propagate the superclass elements to this class.
 879                              Resolver::resolveClass(cimClass, _rep->_context, nameSpace);
 880                          }
 881 kumpf          1.104 
 882 kumpf          1.195     // Remove properties based on propertyList
 883                          if (!propertyList.isNull())
 884 karl           1.97      {
 885 kumpf          1.195         // Remove properties that are not in the property list.
 886 kumpf          1.104         // Work backwards because removal may be cheaper. Sint32 covers count=0
 887 kumpf          1.195         for (Sint32 i = cimClass.getPropertyCount() - 1; i >= 0; i--)
 888 kumpf          1.104         {
 889 kumpf          1.195             if (!_containsProperty(cimClass.getProperty(i), propertyList))
 890 kumpf          1.104             {
 891                                      cimClass.removeProperty(i);
 892                                  }
 893                              }
 894                          }
 895                      
 896                          // If includequalifiers false, remove all qualifiers from
 897                          // properties, methods and parameters.
 898 kumpf          1.169     if (!includeQualifiers)
 899 kumpf          1.104     {
 900                              _removeAllQualifiers(cimClass);
 901                          }
 902 kumpf          1.169 
 903 kumpf          1.104     // if ClassOrigin Flag false, remove classOrigin info from class object
 904                          // by setting the property to Null.
 905                          if (!includeClassOrigin)
 906                          {
 907 marek          1.174         PEG_TRACE_CSTRING(TRC_REPOSITORY, Tracer::LEVEL4,
 908 kumpf          1.169             "Remove Class Origins");
 909 kumpf          1.104 
 910                              Uint32 propertyCount = cimClass.getPropertyCount();
 911                              for (Uint32 i = 0; i < propertyCount ; i++)
 912                                  cimClass.getProperty(i).setClassOrigin(CIMName());
 913                      
 914                              Uint32 methodCount =  cimClass.getMethodCount();
 915                              for (Uint32 i=0; i < methodCount ; i++)
 916                                  cimClass.getMethod(i).setClassOrigin(CIMName());
 917                          }
 918 karl           1.97  
 919 kumpf          1.58      PEG_METHOD_EXIT();
 920 mike           1.48      return cimClass;
 921                      }
 922                      
 923 mike           1.184 Boolean CIMRepositoryRep::_checkInstanceAlreadyExists(
 924 kumpf          1.85      const CIMNamespaceName& nameSpace,
 925 kumpf          1.162     const CIMObjectPath& instanceName) const
 926 mike           1.48  {
 927 kumpf          1.162     PEG_METHOD_ENTER(TRC_REPOSITORY,
 928                              "CIMRepository::_checkInstanceAlreadyExists");
 929 kumpf          1.58  
 930 mike           1.53      //
 931 kumpf          1.162     // Get the names of all superclasses and subclasses of this class
 932 mike           1.53      //
 933 mike           1.51  
 934 kumpf          1.85      Array<CIMName> classNames;
 935 kumpf          1.162     CIMName className = instanceName.getClassName();
 936 kumpf          1.94      classNames.append(className);
 937 kumpf          1.192     _nameSpaceManager.getSubClassNames(nameSpace, className, true, classNames);
 938                          _nameSpaceManager.getSuperClassNames(nameSpace, className, classNames);
 939 mike           1.48  
 940 mike           1.53      //
 941 kumpf          1.162     // Search for an instance with the specified key values
 942 mike           1.53      //
 943 mike           1.48  
 944                          for (Uint32 i = 0; i < classNames.size(); i++)
 945                          {
 946 kumpf          1.189         CIMObjectPath tmpInstanceName = CIMObjectPath(
 947                                  String::EMPTY,
 948                                  CIMNamespaceName(),
 949                                  classNames[i],
 950                                  instanceName.getKeyBindings());
 951 mike           1.48  
 952 kumpf          1.189         if (_persistentStore->instanceExists(nameSpace, tmpInstanceName))
 953 mike           1.51          {
 954 kumpf          1.58              PEG_METHOD_EXIT();
 955 mike           1.51              return true;
 956                              }
 957 mike           1.48      }
 958                      
 959 kumpf          1.58      PEG_METHOD_EXIT();
 960 mike           1.48      return false;
 961                      }
 962                      
 963                      CIMInstance CIMRepository::getInstance(
 964 kumpf          1.85      const CIMNamespaceName& nameSpace,
 965 kumpf          1.68      const CIMObjectPath& instanceName,
 966 mike           1.48      Boolean localOnly,
 967                          Boolean includeQualifiers,
 968                          Boolean includeClassOrigin,
 969 mike           1.55      const CIMPropertyList& propertyList)
 970 mike           1.48  {
 971 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::getInstance");
 972                      
 973 mike           1.184     ReadLock lock(_rep->_lock);
 974 kumpf          1.165 
 975 kumpf          1.169     CIMInstance cimInstance = _getInstance(
 976                              nameSpace,
 977                              instanceName,
 978                              localOnly,
 979                              includeQualifiers,
 980                              includeClassOrigin,
 981 kumpf          1.191         propertyList,
 982                              true);
 983 kumpf          1.104 
 984                          PEG_METHOD_EXIT();
 985                          return cimInstance;
 986                      }
 987                      
 988                      CIMInstance CIMRepository::_getInstance(
 989                          const CIMNamespaceName& nameSpace,
 990                          const CIMObjectPath& instanceName,
 991                          Boolean localOnly,
 992                          Boolean includeQualifiers,
 993                          Boolean includeClassOrigin,
 994 kumpf          1.191     const CIMPropertyList& propertyList,
 995                          Boolean resolveInstance)
 996 kumpf          1.104 {
 997                          PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_getInstance");
 998                      
 999 kumpf          1.189     CIMObjectPath normalizedInstanceName =
1000                              _stripInstanceName(nameSpace, instanceName);
1001 r.kieninger    1.125 
1002 kumpf          1.192     if (!_rep->_nameSpaceManager.classExists(
1003 mike           1.184         nameSpace, instanceName.getClassName()))
1004 kumpf          1.162     {
1005                              throw PEGASUS_CIM_EXCEPTION(
1006                                  CIM_ERR_INVALID_CLASS, instanceName.getClassName().getString());
1007                          }
1008                      
1009 kumpf          1.189     CIMInstance cimInstance =
1010                              _rep->_persistentStore->getInstance(nameSpace, normalizedInstanceName);
1011 mike           1.51  
1012 mike           1.54      //
1013                          // Resolve the instance (if requested):
1014                          //
1015                      
1016 kumpf          1.198     if (resolveInstance && includeQualifiers)
1017 mike           1.54      {
1018 kumpf          1.198         // Instances are resolved in persistent storage by the
1019                              // createInstance and modifyInstance operations, but qualifiers
1020                              // are not propagated.  The only reason to perform resolution
1021                              // here is if qualifiers are requested in the instance.
1022                      
1023 kumpf          1.104         CIMConstClass cimClass;
1024 mike           1.184         Resolver::resolveInstance (
1025                                  cimInstance, _rep->_context, nameSpace, cimClass, true);
1026 mike           1.54      }
1027 kumpf          1.99  
1028 kumpf          1.165     _filterInstance(
1029                              cimInstance,
1030                              propertyList,
1031                              localOnly,
1032                              includeQualifiers,
1033                              includeClassOrigin);
1034 kumpf          1.104 
1035 kumpf          1.52      PEG_METHOD_EXIT();
1036 mike           1.48      return cimInstance;
1037                      }
1038                      
1039                      void CIMRepository::deleteClass(
1040 kumpf          1.85      const CIMNamespaceName& nameSpace,
1041                          const CIMName& className)
1042 mike           1.48  {
1043 kumpf          1.61      PEG_METHOD_ENTER(TRC_REPOSITORY,"CIMRepository::deleteClass");
1044 kumpf          1.58  
1045 mike           1.184     WriteLock lock(_rep->_lock);
1046                          AutoFileLock fileLock(_rep->_lockFile);
1047 kumpf          1.104 
1048 mike           1.53      //
1049 kumpf          1.189     // Get the class and check to see if it is an association class.
1050 mike           1.53      //
1051 mike           1.51  
1052 kumpf          1.104     CIMClass cimClass = _getClass(
1053                              nameSpace, className, false, true, false, CIMPropertyList());
1054 mike           1.48      Boolean isAssociation = cimClass.isAssociation();
1055                      
1056 kumpf          1.192     _rep->_nameSpaceManager.checkDeleteClass(nameSpace, className);
1057 kumpf          1.189 
1058                          Array<CIMNamespaceName> dependentNameSpaceNames =
1059 kumpf          1.192         _rep->_nameSpaceManager.getDependentSchemaNameSpaceNames(nameSpace);
1060 kumpf          1.189 
1061 mike           1.53      //
1062 kumpf          1.189     // Ensure no instances of this class exist in the repository.
1063 mike           1.53      //
1064 mike           1.151 
1065 kumpf          1.189     for (Uint32 i = 0; i < dependentNameSpaceNames.size(); i++)
1066                          {
1067                              Array<CIMObjectPath> instanceNames =
1068                                  _rep->_persistentStore->enumerateInstanceNamesForClass(
1069                                      dependentNameSpaceNames[i], className);
1070 mike           1.151 
1071 kumpf          1.189         if (instanceNames.size())
1072                              {
1073                                  throw PEGASUS_CIM_EXCEPTION(
1074                                      CIM_ERR_CLASS_HAS_INSTANCES, className.getString());
1075                              }
1076                          }
1077 mike           1.48  
1078 kumpf          1.189 #ifdef PEGASUS_USE_CLASS_CACHE
1079 kumpf          1.104 
1080 kumpf          1.189     _classCache.evict(_getCacheKey(nameSpace, className));
1081 mike           1.48  
1082 kumpf          1.189 #endif /* PEGASUS_USE_CLASS_CACHE */
1083 kumpf          1.58  
1084 mike           1.53      //
1085 kumpf          1.189     // Delete the class. The NameSpaceManager::deleteClass() method throws
1086                          // an exception if the class has subclasses.
1087 mike           1.53      //
1088                      
1089 kumpf          1.189     CIMName superClassName =
1090 kumpf          1.192         _rep->_nameSpaceManager.getSuperClassName(nameSpace, className);
1091 mike           1.53  
1092 kumpf          1.192     _rep->_nameSpaceManager.deleteClass(nameSpace, className);
1093 mike           1.53  
1094 kumpf          1.190     _rep->_persistentStore->deleteClass(
1095                              nameSpace,
1096                              className,
1097                              superClassName,
1098                              isAssociation,
1099                              dependentNameSpaceNames);
1100 kumpf          1.58  
1101                          PEG_METHOD_EXIT();
1102 mike           1.53  }
1103                      
1104 mike           1.48  void CIMRepository::deleteInstance(
1105 kumpf          1.85      const CIMNamespaceName& nameSpace,
1106 kumpf          1.68      const CIMObjectPath& instanceName)
1107 mike           1.48  {
1108 mike           1.53      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::deleteInstance");
1109 mike           1.51  
1110 kumpf          1.192     _rep->_nameSpaceManager.validateClass(
1111 kumpf          1.189         nameSpace, instanceName.getClassName());
1112                      
1113                          CIMObjectPath normalizedInstanceName =
1114                              _stripInstanceName(nameSpace, instanceName);
1115 r.kieninger    1.125 
1116 mike           1.184     WriteLock lock(_rep->_lock);
1117                          AutoFileLock fileLock(_rep->_lockFile);
1118 kumpf          1.104 
1119 kumpf          1.189     _rep->_persistentStore->deleteInstance(nameSpace, normalizedInstanceName);
1120 mike           1.53  
1121 kumpf          1.58      PEG_METHOD_EXIT();
1122 mike           1.48  }
1123                      
1124                      void CIMRepository::createClass(
1125 kumpf          1.85      const CIMNamespaceName& nameSpace,
1126 kumpf          1.199     const CIMClass& newClass)
1127 mike           1.48  {
1128 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::createClass");
1129                      
1130 mike           1.184     WriteLock lock(_rep->_lock);
1131                          AutoFileLock fileLock(_rep->_lockFile);
1132 kumpf          1.104     _createClass(nameSpace, newClass);
1133                      
1134                          PEG_METHOD_EXIT();
1135                      }
1136                      
1137                      void CIMRepository::_createClass(
1138                          const CIMNamespaceName& nameSpace,
1139                          const CIMClass& newClass)
1140                      {
1141                          PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_createClass");
1142                      
1143 kumpf          1.197     // -- Check whether the class may be created:
1144                      
1145                          _rep->_nameSpaceManager.checkCreateClass(
1146                              nameSpace, newClass.getClassName(), newClass.getSuperClassName());
1147                      
1148 mike           1.48      // -- Resolve the class:
1149 kumpf          1.104 
1150 kumpf          1.194     CIMClass cimClass(newClass.clone());
1151                          Resolver::resolveClass(cimClass, _rep->_context, nameSpace);
1152 mike           1.48  
1153 kumpf          1.190     // -- If an association class, build association entries:
1154 kumpf          1.189 
1155 kumpf          1.190     Array<ClassAssociation> classAssocEntries;
1156 kumpf          1.189 
1157 kumpf          1.190     if (cimClass.isAssociation())
1158                          {
1159                              classAssocEntries = _buildClassAssociationEntries(cimClass);
1160                          }
1161 mike           1.48  
1162 kumpf          1.195     // -- Strip the propagated elements, if required
1163                      
1164                          if (!_rep->_storeCompleteClassDefinitions)
1165                          {
1166                              _stripPropagatedElements(cimClass);
1167                          }
1168                      
1169 kumpf          1.190     // -- Create the class declaration:
1170                      
1171                          _rep->_persistentStore->createClass(nameSpace, cimClass, classAssocEntries);
1172 mike           1.48  
1173                          // -- Create namespace manager entry:
1174                      
1175 kumpf          1.192     _rep->_nameSpaceManager.createClass(
1176 kumpf          1.189         nameSpace, cimClass.getClassName(), cimClass.getSuperClassName());
1177 kumpf          1.58  
1178                          PEG_METHOD_EXIT();
1179 mike           1.48  }
1180                      
1181 kumpf          1.68  CIMObjectPath CIMRepository::createInstance(
1182 kumpf          1.85      const CIMNamespaceName& nameSpace,
1183 kumpf          1.199     const CIMInstance& newInstance)
1184 mike           1.48  {
1185 kumpf          1.61      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::createInstance");
1186 mike           1.51  
1187 mike           1.184     WriteLock lock(_rep->_lock);
1188                          AutoFileLock fileLock(_rep->_lockFile);
1189 kumpf          1.104     CIMObjectPath instanceName = _createInstance(nameSpace, newInstance);
1190                      
1191                          PEG_METHOD_EXIT();
1192                          return instanceName;
1193                      }
1194                      
1195                      CIMObjectPath CIMRepository::_createInstance(
1196                          const CIMNamespaceName& nameSpace,
1197                          const CIMInstance& newInstance)
1198                      {
1199                          PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_createInstance");
1200                      
1201 mike           1.53      //
1202 mike           1.54      // Resolve the instance. Looks up class and fills out properties but
1203                          // not the qualifiers.
1204 mike           1.53      //
1205                      
1206 kumpf          1.200     CIMInstance cimInstance(newInstance.clone());
1207 mike           1.48      CIMConstClass cimClass;
1208 mike           1.184     Resolver::resolveInstance (cimInstance, _rep->_context, nameSpace, cimClass,
1209 kumpf          1.76          false);
1210 kumpf          1.81      CIMObjectPath instanceName = cimInstance.buildPath(cimClass);
1211 mike           1.48  
1212 mike           1.53      //
1213                          // Make sure the class has keys (otherwise it will be impossible to
1214                          // create the instance).
1215                          //
1216 mike           1.48  
1217                          if (!cimClass.hasKeys())
1218                          {
1219 humberto       1.88          PEG_METHOD_EXIT();
1220 kumpf          1.99          throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
1221                                  MessageLoaderParms("Repository.CIMRepository.CLASS_HAS_NO_KEYS",
1222 kumpf          1.104                 "class has no keys: $0",
1223 kumpf          1.99                  cimClass.getClassName().getString()));
1224 mike           1.48      }
1225                      
1226 mike           1.53      //
1227                          // Be sure instance does not already exist:
1228                          //
1229 mike           1.48  
1230 mike           1.184     if (_rep->_checkInstanceAlreadyExists(nameSpace, instanceName))
1231 mike           1.48      {
1232 kumpf          1.52          PEG_METHOD_EXIT();
1233 kumpf          1.104         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_ALREADY_EXISTS,
1234 mike           1.51              instanceName.toString());
1235 mike           1.48      }
1236                      
1237 mike           1.53      //
1238 kumpf          1.190     // Build association entries if an association instance.
1239 mike           1.53      //
1240 mike           1.48  
1241 kumpf          1.190     Array<InstanceAssociation> instAssocEntries;
1242                      
1243 mike           1.48      if (cimClass.isAssociation())
1244 kumpf          1.190     {
1245                              instAssocEntries = _buildInstanceAssociationEntries(
1246                                  nameSpace, cimClass, cimInstance, instanceName);
1247                          }
1248                      
1249                          //
1250                          // Create the instance
1251                          //
1252 mike           1.53  
1253 kumpf          1.189     _rep->_persistentStore->createInstance(
1254 kumpf          1.190         nameSpace, instanceName, cimInstance, instAssocEntries);
1255 mike           1.53  
1256 kumpf          1.52      PEG_METHOD_EXIT();
1257 mike           1.53      return instanceName;
1258 mike           1.48  }
1259                      
1260                      void CIMRepository::modifyClass(
1261 kumpf          1.85      const CIMNamespaceName& nameSpace,
1262 kumpf          1.199     const CIMClass& modifiedClass)
1263 mike           1.48  {
1264 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::modifyClass");
1265                      
1266 mike           1.184     WriteLock lock(_rep->_lock);
1267                          AutoFileLock fileLock(_rep->_lockFile);
1268 kumpf          1.104     _modifyClass(nameSpace, modifiedClass);
1269                      
1270                          PEG_METHOD_EXIT();
1271                      }
1272                      
1273                      void CIMRepository::_modifyClass(
1274                          const CIMNamespaceName& nameSpace,
1275                          const CIMClass& modifiedClass)
1276                      {
1277                          PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_modifyClass");
1278                      
1279 mike           1.53      //
1280                          // Check to see if it is okay to modify this class:
1281                          //
1282 mike           1.48  
1283 kumpf          1.195     CIMName oldSuperClassName;
1284                      
1285 kumpf          1.192     _rep->_nameSpaceManager.checkModifyClass(
1286 kumpf          1.195         nameSpace,
1287                              modifiedClass.getClassName(),
1288                              modifiedClass.getSuperClassName(),
1289                              oldSuperClassName,
1290                              !_rep->_storeCompleteClassDefinitions);
1291 mike           1.48  
1292 mike           1.53      //
1293 kumpf          1.197     // Resolve the class:
1294                          //
1295                      
1296                          CIMClass cimClass(modifiedClass.clone());
1297                          Resolver::resolveClass(cimClass, _rep->_context, nameSpace);
1298                      
1299                          //
1300 mike           1.53      // ATTN: KS
1301                          // Disallow modification of classes which have instances (that are
1302                          // in the repository). And we have no idea whether the class has
1303                          // instances in other repositories or in providers. We should do
1304                          // an enumerate instance names at a higher level (above the repository).
1305                          //
1306 chip           1.118 
1307 mike           1.151 #ifdef PEGASUS_USE_CLASS_CACHE
1308                      
1309 kumpf          1.189     String cacheKey = _getCacheKey(nameSpace, cimClass.getClassName());
1310                          _classCache.evict(cacheKey);
1311 mike           1.151 
1312                      #endif /* PEGASUS_USE_CLASS_CACHE */
1313 mike           1.53  
1314 kumpf          1.190     Boolean isAssociation = cimClass.isAssociation();
1315                          Array<ClassAssociation> classAssocEntries;
1316 kumpf          1.58  
1317 kumpf          1.190     if (isAssociation)
1318 kumpf          1.169     {
1319 kumpf          1.190         classAssocEntries = _buildClassAssociationEntries(cimClass);
1320 konrad.r       1.111     }
1321                      
1322 kumpf          1.195     // Strip the propagated elements, if required
1323                      
1324                          if (!_rep->_storeCompleteClassDefinitions)
1325                          {
1326                              _stripPropagatedElements(cimClass);
1327                          }
1328                      
1329 kumpf          1.190     _rep->_persistentStore->modifyClass(
1330 kumpf          1.195         nameSpace,
1331                              cimClass,
1332                              oldSuperClassName,
1333                              isAssociation,
1334                              classAssocEntries);
1335 mike           1.151 
1336                          //
1337                          // Cache this class:
1338                          //
1339                      
1340                      #ifdef PEGASUS_USE_CLASS_CACHE
1341                      
1342 kumpf          1.189     _classCache.put(cacheKey, cimClass);
1343 mike           1.151 
1344                      #endif /* PEGASUS_USE_CLASS_CACHE */
1345                      
1346 kumpf          1.58      PEG_METHOD_EXIT();
1347 mike           1.48  }
1348                      
1349                      void CIMRepository::modifyInstance(
1350 kumpf          1.85      const CIMNamespaceName& nameSpace,
1351 kumpf          1.70      const CIMInstance& modifiedInstance,
1352 mike           1.51      Boolean includeQualifiers,
1353 kumpf          1.199     const CIMPropertyList& propertyList)
1354 mike           1.48  {
1355 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::modifyInstance");
1356                      
1357 mike           1.184     WriteLock lock(_rep->_lock);
1358                          AutoFileLock fileLock(_rep->_lockFile);
1359 kumpf          1.104 
1360 mike           1.53      //
1361                          // Do this:
1362                          //
1363 mike           1.51  
1364 mike           1.53      CIMInstance cimInstance;   // The instance that replaces the original
1365 mike           1.51  
1366                          if (propertyList.isNull())
1367                          {
1368                              //
1369                              // Replace all the properties in the instance
1370                              //
1371                              if (includeQualifiers)
1372                              {
1373                                  //
1374                                  // Replace the entire instance with the given instance
1375                                  // (this is the default behavior)
1376                                  //
1377 kumpf          1.200             cimInstance = modifiedInstance.clone();
1378 mike           1.51          }
1379                              else
1380                              {
1381                                  //
1382                                  // Replace all the properties in the instance, but keep the
1383                                  // original qualifiers on the instance and on the properties
1384                                  //
1385                      
1386 kumpf          1.104             cimInstance = _getInstance(
1387                                      nameSpace,
1388                                      modifiedInstance.getPath (),
1389                                      false,
1390                                      true,
1391                                      true,
1392 kumpf          1.191                 CIMPropertyList(),
1393                                      false);
1394 mike           1.54  
1395 mike           1.51              CIMInstance newInstance(
1396 kumpf          1.70                  modifiedInstance.getPath ().getClassName());
1397 mike           1.54  
1398 kumpf          1.200             CIMConstInstance givenInstance = modifiedInstance;
1399 mike           1.51  
1400                                  //
1401                                  // Copy over the original instance qualifiers
1402                                  //
1403 mike           1.54  
1404                                  for (Uint32 i = 0; i < cimInstance.getQualifierCount(); i++)
1405 mike           1.51              {
1406                                      newInstance.addQualifier(cimInstance.getQualifier(i));
1407                                  }
1408                      
1409                                  //
1410                                  // Loop through the properties replacing each property in the
1411                                  // original with a new value, but keeping the original qualifiers
1412                                  //
1413                                  for (Uint32 i=0; i<givenInstance.getPropertyCount(); i++)
1414                                  {
1415                                      // Copy the given property value (not qualifiers)
1416 kumpf          1.200                 CIMConstProperty givenProperty = givenInstance.getProperty(i);
1417 mike           1.51                  CIMProperty newProperty(
1418                                          givenProperty.getName(),
1419                                          givenProperty.getValue(),
1420                                          givenProperty.getArraySize(),
1421                                          givenProperty.getReferenceClassName(),
1422                                          givenProperty.getClassOrigin(),
1423                                          givenProperty.getPropagated());
1424                      
1425                                      // Copy the original property qualifiers
1426                                      Uint32 origPos =
1427                                          cimInstance.findProperty(newProperty.getName());
1428                                      if (origPos != PEG_NOT_FOUND)
1429                                      {
1430                                          CIMProperty origProperty = cimInstance.getProperty(origPos);
1431                                          for (Uint32 j=0; j<origProperty.getQualifierCount(); j++)
1432                                          {
1433 r.kieninger    1.133                         newProperty.addQualifier(origProperty.getQualifier(j));
1434 mike           1.51                      }
1435                                      }
1436                      
1437                                      // Add the newly constructed property to the new instance
1438                                      newInstance.addProperty(newProperty);
1439                                  }
1440                      
1441                                  // Use the newly merged instance to replace the original instance
1442                                  cimInstance = newInstance;
1443                              }
1444                          }
1445                          else
1446                          {
1447                              //
1448                              // Replace only the properties specified in the given instance
1449                              //
1450                      
1451 kumpf          1.191         cimInstance = _getInstance(
1452                                  nameSpace,
1453                                  modifiedInstance.getPath(),
1454                                  false,
1455                                  true,
1456                                  true,
1457                                  CIMPropertyList(),
1458                                  false);
1459 mike           1.55  
1460 kumpf          1.200         CIMConstInstance givenInstance = modifiedInstance;
1461 mike           1.51  
1462                              // NOTE: Instance qualifiers are not changed when a property list
1463                              // is specified.  Property qualifiers are replaced with the
1464                              // corresponding property values.
1465                      
1466                              //
1467                              // Loop through the propertyList replacing each property in the original
1468                              //
1469 mike           1.53  
1470 kumpf          1.74          for (Uint32 i=0; i<propertyList.size(); i++)
1471 mike           1.51          {
1472 kumpf          1.74              Uint32 origPropPos = cimInstance.findProperty(propertyList[i]);
1473 mike           1.51              if (origPropPos != PEG_NOT_FOUND)
1474                                  {
1475                                      // Case: Property set in original
1476                                      CIMProperty origProperty =
1477                                          cimInstance.getProperty(origPropPos);
1478                      
1479                                      // Get the given property value
1480                                      Uint32 givenPropPos =
1481 kumpf          1.74                      givenInstance.findProperty(propertyList[i]);
1482 mike           1.51                  if (givenPropPos != PEG_NOT_FOUND)
1483                                      {
1484                                          // Case: Property set in original and given
1485 kumpf          1.200                     CIMConstProperty givenProperty =
1486 mike           1.51                          givenInstance.getProperty(givenPropPos);
1487                      
1488                                          // Copy over the property from the given to the original
1489                                          if (includeQualifiers)
1490                                          {
1491                                              // Case: Total property replacement
1492                                              cimInstance.removeProperty(origPropPos);
1493 kumpf          1.200                         cimInstance.addProperty(givenProperty.clone());
1494 mike           1.51                      }
1495                                          else
1496                                          {
1497                                              // Case: Replace only the property value (not quals)
1498                                              origProperty.setValue(givenProperty.getValue());
1499                                              cimInstance.removeProperty(origPropPos);
1500                                              cimInstance.addProperty(origProperty);
1501                                          }
1502                                      }
1503                                      else
1504                                      {
1505                                          // Case: Property set in original and not in given
1506                                          // Just remove the property (set to null)
1507                                          cimInstance.removeProperty(origPropPos);
1508                                      }
1509                                  }
1510                                  else
1511                                  {
1512                                      // Case: Property not set in original
1513                      
1514                                      // Get the given property value
1515 mike           1.51                  Uint32 givenPropPos =
1516 kumpf          1.74                      givenInstance.findProperty(propertyList[i]);
1517 mike           1.51                  if (givenPropPos != PEG_NOT_FOUND)
1518                                      {
1519                                          // Case: Property set in given and not in original
1520 kumpf          1.200                     CIMConstProperty givenProperty =
1521 mike           1.51                          givenInstance.getProperty(givenPropPos);
1522                      
1523                                          // Copy over the property from the given to the original
1524                                          if (includeQualifiers)
1525                                          {
1526                                              // Case: Total property copy
1527 kumpf          1.200                         cimInstance.addProperty(givenProperty.clone());
1528 mike           1.51                      }
1529                                          else
1530                                          {
1531                                              // Case: Copy only the property value (not qualifiers)
1532                                              CIMProperty newProperty(
1533                                                  givenProperty.getName(),
1534                                                  givenProperty.getValue(),
1535                                                  givenProperty.getArraySize(),
1536                                                  givenProperty.getReferenceClassName(),
1537                                                  givenProperty.getClassOrigin(),
1538                                                  givenProperty.getPropagated());
1539                                              cimInstance.addProperty(newProperty);
1540                                          }
1541                                      }
1542                                      else
1543                                      {
1544                                          // Case: Property not set in original or in given
1545                      
1546                                          // Nothing to do; just make sure the property name is valid
1547                                          // ATTN: This is not the most efficient solution
1548                                          CIMClass cimClass = getClass(
1549 mike           1.51                          nameSpace, cimInstance.getClassName(), false);
1550 kumpf          1.74                      if (cimClass.findProperty(propertyList[i]) == PEG_NOT_FOUND)
1551 mike           1.51                      {
1552                                              // ATTN: This exception may be returned by setProperty
1553 kumpf          1.58                          PEG_METHOD_EXIT();
1554 mike           1.51                          throw PEGASUS_CIM_EXCEPTION(
1555                                                  CIM_ERR_NO_SUCH_PROPERTY, "modifyInstance()");
1556                                          }
1557                                      }
1558                                  }
1559                              }
1560                          }
1561                      
1562 kumpf          1.189     CIMObjectPath normalizedInstanceName =
1563                              _stripInstanceName(nameSpace, modifiedInstance.getPath());
1564 kumpf          1.168 
1565                          //
1566 kumpf          1.189     // Resolve the instance (do not propagate qualifiers from class since
1567                          // this will bloat the instance).
1568 mike           1.53      //
1569                      
1570 kumpf          1.189     CIMConstClass cimClass;
1571                          Resolver::resolveInstance(
1572                              cimInstance, _rep->_context, nameSpace, cimClass, false);
1573 mike           1.48  
1574 mike           1.53      //
1575 kumpf          1.189     // Disallow operation if the instance name was changed:
1576 mike           1.53      //
1577                      
1578 kumpf          1.189     if (cimInstance.buildPath(cimClass) != normalizedInstanceName)
1579 mike           1.51      {
1580 kumpf          1.104         PEG_METHOD_EXIT();
1581                              throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
1582                                  MessageLoaderParms(
1583 kumpf          1.189                 "Repository.CIMRepository.ATTEMPT_TO_MODIFY_KEY_PROPERTY",
1584                                      "Attempted to modify a key property"));
1585 dmitry.mikulin 1.179     }
1586                      
1587 kumpf          1.189     _rep->_persistentStore->modifyInstance(
1588                              nameSpace, normalizedInstanceName, cimInstance);
1589 mike           1.54  
1590 kumpf          1.58      PEG_METHOD_EXIT();
1591 mike           1.48  }
1592                      
1593                      Array<CIMClass> CIMRepository::enumerateClasses(
1594 kumpf          1.85      const CIMNamespaceName& nameSpace,
1595                          const CIMName& className,
1596 mike           1.48      Boolean deepInheritance,
1597                          Boolean localOnly,
1598                          Boolean includeQualifiers,
1599                          Boolean includeClassOrigin)
1600                      {
1601 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::enumerateClasses");
1602 mike           1.51  
1603 mike           1.184     ReadLock lock(_rep->_lock);
1604 kumpf          1.104 
1605 kumpf          1.85      Array<CIMName> classNames;
1606 mike           1.48  
1607 kumpf          1.192     _rep->_nameSpaceManager.getSubClassNames(
1608 mike           1.51          nameSpace, className, deepInheritance, classNames);
1609 mike           1.48  
1610                          Array<CIMClass> result;
1611                      
1612                          for (Uint32 i = 0; i < classNames.size(); i++)
1613                          {
1614 kumpf          1.104         result.append(_getClass(nameSpace, classNames[i], localOnly,
1615                                  includeQualifiers, includeClassOrigin, CIMPropertyList()));
1616 mike           1.48      }
1617                      
1618 kumpf          1.58      PEG_METHOD_EXIT();
1619 mike           1.48      return result;
1620                      }
1621                      
1622 kumpf          1.85  Array<CIMName> CIMRepository::enumerateClassNames(
1623                          const CIMNamespaceName& nameSpace,
1624                          const CIMName& className,
1625 mike           1.48      Boolean deepInheritance)
1626                      {
1627 kumpf          1.59      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::enumerateClassNames");
1628 kumpf          1.58  
1629 mike           1.184     ReadLock lock(_rep->_lock);
1630 kumpf          1.104 
1631 kumpf          1.85      Array<CIMName> classNames;
1632 mike           1.48  
1633 kumpf          1.192     _rep->_nameSpaceManager.getSubClassNames(
1634 schuur         1.112         nameSpace, className, deepInheritance, classNames,true);
1635 mike           1.48  
1636 kumpf          1.58      PEG_METHOD_EXIT();
1637 mike           1.48      return classNames;
1638                      }
1639                      
1640 kumpf          1.163 Array<CIMInstance> CIMRepository::enumerateInstancesForSubtree(
1641 kumpf          1.85      const CIMNamespaceName& nameSpace,
1642                          const CIMName& className,
1643 mike           1.48      Boolean deepInheritance,
1644                          Boolean localOnly,
1645                          Boolean includeQualifiers,
1646                          Boolean includeClassOrigin,
1647 mike           1.51      const CIMPropertyList& propertyList)
1648 mike           1.48  {
1649 kumpf          1.163     PEG_METHOD_ENTER(TRC_REPOSITORY,
1650                              "CIMRepository::enumerateInstancesForSubtree");
1651 kumpf          1.104 
1652 mike           1.184     // It is not necessary to control access to the ReadWriteSem lock here.
1653 kumpf          1.104     // This method calls enumerateInstancesForClass, which does its own
1654                          // access control.
1655                      
1656 karl           1.69      //
1657                          // Get all descendent classes of this class:
1658                          //
1659                      
1660 kumpf          1.85      Array<CIMName> classNames;
1661 kumpf          1.94      classNames.append(className);
1662 kumpf          1.192     _rep->_nameSpaceManager.getSubClassNames(
1663 mike           1.184         nameSpace, className, true, classNames);
1664 karl           1.69  
1665                          //
1666                          // Get all instances for this class and all its descendent classes
1667                          //
1668 kumpf          1.58  
1669 kumpf          1.70      Array<CIMInstance> namedInstances;
1670 kumpf          1.104 
1671 karl           1.69      for (Uint32 i = 0; i < classNames.size(); i++)
1672 karl           1.65      {
1673 karl           1.101         Array<CIMInstance> localNamedInstances =
1674 kumpf          1.163             enumerateInstancesForClass(nameSpace, classNames[i],
1675                                      false, includeQualifiers, includeClassOrigin, propertyList);
1676                      
1677 kumpf          1.198         // The propertyList, includeQualifiers, and includeClassOrigin 
1678                              // filtering is done in enumerateInstancesForClass.  localOnly
1679                              // filtering is not performed, since this flag is deprecated and
1680                              // is not supported for instance operations.
1681                              // ATTN: deepInheritance filtering is not performed.
1682                      
1683 karl           1.101         namedInstances.appendArray(localNamedInstances);
1684 karl           1.65      }
1685 karl           1.98  
1686 karl           1.65      PEG_METHOD_EXIT();
1687                          return namedInstances;
1688 karl           1.69  }
1689 karl           1.65  
1690 kumpf          1.70  Array<CIMInstance> CIMRepository::enumerateInstancesForClass(
1691 kumpf          1.85      const CIMNamespaceName& nameSpace,
1692                          const CIMName& className,
1693 karl           1.69      Boolean localOnly,
1694                          Boolean includeQualifiers,
1695                          Boolean includeClassOrigin,
1696                          const CIMPropertyList& propertyList)
1697                      {
1698 kumpf          1.104     PEG_METHOD_ENTER(TRC_REPOSITORY,
1699 kumpf          1.163         "CIMRepository::enumerateInstancesForClass");
1700 kumpf          1.104 
1701 mike           1.184     ReadLock lock(_rep->_lock);
1702 kumpf          1.104 
1703 kumpf          1.192     _rep->_nameSpaceManager.validateClass(nameSpace, className);
1704 kumpf          1.189 
1705 mike           1.53      //
1706 kumpf          1.163     // Get all instances for this class
1707 mike           1.53      //
1708 mike           1.48  
1709 kumpf          1.189     Array<CIMInstance> namedInstances =
1710                              _rep->_persistentStore->enumerateInstancesForClass(
1711                                  nameSpace, className);
1712 mike           1.48  
1713 kumpf          1.163     // Do any required filtering of properties, qualifiers, classorigin
1714                          // on the returned instances.
1715                          for (Uint32 i = 0 ; i < namedInstances.size(); i++)
1716                          {
1717 kumpf          1.198         if (includeQualifiers)
1718                              {
1719                                  // Instances are resolved in persistent storage by the
1720                                  // createInstance and modifyInstance operations, but qualifiers
1721                                  // are not propagated.  The only reason to perform resolution
1722                                  // here is if qualifiers are requested in the instance.
1723                                  Resolver::resolveInstance(
1724                                      namedInstances[i], _rep->_context, nameSpace, true);
1725                              }
1726 kumpf          1.189 
1727 kumpf          1.163         _filterInstance(namedInstances[i],
1728                                  propertyList,
1729                                  localOnly,
1730                                  includeQualifiers,
1731                                  includeClassOrigin);
1732                          }
1733                      
1734 kumpf          1.58      PEG_METHOD_EXIT();
1735 mike           1.51      return namedInstances;
1736 mike           1.48  }
1737 kumpf          1.104 
1738 kumpf          1.163 Array<CIMObjectPath> CIMRepository::enumerateInstanceNamesForSubtree(
1739 kumpf          1.85      const CIMNamespaceName& nameSpace,
1740                          const CIMName& className)
1741 mike           1.48  {
1742 kumpf          1.163     PEG_METHOD_ENTER(TRC_REPOSITORY,
1743                              "CIMRepository::enumerateInstanceNamesForSubtree");
1744 mike           1.51  
1745 mike           1.184     // It is not necessary to control access to the ReadWriteSem lock here.
1746 kumpf          1.165     // This method calls enumerateInstanceNamesForClass, which does its own
1747                          // access control.
1748 kumpf          1.104 
1749 karl           1.65      //
1750 karl           1.69      // Get names of descendent classes:
1751 karl           1.65      //
1752 kumpf          1.165 
1753 kumpf          1.85      Array<CIMName> classNames;
1754 kumpf          1.94      classNames.append(className);
1755 kumpf          1.192     _rep->_nameSpaceManager.getSubClassNames(
1756 mike           1.184         nameSpace, className, true, classNames);
1757 karl           1.65  
1758                          //
1759 kumpf          1.165     // Enumerate instance names for each of the subclasses
1760 karl           1.65      //
1761 karl           1.69      Array<CIMObjectPath> instanceNames;
1762 karl           1.65  
1763 karl           1.69      for (Uint32 i = 0; i < classNames.size(); i++)
1764                          {
1765 kumpf          1.165         instanceNames.appendArray(
1766                                  enumerateInstanceNamesForClass(nameSpace, classNames[i]));
1767 karl           1.65      }
1768                      
1769 karl           1.69      PEG_METHOD_EXIT();
1770                          return instanceNames;
1771                      }
1772                      
1773                      Array<CIMObjectPath> CIMRepository::enumerateInstanceNamesForClass(
1774 kumpf          1.85      const CIMNamespaceName& nameSpace,
1775 kumpf          1.163     const CIMName& className)
1776 karl           1.69  {
1777 kumpf          1.104     PEG_METHOD_ENTER(TRC_REPOSITORY,
1778 kumpf          1.163         "CIMRepository::enumerateInstanceNamesForClass");
1779 kumpf          1.104 
1780 mike           1.184     ReadLock lock(_rep->_lock);
1781 karl           1.69  
1782 kumpf          1.192     _rep->_nameSpaceManager.validateClass(nameSpace, className);
1783 mike           1.48  
1784 kumpf          1.189     Array<CIMObjectPath> instanceNames =
1785                              _rep->_persistentStore->enumerateInstanceNamesForClass(
1786                                  nameSpace, className);
1787 mike           1.53  
1788 kumpf          1.52      PEG_METHOD_EXIT();
1789 mike           1.48      return instanceNames;
1790                      }
1791 karl           1.69  
1792 mike           1.48  
1793 kumpf          1.71  Array<CIMObject> CIMRepository::associators(
1794 kumpf          1.85      const CIMNamespaceName& nameSpace,
1795 kumpf          1.68      const CIMObjectPath& objectName,
1796 kumpf          1.85      const CIMName& assocClass,
1797                          const CIMName& resultClass,
1798 mike           1.48      const String& role,
1799                          const String& resultRole,
1800                          Boolean includeQualifiers,
1801                          Boolean includeClassOrigin,
1802 mike           1.51      const CIMPropertyList& propertyList)
1803 mike           1.48  {
1804 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::associators");
1805                      
1806 mike           1.184     ReadLock lock(_rep->_lock);
1807 kumpf          1.104 
1808                          Array<CIMObjectPath> names = _associatorNames(
1809 mike           1.51          nameSpace,
1810                              objectName,
1811                              assocClass,
1812                              resultClass,
1813                              role,
1814                              resultRole);
1815 mike           1.48  
1816 kumpf          1.71      Array<CIMObject> result;
1817 mike           1.48  
1818                          for (Uint32 i = 0, n = names.size(); i < n; i++)
1819                          {
1820 kumpf          1.85          CIMNamespaceName tmpNameSpace = names[i].getNameSpace();
1821 mike           1.48  
1822 kumpf          1.85          if (tmpNameSpace.isNull())
1823 mike           1.51              tmpNameSpace = nameSpace;
1824 mike           1.48  
1825 kumpf          1.80          //
1826                              //  ATTN-CAKG-P2-20020726:  The following condition does not correctly
1827                              //  distinguish instanceNames from classNames in every case
1828                              //  The instanceName of a singleton instance of a keyless class also
1829                              //  has no key bindings
1830                              //
1831                              if (names[i].getKeyBindings ().size () == 0)
1832 mike           1.51          {
1833 kumpf          1.68              CIMObjectPath tmpRef = names[i];
1834 mike           1.51              tmpRef.setHost(String());
1835 kumpf          1.95              tmpRef.setNameSpace(CIMNamespaceName());
1836 mike           1.51  
1837 kumpf          1.104             CIMClass cimClass = _getClass(
1838 mike           1.51                  tmpNameSpace,
1839                                      tmpRef.getClassName(),
1840                                      false,
1841                                      includeQualifiers,
1842                                      includeClassOrigin,
1843                                      propertyList);
1844                      
1845                                  CIMObject cimObject(cimClass);
1846 kumpf          1.71              cimObject.setPath (names[i]);
1847                                  result.append(cimObject);
1848 mike           1.51          }
1849                              else
1850                              {
1851 kumpf          1.68              CIMObjectPath tmpRef = names[i];
1852 mike           1.51              tmpRef.setHost(String());
1853 kumpf          1.95              tmpRef.setNameSpace(CIMNamespaceName());
1854 mike           1.51  
1855 kumpf          1.104             CIMInstance cimInstance = _getInstance(
1856 mike           1.51                  tmpNameSpace,
1857                                      tmpRef,
1858                                      false,
1859                                      includeQualifiers,
1860                                      includeClassOrigin,
1861 kumpf          1.191                 propertyList,
1862                                      true);
1863 mike           1.51  
1864                                  CIMObject cimObject(cimInstance);
1865 kumpf          1.71              cimObject.setPath (names[i]);
1866                                  result.append(cimObject);
1867 mike           1.51          }
1868 mike           1.48      }
1869                      
1870 kumpf          1.58      PEG_METHOD_EXIT();
1871 mike           1.48      return result;
1872                      }
1873                      
1874 kumpf          1.68  Array<CIMObjectPath> CIMRepository::associatorNames(
1875 kumpf          1.85      const CIMNamespaceName& nameSpace,
1876 kumpf          1.68      const CIMObjectPath& objectName,
1877 kumpf          1.85      const CIMName& assocClass,
1878                          const CIMName& resultClass,
1879 mike           1.48      const String& role,
1880                          const String& resultRole)
1881                      {
1882 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::associatorNames");
1883 mike           1.51  
1884 mike           1.184     ReadLock lock(_rep->_lock);
1885 kumpf          1.104     Array<CIMObjectPath> result = _associatorNames(
1886                              nameSpace, objectName, assocClass, resultClass, role, resultRole);
1887                      
1888                          PEG_METHOD_EXIT();
1889                          return result;
1890                      }
1891                      
1892                      Array<CIMObjectPath> CIMRepository::_associatorNames(
1893                          const CIMNamespaceName& nameSpace,
1894                          const CIMObjectPath& objectName,
1895                          const CIMName& assocClass,
1896                          const CIMName& resultClass,
1897                          const String& role,
1898                          const String& resultRole)
1899                      {
1900                          PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_associatorNames");
1901                      
1902 mike           1.48      Array<String> associatorNames;
1903                      
1904 kumpf          1.93      // The assocClass parameter implies subclasses, so retrieve them
1905                          Array<CIMName> assocClassList;
1906                          if (!assocClass.isNull())
1907                          {
1908 kumpf          1.192         _rep->_nameSpaceManager.getSubClassNames(
1909 kumpf          1.93              nameSpace, assocClass, true, assocClassList);
1910                              assocClassList.append(assocClass);
1911                          }
1912                      
1913                          // The resultClass parameter implies subclasses, so retrieve them
1914                          Array<CIMName> resultClassList;
1915                          if (!resultClass.isNull())
1916                          {
1917 kumpf          1.192         _rep->_nameSpaceManager.getSubClassNames(
1918 kumpf          1.93              nameSpace, resultClass, true, resultClassList);
1919                              resultClassList.append(resultClass);
1920                          }
1921                      
1922 kumpf          1.80      //
1923                          //  ATTN-CAKG-P2-20020726:  The following condition does not correctly
1924                          //  distinguish instanceNames from classNames in every case
1925                          //  The instanceName of a singleton instance of a keyless class also
1926                          //  has no key bindings
1927                          //
1928                          if (objectName.getKeyBindings ().size () == 0)
1929 mike           1.48      {
1930 kumpf          1.93          CIMName className = objectName.getClassName();
1931                      
1932                              Array<CIMName> classList;
1933 kumpf          1.192         _rep->_nameSpaceManager.getSuperClassNames(
1934 mike           1.184             nameSpace, className, classList);
1935 kumpf          1.93          classList.append(className);
1936                      
1937 kumpf          1.189         Array<CIMNamespaceName> nameSpaceList =
1938 kumpf          1.192             _rep->_nameSpaceManager.getSchemaNameSpaceNames(nameSpace);
1939 mike           1.48  
1940 kumpf          1.189         for (Uint32 i = 0; i < nameSpaceList.size(); i++)
1941 kumpf          1.169         {
1942 kumpf          1.189             Array<String> associatorNamesForNameSpace;
1943                      
1944                                  _rep->_persistentStore->getClassAssociatorNames(
1945                                      nameSpaceList[i],
1946 kumpf          1.169                 classList,
1947                                      assocClassList,
1948                                      resultClassList,
1949                                      role,
1950                                      resultRole,
1951 kumpf          1.189                 associatorNamesForNameSpace);
1952                      
1953                                  associatorNames.appendArray(associatorNamesForNameSpace);
1954 kumpf          1.169         }
1955 mike           1.48      }
1956 kumpf          1.169     else
1957                          {
1958 kumpf          1.192         _rep->_nameSpaceManager.validateClass(
1959 kumpf          1.189             nameSpace, objectName.getClassName());
1960 mike           1.48  
1961 kumpf          1.189         _rep->_persistentStore->getInstanceAssociatorNames(
1962                                  nameSpace,
1963 mike           1.51              objectName,
1964 kumpf          1.93              assocClassList,
1965                                  resultClassList,
1966 mike           1.51              role,
1967                                  resultRole,
1968                                  associatorNames);
1969 mike           1.48      }
1970                      
1971 kumpf          1.68      Array<CIMObjectPath> result;
1972 mike           1.48  
1973                          for (Uint32 i = 0, n = associatorNames.size(); i < n; i++)
1974                          {
1975 kumpf          1.68          CIMObjectPath r = associatorNames[i];
1976 mike           1.48  
1977                              if (r.getHost().size() == 0)
1978                                  r.setHost(System::getHostName());
1979                      
1980 kumpf          1.79          if (r.getNameSpace().isNull())
1981 mike           1.48              r.setNameSpace(nameSpace);
1982                      
1983 mike           1.51          result.append(r);
1984 mike           1.48      }
1985                      
1986 kumpf          1.58      PEG_METHOD_EXIT();
1987 mike           1.48      return result;
1988                      }
1989                      
1990 kumpf          1.71  Array<CIMObject> CIMRepository::references(
1991 kumpf          1.85      const CIMNamespaceName& nameSpace,
1992 kumpf          1.68      const CIMObjectPath& objectName,
1993 kumpf          1.85      const CIMName& resultClass,
1994 mike           1.48      const String& role,
1995                          Boolean includeQualifiers,
1996                          Boolean includeClassOrigin,
1997 mike           1.51      const CIMPropertyList& propertyList)
1998 mike           1.48  {
1999 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::references");
2000                      
2001 mike           1.184     ReadLock lock(_rep->_lock);
2002 kumpf          1.104 
2003                          Array<CIMObjectPath> names = _referenceNames(
2004 mike           1.51          nameSpace,
2005                              objectName,
2006                              resultClass,
2007                              role);
2008 mike           1.48  
2009 kumpf          1.71      Array<CIMObject> result;
2010 mike           1.48  
2011                          for (Uint32 i = 0, n = names.size(); i < n; i++)
2012                          {
2013 kumpf          1.85          CIMNamespaceName tmpNameSpace = names[i].getNameSpace();
2014 mike           1.48  
2015 kumpf          1.85          if (tmpNameSpace.isNull())
2016 mike           1.51              tmpNameSpace = nameSpace;
2017 mike           1.48  
2018 mike           1.51          // ATTN: getInstance() should this be able to handle instance names
2019                              // with host names and namespaces?
2020 mike           1.48  
2021 kumpf          1.68          CIMObjectPath tmpRef = names[i];
2022 mike           1.51          tmpRef.setHost(String());
2023 kumpf          1.95          tmpRef.setNameSpace(CIMNamespaceName());
2024 mike           1.51  
2025 kumpf          1.80          //
2026                              //  ATTN-CAKG-P2-20020726:  The following condition does not correctly
2027                              //  distinguish instanceNames from classNames in every case
2028                              //  The instanceName of a singleton instance of a keyless class also
2029                              //  has no key bindings
2030                              //
2031                              if (objectName.getKeyBindings ().size () == 0)
2032 mike           1.51          {
2033 kumpf          1.104             CIMClass cimClass = _getClass(
2034 mike           1.51                  tmpNameSpace,
2035                                      tmpRef.getClassName(),
2036                                      false,
2037                                      includeQualifiers,
2038                                      includeClassOrigin,
2039                                      propertyList);
2040                      
2041 kumpf          1.71              CIMObject cimObject = CIMObject (cimClass);
2042                                  cimObject.setPath (names[i]);
2043                                  result.append (cimObject);
2044 mike           1.51          }
2045                              else
2046                              {
2047 kumpf          1.104             CIMInstance instance = _getInstance(
2048 mike           1.51                  tmpNameSpace,
2049                                      tmpRef,
2050                                      false,
2051                                      includeQualifiers,
2052                                      includeClassOrigin,
2053 kumpf          1.191                 propertyList,
2054                                      true);
2055 mike           1.48  
2056 kumpf          1.71              CIMObject cimObject = CIMObject (instance);
2057                                  cimObject.setPath (names[i]);
2058                                  result.append (cimObject);
2059 mike           1.51          }
2060 mike           1.48      }
2061                      
2062 kumpf          1.58      PEG_METHOD_EXIT();
2063 mike           1.48      return result;
2064                      }
2065                      
2066 kumpf          1.68  Array<CIMObjectPath> CIMRepository::referenceNames(
2067 kumpf          1.85      const CIMNamespaceName& nameSpace,
2068 kumpf          1.68      const CIMObjectPath& objectName,
2069 kumpf          1.85      const CIMName& resultClass,
2070 mike           1.48      const String& role)
2071                      {
2072 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::referenceNames");
2073                      
2074 mike           1.184     ReadLock lock(_rep->_lock);
2075 kumpf          1.104     Array<CIMObjectPath> result = _referenceNames(
2076                              nameSpace, objectName, resultClass, role);
2077                      
2078                          PEG_METHOD_EXIT();
2079                          return result;
2080                      }
2081                      
2082                      Array<CIMObjectPath> CIMRepository::_referenceNames(
2083                          const CIMNamespaceName& nameSpace,
2084                          const CIMObjectPath& objectName,
2085                          const CIMName& resultClass,
2086                          const String& role)
2087                      {
2088                          PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_referenceNames");
2089                      
2090 mike           1.48      Array<String> tmpReferenceNames;
2091                      
2092 kumpf          1.93      // The resultClass parameter implies subclasses, so retrieve them
2093                          Array<CIMName> resultClassList;
2094 a.dunfey       1.120 
2095 kumpf          1.169     try
2096 kumpf          1.93      {
2097 kumpf          1.169         if (!resultClass.isNull())
2098                              {
2099 kumpf          1.192             _rep->_nameSpaceManager.getSubClassNames(
2100 kumpf          1.169                 nameSpace, resultClass, true, resultClassList);
2101                                  resultClassList.append(resultClass);
2102                              }
2103 karl           1.86  
2104 kumpf          1.169         //  ATTN-CAKG-P2-20020726:  The following condition does not correctly
2105                              //  distinguish instanceNames from classNames in every case
2106                              //  The instanceName of a singleton instance of a keyless class also
2107                              //  has no key bindings
2108                              //
2109                              if (objectName.getKeyBindings ().size () == 0)
2110                              {
2111                                  CIMName className = objectName.getClassName();
2112 kumpf          1.93  
2113 kumpf          1.169             Array<CIMName> classList;
2114 kumpf          1.192             _rep->_nameSpaceManager.getSuperClassNames(
2115 kumpf          1.169                 nameSpace, className, classList);
2116                                  classList.append(className);
2117 kumpf          1.93  
2118 kumpf          1.189             Array<CIMNamespaceName> nameSpaceList =
2119 kumpf          1.192                 _rep->_nameSpaceManager.getSchemaNameSpaceNames(nameSpace);
2120 mike           1.48  
2121 kumpf          1.189             for (Uint32 i = 0; i < nameSpaceList.size(); i++)
2122 kumpf          1.169             {
2123 kumpf          1.189                 Array<String> referenceNamesForNameSpace;
2124                      
2125                                      _rep->_persistentStore->getClassReferenceNames(
2126                                          nameSpaceList[i],
2127                                          classList,
2128                                          resultClassList,
2129                                          role,
2130                                          referenceNamesForNameSpace);
2131 schuur         1.112 
2132 kumpf          1.189                 tmpReferenceNames.appendArray(referenceNamesForNameSpace);
2133 kumpf          1.169             }
2134 mike           1.51          }
2135 kumpf          1.169         else
2136                              {
2137 kumpf          1.192             _rep->_nameSpaceManager.validateClass(
2138 kumpf          1.189                 nameSpace, objectName.getClassName());
2139 schuur         1.112 
2140 kumpf          1.189             _rep->_persistentStore->getInstanceReferenceNames(
2141                                      nameSpace,
2142 kumpf          1.169                 objectName,
2143                                      resultClassList,
2144                                      role,
2145 kumpf          1.189                 tmpReferenceNames);
2146 mike           1.51          }
2147 mike           1.48      }
2148 kumpf          1.169     catch (const CIMException& exception)
2149 kumpf          1.142     {
2150 kumpf          1.169         if (exception.getCode() == CIM_ERR_INVALID_CLASS)
2151                              {
2152                                  throw PEGASUS_CIM_EXCEPTION(
2153                                      CIM_ERR_INVALID_PARAMETER, exception.getMessage());
2154                              }
2155                              else
2156                              {
2157                                  throw;
2158                              }
2159 kumpf          1.142     }
2160 mike           1.48  
2161 kumpf          1.68      Array<CIMObjectPath> result;
2162 mike           1.48  
2163                          for (Uint32 i = 0, n = tmpReferenceNames.size(); i < n; i++)
2164                          {
2165 kumpf          1.68          CIMObjectPath r = tmpReferenceNames[i];
2166 mike           1.48  
2167                              if (r.getHost().size() == 0)
2168                                  r.setHost(System::getHostName());
2169                      
2170 kumpf          1.79          if (r.getNameSpace().isNull())
2171 mike           1.48              r.setNameSpace(nameSpace);
2172                      
2173 mike           1.51          result.append(r);
2174 mike           1.48      }
2175                      
2176 kumpf          1.58      PEG_METHOD_EXIT();
2177 mike           1.48      return result;
2178                      }
2179                      
2180                      CIMValue CIMRepository::getProperty(
2181 kumpf          1.85      const CIMNamespaceName& nameSpace,
2182 kumpf          1.68      const CIMObjectPath& instanceName,
2183 kumpf          1.85      const CIMName& propertyName)
2184 mike           1.48  {
2185 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::getProperty");
2186                      
2187 mike           1.184     ReadLock lock(_rep->_lock);
2188 kumpf          1.104 
2189 mike           1.53      //
2190 kumpf          1.165     // Retrieve the specified instance
2191 mike           1.53      //
2192 mike           1.48  
2193 kumpf          1.165     CIMInstance cimInstance = _getInstance(
2194 kumpf          1.198         nameSpace, instanceName, false, true, true, CIMPropertyList(), false);
2195 mike           1.48  
2196 mike           1.53      //
2197 kumpf          1.165     // Get the requested property from the instance
2198 mike           1.53      //
2199 mike           1.48  
2200                          Uint32 pos = cimInstance.findProperty(propertyName);
2201                      
2202 mike           1.51      // ATTN: This breaks if the property is simply null
2203 kumpf          1.77      if (pos == PEG_NOT_FOUND)
2204 kumpf          1.58      {
2205                              PEG_METHOD_EXIT();
2206 kumpf          1.149         throw PEGASUS_CIM_EXCEPTION(
2207                                  CIM_ERR_NO_SUCH_PROPERTY,
2208                                  propertyName.getString());
2209 kumpf          1.58      }
2210 mike           1.48  
2211                          CIMProperty prop = cimInstance.getProperty(pos);
2212                      
2213 mike           1.53      //
2214                          // Return the value:
2215                          //
2216 mike           1.48  
2217 kumpf          1.58      PEG_METHOD_EXIT();
2218 mike           1.48      return prop.getValue();
2219                      }
2220                      
2221                      void CIMRepository::setProperty(
2222 kumpf          1.85      const CIMNamespaceName& nameSpace,
2223 kumpf          1.68      const CIMObjectPath& instanceName,
2224 kumpf          1.85      const CIMName& propertyName,
2225 kumpf          1.199     const CIMValue& newValue)
2226 mike           1.48  {
2227 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::setProperty");
2228                      
2229 mike           1.184     // It is not necessary to control access to the ReadWriteSem lock here.
2230 kumpf          1.104     // This method calls modifyInstance, which does its own access control.
2231                      
2232 mike           1.51      //
2233                          // Create the instance to pass to modifyInstance()
2234                          //
2235 mike           1.53  
2236 mike           1.51      CIMInstance instance(instanceName.getClassName());
2237                          instance.addProperty(CIMProperty(propertyName, newValue));
2238 kumpf          1.70      instance.setPath (instanceName);
2239 mike           1.51  
2240                          //
2241                          // Create the propertyList to pass to modifyInstance()
2242                          //
2243 mike           1.53  
2244 kumpf          1.79      Array<CIMName> propertyListArray;
2245 mike           1.51      propertyListArray.append(propertyName);
2246                          CIMPropertyList propertyList(propertyListArray);
2247                      
2248                          //
2249                          // Modify the instance to set the value of the given property
2250                          //
2251 kumpf          1.70      modifyInstance(nameSpace, instance, false, propertyList);
2252 kumpf          1.58  
2253                          PEG_METHOD_EXIT();
2254 mike           1.48  }
2255                      
2256                      CIMQualifierDecl CIMRepository::getQualifier(
2257 kumpf          1.85      const CIMNamespaceName& nameSpace,
2258                          const CIMName& qualifierName)
2259 mike           1.48  {
2260 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::getQualifier");
2261                      
2262 mike           1.184     ReadLock lock(_rep->_lock);
2263 kumpf          1.104     CIMQualifierDecl qualifierDecl = _getQualifier(nameSpace, qualifierName);
2264                      
2265                          PEG_METHOD_EXIT();
2266                          return qualifierDecl;
2267                      }
2268                      
2269                      CIMQualifierDecl CIMRepository::_getQualifier(
2270                          const CIMNamespaceName& nameSpace,
2271                          const CIMName& qualifierName)
2272                      {
2273                          PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_getQualifier");
2274                      
2275 kumpf          1.189     CIMQualifierDecl qualifierDecl;
2276 mike           1.48  
2277 kumpf          1.189     String qualifierCacheKey = _getCacheKey(nameSpace, qualifierName);
2278 mike           1.48  
2279 kumpf          1.189     // Check the cache first:
2280 mike           1.48  
2281 kumpf          1.189     if (!_qualifierCache.get(qualifierCacheKey, qualifierDecl))
2282 mike           1.48      {
2283 kumpf          1.189         // Not in cache so load from disk:
2284                      
2285                              Array<CIMNamespaceName> nameSpaceList =
2286 kumpf          1.192             _rep->_nameSpaceManager.getSchemaNameSpaceNames(nameSpace);
2287 mike           1.153 
2288 kumpf          1.189         for (Uint32 i = 0; i < nameSpaceList.size(); i++)
2289 mike           1.153         {
2290 kumpf          1.189             qualifierDecl = _rep->_persistentStore->getQualifier(
2291                                      nameSpaceList[i], qualifierName);
2292 mike           1.153 
2293 kumpf          1.189             if (!qualifierDecl.isUninitialized())
2294                                  {
2295                                      // Put in cache
2296                                      _qualifierCache.put(qualifierCacheKey, qualifierDecl);
2297 mike           1.153 
2298 kumpf          1.189                 PEG_METHOD_EXIT();
2299                                      return qualifierDecl;
2300                                  }
2301                              }
2302 mike           1.153 
2303 kumpf          1.58          PEG_METHOD_EXIT();
2304 kumpf          1.189         throw PEGASUS_CIM_EXCEPTION(
2305                                  CIM_ERR_NOT_FOUND, qualifierName.getString());
2306 mike           1.48      }
2307                      
2308 kumpf          1.58      PEG_METHOD_EXIT();
2309 mike           1.48      return qualifierDecl;
2310                      }
2311                      
2312                      void CIMRepository::setQualifier(
2313 kumpf          1.85      const CIMNamespaceName& nameSpace,
2314 kumpf          1.199     const CIMQualifierDecl& qualifierDecl)
2315 mike           1.48  {
2316 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::setQualifier");
2317 chuck          1.110 
2318 mike           1.184     WriteLock lock(_rep->_lock);
2319                          AutoFileLock fileLock(_rep->_lockFile);
2320 kumpf          1.104     _setQualifier(nameSpace, qualifierDecl);
2321                      
2322                          PEG_METHOD_EXIT();
2323                      }
2324                      
2325                      void CIMRepository::_setQualifier(
2326                          const CIMNamespaceName& nameSpace,
2327                          const CIMQualifierDecl& qualifierDecl)
2328                      {
2329                          PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_setQualifier");
2330                      
2331 kumpf          1.192     _rep->_nameSpaceManager.checkSetOrDeleteQualifier(
2332 kumpf          1.189         nameSpace, qualifierDecl.getName());
2333 mike           1.48  
2334 kumpf          1.189     _rep->_persistentStore->setQualifier(nameSpace, qualifierDecl);
2335 mike           1.48  
2336 kumpf          1.189     String qualifierCacheKey =
2337                              _getCacheKey(nameSpace, qualifierDecl.getName());
2338                          _qualifierCache.put(qualifierCacheKey, (CIMQualifierDecl&)qualifierDecl);
2339 jim.wunderlich 1.136 
2340 kumpf          1.58      PEG_METHOD_EXIT();
2341 mike           1.48  }
2342                      
2343                      void CIMRepository::deleteQualifier(
2344 kumpf          1.85      const CIMNamespaceName& nameSpace,
2345                          const CIMName& qualifierName)
2346 mike           1.48  {
2347 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::deleteQualifier");
2348                      
2349 mike           1.184     WriteLock lock(_rep->_lock);
2350                          AutoFileLock fileLock(_rep->_lockFile);
2351 kumpf          1.104 
2352 kumpf          1.192     _rep->_nameSpaceManager.checkSetOrDeleteQualifier(
2353 kumpf          1.189         nameSpace, qualifierName);
2354 mike           1.48  
2355 kumpf          1.189     _rep->_persistentStore->deleteQualifier(nameSpace, qualifierName);
2356 mike           1.48  
2357 kumpf          1.189     String qualifierCacheKey = _getCacheKey(nameSpace, qualifierName);
2358                          _qualifierCache.evict(qualifierCacheKey);
2359 mike           1.153 
2360 kumpf          1.58      PEG_METHOD_EXIT();
2361 mike           1.48  }
2362                      
2363                      Array<CIMQualifierDecl> CIMRepository::enumerateQualifiers(
2364 kumpf          1.85      const CIMNamespaceName& nameSpace)
2365 mike           1.48  {
2366 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::enumerateQualifiers");
2367                      
2368 mike           1.184     ReadLock lock(_rep->_lock);
2369 kumpf          1.104 
2370 kumpf          1.189     Array<CIMQualifierDecl> qualifiers;
2371 mike           1.48  
2372 kumpf          1.192     _rep->_nameSpaceManager.validateNameSpace(nameSpace);
2373 mike           1.48  
2374 kumpf          1.189     qualifiers = _rep->_persistentStore->enumerateQualifiers(nameSpace);
2375 mike           1.48  
2376 kumpf          1.58      PEG_METHOD_EXIT();
2377 mike           1.48      return qualifiers;
2378                      }
2379                      
2380 kumpf          1.189 void CIMRepository::createNameSpace(
2381                          const CIMNamespaceName& nameSpace,
2382                          const NameSpaceAttributes& attributes)
2383 mike           1.48  {
2384 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::createNameSpace");
2385                      
2386 mike           1.184     WriteLock lock(_rep->_lock);
2387                          AutoFileLock fileLock(_rep->_lockFile);
2388 kumpf          1.189 
2389                          Boolean shareable = false;
2390                          Boolean updatesAllowed = true;
2391                          String parentNameSpace;
2392                      
2393                          for (NameSpaceAttributes::Iterator i = attributes.start(); i; i++)
2394                          {
2395                              String key = i.key();
2396                              if (String::equalNoCase(key, "shareable"))
2397                              {
2398                                  if (String::equalNoCase(i.value(), "true"))
2399                                      shareable = true;
2400                              }
2401                              else if (String::equalNoCase(key, "updatesAllowed"))
2402                              {
2403                                  if (String::equalNoCase(i.value(), "false"))
2404                                      updatesAllowed = false;
2405                              }
2406                              else if (String::equalNoCase(key, "parent"))
2407                              {
2408                                  parentNameSpace = i.value();
2409 kumpf          1.189         }
2410                              else
2411                              {
2412                                  PEG_METHOD_EXIT();
2413                                  throw PEGASUS_CIM_EXCEPTION(
2414                                      CIM_ERR_NOT_SUPPORTED,
2415                                      nameSpace.getString() + " option not supported: " + key);
2416                              }
2417                          }
2418                      
2419 kumpf          1.192     _rep->_nameSpaceManager.createNameSpace(
2420 kumpf          1.189         nameSpace, shareable, updatesAllowed, parentNameSpace);
2421                      
2422                          try
2423                          {
2424                              _rep->_persistentStore->createNameSpace(
2425                                  nameSpace, shareable, updatesAllowed, parentNameSpace);
2426                          }
2427                          catch (...)
2428                          {
2429 kumpf          1.192         _rep->_nameSpaceManager.deleteNameSpace(nameSpace);
2430 kumpf          1.189         throw;
2431                          }
2432 schuur         1.112 
2433                          PEG_METHOD_EXIT();
2434                      }
2435                      
2436 kumpf          1.189 void CIMRepository::modifyNameSpace(
2437                          const CIMNamespaceName& nameSpace,
2438                          const NameSpaceAttributes& attributes)
2439 schuur         1.112 {
2440                          PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::modifyNameSpace");
2441                      
2442 mike           1.184     WriteLock lock(_rep->_lock);
2443                          AutoFileLock fileLock(_rep->_lockFile);
2444 kumpf          1.189 
2445                          Boolean shareable = false;
2446                          Boolean updatesAllowed = true;
2447                      
2448                          for (NameSpaceAttributes::Iterator i = attributes.start(); i; i++)
2449                          {
2450                              String key = i.key();
2451                              if (String::equalNoCase(key, "shareable"))
2452                              {
2453                                  if (String::equalNoCase(i.value(), "true"))
2454                                      shareable = true;
2455                              }
2456                              else if (String::equalNoCase(key, "updatesAllowed"))
2457                              {
2458                                  if (String::equalNoCase(i.value(),"false"))
2459                                      updatesAllowed = false;
2460                              }
2461                              else
2462                              {
2463                                  PEG_METHOD_EXIT();
2464                                  throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED,
2465 kumpf          1.189                 nameSpace.getString() + " option not supported: " + key);
2466                              }
2467                          }
2468                      
2469 kumpf          1.192     _rep->_nameSpaceManager.validateNameSpace(nameSpace);
2470 kumpf          1.189 
2471                          if (!shareable)
2472                          {
2473                              // Check for dependent namespaces
2474                      
2475                              CIMNamespaceName dependentNameSpaceName;
2476                      
2477 kumpf          1.192         if (_rep->_nameSpaceManager.hasDependentNameSpace(
2478 kumpf          1.189                 nameSpace, dependentNameSpaceName))
2479                              {
2480                                  PEG_METHOD_EXIT();
2481                                  throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
2482                                      "Namespace " + nameSpace.getString() +
2483                                          " has dependent namespace " +
2484                                          dependentNameSpaceName.getString());
2485                              }
2486                          }
2487                      
2488                          _rep->_persistentStore->modifyNameSpace(
2489                              nameSpace, shareable, updatesAllowed);
2490                      
2491 kumpf          1.192     _rep->_nameSpaceManager.modifyNameSpace(
2492 kumpf          1.189         nameSpace, shareable, updatesAllowed);
2493 kumpf          1.58  
2494                          PEG_METHOD_EXIT();
2495 mike           1.48  }
2496                      
2497 kumpf          1.85  Array<CIMNamespaceName> CIMRepository::enumerateNameSpaces() const
2498 mike           1.48  {
2499 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::enumerateNameSpaces");
2500                      
2501 mike           1.184     ReadLock lock(const_cast<ReadWriteSem&>(_rep->_lock));
2502 kumpf          1.104 
2503 kumpf          1.85      Array<CIMNamespaceName> nameSpaceNames;
2504 kumpf          1.192     _rep->_nameSpaceManager.getNameSpaceNames(nameSpaceNames);
2505 kumpf          1.58  
2506                          PEG_METHOD_EXIT();
2507 mike           1.48      return nameSpaceNames;
2508                      }
2509                      
2510 kumpf          1.85  void CIMRepository::deleteNameSpace(const CIMNamespaceName& nameSpace)
2511 mike           1.48  {
2512 kumpf          1.58      PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::deleteNameSpace");
2513                      
2514 mike           1.184     WriteLock lock(_rep->_lock);
2515                          AutoFileLock fileLock(_rep->_lockFile);
2516 kumpf          1.58  
2517 kumpf          1.189     // Check for dependent namespaces
2518 mike           1.48  
2519 kumpf          1.189     CIMNamespaceName dependentNameSpaceName;
2520 schuur         1.112 
2521 kumpf          1.192     if (_rep->_nameSpaceManager.hasDependentNameSpace(
2522 kumpf          1.189             nameSpace, dependentNameSpaceName))
2523                          {
2524                              PEG_METHOD_EXIT();
2525                              throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
2526                                  "Namespace " + nameSpace.getString() +
2527                                      " has dependent namespace " +
2528                                      dependentNameSpaceName.getString());
2529                          }
2530 schuur         1.115 
2531 kumpf          1.189     // Make sure the namespace is empty
2532 mike           1.51  
2533 kumpf          1.189     if (!_rep->_persistentStore->isNameSpaceEmpty(nameSpace))
2534                          {
2535                              PEG_METHOD_EXIT();
2536                              throw NonEmptyNameSpace(nameSpace.getString());
2537                          }
2538 kumpf          1.58  
2539 kumpf          1.189     _rep->_persistentStore->deleteNameSpace(nameSpace);
2540 mike           1.53  
2541 kumpf          1.192     _rep->_nameSpaceManager.deleteNameSpace(nameSpace);
2542 kumpf          1.58  
2543                          PEG_METHOD_EXIT();
2544 mike           1.48  }
2545                      
2546 kumpf          1.189 Boolean CIMRepository::getNameSpaceAttributes(const CIMNamespaceName& nameSpace,
2547                              NameSpaceAttributes& attributes)
2548 mike           1.48  {
2549 kumpf          1.189     PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::deleteNameSpace");
2550 kumpf          1.58  
2551 kumpf          1.189     ReadLock lock(const_cast<ReadWriteSem&>(_rep->_lock));
2552                          attributes.clear();
2553 mike           1.51  
2554 kumpf          1.189     Boolean shareable;
2555                          Boolean updatesAllowed;
2556                          String parent;
2557 mike           1.51  
2558 kumpf          1.192     if (!_rep->_nameSpaceManager.getNameSpaceAttributes(
2559 kumpf          1.189         nameSpace, shareable, updatesAllowed, parent))
2560 kumpf          1.58      {
2561                              PEG_METHOD_EXIT();
2562 mike           1.51          return false;
2563 kumpf          1.58      }
2564 mike           1.51  
2565 kumpf          1.189     attributes.insert("name", nameSpace.getString());
2566                      
2567                          if (shareable)
2568                              attributes.insert("shareable", "true");
2569                          else
2570                              attributes.insert("shareable", "false");
2571                      
2572                          if (updatesAllowed)
2573                              attributes.insert("updatesAllowed", "true");
2574                          else
2575                              attributes.insert("updatesAllowed", "false");
2576 mike           1.51  
2577 kumpf          1.189     if (parent.size())
2578                              attributes.insert("parent", parent);
2579 mike           1.51  
2580 kumpf          1.58      PEG_METHOD_EXIT();
2581 mike           1.51      return true;
2582 mike           1.48  }
2583                      
2584 kumpf          1.189 Boolean CIMRepository::isRemoteNameSpace(
2585                          const CIMNamespaceName& nameSpaceName,
2586                          String& remoteInfo)
2587                      {
2588                          PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::isRemoteNamespace");
2589                          ReadLock lock(const_cast<ReadWriteSem&>(_rep->_lock));
2590                          PEG_METHOD_EXIT();
2591 kumpf          1.192     return _rep->_nameSpaceManager.isRemoteNameSpace(
2592 kumpf          1.189         nameSpaceName, remoteInfo);
2593                      }
2594 bob            1.49  
2595 dave.sudlik    1.154 #ifdef PEGASUS_DEBUG
2596 kumpf          1.169     void CIMRepository::DisplayCacheStatistics()
2597 dave.sudlik    1.154     {
2598                      #ifdef PEGASUS_USE_CLASS_CACHE
2599                              cout << "Repository Class Cache Statistics:" << endl;
2600                              _classCache.DisplayCacheStatistics();
2601                      #endif
2602                              cout << "Repository Qualifier Cache Statistics:" << endl;
2603                              _qualifierCache.DisplayCacheStatistics();
2604                          }
2605                      #endif
2606                      
2607 mike           1.184 void CIMRepository::getSubClassNames(
2608                          const CIMNamespaceName& nameSpaceName,
2609                          const CIMName& className,
2610                          Boolean deepInheritance,
2611                          Array<CIMName>& subClassNames) const
2612                      {
2613                          ReadLock lock(const_cast<ReadWriteSem&>(_rep->_lock));
2614 kumpf          1.192     _rep->_nameSpaceManager.getSubClassNames(
2615 kumpf          1.189         nameSpaceName, className, deepInheritance, subClassNames);
2616 mike           1.184 }
2617                      
2618                      void CIMRepository::getSuperClassNames(
2619                          const CIMNamespaceName& nameSpaceName,
2620                          const CIMName& className,
2621                          Array<CIMName>& subClassNames) const
2622                      {
2623                          ReadLock lock(const_cast<ReadWriteSem&>(_rep->_lock));
2624 kumpf          1.192     _rep->_nameSpaceManager.getSuperClassNames(
2625 mike           1.184         nameSpaceName, className, subClassNames);
2626                      }
2627                      
2628                      Boolean CIMRepository::isDefaultInstanceProvider()
2629                      {
2630                          return _rep->_isDefaultInstanceProvider;
2631                      }
2632                      
2633 mike           1.48  PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2