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