1 karl 1.39 //%2005////////////////////////////////////////////////////////////////////////
|
2 mike 1.13 //
|
3 karl 1.38 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
|
6 karl 1.29 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.38 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.39 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 mike 1.13 //
12 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
13 kumpf 1.19 // of this software and associated documentation files (the "Software"), to
14 // deal in the Software without restriction, including without limitation the
15 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
16 mike 1.13 // sell copies of the Software, and to permit persons to whom the Software is
17 // furnished to do so, subject to the following conditions:
|
18 david.dillard 1.40 //
|
19 kumpf 1.19 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
20 mike 1.13 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
21 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
22 kumpf 1.19 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
23 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
25 mike 1.13 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 //==============================================================================
29 //
30 // Author: Mike Brasher (mbrasher@bmc.com)
31 //
|
32 kumpf 1.23 // Modified By: Carol Ann Krug Graves, Hewlett-Packard Company
33 // (carolann_graves@hp.com)
|
34 kumpf 1.27 // Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
|
35 schuur 1.32 // Adrian Schuur (schuur@de.ibm.com)
|
36 a.arora 1.33 // Amit K Arora, IBM (amita@in.ibm.com) for PEP#101
|
37 david.dillard 1.40 // David Dillard, VERITAS Software Corp.
38 // (david.dillard@veritas.com)
|
39 vijay.eli 1.42 // Vijay Eli, IBM (vijay.eli@in.ibm.com) for bug#3346
|
40 mike 1.13 //
41 //%/////////////////////////////////////////////////////////////////////////////
42
|
43 kumpf 1.22 #include <Pegasus/Common/System.h>
|
44 mike 1.13 #include <Pegasus/Common/FileSystem.h>
45 #include <Pegasus/Common/String.h>
46 #include <Pegasus/Common/HashTable.h>
47 #include <Pegasus/Common/Dir.h>
|
48 kumpf 1.15 #include <Pegasus/Common/Tracer.h>
|
49 kumpf 1.23 #include <Pegasus/Common/XmlWriter.h>
|
50 chuck 1.31 #include <Pegasus/Common/CommonUTF.h>
|
51 schuur 1.32 #include "InstanceIndexFile.h"
|
52 mike 1.13 #include "NameSpaceManager.h"
53
54 PEGASUS_NAMESPACE_BEGIN
55
56 static char _CLASSES_DIR[] = "classes";
57 static char _INSTANCES_DIR[] = "instances";
58 static char _QUALIFIERS_DIR[] = "qualifiers";
59
60 static char _CLASSES_SUFFIX[] = "/classes";
61 static char _INSTANCES_SUFFIX[] = "/instances";
62 static char _QUALIFIERS_SUFFIX[] = "/qualifiers";
|
63 kumpf 1.27 static char _ASSOCIATIONS_SUFFIX[] = "/associations";
64
|
65 schuur 1.32
|
66 kumpf 1.27 ////////////////////////////////////////////////////////////////////////////////
67 //
68 // _namespaceNameToDirName()
69 //
70 ////////////////////////////////////////////////////////////////////////////////
71
72 static String _namespaceNameToDirName(const CIMNamespaceName& namespaceName)
73 {
74 String dirName = namespaceName.getString();
75
76 for (Uint32 i=0; i<dirName.size(); i++)
77 {
78 if (dirName[i] == '/')
79 {
80 dirName[i] = '#';
81 }
82 }
|
83 chuck 1.31 #ifdef PEGASUS_REPOSITORY_ESCAPE_UTF8
84 // All chars above 0x7F will be escape.
85 return escapeStringEncoder(dirName);
86 #else
|
87 kumpf 1.27 return dirName;
|
88 chuck 1.31 #endif
|
89 kumpf 1.27 }
90
91 ////////////////////////////////////////////////////////////////////////////////
92 //
93 // _dirNameToNamespaceName()
94 //
95 ////////////////////////////////////////////////////////////////////////////////
96
97 static String _dirNameToNamespaceName(const String& dirName)
98 {
99 String namespaceName = dirName;
100
101 for (Uint32 i=0; i<namespaceName.size(); i++)
102 {
103 if (namespaceName[i] == '#')
104 {
105 namespaceName[i] = '/';
106 }
107 }
|
108 chuck 1.31 #ifdef PEGASUS_REPOSITORY_ESCAPE_UTF8
109 // All chars above 0x7F will be escape.
110 return escapeStringDecoder(namespaceName);
111 #else
|
112 kumpf 1.27 return namespaceName;
|
113 chuck 1.31 #endif
|
114 kumpf 1.27 }
|
115 mike 1.13
116 ////////////////////////////////////////////////////////////////////////////////
117 //
118 // _MakeClassFilePath()
119 //
120 ////////////////////////////////////////////////////////////////////////////////
121
122 static inline String _MakeClassFilePath(
123 const String& nameSpacePath,
|
124 kumpf 1.23 const CIMName& className,
125 const CIMName& superClassName)
|
126 mike 1.13 {
|
127 chuck 1.31 String returnString;
|
128 kumpf 1.23 if (!superClassName.isNull())
|
129 mike 1.13 {
|
130 chuck 1.31 returnString.assign(nameSpacePath);
|
131 kumpf 1.16 returnString.append(_CLASSES_SUFFIX);
132 returnString.append('/');
|
133 kumpf 1.23 returnString.append(className.getString());
|
134 kumpf 1.16 returnString.append('.');
|
135 kumpf 1.23 returnString.append(superClassName.getString());
|
136 mike 1.13 }
137 else
|
138 kumpf 1.15 {
|
139 chuck 1.31 returnString.assign(nameSpacePath);
|
140 kumpf 1.16 returnString.append(_CLASSES_SUFFIX);
141 returnString.append('/');
|
142 kumpf 1.23 returnString.append(className.getString());
|
143 kumpf 1.16 returnString.append(".#");
|
144 kumpf 1.15 }
|
145 chuck 1.31 #ifdef PEGASUS_REPOSITORY_ESCAPE_UTF8
146 // All chars above 0x7F will be escape.
147 return escapeStringEncoder(returnString);
148 #else
149 return returnString;
150 #endif
|
151 mike 1.13 }
152
153 ////////////////////////////////////////////////////////////////////////////////
154 //
155 // _MakeQualifierFilePath()
156 //
157 ////////////////////////////////////////////////////////////////////////////////
158
159 static inline String _MakeQualifierFilePath(
160 const String& nameSpacePath,
|
161 kumpf 1.23 const CIMName& qualifierName)
|
162 mike 1.13 {
|
163 kumpf 1.16 String returnString(nameSpacePath);
164 returnString.append(_QUALIFIERS_SUFFIX);
165 returnString.append('/');
|
166 kumpf 1.23 returnString.append(qualifierName.getString());
|
167 chuck 1.31
168 #ifdef PEGASUS_REPOSITORY_ESCAPE_UTF8
169 // All chars above 0x7F will be escape.
170 return escapeStringEncoder(returnString);
171 #else
|
172 kumpf 1.16 return returnString;
|
173 chuck 1.31 #endif
|
174 mike 1.13 }
175
176 ////////////////////////////////////////////////////////////////////////////////
177 //
|
178 mike 1.14 // _MakeInstanceDataFileBase()
|
179 mike 1.13 //
180 ////////////////////////////////////////////////////////////////////////////////
181
|
182 mike 1.14 static inline String _MakeInstanceDataFileBase(
|
183 mike 1.13 const String& nameSpacePath,
|
184 kumpf 1.23 const CIMName& className)
|
185 mike 1.13 {
|
186 kumpf 1.16 String returnString(nameSpacePath);
187 returnString.append(_INSTANCES_SUFFIX);
188 returnString.append('/');
|
189 kumpf 1.23 returnString.append(className.getString());
|
190 chuck 1.31
191 #ifdef PEGASUS_REPOSITORY_ESCAPE_UTF8
192 // All chars above 0x7F will be escape.
193 return escapeStringEncoder(returnString);
194 #else
|
195 kumpf 1.16 return returnString;
|
196 chuck 1.31 #endif
|
197 mike 1.13 }
198
|
199 schuur 1.32
200 ////////////////////////////////////////////////////////////////////////////////
201 //
202 // NameSpaceManagerRep
203 //
204 ////////////////////////////////////////////////////////////////////////////////
205
206 typedef HashTable <String, NameSpace *, EqualNoCaseFunc, HashLowerCaseFunc>
207 Table;
208
209 struct NameSpaceManagerRep
210 {
211 Table table;
212 };
213
214
|
215 mike 1.13 ////////////////////////////////////////////////////////////////////////////////
216 //
217 // NameSpace
218 //
219 ////////////////////////////////////////////////////////////////////////////////
220
|
221 schuur 1.34 struct specialNameSpace;
|
222 schuur 1.32
|
223 mike 1.13 class NameSpace
224 {
|
225 schuur 1.32 friend class NameSpaceManager;
|
226 mike 1.13 public:
227
|
228 david.dillard 1.40 NameSpace(const String& nameSpacePath,
|
229 schuur 1.34 const CIMNamespaceName& nameSpaceName, specialNameSpace *pns=NULL, String *extDir=NULL);
|
230 schuur 1.32
231 void modify(Boolean shareable, Boolean updatesAllowed,const String& nameSpacePath);
|
232 mike 1.13
233 ~NameSpace();
234
|
235 schuur 1.32 static NameSpace *newNameSpace(int index, NameSpaceManager *nsm, String &repositoryRoot);
236
237 Boolean readOnly() { return ro; }
238 NameSpace *primaryParent();
239 NameSpace *rwParent();
240
|
241 mike 1.13 const String& getNameSpacePath() const { return _nameSpacePath; }
242
|
243 kumpf 1.23 const CIMNamespaceName& getNameSpaceName() const { return _nameSpaceName; }
|
244 mike 1.13
|
245 kumpf 1.23 const String getClassFilePath(const CIMName& className) const;
|
246 mike 1.13
|
247 kumpf 1.23 const String getQualifierFilePath(const CIMName& qualifierName) const;
|
248 mike 1.13
|
249 kumpf 1.23 const String getInstanceDataFileBase(const CIMName& className) const;
|
250 mike 1.13
251 InheritanceTree& getInheritanceTree() { return _inheritanceTree; }
252
253 /** Print this namespace. */
254 void print(PEGASUS_STD(ostream)& os) const;
255
256 private:
257
258 InheritanceTree _inheritanceTree;
259 String _nameSpacePath;
|
260 kumpf 1.23 CIMNamespaceName _nameSpaceName;
|
261 schuur 1.32
262 NameSpace *parent;
263 NameSpace *dependent;
264 NameSpace *nextDependent;
265 Boolean ro,final;
|
266 schuur 1.34 String sharedDirName;
267 String remoteDirName;
|
268 schuur 1.32 };
269
270 static Array<String> *nameSpaceNames=NULL;
|
271 schuur 1.34 static Array<specialNameSpace*> *specialNames=NULL;
|
272 schuur 1.32
|
273 schuur 1.34 #ifdef PEGASUS_ENABLE_REMOTE_CMPI
274 struct specialNameSpace {
275 specialNameSpace()
276 : shared(false), parentSpace(NULL), parent(String::EMPTY),
277 sharedDirName(String::EMPTY), remote(false) {}
278 void setShared(bool r, bool f, String p, String x) {
279 shared=true;
280 ro=r;
281 final=f;
282 parentSpace=NULL;
283 parent=p;
284 sharedDirName=x;
285 }
286 void setShared(bool r, bool f, NameSpace *pns, String p, String x) {
287 shared=true;
288 ro=r;
289 final=f;
290 parentSpace=pns;
291 parent=p;
292 sharedDirName=x;
293 }
294 schuur 1.34 void setRemote(String id, String host, String port, String x) {
295 remote=true;
296 remId=id;
297 remHost=host;
298 remPort=port;
299 remDirName=x;
300 }
|
301 schuur 1.32
|
302 schuur 1.34 Boolean shared;
|
303 schuur 1.32 Boolean ro;
304 Boolean final;
305 NameSpace *parentSpace;
306 String parent;
|
307 schuur 1.34 String sharedDirName;
308
309 Boolean remote;
310 String remId;
311 String remHost;
312 String remPort;
313 String remDirName;
314 };
315 #else
316 struct specialNameSpace {
317 specialNameSpace(bool r, bool f, String p, String x)
318 : ro(r), final(f), parentSpace(NULL), parent(p), sharedDirName(x) {}
319 specialNameSpace(bool r, bool f, NameSpace *pns, String p, String x)
320 : ro(r), final(f), parentSpace(pns), parent(p), sharedDirName(x) {}
321 Boolean ro;
322 Boolean final;
323 NameSpace *parentSpace;
324 String parent;
325 String sharedDirName;
|
326 mike 1.13 };
|
327 schuur 1.34 #endif
|
328 mike 1.13
|
329 schuur 1.35 #ifdef PEGASUS_ENABLE_REMOTE_CMPI
330
331 NameSpace::NameSpace(const String& nameSpacePath,
|
332 schuur 1.32 const CIMNamespaceName& nameSpaceName,
|
333 schuur 1.34 specialNameSpace *pns, String *extDir)
|
334 schuur 1.32 : _nameSpacePath(nameSpacePath), _nameSpaceName(nameSpaceName),
335 parent(NULL), dependent(NULL), nextDependent(NULL),
336 ro(false), final(false)
337 {
338 PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpace::NameSpace()");
339
340 if (pns==NULL) _inheritanceTree.insertFromPath(nameSpacePath +"/classes");
341
342 else {
|
343 schuur 1.34 if (pns->shared) {
|
344 schuur 1.35 ro=pns->ro;
345 final=pns->final;
346 parent=pns->parentSpace;
347 if (parent==NULL)
348 _inheritanceTree.insertFromPath(nameSpacePath +"/classes");
349
350 else {
351 if (!pns->ro) _inheritanceTree.insertFromPath(nameSpacePath +"/classes",
352 &parent->_inheritanceTree,this);
353
354 NameSpace *ens=parent->primaryParent();
355 nextDependent=ens->dependent;
356 ens->dependent=this;
357 }
358 }
359 else _inheritanceTree.insertFromPath(nameSpacePath +"/classes");
360
361 if (pns->remote) {
|
362 konrad.r 1.36 PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4,
|
363 kumpf 1.41 "Remote namespace: " + nameSpacePath +" >"+pns->remDirName);
|
364 schuur 1.35 remoteDirName=pns->remDirName;
365 }
366 }
367 if (extDir) sharedDirName=*extDir;
368 }
369
370 #else
371
372 NameSpace::NameSpace(const String& nameSpacePath,
373 const CIMNamespaceName& nameSpaceName,
374 specialNameSpace *pns, String *extDir)
375 : _nameSpacePath(nameSpacePath), _nameSpaceName(nameSpaceName),
376 parent(NULL), dependent(NULL), nextDependent(NULL),
377 ro(false), final(false)
378 {
379 PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpace::NameSpace()");
380
381 if (pns==NULL) _inheritanceTree.insertFromPath(nameSpacePath +"/classes");
382
383 else {
|
384 schuur 1.32 ro=pns->ro;
385 final=pns->final;
386 parent=pns->parentSpace;
387 if (parent==NULL)
388 _inheritanceTree.insertFromPath(nameSpacePath +"/classes");
389
390 else {
391 if (!pns->ro) _inheritanceTree.insertFromPath(nameSpacePath +"/classes",
392 &parent->_inheritanceTree,this);
393
394 NameSpace *ens=parent->primaryParent();
395 nextDependent=ens->dependent;
396 ens->dependent=this;
397 }
398 }
|
399 schuur 1.34 if (extDir) sharedDirName=*extDir;
|
400 schuur 1.32 }
401
|
402 schuur 1.35 #endif
403
|
404 schuur 1.32 NameSpace::~NameSpace()
|
405 mike 1.13 {
|
406 schuur 1.32
407 }
408
|
409 schuur 1.35 #ifdef PEGASUS_ENABLE_REMOTE_CMPI
410
|
411 schuur 1.32 NameSpace *NameSpace::newNameSpace(int index, NameSpaceManager *nsm, String &repositoryRoot)
412 {
413 PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpace::newNameSpace()");
414
|
415 schuur 1.35 AutoPtr<NameSpace> nameSpace;
|
416 schuur 1.32
|
417 schuur 1.35 String nameSpaceName = _dirNameToNamespaceName((*nameSpaceNames)[index]);
|
418 a.arora 1.33 nameSpace.reset(nsm->lookupNameSpace(nameSpaceName));
|
419 schuur 1.35 if ((nameSpace.get()) != 0) return nameSpace.release();
|
420 schuur 1.32
|
421 schuur 1.34 specialNameSpace *pns=(*specialNames)[index];
|
422 schuur 1.32
|
423 schuur 1.34 if (pns && pns->shared && pns->parent.size()) {
|
424 schuur 1.35 int j=0,m=0;
425 for (m=nameSpaceNames->size(); j<m; j++)
426 if ((*nameSpaceNames)[j]==pns->parent) break;
|
427 david.dillard 1.40 if (j>=m)
|
428 kumpf 1.41 {
|
429 konrad.r 1.36 PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4,
|
430 kumpf 1.41 "Namespace not found in parent namespace.");
431 }
|
432 schuur 1.35 pns->parentSpace=newNameSpace(j,nsm,repositoryRoot);
433 }
434 else if (pns) pns->parentSpace=NULL;
435
436 String nameSpacePath = repositoryRoot + "/" + (*nameSpaceNames)[index];
437 nameSpace.reset(new NameSpace(nameSpacePath, nameSpaceName,pns));
438
439 nsm->_rep->table.insert(nameSpaceName, nameSpace.get());
440 return nameSpace.release();
441 }
442
443 #else
444
445 NameSpace *NameSpace::newNameSpace(int index, NameSpaceManager *nsm, String &repositoryRoot)
446 {
447 PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpace::newNameSpace()");
448
449 AutoPtr<NameSpace> nameSpace;
450
451 String nameSpaceName = _dirNameToNamespaceName((*nameSpaceNames)[index]);
452 nameSpace.reset(nsm->lookupNameSpace(nameSpaceName));
453 schuur 1.35 if ((nameSpace.get()) != 0) return nameSpace.release();
454
455 specialNameSpace *pns=(*specialNames)[index];
456
457 if (pns && pns->parent.size()) {
|
458 schuur 1.32 int j=0,m=0;
459 for (m=nameSpaceNames->size(); j<m; j++)
460 if ((*nameSpaceNames)[j]==pns->parent) break;
|
461 konrad.r 1.36 if (j>=m)
|
462 kumpf 1.41 {
463 PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4,
464 "Namespace not found in parent namespace.");
465 }
|
466 schuur 1.32 pns->parentSpace=newNameSpace(j,nsm,repositoryRoot);
467 }
|
468 schuur 1.35 else if (pns) pns->parentSpace=NULL;
469
470 String nameSpacePath = repositoryRoot + "/" + (*nameSpaceNames)[index];
471 nameSpace.reset(new NameSpace(nameSpacePath, nameSpaceName,pns));
|
472 schuur 1.32
|
473 a.arora 1.33 nsm->_rep->table.insert(nameSpaceName, nameSpace.get());
474 return nameSpace.release();
|
475 schuur 1.32 }
476
|
477 schuur 1.35 #endif
478
|
479 schuur 1.32 void NameSpace::modify(Boolean shareable, Boolean updatesAllowed, const String& nameSpacePath)
480 {
481 PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpace::modify()");
482
|
483 schuur 1.34 String newDir=sharedDirName;
|
484 schuur 1.32 if (newDir.size()==0) newDir="SWF";
485
486 newDir[0]='S';
487 newDir[1]=updatesAllowed ? 'W' : 'R';
488 newDir[2]=shareable ? 'S' : 'F';
489
490 String tmp=newDir;
491 tmp.toLower();
492
493 if (tmp=="swf") {
|
494 schuur 1.34 String path = nameSpacePath+"/"+sharedDirName;
|
495 schuur 1.32 FileSystem::removeFileNoCase(path);
496 newDir="";
497 }
498
|
499 schuur 1.34 else if (sharedDirName!=newDir) {
|
500 schuur 1.32 String path = nameSpacePath+"/"+newDir;
501 if (!FileSystem::makeDirectory(path))
502 throw CannotCreateDirectory(path);
|
503 schuur 1.34 path = nameSpacePath+"/"+sharedDirName;
504 if (sharedDirName.size())
|
505 schuur 1.32 if (!FileSystem::removeDirectoryHier(path))
506 throw CannotRemoveDirectory(path);
507 }
508
509 ro=!updatesAllowed;
510 final=!shareable;
511
|
512 schuur 1.34 sharedDirName=newDir;
|
513 mike 1.13 }
514
|
515 schuur 1.32 NameSpace *NameSpace::primaryParent()
|
516 mike 1.13 {
|
517 schuur 1.32 if (parent==NULL) return this;
518 return parent->primaryParent();
519 }
|
520 mike 1.13
|
521 schuur 1.32 NameSpace *NameSpace::rwParent()
522 {
523 if (!ro) return this;
524 return parent->rwParent();
|
525 mike 1.13 }
526
|
527 kumpf 1.23 const String NameSpace::getClassFilePath(const CIMName& className) const
|
528 mike 1.13 {
|
529 kumpf 1.23 CIMName superClassName;
|
530 mike 1.13
531 if (!_inheritanceTree.getSuperClass(className, superClassName))
|
532 kumpf 1.41 throw PEGASUS_CIM_EXCEPTION
|
533 kumpf 1.26 (CIM_ERR_NOT_FOUND, className.getString());
|
534 mike 1.13
535 return _MakeClassFilePath(_nameSpacePath, className, superClassName);
536 }
537
|
538 kumpf 1.23 const String NameSpace::getQualifierFilePath(const CIMName& qualifierName) const
|
539 mike 1.13 {
540 return _MakeQualifierFilePath(_nameSpacePath, qualifierName);
541 }
542
|
543 kumpf 1.23 const String NameSpace::getInstanceDataFileBase(const CIMName& className) const
|
544 mike 1.13 {
|
545 mike 1.14 return _MakeInstanceDataFileBase(_nameSpacePath, className);
|
546 mike 1.13 }
547
548 void NameSpace::print(PEGASUS_STD(ostream)& os) const
549 {
550 os << "=== NameSpace: " << _nameSpaceName << PEGASUS_STD(endl);
551 os << "_nameSpacePath: " << _nameSpacePath << PEGASUS_STD(endl);
552 _inheritanceTree.print(os);
553 }
554
555 ////////////////////////////////////////////////////////////////////////////////
556 //
557 // NameSpaceManager
558 //
559 ////////////////////////////////////////////////////////////////////////////////
560
561 static Boolean _IsNameSpaceDir(const String& nameSpacePath)
562 {
563 if (!FileSystem::isDirectory(nameSpacePath))
|
564 kumpf 1.41 return false;
|
565 mike 1.13
566 if (!FileSystem::isDirectory(nameSpacePath + _CLASSES_SUFFIX))
|
567 kumpf 1.41 return false;
|
568 mike 1.13
569 if (!FileSystem::isDirectory(nameSpacePath + _INSTANCES_SUFFIX))
|
570 kumpf 1.41 return false;
|
571 mike 1.13
572 if (!FileSystem::isDirectory(nameSpacePath + _QUALIFIERS_SUFFIX))
|
573 kumpf 1.41 return false;
|
574 mike 1.13
575 return true;
576 }
577
|
578 schuur 1.32 static String _CreateNameSpaceDirectories(const String& nameSpacePath,
579 Boolean shareable, Boolean updatesAllowed, const String &parent)
|
580 mike 1.13 {
581 if (!FileSystem::makeDirectory(nameSpacePath))
|
582 kumpf 1.41 throw CannotCreateDirectory(nameSpacePath);
|
583 mike 1.13
584 String classesPath = nameSpacePath + _CLASSES_SUFFIX;
585 String instancesPath = nameSpacePath + _INSTANCES_SUFFIX;
586 String qualifiersPath = nameSpacePath + _QUALIFIERS_SUFFIX;
587
588 if (!FileSystem::makeDirectory(classesPath))
|
589 kumpf 1.41 throw CannotCreateDirectory(classesPath);
|
590 mike 1.13
591 if (!FileSystem::makeDirectory(instancesPath))
|
592 kumpf 1.41 throw CannotCreateDirectory(instancesPath);
|
593 mike 1.13
594 if (!FileSystem::makeDirectory(qualifiersPath))
|
595 kumpf 1.41 throw CannotCreateDirectory(qualifiersPath);
|
596 schuur 1.32
597 String path="";
598 if (shareable || !updatesAllowed || parent.size()) {
599 path=nameSpacePath+"/S"+(updatesAllowed ? "W" : "R")+(shareable ? "S" : "F")+parent;
600 if (!FileSystem::makeDirectory(path))
|
601 kumpf 1.41 throw CannotCreateDirectory(path);
|
602 schuur 1.32 }
603 return path;
|
604 mike 1.13 }
605
606 static Boolean _NameSpaceDirHierIsEmpty(const String& nameSpacePath)
607 {
608 for (Dir dir(nameSpacePath); dir.more(); dir.next())
609 {
|
610 kumpf 1.41 const char* name = dir.getName();
|
611 mike 1.13
|
612 kumpf 1.41 if (strcmp(name, ".") != 0 &&
613 strcmp(name, "..") != 0 &&
614 System::strcasecmp(name, _CLASSES_DIR) != 0 &&
615 System::strcasecmp(name, _INSTANCES_DIR) != 0 &&
616 System::strcasecmp(name, _QUALIFIERS_DIR) != 0)
617 {
618 return true;
619 }
|
620 mike 1.13 }
621
622 String classesPath = nameSpacePath + _CLASSES_SUFFIX;
623 String instancesPath = nameSpacePath + _INSTANCES_SUFFIX;
624 String qualifiersPath = nameSpacePath + _QUALIFIERS_SUFFIX;
625
626 return
|
627 kumpf 1.41 FileSystem::isDirectoryEmpty(classesPath) &&
628 FileSystem::isDirectoryEmpty(instancesPath) &&
629 FileSystem::isDirectoryEmpty(qualifiersPath);
|
630 mike 1.13 }
631
632 NameSpaceManager::NameSpaceManager(const String& repositoryRoot)
633 : _repositoryRoot(repositoryRoot)
634 {
|
635 schuur 1.32 PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::NameSpaceManager()");
636
637 // Create directory if does not already exist:
|
638 mike 1.13
639 if (!FileSystem::isDirectory(_repositoryRoot))
640 {
|
641 kumpf 1.41 if (!FileSystem::makeDirectory(_repositoryRoot))
642 throw CannotCreateDirectory(_repositoryRoot);
|
643 kumpf 1.18
|
644 kumpf 1.41 // Create a root namespace per ...
645 // Specification for CIM Operations over HTTP
646 // Version 1.0
647 // 2.5 Namespace Manipulation
648 //
649 // There are no intrinsic methods defined specifically for the
650 // purpose of manipulating CIM Namespaces. However, the
651 // modelling of the a CIM Namespace using the class
652 // __Namespace, together with the requirement that that
653 // root Namespace MUST be supported by all CIM Servers,
654 // implies that all Namespace operations can be supported.
655 //
|
656 schuur 1.32
657 _CreateNameSpaceDirectories(_repositoryRoot + "/root",false,true,String::EMPTY);
|
658 mike 1.13 }
659
660 _rep = new NameSpaceManagerRep;
661
|
662 schuur 1.32 nameSpaceNames=new Array<String>;
|
663 schuur 1.34 specialNames=new Array<specialNameSpace*>;
|
664 schuur 1.32 String tmp;
|
665 mike 1.13
|
666 schuur 1.34 #ifdef PEGASUS_ENABLE_REMOTE_CMPI
667 for (Dir dir(repositoryRoot); dir.more(); dir.next()) {
|
668 kumpf 1.41 String dirName = dir.getName();
669 if (dirName == ".." || dirName == ".") continue;
670 String specialName=" ";
|
671 schuur 1.34
672 specialNameSpace *sns=NULL;
673 for (Dir dir(repositoryRoot+"/"+dirName); dir.more(); dir.next()) {
|
674 kumpf 1.41 specialName = dir.getName();
675 tmp=specialName;
676 tmp.toLower();
677 if (specialName == ".." || specialName == ".") continue;
|
678 schuur 1.34
679 switch (tmp[0]) {
680 case 's': {
681 if ((tmp[1]=='w' || tmp[1]=='r') &&
|
682 schuur 1.35 (tmp[2]=='f' || tmp[2]=='s')) {
|
683 kumpf 1.41 if (sns==NULL) sns=new specialNameSpace();
|
684 schuur 1.34 sns->setShared(tmp[1]=='r',
685 tmp[2]=='f',
686 specialName.subString(3),
687 specialName);
688 }
|
689 david.dillard 1.40 else
|
690 kumpf 1.41 {
691 PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4,
692 "Namespace " + dirName +
693 " ignored - using incorrect parent namespace specification: " + specialName);
694 }
695 break;
|
696 schuur 1.34 }
697 case 'r': {
|
698 kumpf 1.41 String id=tmp.subString(1,2);
699 Uint32 pos=specialName.find('@');
700 String host,port;
701 if (pos!=PEG_NOT_FOUND) {
702 host=specialName.subString(3,pos-3);
703 port=specialName.subString(pos+1);
704 }
705 else host=specialName.subString(3);
706 if (sns==NULL) sns=new specialNameSpace();
|
707 schuur 1.34 sns->setRemote(id,host,port,specialName);
|
708 kumpf 1.41 PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4,
709 "Remote namespace: " + dirName +" >"+specialName);
710 break;
711 }
712 }
|
713 schuur 1.34 }
714 if (sns==NULL) {
715 nameSpaceNames->prepend(dirName);
716 specialNames->prepend(NULL);
717 }
|
718 kumpf 1.41 else {
|
719 schuur 1.34 nameSpaceNames->append(dirName);
720 specialNames->append(sns);
|
721 kumpf 1.41 }
|
722 schuur 1.34 }
|
723 schuur 1.35
|
724 schuur 1.34 #else
|
725 schuur 1.35
|
726 schuur 1.32 for (Dir dir(repositoryRoot); dir.more(); dir.next()) {
|
727 kumpf 1.41 String dirName = dir.getName();
728 if (dirName == ".." || dirName == ".") continue;
729 String specialName=" ";
|
730 schuur 1.32
731 for (Dir dir(repositoryRoot+"/"+dirName); dir.more(); dir.next())
732 {
|
733 kumpf 1.41 specialName = dir.getName();
734 tmp=specialName;
735 tmp.toLower();
736 if (specialName == ".." || specialName == ".") continue;
|
737 schuur 1.32 if (tmp[0]=='s') break;
738 }
|
739 schuur 1.34
|
740 schuur 1.32 if (tmp[0]=='s') {
741 if ((tmp[1]=='w' || tmp[1]=='r') &&
742 (tmp[2]=='f' || tmp[2]=='s')) {
743 nameSpaceNames->append(dirName);
|
744 schuur 1.34 specialNames->append(new specialNameSpace(tmp[1]=='r',
|
745 schuur 1.32 tmp[2]=='f',
|
746 schuur 1.34 specialName.subString(3),
747 specialName));
|
748 mike 1.13
|
749 kumpf 1.41 continue;
|
750 schuur 1.32 }
|
751 konrad.r 1.36 PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4,
|
752 kumpf 1.41 "Namespace: " + dirName +
753 " ignored - using incorrect parent namespace specification: " + specialName);
|
754 schuur 1.32 }
755 else {
756 nameSpaceNames->prepend(dirName);
|
757 schuur 1.34 specialNames->prepend(NULL);
|
758 schuur 1.32 }
759 }
|
760 schuur 1.34 #endif
|
761 mike 1.13
|
762 schuur 1.32 for (int i=0,m=nameSpaceNames->size(),j=0; i<m; i++) {
763 String dirName = (*nameSpaceNames)[i];
764 if (dirName.size()==0) continue;
765
766 if (!_IsNameSpaceDir(repositoryRoot+"/"+dirName)) {
767 (*nameSpaceNames)[i]=String::EMPTY;
768 i=-1; //restart
|
769 konrad.r 1.36 PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4,
|
770 kumpf 1.41 "Namespace: " + dirName +
771 " ignored - no sub directories found");
|
772 schuur 1.32 continue;
773 }
774
|
775 schuur 1.34 specialNameSpace *pns=(*specialNames)[i];
|
776 schuur 1.32 if (pns && pns->parent.size()) {
777 if ((*nameSpaceNames)[i].size()) {
778 if ((*nameSpaceNames)[i].size()) {
779 for (j=0; j<m; j++)
780 if ((*nameSpaceNames)[j]==pns->parent) break;
|
781 david.dillard 1.40 if (j>=m)
|
782 kumpf 1.41 {
|
783 konrad.r 1.36 PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4,
|
784 kumpf 1.41 "Namespace: " + (*nameSpaceNames)[i] +
785 " ignored - parent namespace not found: " + pns->parent);
|
786 schuur 1.32 (*nameSpaceNames)[i]=String::EMPTY;
787 i=-1; //restart
788 }
|
789 kumpf 1.41 }
|
790 schuur 1.32 }
791 }
792 }
|
793 david.dillard 1.40
|
794 schuur 1.32 // Create a NameSpace object for each directory under repositoryRoot.
795 // This will throw an exception if the directory does not exist:
|
796 mike 1.13
|
797 schuur 1.32 for (int i=0, m=nameSpaceNames->size(); i<m; i++) {
798 if ((*nameSpaceNames)[i].size()==0) continue;
|
799 mike 1.13
|
800 schuur 1.32 try {
|
801 kumpf 1.41 NameSpace::newNameSpace(i,this,_repositoryRoot);
802 }
803 catch (const Exception&) {
804 throw;
805 }
806 }
|
807 mike 1.13
|
808 schuur 1.32 delete nameSpaceNames;
|
809 schuur 1.34 if (specialNames) {
|
810 vijay.eli 1.42 for (int i=0,m=specialNames->size(); i<m; i++)
|
811 vijay.eli 1.43 delete (*specialNames)[i];
|
812 schuur 1.34 delete specialNames;
|
813 mike 1.13 }
|
814 schuur 1.32 nameSpaceNames=NULL;
|
815 schuur 1.34 specialNames=NULL;
|
816 mike 1.13 }
817
818 NameSpaceManager::~NameSpaceManager()
819 {
820 for (Table::Iterator i = _rep->table.start(); i; i++)
|
821 kumpf 1.41 delete i.value();
|
822 mike 1.13
823 delete _rep;
824 }
825
|
826 kumpf 1.23 Boolean NameSpaceManager::nameSpaceExists(
827 const CIMNamespaceName& nameSpaceName) const
|
828 mike 1.13 {
|
829 kumpf 1.25 return _rep->table.contains(nameSpaceName.getString ());
|
830 mike 1.13 }
831
|
832 schuur 1.32 NameSpace *NameSpaceManager::lookupNameSpace(String &ns)
833 {
834 NameSpace *tns;
835 if (!_rep->table.lookup(ns, tns)) return NULL;
836 return tns;
837 }
838
839 void NameSpaceManager::createNameSpace(const CIMNamespaceName& nameSpaceName,
|
840 kumpf 1.41 const NameSpaceAttributes &attributes)
|
841 mike 1.13 {
|
842 kumpf 1.15 PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::createNameSpace()");
843
|
844 mike 1.13 // Throw exception if namespace already exists:
845
|
846 schuur 1.32 String parent="";
847 Boolean shareable=false;
848 Boolean updatesAllowed=true;
849
|
850 mike 1.13 if (nameSpaceExists(nameSpaceName))
|
851 kumpf 1.15 {
852 PEG_METHOD_EXIT();
|
853 kumpf 1.41 throw PEGASUS_CIM_EXCEPTION
|
854 kumpf 1.23 (CIM_ERR_ALREADY_EXISTS, nameSpaceName.getString());
|
855 kumpf 1.15 }
|
856 mike 1.13
|
857 schuur 1.32 for (NameSpaceAttributes::Iterator i = attributes.start(); i; i++) {
858 String key=i.key();
859 if (String::equalNoCase(key,"shareable")) {
860 if (String::equalNoCase(i.value(),"true")) shareable=true;
861 }
862 else if (String::equalNoCase(key,"updatesAllowed")) {
863 if (String::equalNoCase(i.value(),"false")) updatesAllowed=false;
864 }
865 else if (String::equalNoCase(key,"parent"))
866 parent=i.value();
867 else {
868 PEG_METHOD_EXIT();
869 throw PEGASUS_CIM_EXCEPTION
870 (CIM_ERR_NOT_SUPPORTED, nameSpaceName.getString()+
871 " option not supported: "+key);
872 }
873 }
874
875 NameSpace *parentSpace=0;
876 if (parent.size() && !(parentSpace=lookupNameSpace(parent))) {
877 PEG_METHOD_EXIT();
|
878 kumpf 1.41 throw PEGASUS_CIM_EXCEPTION
|
879 schuur 1.32 (CIM_ERR_NOT_FOUND, " parent namespace "+parent+" not found");
880 }
881
882 if (parentSpace && parentSpace->final) {
883 PEG_METHOD_EXIT();
|
884 kumpf 1.41 throw PEGASUS_CIM_EXCEPTION
|
885 schuur 1.32 (CIM_ERR_FAILED, " parent namespace "+parent+" not shareable");
886 }
887
888 if (updatesAllowed && parentSpace && parentSpace->parent) {
889 PEG_METHOD_EXIT();
|
890 kumpf 1.41 throw PEGASUS_CIM_EXCEPTION
|
891 schuur 1.32 (CIM_ERR_FAILED, " parent namespace "+parent+" not a primary namespace");
892 }
893
|
894 chuck 1.31 #ifndef PEGASUS_SUPPORT_UTF8_FILENAME
895 // Do not allow file names to contain characters outsie of 7-bit ascii.
896 String tmp = nameSpaceName.getString();
897 Uint32 len = tmp.size();
898 for(Uint32 i = 0; i < len; ++i)
|
899 kumpf 1.41 if((Uint16)tmp[i] > 0x007F)
900 throw PEGASUS_CIM_EXCEPTION
901 (CIM_ERR_INVALID_PARAMETER, nameSpaceName.getString());
|
902 chuck 1.31 #endif
903
904
|
905 mike 1.13 // Attempt to create all the namespace diretories:
906
|
907 kumpf 1.27 String nameSpaceDirName = _namespaceNameToDirName(nameSpaceName);
|
908 mike 1.13 String nameSpacePath = _repositoryRoot + "/" + nameSpaceDirName;
|
909 schuur 1.32 String parentPath;
910 if (parent.size()) parentPath = _namespaceNameToDirName(parent);
911
912 String extDir =
913 _CreateNameSpaceDirectories(nameSpacePath,shareable,updatesAllowed,parentPath);
|
914 mike 1.13
|
915 schuur 1.34 #ifdef PEGASUS_ENABLE_REMOTE_CMPI
916 specialNameSpace pns;
917 pns.setShared(!updatesAllowed,!shareable,parentSpace,parent,extDir);
918 #else
919 specialNameSpace pns(!updatesAllowed,!shareable,parentSpace,parent,extDir);
920 #endif
|
921 mike 1.13
922 // Create NameSpace object and register it:
923
|
924 a.arora 1.33 AutoPtr<NameSpace> nameSpace;
|
925 mike 1.13
|
926 a.arora 1.33 nameSpace.reset(new NameSpace(nameSpacePath, nameSpaceName, &pns));
|
927 david.dillard 1.40
|
928 a.arora 1.33 _rep->table.insert(nameSpaceName.getString (), nameSpace.release());
|
929 kumpf 1.15
930 PEG_METHOD_EXIT();
|
931 mike 1.13 }
932
|
933 schuur 1.32 void NameSpaceManager::modifyNameSpace(const CIMNamespaceName& nameSpaceName,
934 const NameSpaceAttributes &attributes)
935 {
936 PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::modifyNameSpace()");
937
|
938 a.arora 1.33 NameSpace* nameSpace;
|
939 schuur 1.32
940 if (!_rep->table.lookup(nameSpaceName.getString (), nameSpace))
941 {
942 PEG_METHOD_EXIT();
|
943 kumpf 1.41 throw PEGASUS_CIM_EXCEPTION
|
944 schuur 1.32 (CIM_ERR_INVALID_NAMESPACE, nameSpaceName.getString());
945 }
946
947 Boolean shareable=false;
948 Boolean updatesAllowed=true;
949
950 for (NameSpaceAttributes::Iterator i = attributes.start(); i; i++) {
951 String key=i.key();
952 if (String::equalNoCase(key,"shareable")) {
953 if (String::equalNoCase(i.value(),"true")) shareable=true;
954 }
955 else if (String::equalNoCase(key,"updatesAllowed")) {
956 if (String::equalNoCase(i.value(),"false")) updatesAllowed=false;
957 }
958 else {
959 PEG_METHOD_EXIT();
|
960 kumpf 1.41 throw PEGASUS_CIM_EXCEPTION
|
961 schuur 1.32 (CIM_ERR_NOT_SUPPORTED, nameSpaceName.getString()+
962 " option not supported: "+key);
963 }
964 }
965
966 if (!shareable && !nameSpace->final)
967 for (Table::Iterator i = _rep->table.start(); i; i++)
968 if (i.value()->parent==nameSpace) {
969 PEG_METHOD_EXIT();
970 throw PEGASUS_CIM_EXCEPTION
971 (CIM_ERR_FAILED, "namespace "+nameSpaceName.getString()+
972 " has dependent namespace "+i.value()->_nameSpaceName.getString());
973 }
974
975 String nameSpaceDirName = _namespaceNameToDirName(nameSpaceName);
976 String nameSpacePath = _repositoryRoot + "/" + nameSpaceDirName;
977
978 nameSpace->modify(shareable,updatesAllowed,nameSpacePath);
979
980 PEG_METHOD_EXIT();
981 }
982 schuur 1.32
983
|
984 kumpf 1.23 void NameSpaceManager::deleteNameSpace(const CIMNamespaceName& nameSpaceName)
|
985 mike 1.13 {
|
986 kumpf 1.15 PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::deleteNameSpace()");
987
|
988 mike 1.13 // If no such namespace:
989
990 NameSpace* nameSpace = 0;
991
|
992 kumpf 1.25 if (!_rep->table.lookup(nameSpaceName.getString (), nameSpace))
|
993 kumpf 1.15 {
994 PEG_METHOD_EXIT();
|
995 kumpf 1.41 throw PEGASUS_CIM_EXCEPTION
|
996 kumpf 1.23 (CIM_ERR_INVALID_NAMESPACE, nameSpaceName.getString());
|
997 kumpf 1.15 }
|
998 mike 1.13
|
999 schuur 1.32 for (Table::Iterator i = _rep->table.start(); i; i++)
1000 if (i.value()->parent==nameSpace) {
1001 PEG_METHOD_EXIT();
1002 throw PEGASUS_CIM_EXCEPTION
1003 (CIM_ERR_FAILED, "namespace "+nameSpaceName.getString()+
1004 " has dependent namespace "+i.value()->_nameSpaceName.getString());
1005 }
1006
|
1007 mike 1.13 // Form namespace path:
1008
|
1009 kumpf 1.27 String nameSpaceDirName = _namespaceNameToDirName
|
1010 kumpf 1.24 (nameSpace->getNameSpaceName());
|
1011 mike 1.13 String nameSpacePath = _repositoryRoot + "/" + nameSpaceDirName;
1012
1013 // Delete the entire namespace directory hierarchy:
1014
1015 if (!_NameSpaceDirHierIsEmpty(nameSpacePath))
|
1016 kumpf 1.15 {
1017 PEG_METHOD_EXIT();
|
1018 kumpf 1.41 throw NonEmptyNameSpace(nameSpaceName.getString());
|
1019 kumpf 1.15 }
|
1020 mike 1.13
1021 if (!FileSystem::removeDirectoryHier(nameSpacePath))
|
1022 kumpf 1.15 {
1023 PEG_METHOD_EXIT();
|
1024 kumpf 1.41 throw CannotRemoveDirectory(nameSpacePath);
|
1025 kumpf 1.15 }
|
1026 mike 1.13
1027 // Remove and delete the namespace object:
1028
|
1029 schuur 1.32 NameSpace **pd=NULL,*p,*d;
1030 for (p=nameSpace->parent; p; p=p->parent) {
1031 for (d=p->dependent,pd=&(p->dependent); d;
1032 pd=&(d->nextDependent),d=d->nextDependent) {
1033 if (d==nameSpace) {
1034 *pd=nameSpace->nextDependent;
1035 break;
1036 }
1037 }
1038 }
1039
|
1040 kumpf 1.25 Boolean success = _rep->table.remove(nameSpaceName.getString ());
|
1041 mike 1.13 PEGASUS_ASSERT(success);
1042 delete nameSpace;
|
1043 kumpf 1.15
1044 PEG_METHOD_EXIT();
|
1045 mike 1.13 }
1046
|
1047 schuur 1.34 Boolean NameSpaceManager::isRemoteNameSpace(const CIMNamespaceName& nameSpaceName,
1048 String & remoteInfo)
1049 {
1050 NameSpace* nameSpace = 0;
1051 if (!_rep->table.lookup(nameSpaceName.getString (), nameSpace)) return false;
1052
1053 if (nameSpace->remoteDirName.size()==0) return false;
1054
1055 remoteInfo=nameSpace->remoteDirName;
1056 return true;
1057 }
1058
|
1059 kumpf 1.23 void NameSpaceManager::getNameSpaceNames(Array<CIMNamespaceName>& nameSpaceNames) const
|
1060 mike 1.13 {
1061 nameSpaceNames.clear();
1062
1063 for (Table::Iterator i = _rep->table.start(); i; i++)
|
1064 kumpf 1.41 nameSpaceNames.append(i.key());
|
1065 mike 1.13 }
1066
|
1067 schuur 1.32 Boolean NameSpaceManager::getNameSpaceAttributes(const CIMNamespaceName& nameSpaceName,
1068 NameSpaceAttributes& attributes)
1069 {
1070 String nsn=nameSpaceName.getString();
1071 NameSpace *ns=lookupNameSpace(nsn);
1072
1073 if (ns) {
1074 if (ns->parent) attributes.insert("parent",ns->parent->_nameSpaceName.getString());
1075 attributes.insert("name",nsn);
1076 if (ns->ro) attributes.insert("updatesAllowed","false");
1077 else attributes.insert("updatesAllowed","true");
1078 if (ns->final) attributes.insert("shareable","false");
1079 else attributes.insert("shareable","true");
1080 return true;
1081 }
1082 return false;
1083 }
1084
|
1085 mike 1.13 String NameSpaceManager::getClassFilePath(
|
1086 kumpf 1.23 const CIMNamespaceName& nameSpaceName,
|
1087 schuur 1.32 const CIMName& className,
1088 NameSpaceIntendedOp op) const
1089 {
1090 NameSpace *nameSpace = 0;
1091
1092 if (!_rep->table.lookup(nameSpaceName.getString (), nameSpace)) {
|
1093 kumpf 1.41 throw PEGASUS_CIM_EXCEPTION
|
1094 schuur 1.32 (CIM_ERR_INVALID_NAMESPACE, nameSpaceName.getString());
1095 }
1096
1097 return getClassFilePath(nameSpace,className,op);
1098 }
1099
1100 String NameSpaceManager::getClassFilePath(
1101 NameSpace* nameSpace,
1102 const CIMName& className,
1103 NameSpaceIntendedOp op) const
|
1104 mike 1.13 {
|
1105 kumpf 1.15 PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::getClassFilePath()");
1106
|
1107 schuur 1.32 if (nameSpace->parent==NULL) {
1108 if (nameSpace->ro) switch (op) {
1109 case NameSpaceRead:
1110 break;
1111 case NameSpaceDelete:
1112 case NameSpaceWrite:
1113 PEG_METHOD_EXIT();
|
1114 kumpf 1.41 throw PEGASUS_CIM_EXCEPTION
|
1115 schuur 1.32 (CIM_ERR_ACCESS_DENIED, "R/O Namespace "+
1116 nameSpace->getNameSpaceName().getString());
1117 }
1118 else switch (op) {
1119 case NameSpaceRead:
1120 break;
1121 case NameSpaceWrite:
1122 classExists(nameSpace,className,true);
1123 break;
1124 case NameSpaceDelete:
1125 classHasInstances(nameSpace,className,true);
1126 }
1127 PEG_METHOD_EXIT();
1128 return nameSpace->getClassFilePath(className);
1129 }
1130
1131 if (nameSpace->ro==false) {
1132 switch (op) {
1133 case NameSpaceRead:
1134 if (classExists(nameSpace,className,false)) break;
1135 PEG_METHOD_EXIT();
1136 schuur 1.32 return nameSpace->parent->getClassFilePath(className);
1137 case NameSpaceWrite:
1138 classExists(nameSpace->parent,className,true);
1139 break;
1140 case NameSpaceDelete:
1141 classHasInstances(nameSpace,className,true);
1142 }
1143 PEG_METHOD_EXIT();
1144 return nameSpace->getClassFilePath(className);
1145 }
1146
1147 switch (op) {
1148 case NameSpaceRead:
1149 if (classExists(nameSpace,className,false)) break;
1150 return nameSpace->parent->getClassFilePath(className);
1151 case NameSpaceDelete:
1152 classExists(nameSpace->parent,className,true);
1153 case NameSpaceWrite:
|
1154 kumpf 1.15 PEG_METHOD_EXIT();
|
1155 kumpf 1.41 throw PEGASUS_CIM_EXCEPTION
|
1156 schuur 1.32 (CIM_ERR_ACCESS_DENIED, "R/O Namespace "+
1157 nameSpace->getNameSpaceName().getString());
|
1158 kumpf 1.15 }
1159 PEG_METHOD_EXIT();
|
1160 mike 1.13 return nameSpace->getClassFilePath(className);
1161 }
1162
|
1163 mike 1.14 String NameSpaceManager::getInstanceDataFileBase(
|
1164 kumpf 1.23 const CIMNamespaceName& nameSpaceName,
1165 const CIMName& className) const
|
1166 mike 1.13 {
|
1167 kumpf 1.15 PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::getInstanceDataFileBase()");
1168
|
1169 mike 1.13 NameSpace* nameSpace = 0;
1170
|
1171 kumpf 1.25 if (!_rep->table.lookup(nameSpaceName.getString (), nameSpace))
|
1172 kumpf 1.15 {
1173 PEG_METHOD_EXIT();
|
1174 kumpf 1.41 throw PEGASUS_CIM_EXCEPTION
|
1175 kumpf 1.23 (CIM_ERR_INVALID_NAMESPACE, nameSpaceName.getString());
|
1176 kumpf 1.15 }
|
1177 mike 1.13
|
1178 kumpf 1.15 PEG_METHOD_EXIT();
|
1179 mike 1.14 return nameSpace->getInstanceDataFileBase(className);
|
1180 mike 1.13 }
1181
|
1182 schuur 1.32 String NameSpaceManager::getInstanceDataFileBase(
1183 const NameSpace *nameSpace,
1184 const CIMName& className) const
1185 {
1186 PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::getInstanceDataFileBase()");
1187
1188 PEG_METHOD_EXIT();
1189 return nameSpace->getInstanceDataFileBase(className);
1190 }
1191
|
1192 mike 1.13 String NameSpaceManager::getQualifierFilePath(
|
1193 kumpf 1.23 const CIMNamespaceName& nameSpaceName,
|
1194 schuur 1.32 const CIMName& qualifierName,
1195 NameSpaceIntendedOp op) const
|
1196 mike 1.13 {
|
1197 kumpf 1.15 PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::getQualifierFilePath()");
1198
|
1199 schuur 1.32 NameSpace *nameSpace = 0;
|
1200 mike 1.13
|
1201 schuur 1.32 if (!_rep->table.lookup(nameSpaceName.getString (), nameSpace)) {
|
1202 kumpf 1.41 throw PEGASUS_CIM_EXCEPTION
|
1203 kumpf 1.23 (CIM_ERR_INVALID_NAMESPACE, nameSpaceName.getString());
|
1204 kumpf 1.15 }
|
1205 mike 1.13
|
1206 schuur 1.32 String filePath=nameSpace->getQualifierFilePath(qualifierName);
|
1207 chuck 1.31
|
1208 schuur 1.32 if (nameSpace->parent==NULL) {
1209 if (nameSpace->ro) switch (op) {
1210 case NameSpaceRead:
1211 break;
1212 case NameSpaceDelete:
1213 case NameSpaceWrite:
1214 PEG_METHOD_EXIT();
|
1215 kumpf 1.41 throw PEGASUS_CIM_EXCEPTION
|
1216 schuur 1.32 (CIM_ERR_ACCESS_DENIED, "R/O Namespace "+
1217 nameSpace->getNameSpaceName().getString());
1218 }
1219 PEG_METHOD_EXIT();
1220 return filePath;
1221 }
1222
1223 if (nameSpace->ro==false) {
1224 switch (op) {
1225 case NameSpaceRead:
1226 if (FileSystem::existsNoCase(filePath)) break;
1227 PEG_METHOD_EXIT();
1228 return nameSpace->parent->getQualifierFilePath(qualifierName);
1229 case NameSpaceWrite:
1230 case NameSpaceDelete:
1231 break;
1232 }
1233 PEG_METHOD_EXIT();
1234 return filePath;
1235 }
1236
1237 schuur 1.32 switch (op) {
1238 case NameSpaceRead:
1239 if (FileSystem::existsNoCase(filePath)) break;
|
1240 kumpf 1.15 PEG_METHOD_EXIT();
|
1241 schuur 1.32 return nameSpace->parent->getQualifierFilePath(qualifierName);
1242 case NameSpaceDelete:
1243 case NameSpaceWrite:
1244 PEG_METHOD_EXIT();
|
1245 kumpf 1.41 throw PEGASUS_CIM_EXCEPTION
|
1246 schuur 1.32 (CIM_ERR_ACCESS_DENIED, "R/O Namespace "+
1247 nameSpace->getNameSpaceName().getString());
1248 }
1249 PEG_METHOD_EXIT();
1250 return filePath;
1251
|
1252 mike 1.13 }
1253
1254 void NameSpaceManager::deleteClass(
|
1255 kumpf 1.23 const CIMNamespaceName& nameSpaceName,
1256 const CIMName& className) const
|
1257 mike 1.13 {
|
1258 kumpf 1.15 PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::deleteClass()");
1259
|
1260 mike 1.13 // -- Lookup NameSpace object:
1261
|
1262 schuur 1.32 NameSpace *nameSpace=0,*ns=0;
|
1263 mike 1.13
|
1264 kumpf 1.25 if (!_rep->table.lookup(nameSpaceName.getString (), nameSpace))
|
1265 kumpf 1.15 {
1266 PEG_METHOD_EXIT();
|
1267 kumpf 1.41 throw PEGASUS_CIM_EXCEPTION
|
1268 kumpf 1.23 (CIM_ERR_INVALID_NAMESPACE, nameSpaceName.getString());
|
1269 kumpf 1.15 }
|
1270 mike 1.13 // -- Get path to class file:
1271
|
1272 schuur 1.32 String classFilePath = getClassFilePath(nameSpace,className,NameSpaceDelete);
|
1273 mike 1.13
1274 // -- Remove the file from the inheritance tree:
1275
|
1276 schuur 1.32 if (nameSpace->parent!=NULL)
1277 nameSpace->getInheritanceTree().remove(className,
1278 nameSpace->parent->getInheritanceTree(),nameSpace);
1279 else nameSpace->getInheritanceTree().remove(className,
1280 nameSpace->getInheritanceTree(),NULL);
|
1281 mike 1.13
1282 // -- Remove the file from disk:
1283
1284 if (!FileSystem::removeFileNoCase(classFilePath))
|
1285 kumpf 1.15 {
1286 PEG_METHOD_EXIT();
|
1287 kumpf 1.41 throw CannotRemoveFile(classFilePath);
|
1288 kumpf 1.15 }
1289
|
1290 schuur 1.32 Boolean first=true;
1291 do {
1292 String indexFilePath = getInstanceDataFileBase(nameSpace, className)+".idx";
1293 PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4,
1294 "instance indexFilePath = " + indexFilePath);
1295
1296 String dataFilePath = getInstanceDataFileBase(nameSpace, className)+".instances";
1297 PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4,
1298 "instance dataFilePath = " + dataFilePath);
1299
1300 FileSystem::removeFileNoCase(indexFilePath);
1301 FileSystem::removeFileNoCase(dataFilePath);
1302
1303 if (first) {
1304 nameSpace=nameSpace->dependent;
1305 first=false;
1306 }
1307 else nameSpace=nameSpace->nextDependent;
1308 } while (nameSpace);
1309
|
1310 kumpf 1.15 PEG_METHOD_EXIT();
|
1311 mike 1.13 }
1312
1313 void NameSpaceManager::print(PEGASUS_STD(ostream)& os) const
1314 {
1315 for (Table::Iterator i = _rep->table.start(); i; i++)
1316 {
|
1317 kumpf 1.41 NameSpace* nameSpace = i.value();
1318 nameSpace->print(os);
|
1319 mike 1.13 }
1320
1321 os << PEGASUS_STD(endl);
1322 }
1323
1324 void NameSpaceManager::createClass(
|
1325 kumpf 1.23 const CIMNamespaceName& nameSpaceName,
1326 const CIMName& className,
1327 const CIMName& superClassName,
|
1328 mike 1.13 String& classFilePath)
1329 {
|
1330 kumpf 1.15 PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::createClass()");
1331
|
1332 mike 1.13 // -- Lookup namespace:
1333
|
1334 schuur 1.32 NameSpace *nameSpace=0,*ens=0;
|
1335 mike 1.13
|
1336 kumpf 1.25 if (!_rep->table.lookup(nameSpaceName.getString (), nameSpace))
|
1337 kumpf 1.15 {
1338 PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4, "Invalid NameSpace.");
1339 PEG_METHOD_EXIT();
|
1340 kumpf 1.41 throw PEGASUS_CIM_EXCEPTION
|
1341 kumpf 1.23 (CIM_ERR_INVALID_NAMESPACE, nameSpaceName.getString());
|
1342 kumpf 1.15 }
|
1343 mike 1.13
|
1344 schuur 1.32 if (nameSpace->readOnly()) {
1345 PEG_METHOD_EXIT();
|
1346 kumpf 1.41 throw PEGASUS_CIM_EXCEPTION
|
1347 schuur 1.32 (CIM_ERR_ACCESS_DENIED, "R/O Namespace "+nameSpaceName.getString());
1348 }
1349
|
1350 mike 1.13 InheritanceTree& it = nameSpace->getInheritanceTree();
1351
1352 // -- Be certain class doesn't already exist:
1353
|
1354 schuur 1.32 if (it.containsClass(className)) {
|
1355 kumpf 1.15 PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4, "Class already exists.");
1356 PEG_METHOD_EXIT();
|
1357 kumpf 1.41 throw PEGASUS_CIM_EXCEPTION
|
1358 kumpf 1.23 (CIM_ERR_ALREADY_EXISTS, className.getString());
|
1359 kumpf 1.15 }
|
1360 mike 1.13
|
1361 schuur 1.32 if (nameSpace->parent) {
1362 InheritanceTree& it = nameSpace->parent->getInheritanceTree();
1363 if (it.containsClass(className)) {
1364 PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4, "Class already exists.");
1365 PEG_METHOD_EXIT();
1366 throw PEGASUS_CIM_EXCEPTION
1367 (CIM_ERR_ALREADY_EXISTS, className.getString());
1368 }
1369 }
1370
1371 else {
1372 NameSpace *ns=nameSpace->dependent;
1373 while (ns) {
1374 if (!ns->readOnly()) {
1375 InheritanceTree& it = ns->getInheritanceTree();
1376 if (it.containsClass(className)) {
1377 PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4, "Class already exists.");
1378 PEG_METHOD_EXIT();
1379 throw PEGASUS_CIM_EXCEPTION
1380 (CIM_ERR_ALREADY_EXISTS, className.getString());
1381 }
1382 schuur 1.32 }
1383 ns=ns->nextDependent;
1384 }
1385 }
1386
|
1387 mike 1.13 // -- Be certain superclass exists:
1388
|
1389 schuur 1.32 Boolean xNameSpace=false;
1390 Boolean missing=false;
1391
1392 if (superClassName.isNull()) {
1393 if (nameSpace->parent) xNameSpace=true;
1394 }
1395 else if (!it.containsClass(superClassName)) {
1396 if (nameSpace->parent) {
1397 InheritanceTree& it = nameSpace->parent->getInheritanceTree();
1398 if (!it.containsClass(superClassName)) missing=true;
|
1399 kumpf 1.41 xNameSpace=true;
|
1400 schuur 1.32 }
1401 else missing=false;
1402 }
1403
1404 if (missing) {
|
1405 david.dillard 1.40 PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4,
|
1406 kumpf 1.21 "SuperClass does not exist.");
|
1407 kumpf 1.15 PEG_METHOD_EXIT();
|
1408 kumpf 1.41 throw PEGASUS_CIM_EXCEPTION
|
1409 kumpf 1.23 (CIM_ERR_INVALID_SUPERCLASS, superClassName.getString());
|
1410 kumpf 1.15 }
|
1411 chuck 1.31
1412 #ifndef PEGASUS_SUPPORT_UTF8_FILENAME
1413 // Do not allow file names to contain characters outsie of 7-bit ascii.
1414 String tmp = className.getString();
1415 Uint32 len = tmp.size();
1416 for(Uint32 i = 0; i < len; ++i)
|
1417 kumpf 1.41 if((Uint16)tmp[i] > 0x007F)
1418 throw PEGASUS_CIM_EXCEPTION
1419 (CIM_ERR_INVALID_PARAMETER, nameSpaceName.getString());
|
1420 chuck 1.31 #endif
1421
|
1422 mike 1.13
1423 // -- Insert the entry:
1424
|
1425 schuur 1.32 if (xNameSpace) it.insert(className.getString(), superClassName.getString(),
1426 nameSpace->parent->getInheritanceTree(),nameSpace);
1427 else it.insert(className.getString(), superClassName.getString());
|
1428 mike 1.13
1429 // -- Build the path to the class:
1430
1431 classFilePath = _MakeClassFilePath(
|
1432 kumpf 1.41 nameSpace->getNameSpacePath(), className, superClassName);
|
1433 kumpf 1.15
1434 PEG_METHOD_EXIT();
|
1435 mike 1.13 }
1436
1437 void NameSpaceManager::checkModify(
|
1438 kumpf 1.23 const CIMNamespaceName& nameSpaceName,
1439 const CIMName& className,
1440 const CIMName& superClassName,
|
1441 mike 1.13 String& classFilePath)
1442 {
|
1443 kumpf 1.15 PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::checkModify()");
1444
|
1445 mike 1.13 // -- Lookup namespace:
1446
1447 NameSpace* nameSpace = 0;
1448
|
1449 kumpf 1.25 if (!_rep->table.lookup(nameSpaceName.getString (), nameSpace))
|
1450 kumpf 1.15 {
1451 PEG_METHOD_EXIT();
|
1452 kumpf 1.41 throw PEGASUS_CIM_EXCEPTION
|
1453 kumpf 1.23 (CIM_ERR_INVALID_NAMESPACE, nameSpaceName.getString());
|
1454 kumpf 1.15 }
|
1455 mike 1.13
1456 InheritanceTree& it = nameSpace->getInheritanceTree();
1457
1458 // -- Disallow changing of superclass:
1459
|
1460 kumpf 1.23 CIMName oldSuperClassName;
|
1461 mike 1.13
1462 if (!it.getSuperClass(className, oldSuperClassName))
|
1463 kumpf 1.15 {
1464 PEG_METHOD_EXIT();
|
1465 kumpf 1.41 throw PEGASUS_CIM_EXCEPTION
|
1466 kumpf 1.26 (CIM_ERR_NOT_FOUND, className.getString());
|
1467 kumpf 1.15 }
|
1468 mike 1.13
|
1469 kumpf 1.23 if (!superClassName.equal (oldSuperClassName))
|
1470 mike 1.14 {
|
1471 kumpf 1.15 PEG_METHOD_EXIT();
|
1472 david.dillard 1.40
|
1473 kumpf 1.41 // l10n
1474 // throw PEGASUS_CIM_EXCEPTION(
1475 // CIM_ERR_FAILED, "attempt to change superclass");
1476
1477 throw PEGASUS_CIM_EXCEPTION_L(
1478 CIM_ERR_FAILED,
1479 MessageLoaderParms("Repository.NameSpaceManager.ATTEMPT_TO_CHANGE_SUPERCLASS",
1480 "attempt to change superclass"));
|
1481 humberto 1.28
|
1482 mike 1.14 }
|
1483 mike 1.13
1484 // -- Disallow modification of class with subclasses:
1485
1486 Boolean hasSubClasses;
1487 it.hasSubClasses(className, hasSubClasses);
1488
1489 if (hasSubClasses)
|
1490 kumpf 1.15 {
1491 PEG_METHOD_EXIT();
|
1492 kumpf 1.41 throw PEGASUS_CIM_EXCEPTION
|
1493 kumpf 1.23 (CIM_ERR_CLASS_HAS_CHILDREN, className.getString());
|
1494 kumpf 1.15 }
|
1495 mike 1.13
1496 // -- Build the path to the class:
1497
1498 classFilePath = _MakeClassFilePath(
|
1499 kumpf 1.41 nameSpace->getNameSpacePath(), className, superClassName);
|
1500 kumpf 1.15
1501 PEG_METHOD_EXIT();
|
1502 mike 1.13 }
1503
1504 void NameSpaceManager::getSubClassNames(
|
1505 kumpf 1.23 const CIMNamespaceName& nameSpaceName,
1506 const CIMName& className,
|
1507 mike 1.13 Boolean deepInheritance,
|
1508 schuur 1.32 Array<CIMName>& subClassNames,
|
1509 david.dillard 1.44 Boolean enm) const
|
1510 mike 1.13 {
|
1511 kumpf 1.15 PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::getSubClassNames()");
1512
|
1513 mike 1.13 // -- Lookup namespace:
1514
|
1515 schuur 1.32 NameSpace *nameSpace=0,*dns=0;
|
1516 mike 1.13
|
1517 kumpf 1.25 if (!_rep->table.lookup(nameSpaceName.getString (), nameSpace))
|
1518 kumpf 1.15 {
1519 PEG_METHOD_EXIT();
|
1520 kumpf 1.41 throw PEGASUS_CIM_EXCEPTION
|
1521 kumpf 1.23 (CIM_ERR_INVALID_NAMESPACE, nameSpaceName.getString());
|
1522 kumpf 1.15 }
|
1523 mike 1.13
|
1524 schuur 1.32 if (className.getString()=="" && nameSpace->parent) enm=true;
1525
1526 if (enm && nameSpace->parent) {
1527 dns=nameSpace->rwParent();
1528 nameSpace=nameSpace->primaryParent();
1529 }
|
1530 mike 1.13 InheritanceTree& it = nameSpace->getInheritanceTree();
1531
|
1532 schuur 1.32 if (!it.getSubClassNames(className, deepInheritance, subClassNames, dns)) {
1533 if (nameSpace->parent) {
|
1534 kumpf 1.41 if (enm==false) {
|
1535 schuur 1.32 dns=nameSpace->rwParent();
1536 nameSpace=nameSpace->primaryParent();
1537 InheritanceTree& it = nameSpace->getInheritanceTree();
1538 if (it.getSubClassNames(className, deepInheritance, subClassNames, 0)) return;
|
1539 kumpf 1.41 }
|
1540 schuur 1.32 }
|
1541 kumpf 1.41 else if (dns && enm) {
|
1542 schuur 1.32 InheritanceTree& it = dns->rwParent()->getInheritanceTree();
1543 if (it.getSubClassNames(className, deepInheritance, subClassNames, 0)) return;
|
1544 kumpf 1.41 }
|
1545 kumpf 1.15 PEG_METHOD_EXIT();
|
1546 kumpf 1.41 throw PEGASUS_CIM_EXCEPTION
|
1547 kumpf 1.23 (CIM_ERR_INVALID_CLASS, className.getString());
|
1548 kumpf 1.15 }
1549
1550 PEG_METHOD_EXIT();
|
1551 mike 1.13 }
1552
1553 void NameSpaceManager::getSuperClassNames(
|
1554 kumpf 1.23 const CIMNamespaceName& nameSpaceName,
1555 const CIMName& className,
1556 Array<CIMName>& subClassNames) const
|
1557 mike 1.13 {
|
1558 kumpf 1.15 PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::getSuperClassNames()");
1559
|
1560 mike 1.13 // -- Lookup namespace:
1561
1562 NameSpace* nameSpace = 0;
1563
|
1564 kumpf 1.25 if (!_rep->table.lookup(nameSpaceName.getString (), nameSpace))
|
1565 kumpf 1.15 {
1566 PEG_METHOD_EXIT();
|
1567 kumpf 1.41 throw PEGASUS_CIM_EXCEPTION
|
1568 kumpf 1.23 (CIM_ERR_INVALID_NAMESPACE, nameSpaceName.getString());
|
1569 kumpf 1.15 }
|
1570 schuur 1.35 nameSpace=nameSpace->rwParent();
|
1571 mike 1.13
1572 InheritanceTree& it = nameSpace->getInheritanceTree();
1573
1574 // -- Get names of all superclasses:
1575 if (!it.getSuperClassNames(className, subClassNames))
|
1576 kumpf 1.15 {
1577 PEG_METHOD_EXIT();
|
1578 kumpf 1.41 throw PEGASUS_CIM_EXCEPTION
|
1579 kumpf 1.23 (CIM_ERR_INVALID_CLASS, className.getString());
|
1580 kumpf 1.15 }
1581
1582 PEG_METHOD_EXIT();
|
1583 mike 1.13 }
1584
|
1585 kumpf 1.23 String NameSpaceManager::getQualifiersRoot(const CIMNamespaceName& nameSpaceName) const
|
1586 mike 1.13 {
|
1587 kumpf 1.15 PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::getQualifiersRoot()");
1588
|
1589 mike 1.13 // -- Lookup namespace:
1590
1591 NameSpace* nameSpace = 0;
1592
|
1593 kumpf 1.25 if (!_rep->table.lookup(nameSpaceName.getString (), nameSpace))
|
1594 kumpf 1.15 {
1595 PEG_METHOD_EXIT();
|
1596 kumpf 1.41 throw PEGASUS_CIM_EXCEPTION
|
1597 kumpf 1.23 (CIM_ERR_INVALID_NAMESPACE, nameSpaceName.getString());
|
1598 kumpf 1.15 }
|
1599 mike 1.13
|
1600 kumpf 1.15 PEG_METHOD_EXIT();
|
1601 kumpf 1.16 return nameSpace->getNameSpacePath() + _QUALIFIERS_SUFFIX;
|
1602 kumpf 1.27 }
1603
|
1604 schuur 1.32 Array<String> NameSpaceManager::getAssocClassPath(
1605 const CIMNamespaceName& nameSpaceName,
1606 NameSpaceIntendedOp op) const
|
1607 kumpf 1.27 {
1608 PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::getAssocClassPath()");
1609
1610 // -- Lookup namespace:
1611
1612 NameSpace* nameSpace = 0;
1613
|
1614 schuur 1.32 Array<String> assocClassPathes;
1615
|
1616 kumpf 1.27 if (!_rep->table.lookup(nameSpaceName.getString (), nameSpace))
1617 {
1618 PEG_METHOD_EXIT();
1619 throw PEGASUS_CIM_EXCEPTION
1620 (CIM_ERR_INVALID_NAMESPACE, nameSpaceName.getString());
1621 }
1622
|
1623 schuur 1.32 if (nameSpace->ro) nameSpace = nameSpace->rwParent();
1624
1625 assocClassPathes.append(nameSpace->getNameSpacePath() +
1626 _CLASSES_SUFFIX + _ASSOCIATIONS_SUFFIX);
1627
1628 if (op==NameSpaceRead) {
1629 if (nameSpace->parent) {
1630 nameSpace = nameSpace->primaryParent();
1631 assocClassPathes.append(nameSpace->getNameSpacePath() +
1632 _CLASSES_SUFFIX + _ASSOCIATIONS_SUFFIX);
1633 }
1634 }
1635
|
1636 kumpf 1.27 PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4,
|
1637 schuur 1.32 String("Association class path = ") + assocClassPathes[0]);
|
1638 kumpf 1.27
1639 PEG_METHOD_EXIT();
|
1640 schuur 1.32 return assocClassPathes;
|
1641 kumpf 1.27 }
1642
1643 String NameSpaceManager::getAssocInstPath(
1644 const CIMNamespaceName& nameSpaceName) const
1645 {
1646 PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::getAssocInstPath()");
1647
1648 // -- Lookup namespace:
1649
1650 NameSpace* nameSpace = 0;
1651
1652 if (!_rep->table.lookup(nameSpaceName.getString (), nameSpace))
1653 {
1654 PEG_METHOD_EXIT();
1655 throw PEGASUS_CIM_EXCEPTION
1656 (CIM_ERR_INVALID_NAMESPACE, nameSpaceName.getString());
1657 }
1658
1659 String assocInstPath = nameSpace->getNameSpacePath() +
1660 _INSTANCES_SUFFIX + _ASSOCIATIONS_SUFFIX;
1661 PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4,
1662 kumpf 1.27 String("Association instance path = ") + assocInstPath);
1663
1664 PEG_METHOD_EXIT();
1665 return assocInstPath;
|
1666 mike 1.13 }
1667
|
1668 schuur 1.32 Boolean NameSpaceManager::classHasInstances(
|
1669 kumpf 1.41 NameSpace *nameSpace,
1670 const CIMName& className,
1671 Boolean throwExcp) const
|
1672 schuur 1.32 {
1673 PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::classHasChildren()");
1674
1675 Boolean first=true;
1676
1677 do {
1678 String indexFilePath = getInstanceDataFileBase(nameSpace, className)+".idx";
1679
1680 if (InstanceIndexFile::hasNonFreeEntries(indexFilePath)) {
1681 PEG_METHOD_EXIT();
|
1682 kumpf 1.41 if (throwExcp) throw PEGASUS_CIM_EXCEPTION(CIM_ERR_CLASS_HAS_INSTANCES,
|
1683 schuur 1.32 className.getString());
|
1684 kumpf 1.41 return true;
|
1685 schuur 1.32 }
1686
1687 if (first) {
1688 nameSpace=nameSpace->dependent;
1689 first=false;
1690 }
1691 else nameSpace=nameSpace->nextDependent;
1692
1693 } while (nameSpace);
1694
1695 PEG_METHOD_EXIT();
1696 return false;
1697 }
1698
1699 Boolean NameSpaceManager::classHasInstances(
|
1700 kumpf 1.41 const CIMNamespaceName& nameSpaceName,
1701 const CIMName& className,
1702 Boolean throwExcp) const
|
1703 schuur 1.32 {
1704 PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::classHasChildren()");
1705
1706 NameSpace* nameSpace = 0;
1707
1708 if (!_rep->table.lookup(nameSpaceName.getString (), nameSpace)) {
1709 PEG_METHOD_EXIT();
1710 throw PEGASUS_CIM_EXCEPTION
1711 (CIM_ERR_INVALID_NAMESPACE, nameSpaceName.getString());
1712 }
1713
1714 PEG_METHOD_EXIT();
1715 return classHasInstances(nameSpace,className,throwExcp);
1716 }
1717
1718 Boolean NameSpaceManager::classExists(
|
1719 kumpf 1.41 NameSpace *nameSpace,
1720 const CIMName& className,
1721 Boolean throwExcp) const
|
1722 schuur 1.32 {
1723 PEG_METHOD_ENTER(TRC_REPOSITORY, "NameSpaceManager::classHasChildren()");
1724
1725 Boolean first=true;
1726
1727 do {
1728
1729 InheritanceTree& it = nameSpace->getInheritanceTree();
1730
1731 if (it.containsClass(className)) {
1732 PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4, "Class already exists.");
1733 PEG_METHOD_EXIT();
|
1734 kumpf 1.41 if (throwExcp) throw PEGASUS_CIM_EXCEPTION
|
1735 schuur 1.32 (CIM_ERR_ALREADY_EXISTS, className.getString());
|
1736 kumpf 1.41 return true;
|
1737 schuur 1.32 }
1738
1739 if (first) {
1740 nameSpace=nameSpace->dependent;
1741 first=false;
1742 }
1743 else nameSpace=nameSpace->nextDependent;
1744
1745 } while (nameSpace);
1746
1747 PEG_METHOD_EXIT();
1748 return false;
1749 }
1750
|
1751 mike 1.13 PEGASUS_NAMESPACE_END
|