1 mike 1.30 //%/////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
6 chip 1.33 // of this software and associated documentation files (the "Software"), to
7 // deal in the Software without restriction, including without limitation the
8 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
9 mike 1.30 // sell copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
|
11 chip 1.33 //
12 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
13 mike 1.30 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
14 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
15 chip 1.33 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
18 mike 1.30 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 //
21 //==============================================================================
22 //
23 // Author: Mike Brasher (mbrasher@bmc.com)
24 //
25 // Modified By:
26 //
27 //%/////////////////////////////////////////////////////////////////////////////
28
29 #include <cctype>
30 #include <cstdio>
31 #include <fstream>
32 #include <Pegasus/Common/Pair.h>
33 #include <Pegasus/Common/Destroyer.h>
34 #include <Pegasus/Common/FileSystem.h>
35 #include <Pegasus/Common/Exception.h>
36 #include <Pegasus/Common/XmlReader.h>
37 #include <Pegasus/Common/XmlWriter.h>
38 #include <Pegasus/Common/DeclContext.h>
39 mike 1.30 #include <Pegasus/Common/DeclContext.h>
40 #include "CIMRepository.h"
|
41 bob 1.32 #include "RepositoryDeclContext.h"
|
42 mike 1.30 #include "InstanceIndexFile.h"
|
43 mike 1.31 #include "AssocTable.h"
|
44 mike 1.30
|
45 mike 1.31 #define INDENT_XML_FILES
|
46 mike 1.30
47 PEGASUS_USING_STD;
48
49 PEGASUS_NAMESPACE_BEGIN
50
51 ////////////////////////////////////////////////////////////////////////////////
52 //
53 // _LoadObject()
54 //
55 // Loads objects (classes, instances, and qualifiers) from disk to
56 // memory objects.
57 //
58 ////////////////////////////////////////////////////////////////////////////////
59
60 template<class Object>
61 void _LoadObject(
62 const String& path,
63 Object& object)
64 {
65 // Get the real path of the file:
66
67 mike 1.30 String realPath;
68
69 if (!FileSystem::existsNoCase(path, realPath))
70 throw CannotOpenFile(path);
71
72 // Load file into memory:
73
74 Array<Sint8> data;
75 FileSystem::loadFileToMemory(data, realPath);
76 data.append('\0');
77
78 XmlParser parser((char*)data.getData());
79
80 XmlReader::getObject(parser, object);
81 }
82
83 ////////////////////////////////////////////////////////////////////////////////
84 //
85 // _SaveObject()
86 //
87 // Saves objects (classes, instances, and qualifiers) from memory to
88 mike 1.30 // disk files.
89 //
90 ////////////////////////////////////////////////////////////////////////////////
91
92 template<class Object>
93 void _SaveObject(const String& path, const Object& object)
94 {
95 Array<Sint8> out;
96 object.toXml(out);
97
98 ArrayDestroyer<char> destroyer(path.allocateCString());
99 PEGASUS_STD(ofstream) os(destroyer.getPointer() PEGASUS_IOS_BINARY);
100
101 if (!os)
102 throw CannotOpenFile(path);
103
104 #ifdef INDENT_XML_FILES
|
105 mike 1.31 out.append('\0');
|
106 mike 1.30 XmlWriter::indentedPrint(os, out.getData(), 2);
107 #else
108 os.write((char*)out.getData(), out.size());
109 #endif
110 }
111
|
112 mike 1.36 String _MakeAssocPath(
113 const String& nameSpace,
114 const String& repositoryRoot)
115 {
116 String tmp = nameSpace;
117 tmp.translate('/', '#');
118 return String(Cat(repositoryRoot, "/", tmp, "/associations"));
119 }
120
|
121 mike 1.30
122 ////////////////////////////////////////////////////////////////////////////////
123 //
124 // CIMRepository
125 //
126 // The following are not implemented:
127 //
128 // CIMRepository::setProperty()
129 // CIMRepository::getProperty()
130 // CIMRepository::modifyInstance()
131 // CIMRepository::execQuery()
132 // CIMRepository::execQuery()
133 // CIMRepository::associators()
134 // CIMRepository::associatorNames()
135 // CIMRepository::referencess()
136 // CIMRepository::referencesNames()
137 // CIMRepository::invokeMethod()
138 //
139 // Note that invokeMethod() will not never implemented since it is not
140 // meaningful for a repository.
141 //
142 mike 1.30 // ATTN: need to combine instances of each class into a common file to
143 // improve disk utilization (too many i-nodes in Unix).
144 //
145 // ATTN: make operations on files non-case-sensitive.
146 //
147 ////////////////////////////////////////////////////////////////////////////////
148
|
149 chip 1.33 CIMRepository::CIMRepository(const String& repositoryRoot)
|
150 mike 1.30 : _repositoryRoot(repositoryRoot), _nameSpaceManager(repositoryRoot)
151 {
152 _context = new RepositoryDeclContext(this);
153 }
154
155 CIMRepository::~CIMRepository()
156 {
157 delete _context;
158 }
159
160 CIMClass CIMRepository::getClass(
161 const String& nameSpace,
162 const String& className,
163 Boolean localOnly,
164 Boolean includeQualifiers,
165 Boolean includeClassOrigin,
166 const Array<String>& propertyList)
167 {
168 // ATTN: localOnly, includeQualifiers, and includeClassOrigin are ignored
169 // for now.
170
171 mike 1.30 String classFilePath;
172 classFilePath = _nameSpaceManager.getClassFilePath(nameSpace, className);
173
174 CIMClass cimClass;
175 _LoadObject(classFilePath, cimClass);
176
177 return cimClass;
178 }
179
180 Boolean CIMRepository::_getInstanceIndex(
181 const String& nameSpace,
182 const CIMReference& instanceName,
183 String& className,
184 Uint32& index,
185 Boolean searchSuperClasses) const
186 {
187 // -- Get all descendent classes of this class:
188
189 className = instanceName.getClassName();
|
190 mike 1.31
|
191 mike 1.30 Array<String> classNames;
192 _nameSpaceManager.getSubClassNames(nameSpace, className, true, classNames);
193 classNames.prepend(className);
194
195 // -- Get all superclasses of this one:
196
197 if (searchSuperClasses)
198 _nameSpaceManager.getSuperClassNames(nameSpace, className, classNames);
199
200 // -- Search each qualifying instance file for the instance:
201
202 for (Uint32 i = 0; i < classNames.size(); i++)
203 {
204 CIMReference tmpInstanceName = instanceName;
205 tmpInstanceName.setClassName(classNames[i]);
206
207 // -- Lookup index of instance:
208
209 String path = _getIndexFilePath(nameSpace, classNames[i]);
|
210 chip 1.33
|
211 mike 1.30 if (InstanceIndexFile::lookup(path, tmpInstanceName, index))
212 {
213 className = classNames[i];
214 return true;
215 }
216 }
217
218 return false;
219 }
220
221 CIMInstance CIMRepository::getInstance(
222 const String& nameSpace,
223 const CIMReference& instanceName,
224 Boolean localOnly,
225 Boolean includeQualifiers,
226 Boolean includeClassOrigin,
227 const Array<String>& propertyList)
228 {
229 // -- Get the index for this instance:
230
231 String className;
232 mike 1.30 Uint32 index;
233
234 if (!_getInstanceIndex(nameSpace, instanceName, className, index))
235 {
236 throw PEGASUS_CIM_EXCEPTION(NOT_FOUND, "getInstance()");
237 }
238
239 // -- Load the instance from the file:
240
241 String path = _getInstanceFilePath(nameSpace, className, index);
242 CIMInstance cimInstance;
243 _LoadObject(path, cimInstance);
244 return cimInstance;
245 }
246
247 void CIMRepository::deleteClass(
248 const String& nameSpace,
249 const String& className)
250 {
251 // -- Disallow deletion if class has instances:
252
253 mike 1.30 String path = _getIndexFilePath(nameSpace, className);
254
255 String realPath;
256
257 if (FileSystem::existsNoCase(path, realPath))
258 throw PEGASUS_CIM_EXCEPTION(CLASS_HAS_INSTANCES, className);
259
260 // -- Delete the class (disallowed if there are subclasses):
261
262 _nameSpaceManager.deleteClass(nameSpace, className);
263 }
264
265 void CIMRepository::deleteInstance(
266 const String& nameSpace,
|
267 chip 1.33 const CIMReference& instanceName)
|
268 mike 1.30 {
269 // -- Lookup index of entry from index file:
270
271 String indexFilePath = _getIndexFilePath(
272 nameSpace, instanceName.getClassName());
273
274 Uint32 index;
275
276 if (!InstanceIndexFile::lookup(indexFilePath, instanceName, index))
277 throw PEGASUS_CIM_EXCEPTION(NOT_FOUND, instanceName.toString());
278
279 // -- Attempt to remove the instance file:
280
281 String instanceFilePath = _getInstanceFilePath(
282 nameSpace, instanceName.getClassName(), index);
283
284 if (!FileSystem::removeFileNoCase(instanceFilePath))
285 {
|
286 chip 1.33 throw PEGASUS_CIM_EXCEPTION(FAILED,
|
287 mike 1.30 "failed to remove file in CIMRepository::deleteInstance()");
288 }
289
290 // -- Remove entry from index file:
291
292 InstanceIndexFile::remove(indexFilePath, instanceName);
293
294 // -- Delete index file if it is now empty (zero size):
295
296 Uint32 size;
297
298 if (!FileSystem::getFileSizeNoCase(indexFilePath, size))
299 {
|
300 chip 1.33 throw PEGASUS_CIM_EXCEPTION(FAILED,
|
301 mike 1.30 "unexpected failure in CIMRepository::deleteInstance()");
302 }
303
304 if (size == 0 && !FileSystem::removeFileNoCase(indexFilePath))
305 {
|
306 chip 1.33 throw PEGASUS_CIM_EXCEPTION(FAILED,
|
307 mike 1.30 "unexpected failure in CIMRepository::deleteInstance()");
308 }
|
309 mike 1.36
310 // -- Remove if from the association table (if it is really association).
311 // -- We ignore the return value intentionally. If it is an association,
312 // -- true is returned. Otherwise, true is returned.
313
314 String assocFileName = _MakeAssocPath(nameSpace, _repositoryRoot);
|
315 mike 1.37
316
317 if (FileSystem::exists(assocFileName))
318 AssocTable::deleteAssociation(assocFileName, instanceName);
|
319 mike 1.30 }
320
321 void CIMRepository::createClass(
322 const String& nameSpace,
|
323 chip 1.33 const CIMClass& newClass)
|
324 mike 1.30 {
325 // -- Resolve the class:
|
326 chip 1.33 CIMClass cimClass(newClass);
327
328 cimClass.resolve(_context, nameSpace);
|
329 mike 1.30
330 // -- Create namespace manager entry:
331
332 String classFilePath;
333
|
334 chip 1.33 _nameSpaceManager.createClass(nameSpace, cimClass.getClassName(),
335 cimClass.getSuperClassName(), classFilePath);
|
336 mike 1.30
337 // -- Create the class file:
338
|
339 chip 1.33 _SaveObject(classFilePath, cimClass);
|
340 mike 1.30 }
341
342 /*------------------------------------------------------------------------------
343
344 This routine does the following:
345
346 1. Creates two entries in the association file for each relationship
347 formed by this new assocation instance. A binary association
348 (one with two references) ties two instances together. Suppose
349 there are two instances: I1 and I2. Then two entries are created:
350
351 I2 -> I1
352 I1 -> I2
353
354 For a ternary relationship, six entries will be created. Suppose
355 there are three instances: I1, I2, and I3:
356
357 I1 -> I2
358 I1 -> I3
359 I2 -> I1
360 I2 -> I3
361 mike 1.30 I3 -> I1
362 I3 -> I2
363
364 So for an N-ary relationship, there will be 2*N entries created.
365
366 2. Verifies that the association instance refers to real objects.
367 (note that an association reference may refer to either an instance
368 or a class). Throws an exception if one of the references does not
369 refer to a valid object.
370
371 ------------------------------------------------------------------------------*/
372
373 void CIMRepository::_createAssociationEntries(
|
374 chip 1.33 const String& nameSpace,
375 const CIMConstClass& cimClass,
|
376 mike 1.30 const CIMInstance& cimInstance,
377 const CIMReference& instanceName)
378 {
|
379 mike 1.31 // Open input file:
|
380 chip 1.33
|
381 mike 1.36 String assocFileName = _MakeAssocPath(nameSpace, _repositoryRoot);
|
382 mike 1.31 ofstream os;
383
384 if (!OpenAppend(os, assocFileName))
385 throw CannotOpenFile(assocFileName);
386
|
387 mike 1.30 // Get the association's instance name and class name:
388
389 String assocInstanceName = instanceName.toString();
390 String assocClassName = instanceName.getClassName();
391
392 // For each property:
393
394 for (Uint32 i = 0, n = cimInstance.getPropertyCount(); i < n; i++)
395 {
|
396 mike 1.31 CIMConstProperty fromProp = cimInstance.getProperty(i);
|
397 mike 1.30
398 // If a reference property:
399
|
400 mike 1.31 if (fromProp.getType() == CIMType::REFERENCE)
|
401 mike 1.30 {
402 // For each property:
403
404 for (Uint32 j = 0, n = cimInstance.getPropertyCount(); j < n; j++)
405 {
|
406 mike 1.31 CIMConstProperty toProp = cimInstance.getProperty(j);
|
407 mike 1.30
408 // If a reference property and not the same property:
409
|
410 mike 1.31 if (toProp.getType() == CIMType::REFERENCE &&
411 fromProp.getName() != toProp.getName())
|
412 mike 1.30 {
|
413 mike 1.31 CIMReference fromRef;
414 fromProp.getValue().get(fromRef);
|
415 mike 1.30
|
416 mike 1.31 CIMReference toRef;
417 toProp.getValue().get(toRef);
|
418 mike 1.30
|
419 mike 1.31 String fromObjectName = fromRef.toString();
420 String fromClassName = fromRef.getClassName();
421 String fromPropertyName = fromProp.getName();
422 String toObjectName = toRef.toString();
423 String toClassName = toRef.getClassName();
424 String toPropertyName = toProp.getName();
425
426 AssocTable::append(
427 os,
428 assocInstanceName,
429 assocClassName,
430 fromObjectName,
431 fromClassName,
432 fromPropertyName,
433 toObjectName,
434 toClassName,
435 toPropertyName);
|
436 mike 1.30 }
437 }
438 }
439 }
440 }
441
|
442 mike 1.36 // ATTN-A: Check to see if the objects referred to by the association
443 // really exist and throw an exception if they do not.
444
|
445 mike 1.30 void CIMRepository::createInstance(
446 const String& nameSpace,
|
447 chip 1.33 const CIMInstance& newInstance)
|
448 mike 1.30 {
449 // -- Resolve the instance (looks up class):
|
450 chip 1.33 CIMInstance cimInstance(newInstance);
|
451 mike 1.30
452 CIMConstClass cimClass;
|
453 chip 1.33 cimInstance.resolve(_context, nameSpace, cimClass);
454 CIMReference instanceName = cimInstance.getInstanceName(cimClass);
|
455 mike 1.30
|
456 mike 1.31 // -- Make sure the class has keys (otherwise it will be impossible to
457 // -- create the instance.
458
459 if (!cimClass.hasKeys())
460 {
461 String message = "class has no keys: ";
462 message += cimClass.getClassName();
463 throw PEGASUS_CIM_EXCEPTION(FAILED, message);
464 }
465
|
466 mike 1.30 // -- Be sure instance does not already exist:
467
468 String className;
469 Uint32 dummyIndex;
470
471 if (_getInstanceIndex(nameSpace, instanceName, className, dummyIndex, true))
472 {
473 throw PEGASUS_CIM_EXCEPTION(ALREADY_EXISTS, instanceName.toString());
474 }
475
476 // -- Handle if association:
477
478 if (cimClass.isAssociation())
479 {
|
480 chip 1.33 _createAssociationEntries(nameSpace,
481 cimClass, cimInstance, instanceName);
|
482 mike 1.30 }
483
484 // -- Get common base (of instance file and index file):
485
486 String instanceFileBase = _nameSpaceManager.getInstanceFileBase(
|
487 chip 1.33 nameSpace, cimInstance.getClassName());
|
488 mike 1.30
489 // -- Make index file entry:
490
491 String indexFilePath = _getIndexFilePath(
|
492 chip 1.33 nameSpace, cimInstance.getClassName());
|
493 mike 1.30 Uint32 index;
494
495 if (!InstanceIndexFile::insert(indexFilePath, instanceName, index))
496 throw PEGASUS_CIM_EXCEPTION(ALREADY_EXISTS, instanceName.toString());
497
498 // -- Save instance to file:
499
|
500 chip 1.33 String instanceFilePath = _getInstanceFilePath(nameSpace,
501 cimInstance.getClassName(), index);
|
502 mike 1.30
|
503 chip 1.33 _SaveObject(instanceFilePath, cimInstance);
|
504 mike 1.30 }
505
506 void CIMRepository::modifyClass(
507 const String& nameSpace,
|
508 chip 1.33 const CIMClass& modifiedClass)
|
509 mike 1.30 {
510 // -- Resolve the class:
|
511 chip 1.33 CIMClass cimClass(modifiedClass);
|
512 mike 1.30
|
513 chip 1.33 cimClass.resolve(_context, nameSpace);
|
514 mike 1.30
515 // -- Check to see if it is okay to modify this class:
516
517 String classFilePath;
518
|
519 chip 1.33 _nameSpaceManager.checkModify(nameSpace, cimClass.getClassName(),
520 cimClass.getSuperClassName(), classFilePath);
|
521 mike 1.30
522 // -- Delete the old file containing the class:
523
524 if (!FileSystem::removeFileNoCase(classFilePath))
525 {
|
526 chip 1.33 throw PEGASUS_CIM_EXCEPTION(FAILED,
|
527 mike 1.30 "failed to remove file in CIMRepository::modifyClass()");
528 }
529
530 // -- Create new class file:
531
|
532 chip 1.33 _SaveObject(classFilePath, cimClass);
|
533 mike 1.30 }
534
535 void CIMRepository::modifyInstance(
536 const String& nameSpace,
|
537 chip 1.33 const CIMInstance& modifiedInstance)
|
538 mike 1.30 {
539 // -- Resolve the instance (looks up the class):
|
540 chip 1.33 CIMInstance cimInstance(modifiedInstance);
|
541 mike 1.30
542 CIMConstClass cimClass;
|
543 chip 1.33 cimInstance.resolve(_context, nameSpace, cimClass);
|
544 mike 1.30
545 // -- Lookup index of entry from index file:
546
|
547 chip 1.33 CIMReference instanceName = cimInstance.getInstanceName(cimClass);
|
548 mike 1.30
549 String indexFilePath = _getIndexFilePath(
550 nameSpace, instanceName.getClassName());
551
552 Uint32 index;
553
554 if (!InstanceIndexFile::lookup(indexFilePath, instanceName, index))
555 throw PEGASUS_CIM_EXCEPTION(NOT_FOUND, instanceName.toString());
556
557 // -- Attempt to remove the instance file:
558
559 String instanceFilePath = _getInstanceFilePath(
560 nameSpace, instanceName.getClassName(), index);
561
562 if (!FileSystem::removeFileNoCase(instanceFilePath))
563 {
|
564 chip 1.33 throw PEGASUS_CIM_EXCEPTION(FAILED,
|
565 mike 1.30 "failed to remove file in CIMRepository::deleteInstance()");
566 }
567
568 // -- Save instance to file:
569
|
570 chip 1.33 _SaveObject(instanceFilePath, cimInstance);
|
571 mike 1.30 }
572
573 Array<CIMClass> CIMRepository::enumerateClasses(
574 const String& nameSpace,
575 const String& className,
576 Boolean deepInheritance,
577 Boolean localOnly,
578 Boolean includeQualifiers,
579 Boolean includeClassOrigin)
580 {
581 Array<String> classNames;
582
583 _nameSpaceManager.getSubClassNames(
584 nameSpace, className, deepInheritance, classNames);
585
586 Array<CIMClass> result;
587
588 for (Uint32 i = 0; i < classNames.size(); i++)
589 {
|
590 chip 1.33 result.append(getClass(nameSpace, classNames[i], localOnly,
|
591 mike 1.30 includeQualifiers, includeClassOrigin));
592 }
593
594 return result;
595 }
596
597 Array<String> CIMRepository::enumerateClassNames(
598 const String& nameSpace,
599 const String& className,
600 Boolean deepInheritance)
601 {
602 Array<String> classNames;
603
604 _nameSpaceManager.getSubClassNames(
605 nameSpace, className, deepInheritance, classNames);
606
607 return classNames;
608 return Array<String>();
609 }
610
611 Array<CIMInstance> CIMRepository::enumerateInstances(
612 mike 1.30 const String& nameSpace,
613 const String& className,
614 Boolean deepInheritance,
615 Boolean localOnly,
616 Boolean includeQualifiers,
617 Boolean includeClassOrigin,
618 const Array<String>& propertyList)
619 {
620 // -- Get all descendent classes of this class:
621
622 Array<String> classNames;
623 _nameSpaceManager.getSubClassNames(
624 nameSpace, className, true, classNames);
625 classNames.prepend(className);
626
627 // -- Search each qualifying instance file for the instance:
628
629 Array<CIMReference> instanceNames;
630 Array<Uint32> indices;
631 Array<CIMInstance> instances;
632 Uint32 start = 0;
633 mike 1.30
634 for (Uint32 i = 0; i < classNames.size(); i++)
635 {
636 // -- Form the name of the class index file:
637
638 String path = _getIndexFilePath(nameSpace, classNames[i]);
639
640 // Get all instance names for that class:
|
641 chip 1.33
|
642 mike 1.30 InstanceIndexFile::appendInstanceNamesTo(path, instanceNames, indices);
643 PEGASUS_ASSERT(instanceNames.size() == indices.size());
644
645 // -- Load up all the instances of this class:
646
647 for (Uint32 j = start; j < instanceNames.size(); j++)
648 {
649 String instanceFilePath = _getInstanceFilePath(
650 nameSpace, classNames[i], indices[i]);
651
652 CIMInstance tmpInstance;
653 _LoadObject(instanceFilePath, tmpInstance);
654 instances.append(tmpInstance);
655 }
656
657 start = instanceNames.size();
658 }
659
660 return instances;
661 }
662
663 mike 1.30 Array<CIMReference> CIMRepository::enumerateInstanceNames(
664 const String& nameSpace,
|
665 chip 1.33 const String& className)
|
666 mike 1.30 {
667 // -- Get all descendent classes of this class:
668
669 Array<String> classNames;
670 _nameSpaceManager.getSubClassNames(nameSpace, className, true, classNames);
671 classNames.prepend(className);
672
673 // -- Search each qualifying instance file for the instance:
674
675 Array<CIMReference> instanceNames;
676 Array<Uint32> indices;
677
678 for (Uint32 i = 0; i < classNames.size(); i++)
679 {
680 // -- Form the name of the class index file:
681
682 String path = _getIndexFilePath(nameSpace, classNames[i]);
683
684 // Get all instances for that class:
|
685 chip 1.33
|
686 mike 1.30 InstanceIndexFile::appendInstanceNamesTo(path, instanceNames, indices);
687 }
688
689 return instanceNames;
690 }
691
692 Array<CIMInstance> CIMRepository::execQuery(
693 const String& queryLanguage,
|
694 chip 1.33 const String& query)
695 {
|
696 mike 1.30 throw PEGASUS_CIM_EXCEPTION(NOT_SUPPORTED, "execQuery()");
697
698 return Array<CIMInstance>();
699 }
700
|
701 mike 1.37 Array<CIMObjectWithPath> CIMRepository::associators(
|
702 mike 1.30 const String& nameSpace,
703 const CIMReference& objectName,
704 const String& assocClass,
705 const String& resultClass,
706 const String& role,
707 const String& resultRole,
708 Boolean includeQualifiers,
709 Boolean includeClassOrigin,
710 const Array<String>& propertyList)
|
711 chip 1.33 {
|
712 mike 1.38 PEGASUS_TRACE;
|
713 mike 1.34 Array<CIMReference> names = associatorNames(
714 nameSpace,
715 objectName,
716 assocClass,
717 resultClass,
718 role,
719 resultRole);
720
|
721 mike 1.38 PEGASUS_OUT(names.size());
722 PEGASUS_TRACE;
|
723 mike 1.37 Array<CIMObjectWithPath> result;
|
724 mike 1.34
725 for (Uint32 i = 0, n = names.size(); i < n; i++)
726 {
|
727 mike 1.38 PEGASUS_TRACE;
|
728 mike 1.34 String tmpNameSpace = names[i].getNameSpace();
729
730 if (tmpNameSpace.size() == 0)
731 tmpNameSpace = nameSpace;
732
|
733 mike 1.37 CIMReference reference = names[i];
734
735 if (reference.isClassName())
736 {
737 CIMClass cimClass = getClass(
738 tmpNameSpace,
739 reference.getClassName(),
740 false,
741 includeQualifiers,
742 includeClassOrigin,
743 propertyList);
744
745 result.append(CIMObjectWithPath(reference, CIMObject(cimClass)));
746 }
747 else
748 {
749 CIMInstance cimInstance = getInstance(
750 tmpNameSpace,
751 reference,
752 false,
753 includeQualifiers,
754 mike 1.37 includeClassOrigin,
755 propertyList);
|
756 mike 1.34
|
757 mike 1.37 result.append(CIMObjectWithPath(reference, CIMObject(cimInstance)));
758 }
|
759 mike 1.34 }
760
761 return result;
|
762 mike 1.30 }
763
764 Array<CIMReference> CIMRepository::associatorNames(
765 const String& nameSpace,
766 const CIMReference& objectName,
767 const String& assocClass,
768 const String& resultClass,
769 const String& role,
770 const String& resultRole)
|
771 mike 1.31 {
|
772 mike 1.36 String assocFileName = _MakeAssocPath(nameSpace, _repositoryRoot);
|
773 mike 1.31 Array<String> associatorNames;
774
|
775 mike 1.38 // The return value of this function is ignored since it is okay for
776 // the given object not to have any associators (in this case we just
777 // return a zero-sized array of associators.
778
779 AssocTable::getAssociatorNames(
|
780 mike 1.31 assocFileName,
781 objectName.toString(),
782 assocClass,
783 resultClass,
784 role,
785 resultRole,
|
786 mike 1.38 associatorNames);
|
787 mike 1.31
788 Array<CIMReference> result;
|
789 mike 1.38
|
790 mike 1.31 for (Uint32 i = 0, n = associatorNames.size(); i < n; i++)
791 result.append(associatorNames[i]);
792
793 return result;
|
794 mike 1.30 }
795
796 Array<CIMInstance> CIMRepository::references(
797 const String& nameSpace,
798 const CIMReference& objectName,
799 const String& resultClass,
800 const String& role,
801 Boolean includeQualifiers,
802 Boolean includeClassOrigin,
803 const Array<String>& propertyList)
804 {
|
805 mike 1.35 Array<CIMReference> names = referenceNames(
806 nameSpace,
807 objectName,
808 resultClass,
809 role);
810
811 Array<CIMInstance> result;
812
813 for (Uint32 i = 0, n = names.size(); i < n; i++)
814 {
815 String tmpNameSpace = names[i].getNameSpace();
816
817 if (tmpNameSpace.size() == 0)
818 tmpNameSpace = nameSpace;
819
820 CIMInstance instance = getInstance(
821 tmpNameSpace,
822 names[i],
823 false,
824 includeQualifiers,
825 includeClassOrigin,
826 mike 1.35 propertyList);
827
828 result.append(instance);
829 }
830
831 return result;
|
832 mike 1.30 }
833
834 Array<CIMReference> CIMRepository::referenceNames(
835 const String& nameSpace,
836 const CIMReference& objectName,
837 const String& resultClass,
838 const String& role)
|
839 chip 1.33 {
|
840 mike 1.36 String assocFileName = _MakeAssocPath(nameSpace, _repositoryRoot);
|
841 mike 1.35 Array<String> tmpReferenceNames;
842
843 if (!AssocTable::getReferenceNames(
844 assocFileName,
845 objectName,
846 resultClass,
847 role,
848 tmpReferenceNames))
849 {
850 throw PEGASUS_CIM_EXCEPTION(FAILED, "references not found for: "
851 + objectName.toString());
852 }
853
854 Array<CIMReference> result;
855
856 for (Uint32 i = 0, n = tmpReferenceNames.size(); i < n; i++)
857 result.append(tmpReferenceNames[i]);
858
859 return result;
|
860 mike 1.30 }
861
862 CIMValue CIMRepository::getProperty(
863 const String& nameSpace,
864 const CIMReference& instanceName,
|
865 chip 1.33 const String& propertyName)
|
866 mike 1.30 {
867 // -- Get the index for this instance:
868
869 String className;
870 Uint32 index;
871
872 if (!_getInstanceIndex(nameSpace, instanceName, className, index))
873 throw PEGASUS_CIM_EXCEPTION(NOT_FOUND, "getProperty()");
874
875 // -- Load the instance into memory:
876
877 String path = _getInstanceFilePath(nameSpace, className, index);
878 CIMInstance cimInstance;
879 _LoadObject(path, cimInstance);
880
881 // -- Grab the property from the instance:
882
883 Uint32 pos = cimInstance.findProperty(propertyName);
884
885 if (pos == PEGASUS_NOT_FOUND)
886 throw PEGASUS_CIM_EXCEPTION(NO_SUCH_PROPERTY, "getProperty()");
887 mike 1.30
888 CIMProperty prop = cimInstance.getProperty(pos);
889
890 // -- Return the value:
891
892 return prop.getValue();
893 }
894
895 void CIMRepository::setProperty(
896 const String& nameSpace,
897 const CIMReference& instanceName,
898 const String& propertyName,
899 const CIMValue& newValue)
900 {
901 // -- Load the instance:
902
903 CIMInstance instance = getInstance(
904 nameSpace, instanceName, false, true);
905
906 // -- Get the class:
907
908 mike 1.30 CIMClass cimClass = getClass(nameSpace, instance.getClassName(),
909 false, true);
910
911 // -- Save instance name:
912
913 CIMReference oldRef = instance.getInstanceName(cimClass);
914
915 // -- Modify the property (disallow if property is a key):
916
917 Uint32 pos = instance.findProperty(propertyName);
918
919 if (pos == PEGASUS_NOT_FOUND)
920 throw PEGASUS_CIM_EXCEPTION(NO_SUCH_PROPERTY, "setProperty()");
921
922 CIMProperty prop = instance.getProperty(pos);
923
924 prop.setValue(newValue);
925
926 // -- Disallow if instance name is changed by this operation (attempt
927 // -- to modify a key property.
928
929 mike 1.30 CIMReference newRef = instance.getInstanceName(cimClass);
930
931 if (oldRef != newRef)
932 {
|
933 chip 1.33 throw PEGASUS_CIM_EXCEPTION(FAILED,
|
934 mike 1.30 "setProperty(): attempted to modify a key property");
935 }
936
937 // -- Modify the instance:
938
939 modifyInstance(nameSpace, instance);
940 }
941
942 CIMQualifierDecl CIMRepository::getQualifier(
943 const String& nameSpace,
|
944 chip 1.33 const String& qualifierName)
|
945 mike 1.30 {
946 // -- Get path of qualifier file:
947
948 String qualifierFilePath = _nameSpaceManager.getQualifierFilePath(
949 nameSpace, qualifierName);
950
951 // -- Load qualifier:
952
953 CIMQualifierDecl qualifierDecl;
954
955 try
956 {
957 _LoadObject(qualifierFilePath, qualifierDecl);
958 }
959 catch (CannotOpenFile&)
960 {
961 return CIMQualifierDecl();
962 }
963
964 return qualifierDecl;
965 }
966 mike 1.30
967 void CIMRepository::setQualifier(
968 const String& nameSpace,
|
969 chip 1.33 const CIMQualifierDecl& qualifierDecl)
|
970 mike 1.30 {
971 // -- Get path of qualifier file:
972
973 String qualifierFilePath = _nameSpaceManager.getQualifierFilePath(
974 nameSpace, qualifierDecl.getName());
975
976 // -- If qualifier alread exists, throw exception:
977
978 if (FileSystem::existsNoCase(qualifierFilePath))
979 throw PEGASUS_CIM_EXCEPTION(ALREADY_EXISTS, qualifierDecl.getName());
980
981 // -- Save qualifier:
982
983 _SaveObject(qualifierFilePath, qualifierDecl);
984 }
985
986 void CIMRepository::deleteQualifier(
987 const String& nameSpace,
|
988 chip 1.33 const String& qualifierName)
|
989 mike 1.30 {
990 // -- Get path of qualifier file:
991
992 String qualifierFilePath = _nameSpaceManager.getQualifierFilePath(
993 nameSpace, qualifierName);
994
995 // -- Delete qualifier:
996
997 if (!FileSystem::removeFileNoCase(qualifierFilePath))
998 throw PEGASUS_CIM_EXCEPTION(NOT_FOUND, qualifierName);
999 }
1000
1001 Array<CIMQualifierDecl> CIMRepository::enumerateQualifiers(
1002 const String& nameSpace)
1003 {
1004 String qualifiersRoot = _nameSpaceManager.getQualifiersRoot(nameSpace);
1005
1006 Array<String> qualifierNames;
1007
1008 if (!FileSystem::getDirectoryContents(qualifiersRoot, qualifierNames))
1009 {
|
1010 chip 1.33 throw PEGASUS_CIM_EXCEPTION(FAILED,
|
1011 mike 1.30 "enumerateQualifiers(): internal error");
1012 }
1013
1014 Array<CIMQualifierDecl> qualifiers;
1015
1016 for (Uint32 i = 0; i < qualifierNames.size(); i++)
1017 {
1018 CIMQualifierDecl qualifier = getQualifier(nameSpace, qualifierNames[i]);
1019 qualifiers.append(qualifier);
1020 }
1021
1022 return qualifiers;
1023 }
1024
1025 CIMValue CIMRepository::invokeMethod(
1026 const String& nameSpace,
1027 const CIMReference& instanceName,
1028 const String& methodName,
1029 const Array<CIMValue>& inParameters,
|
1030 chip 1.33 Array<CIMValue>& outParameters)
|
1031 mike 1.30 {
1032 throw PEGASUS_CIM_EXCEPTION(NOT_SUPPORTED, "invokeMethod()");
1033 return CIMValue();
1034 }
1035
1036 void CIMRepository::createNameSpace(const String& nameSpace)
1037 {
1038 _nameSpaceManager.createNameSpace(nameSpace);
1039 }
1040
1041 Array<String> CIMRepository::enumerateNameSpaces() const
1042 {
1043 Array<String> nameSpaceNames;
1044 _nameSpaceManager.getNameSpaceNames(nameSpaceNames);
1045 return nameSpaceNames;
1046 }
1047
1048 void CIMRepository::deleteNameSpace(const String& nameSpace)
1049 {
1050 _nameSpaceManager.deleteNameSpace(nameSpace);
1051 }
1052 mike 1.30
1053 String CIMRepository::_getIndexFilePath(
1054 const String& nameSpace,
1055 const String& className) const
1056 {
1057 String tmp = _nameSpaceManager.getInstanceFileBase(nameSpace, className);
1058 tmp.append(".idx");
1059 return tmp;
1060 }
1061
1062 String CIMRepository::_getInstanceFilePath(
1063 const String& nameSpace,
1064 const String& className,
1065 Uint32 index) const
1066 {
1067 String tmp = _nameSpaceManager.getInstanceFileBase(nameSpace, className);
1068 char extension[32];
1069 sprintf(extension, ".%d", index);
1070 tmp += extension;
1071 return tmp;
1072 }
1073 mike 1.30
1074 PEGASUS_NAMESPACE_END
|