![]() ![]() |
![]() |
1 mike 1.1 //BEGIN_LICENSE 2 // 3 // Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM 4 // 5 // Permission is hereby granted, free of charge, to any person obtaining a 6 // copy of this software and associated documentation files (the "Software"), 7 // to deal in the Software without restriction, including without limitation 8 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 // and/or sell copies of the Software, and to permit persons to whom the 10 // Software is furnished to do so, subject to the following conditions: 11 // 12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 15 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 17 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 18 // DEALINGS IN THE SOFTWARE. 19 // 20 //END_LICENSE 21 //BEGIN_HISTORY 22 mike 1.1 // 23 // Author: 24 // | ||
25 mike 1.2 // $Log: Repository.cpp,v $ | ||
26 mike 1.6 // Revision 1.5 2001/02/11 05:45:33 mike 27 // Added case insensitive logic for files in Repository 28 // | ||
29 mike 1.5 // Revision 1.4 2001/01/31 08:20:51 mike 30 // Added dispatcher framework. 31 // Added enumerateInstanceNames. 32 // | ||
33 mike 1.4 // Revision 1.3 2001/01/28 04:11:03 mike 34 // fixed qualifier resolution 35 // | ||
36 mike 1.3 // Revision 1.2 2001/01/25 02:12:05 mike 37 // Added meta-qualifiers to LoadRepository program. 38 // | ||
39 mike 1.2 // Revision 1.1.1.1 2001/01/14 19:53:55 mike 40 // Pegasus import 41 // | ||
42 mike 1.1 // 43 //END_HISTORY 44 45 #include <cctype> 46 #include <fstream> 47 #include <Pegasus/Common/Pair.h> 48 #include <Pegasus/Common/Destroyer.h> 49 #include <Pegasus/Common/FileSystem.h> 50 #include <Pegasus/Common/Exception.h> 51 #include <Pegasus/Common/XmlReader.h> 52 #include <Pegasus/Common/XmlWriter.h> 53 #include <Pegasus/Common/DeclContext.h> | ||
54 mike 1.6 #include <Pegasus/Common/DeclContext.h> | ||
55 mike 1.1 #include "Repository.h" | ||
56 mike 1.6 #include "InstanceIndexFile.h" | ||
57 mike 1.1 58 #define INDENT_XML_FILES 59 60 PEGASUS_NAMESPACE_BEGIN 61 62 //////////////////////////////////////////////////////////////////////////////// 63 // 64 // Local functions 65 // 66 //////////////////////////////////////////////////////////////////////////////// 67 68 //------------------------------------------------------------------------------ 69 // 70 // This routine matches files in the classes directory (given by path) 71 // that match the second and third arguments, which are eight class names 72 // or asterisks (which are wild cards). All the files in the ./classes 73 // directory are of the form <className.superClassName>. For classes 74 // with no superClass, the superClassName is "#". We consider a couple of 75 // examples. To find all direct subclasses of "MyClass", we invoke it 76 // as follows: 77 // 78 mike 1.1 // _GlobClassesDir(path, "*", "MyClass"); 79 // 80 // To find the file which contains the class called "MyClass", we invoke 81 // it like this. 82 // 83 // _GlobClassesDir(path, "MyClass", "*"); 84 // 85 // Since base classes are of the form "<ClassName>.#", all baseclasses may 86 // be found with: 87 // 88 // _GlobClassesDir(path, "*", "#"); 89 // 90 // Note that the results (the array of filenames which are returned) must 91 // be processed further to get the actual class names. The name of the 92 // class is the filename less the extension. Or this: 93 // 94 // String className = fileName.subString(fileName.find(0, '.')); 95 // 96 //------------------------------------------------------------------------------ 97 98 Array<String> _GlobClassesDir( 99 mike 1.1 const String& path, | ||
100 mike 1.5 const String& className_, 101 const String& superClassName_) | ||
102 mike 1.1 { | ||
103 mike 1.5 String className = className_; 104 String superClassName = superClassName_; | ||
105 mike 1.1 Array<String> fileNames; 106 107 if (!FileSystem::getDirectoryContents(path, fileNames)) 108 throw NoSuchDirectory(path); 109 110 Array<String> result; 111 112 for (Uint32 i = 0; i < fileNames.getSize(); i++) 113 { 114 const String& tmp = fileNames[i]; 115 116 Uint32 dot = tmp.find('.'); 117 118 // Ignore files that do not contain a dot: 119 120 if (dot == Uint32(-1)) 121 continue; 122 123 String first = tmp.subString(0, dot); 124 String second = tmp.subString(dot + 1); 125 126 mike 1.1 if ((className == "*" || first == className) && 127 (superClassName == "*" || second == superClassName)) 128 { 129 result.append(tmp); 130 } 131 } 132 133 return result; 134 } 135 136 static Boolean _SkipIdentifier(Char16*& p) 137 { 138 if (!*p || !(isalpha(*p) || *p == '_')) 139 return false; 140 141 for (p++; *p; p++) 142 { 143 if (!(isalnum(*p) || *p == '_')) 144 return true; 145 } 146 147 mike 1.1 return true; 148 } 149 150 static void _MakeNameSpacePath( 151 const String& root, 152 const String& nameSpace, 153 String& path) 154 { 155 path = root; 156 path.append('/'); 157 158 path.append(nameSpace); 159 160 Char16* p = (Char16*)(path.getData() + root.getLength() + 1); 161 162 while (*p) 163 { 164 // Either we will encounter a slash or an identifier: 165 166 if (*p == '/') 167 { 168 mike 1.1 if (p[1] == '/') 169 throw CimException(CimException::INVALID_NAMESPACE); 170 171 *p++ = '#'; 172 } 173 else if (!_SkipIdentifier(p)) 174 throw CimException(CimException::INVALID_NAMESPACE); 175 } 176 177 // The last element may NOT be a slash (slashes are translated to 178 // #'s above). 179 180 if (p[-1] == '#') 181 throw CimException(CimException::INVALID_NAMESPACE); 182 } 183 184 void _FindClass( 185 const String& root, 186 const String& nameSpace, 187 const String& className, 188 String& path) 189 mike 1.1 { 190 const char CLASSES[] = "/classes/"; 191 _MakeNameSpacePath(root, nameSpace, path); 192 193 if (!FileSystem::isDirectory(path)) 194 throw CimException(CimException::INVALID_NAMESPACE); 195 196 path.append(CLASSES); 197 198 Array<String> fileNames = _GlobClassesDir(path, className, "*"); 199 200 Uint32 size = fileNames.getSize(); 201 202 if (size == 0) 203 throw CimException(CimException::INVALID_CLASS); 204 205 PEGASUS_ASSERT(size == 1); 206 path.append(fileNames[0]); 207 } 208 209 inline Uint32 _min(Uint32 x, Uint32 y) 210 mike 1.1 { 211 return x < y ? x : y; 212 } 213 214 static void _MakeNewClassPath( 215 const String& root, 216 const String& nameSpace, 217 const String& className, 218 const String& superClassName, 219 String& path) 220 { 221 const char CLASSES[] = "/classes/"; 222 _MakeNameSpacePath(root, nameSpace, path); 223 224 if (!FileSystem::isDirectory(path)) 225 throw CimException(CimException::INVALID_NAMESPACE); 226 227 path.append(CLASSES); 228 path.append(className); 229 path.append('.'); 230 231 mike 1.1 if (superClassName.getLength() == 0) 232 path.append("#"); 233 else 234 path.append(superClassName); 235 } 236 237 static void _MakeQualfierPath( 238 const String& root, 239 const String& nameSpace, 240 const String& qualifierName, 241 String& path) 242 { 243 const char QUALIFIERS[] = "/qualifiers/"; 244 _MakeNameSpacePath(root, nameSpace, path); 245 246 if (!FileSystem::isDirectory(path)) 247 throw CimException(CimException::INVALID_NAMESPACE); 248 249 path.append(QUALIFIERS); 250 path.append(qualifierName); 251 } 252 mike 1.1 | ||
253 mike 1.6 static void _MakeInstanceIndexPath( 254 const String& root, 255 const String& nameSpace, 256 const String& className, 257 String& path) 258 { 259 const char INSTANCES[] = "/instances/"; 260 _MakeNameSpacePath(root, nameSpace, path); 261 262 if (!FileSystem::isDirectory(path)) 263 throw CimException(CimException::INVALID_NAMESPACE); 264 265 path.append(INSTANCES); 266 path.append(className); 267 path.append(".idx"); 268 } 269 270 static void _MakeInstancePath( 271 const String& root, 272 const String& nameSpace, 273 const String& className, 274 mike 1.6 Uint32 index, 275 String& path) 276 { 277 const char INSTANCES[] = "/instances/"; 278 _MakeNameSpacePath(root, nameSpace, path); 279 280 if (!FileSystem::isDirectory(path)) 281 throw CimException(CimException::INVALID_NAMESPACE); 282 283 path.append(INSTANCES); 284 path.append(className); 285 path.append('.'); 286 287 char buffer[32]; 288 sprintf(buffer, "%d", index); 289 path.append(buffer); 290 } 291 | ||
292 mike 1.1 template<class Object> 293 void _LoadObject( 294 const String& path, 295 Object& object) 296 { | ||
297 mike 1.5 // Get the real path of the file: | ||
298 mike 1.1 | ||
299 mike 1.5 String realPath; | ||
300 mike 1.1 | ||
301 mike 1.5 if (!FileSystem::existsIgnoreCase(path, realPath)) | ||
302 mike 1.1 throw CannotOpenFile(path); 303 304 // Load file into memory: 305 306 Array<Sint8> data; | ||
307 mike 1.5 FileSystem::loadFileToMemory(data, realPath); | ||
308 mike 1.1 data.append('\0'); 309 310 XmlParser parser((char*)data.getData()); 311 312 XmlReader::getObject(parser, object); 313 } 314 315 template<class Object> 316 void _SaveObject(const String& path, Object& object) 317 { 318 Array<Sint8> out; 319 object.toXml(out); 320 out.append('\0'); 321 322 Destroyer<char> destroyer(path.allocateCString()); 323 324 #ifdef PEGASUS_OS_TYPE_WINDOWS 325 std::ofstream os(destroyer.getPointer(), std::ios::binary); 326 #else 327 std::ofstream os(destroyer.getPointer()); 328 #endif 329 mike 1.1 330 if (!os) 331 throw CannotOpenFile(path); 332 333 #ifdef INDENT_XML_FILES 334 XmlWriter::indentedPrint(os, out.getData(), 2); 335 #else 336 os.write((char*)out.getData(), out.getSize()); 337 #endif 338 } 339 340 static void _AppendClassNames( 341 const String& path, 342 const String& className, 343 const String& superClassName, 344 Array<String>& classNames) 345 { 346 Array<String> allFiles; 347 348 if (!FileSystem::getDirectoryContents(path, allFiles)) 349 throw NoSuchDirectory(path); 350 mike 1.1 351 // Append all the direct sublclasses of the class to the output argument: 352 353 Array<String> fileNames = 354 _GlobClassesDir(path, className, superClassName); 355 356 for (Uint32 i = 0, n = fileNames.getSize(); i < n; i++) 357 { 358 String& tmp = fileNames[i]; 359 Uint32 pos = tmp.find('.'); 360 361 PEGASUS_ASSERT(pos != Uint32(-1)); 362 363 if (pos != Uint32(-1)) 364 tmp.remove(pos); 365 366 classNames.append(tmp); 367 } 368 } 369 370 typedef Pair<String,String> Node; 371 mike 1.1 372 static void _AppendSubclassesDeepAux( 373 const Array<Node>& table, 374 const String& className, 375 Array<String>& classNames) 376 { 377 for (Uint32 i = 0, n = table.getSize(); i < n; i++) 378 { 379 if (className == table[i].second) 380 { 381 classNames.append(table[i].first); 382 _AppendSubclassesDeepAux(table, table[i].first, classNames); 383 } 384 } 385 } 386 387 static void _AppendSubclassesDeep( 388 const String& path, 389 const String& className, 390 Array<String>& classNames) 391 { 392 mike 1.1 Array<String> allFiles; 393 394 if (!FileSystem::getDirectoryContents(path, allFiles)) 395 throw NoSuchDirectory(path); 396 397 Array<Node> table; 398 table.reserve(allFiles.getSize()); 399 400 for (Uint32 i = 0, n = allFiles.getSize(); i < n; i++) 401 { 402 const String& fileName = allFiles[i]; 403 404 Uint32 dot = fileName.find('.'); 405 406 if (dot == Uint32(-1)) 407 continue; 408 409 String first = fileName.subString(0, dot); 410 String second = fileName.subString(dot + 1); 411 412 if (second == "#") 413 mike 1.1 table.append(Node(first, String())); 414 else 415 table.append(Node(first, second)); 416 } 417 418 _AppendSubclassesDeepAux(table, className, classNames); 419 } 420 421 static Boolean _HasSubclasses( 422 const String& root, 423 const String& nameSpace, 424 const String& className) 425 { 426 const char CLASSES[] = "/classes"; 427 String path; 428 _MakeNameSpacePath(root, nameSpace, path); 429 path.append(CLASSES); 430 431 Array<String> fileNames = _GlobClassesDir(path, "*", className); 432 433 return fileNames.getSize() != 0; 434 mike 1.1 } 435 436 //////////////////////////////////////////////////////////////////////////////// 437 // 438 // RepositoryDeclContext 439 // 440 //////////////////////////////////////////////////////////////////////////////// 441 442 class RepositoryDeclContext : public DeclContext 443 { 444 public: 445 446 RepositoryDeclContext(Repository* repository); 447 448 virtual ~RepositoryDeclContext(); 449 450 virtual QualifierDecl lookupQualifierDecl( 451 const String& nameSpace, 452 const String& qualifierName) const; 453 454 virtual ClassDecl lookupClassDecl( 455 mike 1.1 const String& nameSpace, 456 const String& className) const; 457 458 private: 459 460 Repository* _repository; 461 }; 462 463 RepositoryDeclContext::RepositoryDeclContext(Repository* repository) 464 : _repository(repository) 465 { 466 467 } 468 469 RepositoryDeclContext::~RepositoryDeclContext() 470 { 471 472 } 473 474 QualifierDecl RepositoryDeclContext::lookupQualifierDecl( 475 const String& nameSpace, 476 mike 1.1 const String& qualifierName) const 477 { 478 // Ignore the exception since this routine is only supposed report 479 // whether it can be found: 480 481 try 482 { 483 return _repository->getQualifier(nameSpace, qualifierName); 484 } 485 catch (Exception&) 486 { 487 return QualifierDecl(); 488 } 489 } 490 491 ClassDecl RepositoryDeclContext::lookupClassDecl( 492 const String& nameSpace, 493 const String& className) const 494 { 495 // Ignore the exception since this routine is only supposed report 496 // whether it can be found: 497 mike 1.1 498 try 499 { 500 return _repository->getClass(nameSpace, className, false, true, true); 501 } 502 catch (Exception&) 503 { 504 return ClassDecl(); 505 } 506 } 507 508 //////////////////////////////////////////////////////////////////////////////// 509 // 510 // Repository 511 // 512 //////////////////////////////////////////////////////////////////////////////// 513 514 Repository::Repository(const String& path) 515 { 516 const char REPOSITORY[] = "/repository"; 517 _root = path; 518 mike 1.1 _root.append(REPOSITORY); 519 520 if (!FileSystem::isDirectory(_root)) 521 { 522 if (!FileSystem::makeDirectory(_root)) 523 throw CannotCreateDirectory(_root); 524 } 525 526 _context = new RepositoryDeclContext(this); 527 } 528 529 Repository::~Repository() 530 { 531 532 } 533 534 ClassDecl Repository::getClass( 535 const String& nameSpace, 536 const String& className, 537 Boolean localOnly, 538 Boolean includeQualifiers, 539 mike 1.1 Boolean includeClassOrigin, 540 const Array<String>& propertyList) 541 { 542 // Form the path to the class: 543 544 String path; 545 _FindClass(_root, nameSpace, className, path); 546 547 // Load the class: 548 549 ClassDecl classDecl; 550 _LoadObject(path, classDecl); 551 552 return ClassDecl(classDecl); 553 } 554 555 InstanceDecl Repository::getInstance( 556 const String& nameSpace, 557 const Reference& instanceName, 558 Boolean localOnly, 559 Boolean includeQualifiers, 560 mike 1.1 Boolean includeClassOrigin, 561 const Array<String>& propertyList) 562 { 563 throw CimException(CimException::NOT_SUPPORTED); 564 return InstanceDecl(); 565 } 566 567 void Repository::deleteClass( 568 const String& nameSpace, 569 const String& className) 570 { 571 // Get path of class file: 572 573 String path; 574 _FindClass(_root, nameSpace, className, path); 575 576 // Disallow if the class has subclasses: 577 578 if (_HasSubclasses(_root, nameSpace, className)) 579 throw CimException(CimException::CLASS_HAS_CHILDREN); 580 581 mike 1.1 // ATTN-C: check to see if the class has instances: 582 583 // Remove the class: 584 585 if (!FileSystem::removeFile(path)) 586 throw FailedToRemoveFile(path); 587 } 588 589 void Repository::deleteInstance( 590 const String& nameSpace, 591 const Reference& instanceName) 592 { 593 throw CimException(CimException::NOT_SUPPORTED); 594 } 595 596 void Repository::createClass( 597 const String& nameSpace, 598 ClassDecl& newClass) 599 { 600 // Form the path to the class: 601 602 mike 1.1 String path; 603 const String& className = newClass.getClassName(); 604 const String& superClassName = newClass.getSuperClassName(); | ||
605 mike 1.5 _MakeNewClassPath( 606 _root, nameSpace, className, superClassName, path); | ||
607 mike 1.1 | ||
608 mike 1.5 String realPath; 609 610 if (FileSystem::existsIgnoreCase(path, realPath)) | ||
611 mike 1.1 throw CimException(CimException::ALREADY_EXISTS); | ||
612 mike 1.5 else 613 realPath = path; | ||
614 mike 1.1 615 // Validate the new class: 616 617 newClass.resolve(_context, nameSpace); 618 619 // Save the class: 620 | ||
621 mike 1.5 _SaveObject(realPath, newClass); | ||
622 mike 1.1 } 623 624 void Repository::createInstance( 625 const String& nameSpace, | ||
626 mike 1.6 InstanceDecl& newInstance) 627 { 628 // Form the reference to this instance: 629 630 String instanceName; 631 632 #if 0 633 // ATTN: fix this: 634 Reference::referenceToInstanceName( 635 newInstance.makeReference(), instanceName); 636 #else 637 instanceName = "MyClass.key1=123456"; 638 #endif 639 640 // Get the instance-name and create an entry 641 642 String indexPath; 643 644 _MakeInstanceIndexPath( 645 _root, nameSpace, newInstance.getClassName(), indexPath); 646 647 mike 1.6 Uint32 index; 648 649 if (!InstanceIndexFile::insert(indexPath, instanceName, index)) 650 throw CimException(CimException::FAILED); 651 652 // Save the instance to file: 653 654 String path; 655 656 _MakeInstancePath( 657 _root, nameSpace, newInstance.getClassName(), index, path); 658 659 newInstance.resolve(_context, nameSpace); 660 661 std::cout << "path: " << path << std::endl; 662 _SaveObject(path, newInstance); | ||
663 mike 1.1 } 664 665 void Repository::modifyClass( 666 const String& nameSpace, 667 ClassDecl& modifiedClass) 668 { 669 // ATTN: need lots of semantic checking here: 670 671 // Get the old class: 672 673 ClassDecl oldClass = getClass( 674 nameSpace, modifiedClass.getClassName(), false, true, true); 675 676 // Disallow changing the name of the super-class: 677 678 if (modifiedClass.getSuperClassName() != oldClass.getSuperClassName()) 679 throw CimException(CimException::INVALID_SUPERCLASS); 680 681 // Delete the old class: 682 683 deleteClass(nameSpace, modifiedClass.getClassName()); 684 mike 1.1 685 // Create the class again: 686 687 createClass(nameSpace, modifiedClass); 688 } 689 690 void Repository::modifyInstance( 691 const String& nameSpace, 692 const InstanceDecl& modifiedInstance) 693 { 694 throw CimException(CimException::NOT_SUPPORTED); 695 } 696 697 Array<ClassDecl> Repository::enumerateClasses( 698 const String& nameSpace, 699 const String& className, 700 Boolean deepInheritance, 701 Boolean localOnly, 702 Boolean includeQualifiers, 703 Boolean includeClassOrigin) 704 { 705 mike 1.1 Array<String> classNames = 706 enumerateClassNames(nameSpace, className, deepInheritance); 707 708 Array<ClassDecl> result; 709 710 for (Uint32 i = 0; i < classNames.getSize(); i++) 711 { 712 result.append(getClass(nameSpace, classNames[i], localOnly, 713 includeQualifiers, includeClassOrigin)); 714 } 715 716 return result; 717 } 718 719 Array<String> Repository::enumerateClassNames( 720 const String& nameSpace, 721 const String& className, 722 Boolean deepInheritance) 723 { 724 // Build the path to the classes directory: 725 726 mike 1.1 const char CLASSES[] = "/classes/"; 727 String path; 728 _MakeNameSpacePath(_root, nameSpace, path); 729 path.append(CLASSES); 730 731 if (!FileSystem::isDirectory(path)) 732 throw CimException(CimException::INVALID_NAMESPACE); 733 734 if (deepInheritance) 735 { 736 if (className == String::EMPTY) 737 { 738 Array<String> classNames; 739 _AppendSubclassesDeep(path, String(), classNames); 740 return classNames; 741 } 742 else 743 { 744 Array<String> classNames; 745 _AppendSubclassesDeep(path, className, classNames); 746 return classNames; 747 mike 1.1 } 748 } 749 else 750 { 751 if (className == String::EMPTY) 752 { 753 Array<String> classNames; 754 _AppendClassNames(path, "*", "#", classNames); 755 return classNames; 756 } 757 else 758 { 759 Array<String> classNames; 760 _AppendClassNames(path, "*", className, classNames); 761 return classNames; 762 } 763 } 764 765 // Unreachable: 766 return Array<String>(); 767 } 768 mike 1.1 769 Array<InstanceDecl> Repository::enumerateInstances( 770 const String& nameSpace, 771 const String& className, 772 Boolean deepInheritance, 773 Boolean localOnly, 774 Boolean includeQualifiers, 775 Boolean includeClassOrigin, 776 const Array<String>& propertyList) 777 { 778 throw CimException(CimException::NOT_SUPPORTED); 779 return Array<InstanceDecl>(); 780 } 781 | ||
782 mike 1.4 Array<Reference> Repository::enumerateInstanceNames( | ||
783 mike 1.1 const String& nameSpace, 784 const String& className) 785 { 786 throw CimException(CimException::NOT_SUPPORTED); | ||
787 mike 1.4 return Array<Reference>(); | ||
788 mike 1.1 } 789 790 Array<InstanceDecl> Repository::execQuery( 791 const String& queryLanguage, 792 const String& query) 793 { 794 throw CimException(CimException::NOT_SUPPORTED); 795 return Array<InstanceDecl>(); 796 } 797 798 Array<InstanceDecl> Repository::associators( 799 const String& nameSpace, 800 const Reference& objectName, 801 const String& assocClass, 802 const String& resultClass, 803 const String& role, 804 const String& resultRole, 805 Boolean includeQualifiers, 806 Boolean includeClassOrigin, 807 const Array<String>& propertyList) 808 { 809 mike 1.1 throw CimException(CimException::NOT_SUPPORTED); 810 return Array<InstanceDecl>(); 811 } 812 813 Array<Reference> Repository::associatorNames( 814 const String& nameSpace, 815 const Reference& objectName, 816 const String& assocClass, 817 const String& resultClass, 818 const String& role, 819 const String& resultRole) 820 { 821 throw CimException(CimException::NOT_SUPPORTED); 822 return Array<Reference>(); 823 } 824 825 Array<InstanceDecl> Repository::references( 826 const String& nameSpace, 827 const Reference& objectName, 828 const String& resultClass, 829 const String& role, 830 mike 1.1 Boolean includeQualifiers, 831 Boolean includeClassOrigin, 832 const Array<String>& propertyList) 833 { 834 throw CimException(CimException::NOT_SUPPORTED); 835 return Array<InstanceDecl>(); 836 } 837 838 Array<Reference> Repository::referenceNames( 839 const String& nameSpace, 840 const Reference& objectName, 841 const String& resultClass, 842 const String& role) 843 { 844 throw CimException(CimException::NOT_SUPPORTED); 845 return Array<Reference>(); 846 } 847 848 Value Repository::getProperty( 849 const String& nameSpace, 850 const Reference& instanceName, 851 mike 1.1 const String& propertyName) 852 { 853 throw CimException(CimException::NOT_SUPPORTED); 854 return Value(); 855 } 856 857 void Repository::setProperty( 858 const String& nameSpace, 859 const Reference& instanceName, 860 const String& propertyName, 861 const Value& newValue) 862 { 863 throw CimException(CimException::NOT_SUPPORTED); 864 } 865 866 QualifierDecl Repository::getQualifier( 867 const String& nameSpace, 868 const String& qualifierName) 869 { 870 // Form the path of the qualifier file: 871 872 mike 1.1 String path; 873 _MakeQualfierPath(_root, nameSpace, qualifierName, path); 874 875 // If it does not exist: 876 | ||
877 mike 1.5 String realPath; 878 879 if (!FileSystem::existsIgnoreCase(path, realPath)) | ||
880 mike 1.1 throw CimException(CimException::NOT_FOUND); 881 882 // Load the qualifier: 883 884 QualifierDecl qualifierDecl; | ||
885 mike 1.5 _LoadObject(realPath, qualifierDecl); 886 887 // Return the qualifier: | ||
888 mike 1.1 889 return QualifierDecl(qualifierDecl); 890 } 891 892 void Repository::setQualifier( 893 const String& nameSpace, 894 const QualifierDecl& qualifierDecl) 895 { 896 // Form the path of the qualifier: 897 898 String path; 899 _MakeQualfierPath(_root, nameSpace, qualifierDecl.getName(), path); 900 901 // If the qualifier already exists, delete it: 902 | ||
903 mike 1.5 String realPath; 904 905 if (FileSystem::existsIgnoreCase(path, realPath)) | ||
906 mike 1.1 { | ||
907 mike 1.5 if (!FileSystem::removeFile(realPath)) | ||
908 mike 1.1 throw FailedToRemoveDirectory(path); 909 } | ||
910 mike 1.5 else 911 realPath = path; | ||
912 mike 1.1 913 // Write the qualifier to file: 914 | ||
915 mike 1.5 _SaveObject(realPath, qualifierDecl); | ||
916 mike 1.1 } 917 918 void Repository::deleteQualifier( 919 const String& nameSpace, 920 const String& qualifierName) 921 { 922 String path; 923 _MakeQualfierPath(_root, nameSpace, qualifierName, path); 924 | ||
925 mike 1.5 String realPath; 926 927 if (!FileSystem::existsIgnoreCase(path, realPath)) | ||
928 mike 1.1 throw CimException(CimException::NOT_FOUND); 929 | ||
930 mike 1.5 if (!FileSystem::removeFile(realPath)) | ||
931 mike 1.1 throw FailedToRemoveFile(path); 932 } 933 934 Array<QualifierDecl> Repository::enumerateQualifiers( 935 const String& nameSpace) 936 { 937 // Build the path to the qualifiers directory: 938 939 const char QUALIFIERS[] = "/qualifiers/"; 940 String path; 941 _MakeNameSpacePath(_root, nameSpace, path); 942 path.append(QUALIFIERS); 943 944 if (!FileSystem::isDirectory(path)) 945 throw CimException(CimException::INVALID_NAMESPACE); 946 947 // Get the names of the qualifiers: 948 949 Array<String> qualifierNames; 950 951 if (!FileSystem::getDirectoryContents(path, qualifierNames)) 952 mike 1.1 throw NoSuchDirectory(path); 953 954 // Load each qualifier into the result array: 955 956 Array<QualifierDecl> result; 957 958 for (Uint32 i = 0, n = qualifierNames.getSize(); i < n; i++) 959 { 960 QualifierDecl tmp = getQualifier(nameSpace, qualifierNames[i]); 961 result.append(tmp); 962 } 963 964 return result; 965 } 966 967 Value Repository::invokeMethod( 968 const String& nameSpace, 969 const Reference& instanceName, 970 const String& methodName, 971 const Array<Value>& inParameters, 972 Array<Value>& outParameters) 973 mike 1.1 { 974 throw CimException(CimException::NOT_SUPPORTED); 975 return Value(); 976 } 977 978 //////////////////////////////////////////////////////////////////////////////// 979 // 980 // New methods 981 // 982 //////////////////////////////////////////////////////////////////////////////// 983 984 void Repository::createNameSpace(const String& nameSpace) 985 { 986 String path; 987 _MakeNameSpacePath(_root, nameSpace, path); 988 989 if (FileSystem::exists(path)) 990 throw AlreadyExists(nameSpace); 991 992 if (!FileSystem::makeDirectory(path)) 993 throw CannotCreateDirectory(path); 994 mike 1.1 995 // Create "./qualifiers" directory: 996 997 String qualifiersDir = path; 998 qualifiersDir.append("/qualifiers"); 999 1000 if (!FileSystem::makeDirectory(qualifiersDir)) 1001 throw CannotCreateDirectory(qualifiersDir); 1002 1003 // Create "./classes" directory: 1004 1005 String classesDir = path; 1006 classesDir.append("/classes"); 1007 1008 if (!FileSystem::makeDirectory(classesDir)) 1009 throw CannotCreateDirectory(classesDir); 1010 1011 // Create "./instances" directory: 1012 1013 String instancesDir = path; 1014 instancesDir.append("/instances"); 1015 mike 1.1 1016 if (!FileSystem::makeDirectory(instancesDir)) 1017 throw CannotCreateDirectory(instancesDir); 1018 } 1019 1020 Array<String> Repository::enumerateNameSpaces() const 1021 { 1022 Array<String> result; 1023 1024 if (!FileSystem::getDirectoryContents(_root, result)) 1025 throw NoSuchDirectory(_root); 1026 1027 for (Uint32 i = 0, n = result.getSize(); i < n; i++) 1028 { 1029 const String& tmp = result[i]; 1030 1031 for (Char16* p = (Char16*)tmp.getData(); *p; p++) 1032 { 1033 if (*p == '#') 1034 *p = '/'; 1035 } 1036 mike 1.1 } 1037 1038 return result; | ||
1039 mike 1.3 } 1040 1041 // Recall flavor defaults: TOSUBCLASS | OVERRIDABLE 1042 1043 void Repository::createMetaQualifiers(const String& nameSpace) 1044 { 1045 // Qualifier CimType : string = null, 1046 // Scope(property, parameter) 1047 1048 setQualifier(nameSpace, QualifierDecl("cimtype", String(), 1049 Scope::PROPERTY | Scope::REFERENCE | Scope::PARAMETER)); 1050 1051 // Qualifier id : sint32 = null, 1052 // Scope(any), 1053 // Flavor(toinstance) 1054 1055 setQualifier(nameSpace, QualifierDecl("id", Sint32(0), 1056 Scope::ANY, 1057 Flavor::TOINSTANCE)); 1058 1059 // Qualifier OctetString : boolean = false, Scope(property) 1060 mike 1.3 1061 setQualifier(nameSpace, QualifierDecl("octetstring", false, 1062 Scope::PROPERTY)); 1063 1064 // Qualifier Abstract : boolean = false, 1065 // Scope(class, association, indication), 1066 // Flavor(disableoverride, restricted); 1067 1068 setQualifier(nameSpace, QualifierDecl("abstract", false, 1069 Scope::CLASS | Scope::ASSOCIATION | Scope::INDICATION, 1070 Flavor::NONE)); 1071 1072 // Qualifier Aggregate : boolean = false, 1073 // Scope(reference), 1074 // Flavor(disableoverride, tosubclass); 1075 1076 setQualifier(nameSpace, QualifierDecl("aggregate", false, 1077 Scope::REFERENCE, Flavor::TOSUBCLASS)); 1078 1079 // Qualifier Aggregation : boolean = false, 1080 // Scope(association), 1081 mike 1.3 // Flavor(disableoverride, tosubclass); 1082 1083 setQualifier(nameSpace, QualifierDecl("aggregation", false, 1084 Scope::ASSOCIATION, Flavor::TOSUBCLASS)); 1085 1086 // Qualifier Alias : string = null, 1087 // Scope(property, reference, method), 1088 // Flavor(translatable); 1089 1090 setQualifier(nameSpace, QualifierDecl("alias", String(), 1091 Scope::PROPERTY | Scope::REFERENCE | Scope::METHOD, 1092 Flavor::DEFAULTS | Flavor::TRANSLATABLE)); 1093 1094 // Qualifier ArrayType : string = "Bag", 1095 // Scope(property, parameter); 1096 1097 setQualifier(nameSpace, QualifierDecl("arraytype", "Bag", 1098 Scope::PROPERTY | Scope::PARAMETER)); 1099 1100 // Qualifier Association : boolean = false, 1101 // Scope(class, association), 1102 mike 1.3 // Flavor(disableoverride); 1103 1104 setQualifier(nameSpace, QualifierDecl("association", false, 1105 Scope::CLASS | Scope::ASSOCIATION, 1106 Flavor::TOSUBCLASS)); 1107 1108 // Qualifier BitMap : string[], 1109 // Scope(property, method, parameter); 1110 1111 setQualifier(nameSpace, QualifierDecl("bitmap", Array<String>(), 1112 Scope::PROPERTY | Scope::METHOD | Scope::PARAMETER)); 1113 1114 // Qualifier BitValues : string[], 1115 // Scope(property, method, parameter), 1116 // Flavor(Translatable); 1117 1118 setQualifier(nameSpace, QualifierDecl("bitvalues", Array<String>(), 1119 Scope::PROPERTY | Scope::METHOD | Scope::PARAMETER, 1120 Flavor::DEFAULTS | Flavor::TRANSLATABLE)); 1121 1122 // Qualifier Counter : boolean = false, 1123 mike 1.3 // Scope(property, method, parameter); 1124 1125 setQualifier(nameSpace, QualifierDecl("counter", false, 1126 Scope::PROPERTY | Scope::METHOD | Scope::PARAMETER)); 1127 1128 // Qualifier Delete : boolean = false, 1129 // Scope(association, reference); 1130 1131 setQualifier(nameSpace, QualifierDecl("delete", false, 1132 Scope::ASSOCIATION | Scope::REFERENCE)); 1133 1134 // Qualifier Description : string = null, 1135 // Scope(any), 1136 // Flavor(translatable); 1137 1138 setQualifier(nameSpace, QualifierDecl("description", String(), 1139 Scope::ANY, 1140 Flavor::TRANSLATABLE)); 1141 1142 // Qualifier DisplayName : string = null, 1143 // Scope(any), 1144 mike 1.3 // Flavor(translatable); 1145 1146 setQualifier(nameSpace, QualifierDecl("displayname", String(), 1147 Scope::ANY, 1148 Flavor::DEFAULTS | Flavor::TRANSLATABLE)); 1149 1150 // Qualifier Expensive : boolean = false, 1151 // Scope(property, reference, method, class, association); 1152 1153 setQualifier(nameSpace, QualifierDecl("expensive", false, 1154 Scope::PROPERTY | Scope::REFERENCE | Scope::METHOD | Scope::CLASS | 1155 Scope::ASSOCIATION)); 1156 1157 // Qualifier Gauge : boolean = false, 1158 // Scope(property, method, parameter); 1159 1160 setQualifier(nameSpace, QualifierDecl("gauge", false, 1161 Scope::PROPERTY | Scope::METHOD | Scope::PARAMETER)); 1162 1163 // Qualifier Ifdeleted : boolean = false, 1164 // Scope(association, reference); 1165 mike 1.3 1166 setQualifier(nameSpace, QualifierDecl("ifdeleted", false, 1167 Scope::ASSOCIATION | Scope::REFERENCE)); 1168 1169 // Qualifier In : boolean = true, 1170 // Scope(parameter), 1171 // Flavor(disableoverride); 1172 1173 setQualifier(nameSpace, QualifierDecl("in", true, 1174 Scope::PARAMETER, 1175 Flavor::TOSUBCLASS)); 1176 1177 // Qualifier Indication : boolean = false, 1178 // Scope(class, indication), 1179 // Flavor(disableoverride); 1180 1181 setQualifier(nameSpace, QualifierDecl("indication", false, 1182 Scope::CLASS | Scope::INDICATION, 1183 Flavor::TOSUBCLASS)); 1184 1185 // Qualifier Invisible : boolean = false, 1186 mike 1.3 // Scope(reference, association, class, property, method); 1187 1188 setQualifier(nameSpace, QualifierDecl("invisible", false, 1189 Scope::REFERENCE | Scope::ASSOCIATION | Scope::CLASS | Scope::PROPERTY | 1190 Scope::METHOD)); 1191 1192 // Qualifier Key : boolean = false, 1193 // Scope(property, reference), 1194 // Flavor(disableoverride); 1195 1196 setQualifier(nameSpace, QualifierDecl("key", false, 1197 Scope::PROPERTY | Scope::REFERENCE, 1198 Flavor::TOSUBCLASS)); 1199 1200 // Qualifier Large : boolean = false, 1201 // Scope(property, class); 1202 1203 setQualifier(nameSpace, QualifierDecl("large", false, 1204 Scope::PROPERTY | Scope::CLASS)); 1205 1206 // Qualifier MappingStrings : string[], 1207 mike 1.3 // Scope(class, property, association, indication, reference); 1208 1209 setQualifier(nameSpace, QualifierDecl("mappingstrings", Array<String>(), 1210 Scope::CLASS | Scope::PROPERTY | Scope::ASSOCIATION | 1211 Scope::INDICATION | Scope::REFERENCE)); 1212 1213 // Qualifier Max : uint32 = null, Scope(reference); 1214 1215 setQualifier(nameSpace, QualifierDecl("max", Sint32(0), 1216 Scope::PROPERTY | Scope::REFERENCE)); 1217 1218 // Qualifier MaxLen : uint32 = null, 1219 // Scope(property, method, parameter); 1220 1221 #if 0 1222 setQualifier(nameSpace, QualifierDecl("maxlen", Uint32(0), 1223 Scope::PROPERTY | Scope::METHOD | Scope::PARAMETER)); 1224 #else 1225 setQualifier(nameSpace, QualifierDecl("maxlen", Sint32(0), 1226 Scope::PROPERTY | Scope::METHOD | Scope::PARAMETER)); 1227 #endif 1228 mike 1.3 1229 // Qualifier MaxValue : sint64 = null, 1230 // Scope(property, method, parameter); 1231 // ATTN: XML schema requires sint32! 1232 1233 setQualifier(nameSpace, QualifierDecl("maxvalue", Sint32(0), 1234 Scope::PROPERTY | Scope::METHOD | Scope::PARAMETER)); 1235 1236 // Qualifier Min : sint32 = null, Scope(reference); 1237 1238 setQualifier(nameSpace, QualifierDecl("min", Sint32(0), 1239 Scope::REFERENCE)); 1240 1241 // Qualifier MinValue : sint64 = null, 1242 // Scope(property, method, parameter); 1243 // ATTN: Type expected by XML spec is sint32! 1244 1245 setQualifier(nameSpace, QualifierDecl("minvalue", Sint32(0), 1246 Scope::PROPERTY | Scope::METHOD | Scope::PARAMETER)); 1247 1248 // Qualifier ModelCorrespondence : string[], 1249 mike 1.3 // Scope(property); 1250 1251 setQualifier(nameSpace, QualifierDecl("modelcorrespondence", 1252 Array<String>(), 1253 Scope::PROPERTY)); 1254 1255 // Qualifier NonLocal : string = null, 1256 // Scope(reference); 1257 1258 setQualifier(nameSpace, QualifierDecl("nonlocal", String(), 1259 Scope::REFERENCE)); 1260 1261 // Qualifier NullValue : string = null, 1262 // Scope(property), 1263 // Flavor(tosubclass, disableoverride); 1264 1265 setQualifier(nameSpace, QualifierDecl("nullvalue", String(), 1266 Scope::PROPERTY, 1267 Flavor::TOSUBCLASS)); 1268 1269 // Qualifier Out : boolean = false, 1270 mike 1.3 // Scope(parameter), 1271 // Flavor(disableoverride); 1272 1273 setQualifier(nameSpace, QualifierDecl("out", false, 1274 Scope::PARAMETER, 1275 Flavor::TOSUBCLASS)); 1276 1277 // Qualifier Override : string = null, 1278 // Scope(property, method, reference), 1279 // Flavor(disableoverride); 1280 1281 setQualifier(nameSpace, QualifierDecl("override", String(), 1282 Scope::PROPERTY | Scope::METHOD | Scope::REFERENCE, 1283 Flavor::TOSUBCLASS)); 1284 1285 // Qualifier Propagated : string = null, 1286 // Scope(property, reference), 1287 // Flavor(disableoverride); 1288 1289 setQualifier(nameSpace, QualifierDecl("propagated", String(), 1290 Scope::PROPERTY | Scope::REFERENCE, 1291 mike 1.3 Flavor::TOSUBCLASS)); 1292 1293 // Qualifier Provider : string = null, 1294 // Scope(any); 1295 1296 setQualifier(nameSpace, QualifierDecl("provider", String(), 1297 Scope::ANY)); 1298 1299 // Qualifier Read : boolean = true, Scope(property); 1300 1301 setQualifier(nameSpace, QualifierDecl("read", true, 1302 Scope::PROPERTY)); 1303 1304 // Qualifier Required : boolean = false, 1305 // Scope(property); 1306 1307 setQualifier(nameSpace, QualifierDecl("required", false, 1308 Scope::PROPERTY)); 1309 1310 // Qualifier Revision : string = null, 1311 // Scope(schema, class, association, indication), 1312 mike 1.3 // Flavor(translatable); 1313 // ATTN: No such scope as Scope::SCHEMA 1314 1315 setQualifier(nameSpace, QualifierDecl("revision", String(), 1316 Scope::CLASS | Scope::ASSOCIATION | Scope::INDICATION, 1317 Flavor::DEFAULTS | Flavor::TRANSLATABLE)); 1318 1319 // Qualifier Schema : string = null, 1320 // Scope(property, method), 1321 // Flavor(disableoverride, translatable); 1322 1323 setQualifier(nameSpace, QualifierDecl("schema", String(), 1324 Scope::PROPERTY | Scope::METHOD, 1325 Flavor::TOSUBCLASS | Flavor::TRANSLATABLE)); 1326 1327 // Qualifier Source : string = null, 1328 // Scope(class, association, indication); 1329 1330 setQualifier(nameSpace, QualifierDecl("source", String(), 1331 Scope::CLASS | Scope::ASSOCIATION | Scope::INDICATION)); 1332 1333 mike 1.3 // Qualifier SourceType : string = null, 1334 // Scope(class, association, indication,reference); 1335 1336 setQualifier(nameSpace, QualifierDecl("sourcetype", String(), 1337 Scope::CLASS | Scope::ASSOCIATION | Scope:: INDICATION | 1338 Scope::REFERENCE)); 1339 1340 // Qualifier Static : boolean = false, 1341 // Scope(property, method), Flavor(disableoverride); 1342 1343 setQualifier(nameSpace, QualifierDecl("static", false, 1344 Scope::PROPERTY | Scope::METHOD, 1345 Flavor::TOSUBCLASS)); 1346 1347 // Qualifier Syntax : string = null, 1348 // Scope(property, reference, method, parameter); 1349 1350 setQualifier(nameSpace, QualifierDecl("syntax", String(), 1351 Scope::PROPERTY | Scope::REFERENCE | Scope::METHOD | Scope::PARAMETER)); 1352 1353 // Qualifier SyntaxType : string = null, 1354 mike 1.3 // Scope(property, reference, method, parameter); 1355 1356 setQualifier(nameSpace, QualifierDecl("syntaxtype", String(), 1357 Scope::PROPERTY | Scope::REFERENCE | Scope::METHOD | Scope::PARAMETER)); 1358 1359 // Qualifier Terminal : boolean = false, 1360 // Scope(class); 1361 1362 setQualifier(nameSpace, QualifierDecl("terminal", false, 1363 Scope::CLASS)); 1364 1365 // Qualifier TriggerType : string = null, 1366 // Scope(class, property, reference, method, association, indication); 1367 1368 setQualifier(nameSpace, QualifierDecl("triggertype", String(), 1369 Scope::CLASS | Scope::PROPERTY | Scope::REFERENCE | Scope::METHOD | 1370 Scope::ASSOCIATION | Scope::INDICATION)); 1371 1372 // Qualifier Units : string = null, 1373 // Scope(property, method, parameter), 1374 // Flavor(translatable); 1375 mike 1.3 1376 setQualifier(nameSpace, QualifierDecl("units", String(), 1377 Scope::PROPERTY | Scope::METHOD | Scope::PARAMETER, 1378 Flavor::DEFAULTS | Flavor::TRANSLATABLE)); 1379 1380 // Qualifier UnknownValues : string[], 1381 // Scope(property), 1382 // Flavor(disableoverride, tosubclass); 1383 1384 setQualifier(nameSpace, QualifierDecl("unknownvalues", Array<String>(), 1385 Scope::PROPERTY, 1386 Flavor::TOSUBCLASS)); 1387 1388 // Qualifier UnsupportedValues : string[], 1389 // Scope(property), 1390 // Flavor(disableoverride, tosubclass); 1391 1392 setQualifier(nameSpace, QualifierDecl("unsupportedvalues", Array<String>(), 1393 Scope::PROPERTY, 1394 Flavor::TOSUBCLASS)); 1395 1396 mike 1.3 // Qualifier ValueMap : string[], 1397 // Scope(property, method, parameter); 1398 1399 setQualifier(nameSpace, QualifierDecl("valuemap", Array<String>(), 1400 Scope::PROPERTY | Scope::METHOD | Scope::PARAMETER)); 1401 1402 // Qualifier Values : string[], 1403 // Scope(property, method, parameter), 1404 // Flavor(translatable); 1405 1406 setQualifier(nameSpace, QualifierDecl("values", Array<String>(), 1407 Scope::PROPERTY | Scope::METHOD | Scope::PARAMETER, 1408 Flavor::DEFAULTS | Flavor::TRANSLATABLE)); 1409 1410 // Qualifier Version : string = null, 1411 // Scope(schema, class, association, indication), 1412 // Flavor(translatable); 1413 // ATTN: No such scope as Scope::SCHEMA 1414 1415 setQualifier(nameSpace, QualifierDecl("version", String(), 1416 Scope::CLASS | Scope::ASSOCIATION | Scope::INDICATION, 1417 mike 1.3 Flavor::DEFAULTS | Flavor::TRANSLATABLE)); 1418 1419 // Qualifier Weak : boolean = false, 1420 // Scope(reference), 1421 // Flavor(disableoverride, tosubclass); 1422 1423 setQualifier(nameSpace, QualifierDecl("weak", false, 1424 Scope::REFERENCE, 1425 Flavor::TOSUBCLASS)); 1426 1427 // Qualifier Write : boolean = false, 1428 // Scope(property); 1429 1430 setQualifier(nameSpace, QualifierDecl("write", false, 1431 Scope::PROPERTY)); | ||
1432 mike 1.1 } 1433 1434 PEGASUS_NAMESPACE_END |
No CVS admin address has been configured |
Powered by ViewCVS 0.9.2 |