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

   1 martin 1.64 //%LICENSE////////////////////////////////////////////////////////////////
   2 martin 1.65 //
   3 martin 1.64 // Licensed to The Open Group (TOG) under one or more contributor license
   4             // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
   5             // this work for additional information regarding copyright ownership.
   6             // Each contributor licenses this file to you under the OpenPegasus Open
   7             // Source License; you may not use this file except in compliance with the
   8             // License.
   9 martin 1.65 //
  10 martin 1.64 // Permission is hereby granted, free of charge, to any person obtaining a
  11             // copy of this software and associated documentation files (the "Software"),
  12             // to deal in the Software without restriction, including without limitation
  13             // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  14             // and/or sell copies of the Software, and to permit persons to whom the
  15             // Software is furnished to do so, subject to the following conditions:
  16 martin 1.65 //
  17 martin 1.64 // The above copyright notice and this permission notice shall be included
  18             // in all copies or substantial portions of the Software.
  19 martin 1.65 //
  20 martin 1.64 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  21 martin 1.65 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22 martin 1.64 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  23             // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  24             // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  25             // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  26             // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27 martin 1.65 //
  28 martin 1.64 //////////////////////////////////////////////////////////////////////////
  29 mike   1.13 //
  30             //%/////////////////////////////////////////////////////////////////////////////
  31             
  32             #include <Pegasus/Common/HashTable.h>
  33 kumpf  1.15 #include <Pegasus/Common/Tracer.h>
  34 kumpf  1.59 #include <Pegasus/Common/MessageLoader.h>
  35             #include <Pegasus/Common/Pair.h>
  36 schuur 1.32 #include "InstanceIndexFile.h"
  37 mike   1.13 #include "NameSpaceManager.h"
  38             
  39             PEGASUS_NAMESPACE_BEGIN
  40             
  41 schuur 1.32 ////////////////////////////////////////////////////////////////////////////////
  42             //
  43             // NameSpaceManagerRep
  44             //
  45             ////////////////////////////////////////////////////////////////////////////////
  46             
  47 kumpf  1.47 typedef HashTable <String, NameSpace*, EqualNoCaseFunc, HashLowerCaseFunc>
  48 schuur 1.32     Table;
  49             
  50             struct NameSpaceManagerRep
  51             {
  52                 Table table;
  53             };
  54             
  55             
  56 mike   1.13 ////////////////////////////////////////////////////////////////////////////////
  57             //
  58             // NameSpace
  59             //
  60             ////////////////////////////////////////////////////////////////////////////////
  61             
  62             class NameSpace
  63             {
  64 schuur 1.32    friend class NameSpaceManager;
  65 mike   1.13 public:
  66             
  67 kumpf  1.47     NameSpace(
  68                     const CIMNamespaceName& nameSpaceName,
  69 kumpf  1.60         Boolean shareable_,
  70                     Boolean updatesAllowed_,
  71                     NameSpace* parentNameSpace,
  72                     const String& remoteInfo_,
  73                     const Array<Pair<String, String> >& classList);
  74 schuur 1.32 
  75 kumpf  1.47     void modify(
  76 kumpf  1.60         Boolean shareable_,
  77                     Boolean updatesAllowed_);
  78 mike   1.13 
  79                 ~NameSpace();
  80             
  81 kumpf  1.60     Boolean readOnly() { return !updatesAllowed; }
  82 kumpf  1.47     NameSpace* primaryParent();
  83                 NameSpace* rwParent();
  84 schuur 1.32 
  85 kumpf  1.59     CIMName getSuperClassName(const CIMName& className) const;
  86 mike   1.13 
  87 kumpf  1.23     const CIMNamespaceName& getNameSpaceName() const { return _nameSpaceName; }
  88 mike   1.13 
  89                 InheritanceTree& getInheritanceTree() { return _inheritanceTree; }
  90             
  91                 /** Print this namespace. */
  92                 void print(PEGASUS_STD(ostream)& os) const;
  93             
  94             private:
  95             
  96 kumpf  1.59     /** Build an inheritance tree based on the classes and their superclasses
  97                     contained in the specified namespace.
  98                 */
  99                 void _buildInheritanceTree(
 100                     const CIMNamespaceName& nameSpace,
 101                     Array<Pair<String, String> > classList,
 102 kumpf  1.60         InheritanceTree* parentTree = NULL);
 103 kumpf  1.59 
 104 mike   1.13     InheritanceTree _inheritanceTree;
 105 kumpf  1.23     CIMNamespaceName _nameSpaceName;
 106 schuur 1.32 
 107 kumpf  1.47     NameSpace* parent;
 108                 NameSpace* dependent;
 109                 NameSpace* nextDependent;
 110 kumpf  1.60     Boolean shareable;
 111                 Boolean updatesAllowed;
 112 kumpf  1.59     String remoteInfo;
 113 schuur 1.32 };
 114             
 115 kumpf  1.47 NameSpace::NameSpace(
 116                 const CIMNamespaceName& nameSpaceName,
 117 kumpf  1.60     Boolean shareable_,
 118                 Boolean updatesAllowed_,
 119                 NameSpace* parentNameSpace,
 120                 const String& remoteInfo_,
 121                 const Array<Pair<String, String> >& classList)
 122 kumpf  1.59     : _nameSpaceName(nameSpaceName),
 123 kumpf  1.60       parent(parentNameSpace),
 124 kumpf  1.47       dependent(NULL),
 125                   nextDependent(NULL),
 126 kumpf  1.60       shareable(shareable_),
 127                   updatesAllowed(updatesAllowed_),
 128                   remoteInfo(remoteInfo_)
 129 schuur 1.32 {
 130 kumpf  1.60     PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpace::NameSpace");
 131 schuur 1.32 
 132 kumpf  1.60     if (!parent)
 133 kumpf  1.47     {
 134 kumpf  1.59         _buildInheritanceTree(nameSpaceName, classList);
 135 kumpf  1.47     }
 136                 else
 137                 {
 138 kumpf  1.60         if (updatesAllowed)
 139 kumpf  1.47         {
 140 kumpf  1.60             _buildInheritanceTree(
 141                             nameSpaceName,
 142                             classList,
 143                             &parent->_inheritanceTree);
 144                     }
 145 kumpf  1.47 
 146 kumpf  1.60         NameSpace* ens = parent->primaryParent();
 147                     nextDependent = ens->dependent;
 148                     ens->dependent = this;
 149                 }
 150 schuur 1.32 
 151 kumpf  1.60     if (remoteInfo.size())
 152                 {
 153 thilo.boehm 1.61         PEG_TRACE((TRC_REPOSITORY, Tracer::LEVEL4,
 154                              "Remote namespace: %s >%s",
 155                              (const char*)nameSpaceName.getString().getCString(),
 156                              (const char*)remoteInfo.getCString()));
 157 kumpf       1.47     }
 158 schuur      1.35 
 159 ouyang.jian 1.53     PEG_METHOD_EXIT();
 160 schuur      1.32 }
 161                  
 162                  NameSpace::~NameSpace()
 163 mike        1.13 {
 164 schuur      1.32 }
 165                  
 166 kumpf       1.47 void NameSpace::modify(
 167 kumpf       1.60     Boolean shareable_,
 168                      Boolean updatesAllowed_)
 169 kumpf       1.47 {
 170                      PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpace::modify()");
 171                  
 172 kumpf       1.60     updatesAllowed = updatesAllowed_;
 173                      shareable = shareable_;
 174 schuur      1.32 
 175 ouyang.jian 1.53     PEG_METHOD_EXIT();
 176 mike        1.13 }
 177                  
 178 kumpf       1.47 NameSpace* NameSpace::primaryParent()
 179 mike        1.13 {
 180 kumpf       1.47     if (parent == NULL)
 181                          return this;
 182                      return parent->primaryParent();
 183 schuur      1.32 }
 184 mike        1.13 
 185 kumpf       1.47 NameSpace* NameSpace::rwParent()
 186 schuur      1.32 {
 187 kumpf       1.60    if (updatesAllowed)
 188 kumpf       1.47        return this;
 189 schuur      1.32    return parent->rwParent();
 190 mike        1.13 }
 191                  
 192 kumpf       1.59 CIMName NameSpace::getSuperClassName(const CIMName& className) const
 193 mike        1.13 {
 194 kumpf       1.23     CIMName superClassName;
 195 mike        1.13 
 196                      if (!_inheritanceTree.getSuperClass(className, superClassName))
 197 kumpf       1.59     {
 198 kumpf       1.47         throw PEGASUS_CIM_EXCEPTION(
 199                              CIM_ERR_NOT_FOUND, className.getString());
 200 kumpf       1.59     }
 201 mike        1.13 
 202 kumpf       1.59     return superClassName;
 203 mike        1.13 }
 204                  
 205                  void NameSpace::print(PEGASUS_STD(ostream)& os) const
 206                  {
 207 kumpf       1.54     os << "=== NameSpace: " << _nameSpaceName.getString() << PEGASUS_STD(endl);
 208 mike        1.13     _inheritanceTree.print(os);
 209                  }
 210                  
 211 kumpf       1.59 void NameSpace::_buildInheritanceTree(
 212                      const CIMNamespaceName& nameSpace,
 213                      Array<Pair<String, String> > classList,
 214 kumpf       1.60     InheritanceTree* parentTree)
 215 kumpf       1.59 {
 216                      for (Uint32 i = 0; i < classList.size(); i++)
 217                      {
 218 kumpf       1.60         if (parentTree)
 219                          {
 220 kumpf       1.59             _inheritanceTree.insert(
 221 kumpf       1.60                 classList[i].first, classList[i].second, *parentTree, this);
 222                          }
 223 kumpf       1.59         else
 224 kumpf       1.60         {
 225 kumpf       1.59             _inheritanceTree.insert(classList[i].first, classList[i].second);
 226 kumpf       1.60         }
 227 kumpf       1.59     }
 228                  }
 229                  
 230 mike        1.13 ////////////////////////////////////////////////////////////////////////////////
 231                  //
 232                  // NameSpaceManager
 233                  //
 234                  ////////////////////////////////////////////////////////////////////////////////
 235                  
 236 kumpf       1.60 NameSpaceManager::NameSpaceManager()
 237 mike        1.13 {
 238 kumpf       1.47     PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::NameSpaceManager()");
 239 schuur      1.32 
 240 kumpf       1.59     _rep = new NameSpaceManagerRep;
 241 mike        1.13 
 242 ouyang.jian 1.53     PEG_METHOD_EXIT();
 243 mike        1.13 }
 244                  
 245                  NameSpaceManager::~NameSpaceManager()
 246                  {
 247                      for (Table::Iterator i = _rep->table.start(); i; i++)
 248 kumpf       1.41         delete i.value();
 249 mike        1.13 
 250                      delete _rep;
 251                  }
 252                  
 253 kumpf       1.60 void NameSpaceManager::initializeNameSpace(
 254                      const NamespaceDefinition& nameSpace,
 255                      const Array<Pair<String, String> >& classList)
 256                  {
 257                      PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::initializeNameSpace");
 258                  
 259                      NameSpace* parentNameSpace = 0;
 260                  
 261                      if (!nameSpace.parentNameSpace.isNull())
 262                      {
 263                          parentNameSpace =
 264                              _lookupNameSpace(nameSpace.parentNameSpace.getString());
 265                          PEGASUS_ASSERT(parentNameSpace);
 266                      }
 267                  
 268                      _rep->table.insert(
 269                          nameSpace.name.getString(),
 270                          new NameSpace(
 271                              nameSpace.name.getString(),
 272                              nameSpace.shareable,
 273                              nameSpace.updatesAllowed,
 274 kumpf       1.60             parentNameSpace,
 275                              nameSpace.remoteInfo,
 276                              classList));
 277                  
 278                      PEG_METHOD_EXIT();
 279                  }
 280                  
 281 kumpf       1.23 Boolean NameSpaceManager::nameSpaceExists(
 282                      const CIMNamespaceName& nameSpaceName) const
 283 mike        1.13 {
 284 kumpf       1.47     return _rep->table.contains(nameSpaceName.getString());
 285 mike        1.13 }
 286                  
 287 kumpf       1.59 NameSpace* NameSpaceManager::_lookupNameSpace(const String& ns)
 288 schuur      1.32 {
 289 kumpf       1.47     NameSpace* tns;
 290                      if (!_rep->table.lookup(ns, tns))
 291 kumpf       1.59     {
 292 kumpf       1.47         return NULL;
 293 kumpf       1.59     }
 294                      return tns;
 295                  }
 296                  
 297                  NameSpace* NameSpaceManager::_getNameSpace(const CIMNamespaceName& ns) const
 298                  {
 299                      NameSpace* tns;
 300                      if (!_rep->table.lookup(ns.getString(), tns))
 301                      {
 302                          PEG_TRACE_CSTRING(TRC_REPOSITORY, Tracer::LEVEL1, "Invalid NameSpace.");
 303                          throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_NAMESPACE, ns.getString());
 304                      }
 305 kumpf       1.47     return tns;
 306 schuur      1.32 }
 307                  
 308 kumpf       1.47 void NameSpaceManager::createNameSpace(
 309                      const CIMNamespaceName& nameSpaceName,
 310 kumpf       1.59     Boolean shareable,
 311                      Boolean updatesAllowed,
 312 venkat.puvvada 1.63     const String& parent,
 313                         const String& remoteInfo)
 314 mike           1.13 {
 315 kumpf          1.59     PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::createNameSpace");
 316 schuur         1.32 
 317 mike           1.13     if (nameSpaceExists(nameSpaceName))
 318 kumpf          1.15     {
 319                             PEG_METHOD_EXIT();
 320 kumpf          1.47         throw PEGASUS_CIM_EXCEPTION(
 321                                 CIM_ERR_ALREADY_EXISTS, nameSpaceName.getString());
 322 kumpf          1.15     }
 323 mike           1.13 
 324 kumpf          1.60     NameSpace* parentNameSpace = 0;
 325                         if (parent.size() && !(parentNameSpace = _lookupNameSpace(parent)))
 326 kumpf          1.47     {
 327 schuur         1.32         PEG_METHOD_EXIT();
 328 kumpf          1.47         throw PEGASUS_CIM_EXCEPTION(
 329 kumpf          1.59             CIM_ERR_FAILED, "Parent namespace " + parent + " not found");
 330 schuur         1.32     }
 331                     
 332 kumpf          1.60     if (parentNameSpace && !parentNameSpace->shareable)
 333 kumpf          1.47     {
 334 schuur         1.32         PEG_METHOD_EXIT();
 335 kumpf          1.47         throw PEGASUS_CIM_EXCEPTION(
 336 kumpf          1.59             CIM_ERR_FAILED, "Parent namespace " + parent + " not shareable");
 337 schuur         1.32     }
 338                     
 339 kumpf          1.60     if (updatesAllowed && parentNameSpace && parentNameSpace->parent)
 340 kumpf          1.47     {
 341 schuur         1.32         PEG_METHOD_EXIT();
 342 kumpf          1.47         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
 343 kumpf          1.59             "Parent namespace " + parent + " not a primary namespace");
 344 schuur         1.32     }
 345                     
 346 kumpf          1.59     // Create NameSpace object and register it:
 347 mike           1.13 
 348 kumpf          1.60     NameSpace* nameSpace = new NameSpace(
 349                             nameSpaceName,
 350                             shareable,
 351                             updatesAllowed,
 352                             parentNameSpace,
 353 venkat.puvvada 1.63         remoteInfo,
 354 kumpf          1.60         Array<Pair<String, String> >());
 355 david.dillard  1.40 
 356 kumpf          1.60     _rep->table.insert(nameSpaceName.getString(), nameSpace);
 357 kumpf          1.15 
 358                         PEG_METHOD_EXIT();
 359 mike           1.13 }
 360                     
 361 kumpf          1.47 void NameSpaceManager::modifyNameSpace(
 362                         const CIMNamespaceName& nameSpaceName,
 363 kumpf          1.59     Boolean shareable,
 364                         Boolean updatesAllowed)
 365 schuur         1.32 {
 366                         PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::modifyNameSpace()");
 367                     
 368 kumpf          1.59     NameSpace* nameSpace = _getNameSpace(nameSpaceName);
 369 schuur         1.32 
 370 kumpf          1.59     nameSpace->modify(shareable, updatesAllowed);
 371 schuur         1.32 
 372                         PEG_METHOD_EXIT();
 373                     }
 374                     
 375 kumpf          1.23 void NameSpaceManager::deleteNameSpace(const CIMNamespaceName& nameSpaceName)
 376 mike           1.13 {
 377 kumpf          1.15     PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::deleteNameSpace()");
 378                     
 379 kumpf          1.59     NameSpace* nameSpace = _getNameSpace(nameSpaceName);
 380 mike           1.13 
 381                         // Remove and delete the namespace object:
 382                     
 383 kumpf          1.47     NameSpace **pd = NULL, *p, *d;
 384                         for (p=nameSpace->parent; p; p=p->parent)
 385                         {
 386                             for (d = p->dependent, pd = &(p->dependent); d;
 387                                  pd = &(d->nextDependent), d = d->nextDependent)
 388                             {
 389                                 if (d == nameSpace)
 390                                 {
 391                                     *pd = nameSpace->nextDependent;
 392                                     break;
 393                                 }
 394                             }
 395 schuur         1.32     }
 396                     
 397 kumpf          1.47     Boolean success = _rep->table.remove(nameSpaceName.getString());
 398 mike           1.13     PEGASUS_ASSERT(success);
 399                         delete nameSpace;
 400 kumpf          1.15 
 401                         PEG_METHOD_EXIT();
 402 mike           1.13 }
 403                     
 404 kumpf          1.47 Boolean NameSpaceManager::isRemoteNameSpace(
 405                         const CIMNamespaceName& nameSpaceName,
 406                         String& remoteInfo)
 407 schuur         1.34 {
 408                         NameSpace* nameSpace = 0;
 409 kumpf          1.47     if (!_rep->table.lookup(nameSpaceName.getString(), nameSpace))
 410                             return false;
 411 schuur         1.34 
 412 kumpf          1.59     if (nameSpace->remoteInfo.size() == 0)
 413 kumpf          1.47         return false;
 414 schuur         1.34 
 415 kumpf          1.59     remoteInfo = nameSpace->remoteInfo;
 416 schuur         1.34     return true;
 417                     }
 418                     
 419 kumpf          1.47 void NameSpaceManager::getNameSpaceNames(
 420                         Array<CIMNamespaceName>& nameSpaceNames) const
 421 mike           1.13 {
 422                         nameSpaceNames.clear();
 423                     
 424                         for (Table::Iterator i = _rep->table.start(); i; i++)
 425 kumpf          1.41         nameSpaceNames.append(i.key());
 426 mike           1.13 }
 427                     
 428 kumpf          1.47 Boolean NameSpaceManager::getNameSpaceAttributes(
 429                         const CIMNamespaceName& nameSpaceName,
 430 kumpf          1.59     Boolean& shareable,
 431                         Boolean& updatesAllowed,
 432 venkat.puvvada 1.63     String& parent,
 433                         String& remoteInfo)
 434 schuur         1.32 {
 435 kumpf          1.59     NameSpace* ns = _lookupNameSpace(nameSpaceName.getString());
 436 schuur         1.32 
 437 kumpf          1.47     if (ns)
 438                         {
 439 kumpf          1.60         shareable = ns->shareable;
 440                             updatesAllowed = ns->updatesAllowed;
 441 kumpf          1.47         if (ns->parent)
 442 kumpf          1.59         {
 443                                 parent = ns->parent->_nameSpaceName.getString();
 444                             }
 445 venkat.puvvada 1.63         remoteInfo = ns->remoteInfo;
 446 kumpf          1.47         return true;
 447 schuur         1.32     }
 448 kumpf          1.59 
 449 schuur         1.32     return false;
 450                     }
 451                     
 452 kumpf          1.59 void NameSpaceManager::validateNameSpace(
 453                         const CIMNamespaceName& nameSpaceName) const
 454                     {
 455                         // Throws CIM_ERR_INVALID_NAMESPACE if the namespace does not exist.
 456                         NameSpace* nameSpace = _getNameSpace(nameSpaceName);
 457                     }
 458                     
 459                     Array<CIMNamespaceName> NameSpaceManager::getDependentSchemaNameSpaceNames(
 460                         const CIMNamespaceName& nameSpaceName) const
 461 schuur         1.32 {
 462 kumpf          1.59     PEG_METHOD_ENTER(TRC_REPOSITORY,
 463                             "NameSpaceManager::getDependentSchemaNameSpaceNames()");
 464                     
 465                         Array<CIMNamespaceName> nameSpaceNames;
 466 schuur         1.32 
 467 kumpf          1.59     NameSpace* nameSpace = _getNameSpace(nameSpaceName);
 468                         nameSpaceNames.append(nameSpace->getNameSpaceName());
 469                         nameSpace = nameSpace->dependent;
 470                         while (nameSpace)
 471 kumpf          1.47     {
 472 kumpf          1.59         nameSpaceNames.append(nameSpace->getNameSpaceName());
 473                             nameSpace = nameSpace->nextDependent;
 474 schuur         1.32     }
 475                     
 476 kumpf          1.59     PEG_METHOD_EXIT();
 477                         return nameSpaceNames;
 478 schuur         1.32 }
 479                     
 480 kumpf          1.59 Boolean NameSpaceManager::hasDependentNameSpace(
 481                         const CIMNamespaceName& nameSpaceName,
 482                         CIMNamespaceName& dependentNameSpaceName) const
 483 mike           1.13 {
 484 kumpf          1.59     PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::hasDependentNameSpace");
 485 kumpf          1.15 
 486 kumpf          1.59     Array<CIMNamespaceName> nameSpaceNames;
 487                         NameSpace* nameSpace = _getNameSpace(nameSpaceName);
 488 kumpf          1.47 
 489 kumpf          1.59     for (Table::Iterator i = _rep->table.start(); i; i++)
 490 kumpf          1.47     {
 491 kumpf          1.59         if (i.value()->parent == nameSpace)
 492 kumpf          1.47         {
 493 kumpf          1.59             dependentNameSpaceName = i.value()->getNameSpaceName();
 494 kumpf          1.47             PEG_METHOD_EXIT();
 495 kumpf          1.59             return true;
 496 kumpf          1.47         }
 497 schuur         1.32     }
 498                     
 499 kumpf          1.59     PEG_METHOD_EXIT();
 500                         return false;
 501                     }
 502                     
 503                     Array<CIMNamespaceName> NameSpaceManager::getSchemaNameSpaceNames(
 504                         const CIMNamespaceName& nameSpaceName) const
 505                     {
 506                         PEG_METHOD_ENTER(TRC_REPOSITORY,
 507                             "NameSpaceManager::getSchemaNameSpaceNames()");
 508                     
 509                         Array<CIMNamespaceName> nameSpaceNames;
 510                     
 511                         NameSpace* nameSpace = _getNameSpace(nameSpaceName);
 512                     
 513 kumpf          1.60     if (!nameSpace->updatesAllowed)
 514 kumpf          1.59     {
 515                             // Skip over a read-only namespace; no schema is defined here.
 516                             nameSpace = nameSpace->rwParent();
 517                         }
 518                     
 519                         nameSpaceNames.append(nameSpace->getNameSpaceName());
 520                     
 521                         if (nameSpace->parent)
 522 kumpf          1.47     {
 523 kumpf          1.59         // A R/W namespace may depend only on a primary namespace.
 524                             nameSpaceNames.append(nameSpace->primaryParent()->getNameSpaceName());
 525 kumpf          1.15     }
 526 kumpf          1.59 
 527 kumpf          1.15     PEG_METHOD_EXIT();
 528 kumpf          1.59     return nameSpaceNames;
 529 mike           1.13 }
 530                     
 531 kumpf          1.59 void NameSpaceManager::validateClass(
 532 kumpf          1.23     const CIMNamespaceName& nameSpaceName,
 533                         const CIMName& className) const
 534 mike           1.13 {
 535 kumpf          1.59     PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::validateClass");
 536                     
 537                         CIMName superClassName;
 538                         NameSpace* nameSpace = _getNameSpace(nameSpaceName);
 539 kumpf          1.15 
 540 kumpf          1.60     if (!nameSpace->updatesAllowed)
 541 kumpf          1.59     {
 542                             // Skip over a read-only namespace; no schema is defined here.
 543                             nameSpace = nameSpace->rwParent();
 544                         }
 545 mike           1.13 
 546 kumpf          1.59     if (nameSpace->getInheritanceTree().getSuperClass(
 547                                 className, superClassName))
 548 kumpf          1.15     {
 549                             PEG_METHOD_EXIT();
 550 kumpf          1.59         return;
 551                         }
 552                     
 553                         if (nameSpace->parent)
 554                         {
 555                             // A R/W namespace may depend only on a primary namespace.
 556                             if (nameSpace->primaryParent()->getInheritanceTree().getSuperClass(
 557                                     className, superClassName))
 558                             {
 559                                 PEG_METHOD_EXIT();
 560                                 return;
 561                             }
 562 kumpf          1.15     }
 563 mike           1.13 
 564 kumpf          1.15     PEG_METHOD_EXIT();
 565 kumpf          1.59     throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_CLASS, className.getString());
 566 mike           1.13 }
 567                     
 568 kumpf          1.59 CIMName NameSpaceManager::getSuperClassName(
 569                         const CIMNamespaceName& nameSpaceName,
 570 schuur         1.32     const CIMName& className) const
 571                     {
 572 kumpf          1.59     NameSpace* nameSpace = _getNameSpace(nameSpaceName);
 573                         return nameSpace->getSuperClassName(className);
 574 schuur         1.32 }
 575                     
 576 kumpf          1.59 void NameSpaceManager::locateClass(
 577 kumpf          1.23     const CIMNamespaceName& nameSpaceName,
 578 kumpf          1.59     const CIMName& className,
 579                         CIMNamespaceName& actualNameSpaceName,
 580                         CIMName& superClassName) const
 581 mike           1.13 {
 582 kumpf          1.59     PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::locateClass");
 583 kumpf          1.15 
 584 kumpf          1.59     NameSpace* nameSpace = _getNameSpace(nameSpaceName);
 585 mike           1.13 
 586 kumpf          1.59     if (nameSpace->parent != NULL)
 587 kumpf          1.47     {
 588 kumpf          1.59         if (!classExists(nameSpace, className, false))
 589                             {
 590                                 actualNameSpaceName = nameSpace->parent->getNameSpaceName();
 591                                 superClassName = nameSpace->parent->getSuperClassName(className);
 592                                 PEG_METHOD_EXIT();
 593                                 return;
 594                             }
 595 kumpf          1.15     }
 596 mike           1.13 
 597 kumpf          1.59     actualNameSpaceName = nameSpace->getNameSpaceName();
 598                         superClassName = nameSpace->getSuperClassName(className);
 599                         PEG_METHOD_EXIT();
 600                     }
 601                     
 602                     void NameSpaceManager::checkDeleteClass(
 603                         const CIMNamespaceName& nameSpaceName,
 604                         const CIMName& className) const
 605                     {
 606                         PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::checkDeleteClass");
 607 chuck          1.31 
 608 kumpf          1.59     NameSpace* nameSpace = _getNameSpace(nameSpaceName);
 609 schuur         1.32 
 610 kumpf          1.60     if (!nameSpace->updatesAllowed)
 611 kumpf          1.47     {
 612 kumpf          1.59         if (nameSpace->parent != NULL)
 613 kumpf          1.47         {
 614 kumpf          1.59             // Note: I think this is already checked in
 615                                 // CIMRepository::deleteClass
 616                                 classExists(nameSpace->parent, className, true);
 617 kumpf          1.47         }
 618 kumpf          1.59 
 619 kumpf          1.47         PEG_METHOD_EXIT();
 620 kumpf          1.59         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_ACCESS_DENIED,
 621                                 "R/O Namespace " + nameSpace->getNameSpaceName().getString());
 622 kumpf          1.47     }
 623                     
 624 kumpf          1.59     PEG_METHOD_EXIT();
 625                     }
 626                     
 627                     void NameSpaceManager::checkSetOrDeleteQualifier(
 628                         const CIMNamespaceName& nameSpaceName,
 629                         const CIMName& qualifierName) const
 630                     {
 631                         PEG_METHOD_ENTER(TRC_REPOSITORY,
 632                             "NameSpaceManager::checkSetOrDeleteQualifier");
 633                     
 634                         NameSpace* nameSpace = _getNameSpace(nameSpaceName);
 635                     
 636 kumpf          1.60     if (!nameSpace->updatesAllowed)
 637 kumpf          1.47     {
 638 schuur         1.32         PEG_METHOD_EXIT();
 639 kumpf          1.47         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_ACCESS_DENIED,
 640                                 "R/O Namespace " + nameSpace->getNameSpaceName().getString());
 641 schuur         1.32     }
 642 kumpf          1.59 
 643 schuur         1.32     PEG_METHOD_EXIT();
 644 mike           1.13 }
 645                     
 646                     void NameSpaceManager::deleteClass(
 647 kumpf          1.23     const CIMNamespaceName& nameSpaceName,
 648                         const CIMName& className) const
 649 mike           1.13 {
 650 kumpf          1.15     PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::deleteClass()");
 651                     
 652 kumpf          1.59     NameSpace* nameSpace = _getNameSpace(nameSpaceName);
 653 mike           1.13 
 654                         // -- Remove the file from the inheritance tree:
 655                     
 656 kumpf          1.47     if (nameSpace->parent != NULL)
 657                             nameSpace->getInheritanceTree().remove(
 658                                 className, nameSpace->parent->getInheritanceTree(), nameSpace);
 659                         else
 660                             nameSpace->getInheritanceTree().remove(
 661                                 className, nameSpace->getInheritanceTree(), NULL);
 662 mike           1.13 
 663 kumpf          1.15     PEG_METHOD_EXIT();
 664 mike           1.13 }
 665                     
 666                     void NameSpaceManager::print(PEGASUS_STD(ostream)& os) const
 667                     {
 668                         for (Table::Iterator i = _rep->table.start(); i; i++)
 669                         {
 670 kumpf          1.41         NameSpace* nameSpace = i.value();
 671                             nameSpace->print(os);
 672 mike           1.13     }
 673                     
 674                         os << PEGASUS_STD(endl);
 675                     }
 676                     
 677 kumpf          1.59 void NameSpaceManager::checkCreateClass(
 678 kumpf          1.23     const CIMNamespaceName& nameSpaceName,
 679                         const CIMName& className,
 680 kumpf          1.59     const CIMName& superClassName)
 681 mike           1.13 {
 682 kumpf          1.59     PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::checkCreateClass()");
 683 kumpf          1.15 
 684 kumpf          1.59     NameSpace* nameSpace = _getNameSpace(nameSpaceName);
 685 mike           1.13 
 686 kumpf          1.47     if (nameSpace->readOnly())
 687                         {
 688 schuur         1.32         PEG_METHOD_EXIT();
 689 kumpf          1.47         throw PEGASUS_CIM_EXCEPTION(
 690                                 CIM_ERR_ACCESS_DENIED, "R/O Namespace "+nameSpaceName.getString());
 691 schuur         1.32     }
 692                     
 693 mike           1.13     InheritanceTree& it = nameSpace->getInheritanceTree();
 694                     
 695                         // -- Be certain class doesn't already exist:
 696                     
 697 kumpf          1.47     if (it.containsClass(className))
 698                         {
 699 marek          1.56         PEG_TRACE_CSTRING(TRC_REPOSITORY, Tracer::LEVEL1,
 700 kumpf          1.47             "Class already exists.");
 701 kumpf          1.15         PEG_METHOD_EXIT();
 702 kumpf          1.47         throw PEGASUS_CIM_EXCEPTION(
 703                                 CIM_ERR_ALREADY_EXISTS, className.getString());
 704 kumpf          1.15     }
 705 mike           1.13 
 706 kumpf          1.47     if (nameSpace->parent)
 707                         {
 708 kumpf          1.59         // Check the parent namespace for a class with this name.  Since
 709                             // this namespace is R/W, its parent namespace is a primary
 710                             // namespace (has no parent of its own).
 711                     
 712 kumpf          1.57         InheritanceTree& parentIt = nameSpace->parent->getInheritanceTree();
 713                             if (parentIt.containsClass(className))
 714 kumpf          1.47         {
 715 marek          1.56             PEG_TRACE_CSTRING(TRC_REPOSITORY, Tracer::LEVEL1,
 716 kumpf          1.47                 "Class already exists.");
 717                                 PEG_METHOD_EXIT();
 718                                 throw PEGASUS_CIM_EXCEPTION(
 719                                     CIM_ERR_ALREADY_EXISTS, className.getString());
 720                             }
 721                         }
 722                         else
 723                         {
 724 kumpf          1.59         // Check for a collision in the direct dependent namespaces.  A
 725                             // dependent of a dependent namespace must be read-only and therefore
 726                             // cannot contain a class definition.
 727                     
 728 kumpf          1.47         NameSpace* ns = nameSpace->dependent;
 729                             while (ns)
 730                             {
 731                                 if (!ns->readOnly())
 732                                 {
 733 kumpf          1.57                 InheritanceTree& dependentIt = ns->getInheritanceTree();
 734                                     if (dependentIt.containsClass(className))
 735 kumpf          1.47                 {
 736 marek          1.56                     PEG_TRACE_CSTRING(TRC_REPOSITORY, Tracer::LEVEL1,
 737 kumpf          1.47                         "Class already exists.");
 738                                         PEG_METHOD_EXIT();
 739                                         throw PEGASUS_CIM_EXCEPTION(
 740                                             CIM_ERR_ALREADY_EXISTS, className.getString());
 741                                     }
 742                                 }
 743                                 ns = ns->nextDependent;
 744                             }
 745 schuur         1.32     }
 746                     
 747 kumpf          1.59     // Verify the superclass exists.  This will have already been checked
 748                         // if the class has been resolved, but we do not assume that dependency
 749                         // here.
 750                     
 751                         if (!superClassName.isNull() && !it.containsClass(superClassName) &&
 752                             !(nameSpace->parent &&
 753                               nameSpace->parent->getInheritanceTree().containsClass(
 754                                  superClassName)))
 755 kumpf          1.47     {
 756 marek          1.56         PEG_TRACE_CSTRING(TRC_REPOSITORY, Tracer::LEVEL1,
 757 kumpf          1.47             "SuperClass does not exist.");
 758 kumpf          1.15         PEG_METHOD_EXIT();
 759 kumpf          1.47         throw PEGASUS_CIM_EXCEPTION(
 760                                 CIM_ERR_INVALID_SUPERCLASS, superClassName.getString());
 761 kumpf          1.15     }
 762 chuck          1.31 
 763 kumpf          1.59     PEG_METHOD_EXIT();
 764                     }
 765                     
 766                     void NameSpaceManager::createClass(
 767                         const CIMNamespaceName& nameSpaceName,
 768                         const CIMName& className,
 769                         const CIMName& superClassName)
 770                     {
 771                         PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::createClass()");
 772 chuck          1.31 
 773 kumpf          1.59     NameSpace* nameSpace = _getNameSpace(nameSpaceName);
 774                         InheritanceTree& it = nameSpace->getInheritanceTree();
 775 mike           1.13 
 776 kumpf          1.59     // Insert the entry into the inheritance tree
 777 mike           1.13 
 778 kumpf          1.59     if (nameSpace->parent &&
 779                             (superClassName.isNull() || !it.containsClass(superClassName)))
 780                         {
 781 kumpf          1.47         it.insert(
 782                                 className.getString(),
 783                                 superClassName.getString(),
 784                                 nameSpace->parent->getInheritanceTree(),
 785                                 nameSpace);
 786 kumpf          1.59     }
 787 kumpf          1.47     else
 788 kumpf          1.59     {
 789 kumpf          1.47         it.insert(className.getString(), superClassName.getString());
 790 kumpf          1.59     }
 791 kumpf          1.15 
 792                         PEG_METHOD_EXIT();
 793 mike           1.13 }
 794                     
 795 kumpf          1.59 void NameSpaceManager::checkModifyClass(
 796 kumpf          1.23     const CIMNamespaceName& nameSpaceName,
 797                         const CIMName& className,
 798 kumpf          1.62     const CIMName& superClassName,
 799                         CIMName& oldSuperClassName,
 800                         Boolean allowNonLeafModification)
 801 mike           1.13 {
 802 kumpf          1.59     PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::checkModifyClass");
 803 mike           1.13 
 804 kumpf          1.59     NameSpace* nameSpace = _getNameSpace(nameSpaceName);
 805 mike           1.13 
 806                         InheritanceTree& it = nameSpace->getInheritanceTree();
 807                     
 808                         if (!it.getSuperClass(className, oldSuperClassName))
 809 kumpf          1.15     {
 810                             PEG_METHOD_EXIT();
 811 kumpf          1.47         throw PEGASUS_CIM_EXCEPTION(
 812                                 CIM_ERR_NOT_FOUND, className.getString());
 813 kumpf          1.15     }
 814 mike           1.13 
 815 kumpf          1.62     if (allowNonLeafModification)
 816 mike           1.14     {
 817 kumpf          1.62         if (!superClassName.isNull())
 818                             {
 819                                 Array<CIMName> superClassNames;
 820                     
 821                                 // Make sure the new superclass exists and is not a subclass of the
 822                                 // class being modified.
 823                     
 824                                 if (!it.getSuperClassNames(superClassName, superClassNames))
 825                                 {
 826                                     PEG_METHOD_EXIT();
 827                                     throw PEGASUS_CIM_EXCEPTION(
 828                                         CIM_ERR_INVALID_SUPERCLASS, superClassName.getString());
 829                                 }
 830                     
 831                                 for (Uint32 i = 0; i < superClassNames.size(); i++)
 832                                 {
 833                                     if (superClassNames[i] == className)
 834                                     {
 835                                         // The modified class is a parent of the new superclass!
 836                                         PEG_METHOD_EXIT();
 837                                         throw PEGASUS_CIM_EXCEPTION(
 838 kumpf          1.62                         CIM_ERR_INVALID_SUPERCLASS, superClassName.getString());
 839                                     }
 840                                 }
 841                             }
 842 mike           1.14     }
 843 kumpf          1.62     else
 844                         {
 845                             // -- Disallow changing of superclass:
 846                     
 847                             if (!superClassName.equal(oldSuperClassName))
 848                             {
 849                                 PEG_METHOD_EXIT();
 850                                 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
 851                                     MessageLoaderParms(
 852                                         "Repository.NameSpaceManager.ATTEMPT_TO_CHANGE_SUPERCLASS",
 853                                         "attempt to change superclass"));
 854                             }
 855 mike           1.13 
 856 kumpf          1.62         // -- Disallow modification of class with subclasses:
 857 mike           1.13 
 858 kumpf          1.62         Boolean hasSubClasses;
 859                             it.hasSubClasses(className, hasSubClasses);
 860 mike           1.13 
 861 kumpf          1.62         if (hasSubClasses)
 862                             {
 863                                 PEG_METHOD_EXIT();
 864                                 throw PEGASUS_CIM_EXCEPTION(
 865                                     CIM_ERR_CLASS_HAS_CHILDREN, className.getString());
 866                             }
 867 kumpf          1.15     }
 868 mike           1.13 
 869 kumpf          1.15     PEG_METHOD_EXIT();
 870 mike           1.13 }
 871                     
 872                     void NameSpaceManager::getSubClassNames(
 873 kumpf          1.23     const CIMNamespaceName& nameSpaceName,
 874                         const CIMName& className,
 875 mike           1.13     Boolean deepInheritance,
 876 schuur         1.32     Array<CIMName>& subClassNames,
 877 david.dillard  1.44     Boolean enm) const
 878 mike           1.13 {
 879 kumpf          1.15     PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::getSubClassNames()");
 880                     
 881 kumpf          1.59     NameSpace* nameSpace = _getNameSpace(nameSpaceName);
 882                         NameSpace* dns = 0;
 883 mike           1.13 
 884 kumpf          1.47     if (className.getString()=="" && nameSpace->parent)
 885                             enm=true;
 886 schuur         1.32 
 887 kumpf          1.47     if (enm && nameSpace->parent)
 888                         {
 889                             dns=nameSpace->rwParent();
 890                             nameSpace=nameSpace->primaryParent();
 891 schuur         1.32     }
 892 mike           1.13     InheritanceTree& it = nameSpace->getInheritanceTree();
 893                     
 894 kumpf          1.47     if (!it.getSubClassNames(className, deepInheritance, subClassNames, dns))
 895                         {
 896                             if (nameSpace->parent)
 897                             {
 898                                 if (enm == false)
 899                                 {
 900                                     dns=nameSpace->rwParent();
 901                                     nameSpace=nameSpace->primaryParent();
 902 kumpf          1.57                 InheritanceTree& parentIt = nameSpace->getInheritanceTree();
 903                                     if (parentIt.getSubClassNames(
 904 kumpf          1.47                     className, deepInheritance, subClassNames, 0))
 905                                     {
 906 ouyang.jian    1.53                     PEG_METHOD_EXIT();
 907 kumpf          1.47                     return;
 908                                     }
 909                                 }
 910                             }
 911                             else if (dns && enm)
 912                             {
 913 kumpf          1.57             InheritanceTree& parentIt = dns->rwParent()->getInheritanceTree();
 914                                 if (parentIt.getSubClassNames(
 915 kumpf          1.47                     className, deepInheritance, subClassNames, 0))
 916                                 {
 917 ouyang.jian    1.53                 PEG_METHOD_EXIT();
 918 kumpf          1.47                 return;
 919                                 }
 920 kumpf          1.41         }
 921 kumpf          1.15         PEG_METHOD_EXIT();
 922 kumpf          1.47         throw PEGASUS_CIM_EXCEPTION(
 923                                 CIM_ERR_INVALID_CLASS, className.getString());
 924 kumpf          1.15     }
 925                     
 926                         PEG_METHOD_EXIT();
 927 mike           1.13 }
 928                     
 929                     void NameSpaceManager::getSuperClassNames(
 930 kumpf          1.23     const CIMNamespaceName& nameSpaceName,
 931                         const CIMName& className,
 932                         Array<CIMName>& subClassNames) const
 933 mike           1.13 {
 934 kumpf          1.15     PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::getSuperClassNames()");
 935                     
 936 kumpf          1.59     NameSpace* nameSpace = _getNameSpace(nameSpaceName);
 937 mike           1.13 
 938 schuur         1.35     nameSpace=nameSpace->rwParent();
 939 mike           1.13 
 940                         InheritanceTree& it = nameSpace->getInheritanceTree();
 941                     
 942                         // -- Get names of all superclasses:
 943                         if (!it.getSuperClassNames(className, subClassNames))
 944 kumpf          1.15     {
 945                             PEG_METHOD_EXIT();
 946 kumpf          1.47         throw PEGASUS_CIM_EXCEPTION(
 947                                 CIM_ERR_INVALID_CLASS, className.getString());
 948 kumpf          1.15     }
 949                     
 950                         PEG_METHOD_EXIT();
 951 mike           1.13 }
 952                     
 953 schuur         1.32 Boolean NameSpaceManager::classExists(
 954 kumpf          1.41     NameSpace *nameSpace,
 955                         const CIMName& className,
 956                         Boolean throwExcp) const
 957 schuur         1.32 {
 958 kumpf          1.46     PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::classExists()");
 959 schuur         1.32 
 960                         Boolean first=true;
 961                     
 962 kumpf          1.47     do
 963                         {
 964                             InheritanceTree& it = nameSpace->getInheritanceTree();
 965 schuur         1.32 
 966 kumpf          1.47         if (it.containsClass(className))
 967                             {
 968                                 if (throwExcp)
 969 kumpf          1.58             {
 970                                     PEG_TRACE_CSTRING(TRC_REPOSITORY, Tracer::LEVEL1,
 971                                         "Class already exists.");
 972                                     PEG_METHOD_EXIT();
 973 kumpf          1.47                 throw PEGASUS_CIM_EXCEPTION(
 974                                         CIM_ERR_ALREADY_EXISTS, className.getString());
 975 kumpf          1.58             }
 976                                 PEG_METHOD_EXIT();
 977 kumpf          1.47             return true;
 978                             }
 979 schuur         1.32 
 980 kumpf          1.47         if (first)
 981                             {
 982                                 nameSpace = nameSpace->dependent;
 983                                 first = false;
 984                             }
 985                             else
 986                                 nameSpace = nameSpace->nextDependent;
 987 schuur         1.32     } while (nameSpace);
 988                     
 989                         PEG_METHOD_EXIT();
 990                         return false;
 991                     }
 992                     
 993 kumpf          1.46 Boolean NameSpaceManager::classExists(
 994                         const CIMNamespaceName& nameSpaceName,
 995                         const CIMName& className) const
 996                     {
 997                         PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::classExists()");
 998                     
 999 kumpf          1.59     NameSpace* nameSpace = _getNameSpace(nameSpaceName);
1000 kumpf          1.46 
1001                         Boolean exists = classExists(nameSpace, className, false);
1002                     
1003                         PEG_METHOD_EXIT();
1004                         return exists;
1005                     }
1006                     
1007 mike           1.13 PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2