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