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