1 mike 1.15 //%/////////////////////////////////////////////////////////////////////////////
2 //
|
3 kumpf 1.17 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
4 // The Open Group, Tivoli Systems
|
5 mike 1.15 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 kumpf 1.17 // of this software and associated documentation files (the "Software"), to
8 // deal in the Software without restriction, including without limitation the
9 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
10 mike 1.15 // sell copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
|
13 kumpf 1.17 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
14 mike 1.15 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
15 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
16 kumpf 1.17 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
19 mike 1.15 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 //
22 //==============================================================================
23 //
24 // Author: Mike Brasher (mbrasher@bmc.com)
25 //
|
26 kumpf 1.22 // Modified By: Carol Ann Krug Graves, Hewlett-Packard Company
27 // (carolann_graves@hp.com)
|
28 mike 1.15 //
29 //%/////////////////////////////////////////////////////////////////////////////
30
31 #ifndef Pegasus_InheritanceTree_h
32 #define Pegasus_InheritanceTree_h
33
34 #include <iostream>
35 #include <Pegasus/Common/Config.h>
|
36 kumpf 1.21 #include <Pegasus/Common/ArrayInternal.h>
|
37 kumpf 1.22 #include <Pegasus/Common/CIMName.h>
|
38 mike 1.15 #include <Pegasus/Common/String.h>
|
39 kumpf 1.20 #include <Pegasus/Common/InternalException.h>
|
40 kumpf 1.19 #include <Pegasus/Repository/Linkage.h>
|
41 humberto 1.23 #include <Pegasus/Common/MessageLoader.h> //l10n
|
42 mike 1.15
43 PEGASUS_NAMESPACE_BEGIN
44
45 struct InheritanceTreeRep;
46
47 /** The InheritanceTree class tracks inheritance relationships of CIM classes.
48
49 This class is a memory resident version of the repository's persistent
50 inheritance information (represented using file names). The InheritanceTree
51 provides O(1) access (via hashing) to any class in the inheritance tree.
52
53 The inheritance tree provides methods for interrogating certain kinds of
54 information about a class, including:
55
56 <ul>
57 <li>the superclass</li>
58 <li>the subclasses</li>
59 <li>the descendent classes</li>
60 </ul>
61
62 The insert() method is used to build up an InheritanceTree. The insert()
63 mike 1.15 method is called for each class-subclass relationship. For example, consider
64 the following list of class-subclass pairs:
65
66 <pre>
67 { "D", "B" }
68 { "E", "B" }
69 { "B", "A" }
70 { "C", "A" }
71 { "F", "C" }
72 </pre>
73
74 These pairs specify the following inheritance tree:
75
76 <pre>
77 A
78 / \
79 B C
80 / \ \
81 D E F
82 </pre>
83
84 mike 1.15 The pairs above may be used to build a class tree as follows:
85
86 <pre>
87 InheritanceTree it;
88 it.insert("D", "B");
89 it.insert("E", "B");
90 it.insert("B", "A");
91 it.insert("C", "A");
92 it.insert("F", "C");
93 it.insert("A", "");
94 it.check();
95 </pre>
96
97 The check() method determines whether insert() was called for every class
98 used as a superclass. In the following example, check() would fail (and
99 throw and exception) since the "B" class is passed as a superclass (second
100 argument) in two insert() calls but was never passed as the class itself
101 (first argument) in any insert() call:
102
103 <pre>
104 InheritanceTree it;
105 mike 1.15 it.insert("D", "B");
106 it.insert("E", "B");
107 it.insert("C", "A");
108 it.insert("F", "C");
109 it.insert("A", "");
110 it.check();
111 </pre>
112
113 In this case, check() throws an InvalidInheritanceTree exception.
114
115 The InheritanceTree may be printed by calling the print() method.
116
117 The insertFromPath() method is used to build up an InheritanceTree from
118 the file names in a certain directory as used by the CIMRepository. The
119 CIMRepository contains a disk file per class and the name has this form:
120
121 <pre>
122 <ClassName>.<SuperClassName>
123 </pre>
124
125 For example, a class called "ThisClass" with super class "ThatClass"
126 mike 1.15 has this name:
127
128 <pre>
129 ThisClass.ThisClass
130 </pre>
131
132 The file or course contains the XML encoding of the ThisClass class (which
133 is irrelevant for the InheritanceTree). A root class (with no superclass
134 has the following form):
135
136 <pre>
137 <ClassName>.#
138 </pre>
139
140 Suppose that ThatClass is a root class; then its file name is:
141
142 <pre>
143 ThatClass.#
144 </pre>
145
146 It must be obvious by now that the insertFromPath() method just scans
147 mike 1.15 the file names in a directory and calls insert() for each one (splitting
148 the class name from superclass name and translating '#' to an empty string).
149
150 The insertFromPath() method does NOT call check(), so it still must be
151 called to verify the InheritanceTree.
152 */
153 class PEGASUS_REPOSITORY_LINKAGE InheritanceTree
154 {
155 public:
156
157 /** Default constructor. */
158 InheritanceTree();
159
160 /** Destructor. */
161 ~InheritanceTree();
162
163 /** Inserts a class-subclass relationship into the inheritance three.
164 Note that a class CAN be inserted before its superclass, in which case
165 a provisional entry is made for the superclass and flagged as such;
166 when the superclass is later inserted, the provisional flag is cleared.
167 @param className - name of class being inserted.
168 mike 1.15 @param superClassName - name of super class of class.
169 */
170 void insert(const String& className, const String& superClassName);
171
172 /** Scan directory for file names of the form <ClassName>.<SuperClass> and
173 call insert on insert for each one. Note that root classes (classes with
174 no superclass) will use "#" for a SuperClass name.
175 @param path - directory that contains files describing inheritance
176 infoformation.
177 @exception throws CannotOpenDirectory is invalid path specifies an
178 invalid directory.
179 */
180 void insertFromPath(const String& path);
181
182 /** Checks that every superClassName passed to insert() was also passed
183 as a className argument to insert(). In other words, it checks that
184 there are no provisional entries as described in the insert() method.
185 @exception InvalidInheritanceTree
186 */
187 void check() const;
188
189 mike 1.15 /** Get subclass names of the given class.
190 @param className - class whose subclass names will be gotten. If
191 className is empty, all classnames are returned.
192 @param deepInheritance - if true all descendent classes of class
193 are returned. If className is empty, only root classes are returned.
194 @param subClassNames - output argument to hold subclass names.
195 @return true on success. False if no such class.
196 */
197 Boolean getSubClassNames(
|
198 kumpf 1.22 const CIMName& className,
|
199 mike 1.15 Boolean deepInheritance,
|
200 kumpf 1.22 Array<CIMName>& subClassNames) const;
|
201 mike 1.15
202 /** Returns true if class1 is a subclass of class2.
203 */
|
204 kumpf 1.22 Boolean isSubClass(const CIMName& class1, const CIMName& class2) const;
|
205 mike 1.15
206 /** Get the names of all superclasses of this class (direct and indirect).
207 */
208 Boolean getSuperClassNames(
|
209 kumpf 1.22 const CIMName& className,
210 Array<CIMName>& subClassNames) const;
|
211 mike 1.15
212 /** Get the superclass of the given class.
213 @param className name of class.
214 @param superClassName name of superclass upon return.
215 @return true if class was found; false otherwise.
216 */
217 Boolean getSuperClass(
|
218 kumpf 1.22 const CIMName& className,
219 CIMName& superClassName) const;
|
220 mike 1.15
221 /** Returns true if the given class has sub-classes. */
222 Boolean hasSubClasses(
|
223 kumpf 1.22 const CIMName& className,
|
224 mike 1.15 Boolean& hasSubClasses) const;
225
226 /** Returns true if this inhertance tree contains the given class. */
|
227 kumpf 1.22 Boolean containsClass(const CIMName& className) const;
|
228 mike 1.15
229 /** Removes the given class from the class graph.
230 @exception CIMException(CIM_ERR_CLASS_HAS_CHILDREN)
231 @exception CIMException(CIM_ERR_INVALID_CLASS)
232 */
|
233 kumpf 1.22 void remove(const CIMName& className);
|
234 mike 1.15
235 /** Prints the class */
236 void print(PEGASUS_STD(ostream)& os) const;
237
238 private:
239
240 InheritanceTree(const InheritanceTree&) { }
241
242 InheritanceTree& operator=(const InheritanceTree&) { return *this; }
243
244 InheritanceTreeRep* _rep;
245 };
246
247 /** The InvalidInheritanceTree exception is thrown when the
248 InheritanceTreeRep::check() method determines that an inheritance tree
249 was not fully specified (when any class was passed as a superClassName
250 argument to insert() but never as a className argument.
251 */
252 class InvalidInheritanceTree : public Exception
253 {
254 public:
|
255 humberto 1.23 //l10n start
256 //InvalidInheritanceTree(const String& className)
257 //: Exception("Invalid inheritance tree: unknown class: " + className) { }
258 InvalidInheritanceTree(const String& className)
259 : Exception(MessageLoaderParms("Repository.InheritanceTree.INVALID_INHERITANCE_TREE",
260 "Invalid inheritance tree: unknown class: $0", className)) { }
261 //l10n end
|
262 mike 1.15 };
263
264 PEGASUS_NAMESPACE_END
265
266 #endif /* Pegasus_InheritanceTree_h */
|