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