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