1 //%2003////////////////////////////////////////////////////////////////////////
3 // 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 // IBM Corp.; EMC Corporation, The Open Group.
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
15 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
16 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
17 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
18 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
19 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 //==============================================================================
26 // Author: Mike Brasher (mbrasher@bmc.com)
28 // Modified By: Carol Ann Krug Graves, Hewlett-Packard Company
29 // (carolann_graves@hp.com)
31 //%/////////////////////////////////////////////////////////////////////////////
33 #ifndef Pegasus_InheritanceTree_h
34 #define Pegasus_InheritanceTree_h
37 #include <Pegasus/Common/Config.h>
38 #include <Pegasus/Common/ArrayInternal.h>
39 #include <Pegasus/Common/CIMName.h>
40 #include <Pegasus/Common/String.h>
41 #include <Pegasus/Common/InternalException.h>
42 #include <Pegasus/Repository/Linkage.h>
43 #include <Pegasus/Common/MessageLoader.h> //l10n
45 PEGASUS_NAMESPACE_BEGIN
47 struct InheritanceTreeRep;
49 /** The InheritanceTree class tracks inheritance relationships of CIM classes.
51 This class is a memory resident version of the repository's persistent
52 inheritance information (represented using file names). The InheritanceTree
53 provides O(1) access (via hashing) to any class in the inheritance tree.
55 The inheritance tree provides methods for interrogating certain kinds of
56 information about a class, including:
59 <li>the superclass</li>
60 <li>the subclasses</li>
61 <li>the descendent classes</li>
64 The insert() method is used to build up an InheritanceTree. The insert()
65 method is called for each class-subclass relationship. For example, consider
66 the following list of class-subclass pairs:
76 These pairs specify the following inheritance tree:
86 The pairs above may be used to build a class tree as follows:
99 The check() method determines whether insert() was called for every class
100 used as a superclass. In the following example, check() would fail (and
101 throw and exception) since the "B" class is passed as a superclass (second
102 argument) in two insert() calls but was never passed as the class itself
103 (first argument) in any insert() call:
115 In this case, check() throws an InvalidInheritanceTree exception.
117 The InheritanceTree may be printed by calling the print() method.
119 The insertFromPath() method is used to build up an InheritanceTree from
120 the file names in a certain directory as used by the CIMRepository. The
121 CIMRepository contains a disk file per class and the name has this form:
124 <ClassName>.<SuperClassName>
127 For example, a class called "ThisClass" with super class "ThatClass"
134 The file or course contains the XML encoding of the ThisClass class (which
135 is irrelevant for the InheritanceTree). A root class (with no superclass
136 has the following form):
142 Suppose that ThatClass is a root class; then its file name is:
148 It must be obvious by now that the insertFromPath() method just scans
149 the file names in a directory and calls insert() for each one (splitting
150 the class name from superclass name and translating '#' to an empty string).
152 The insertFromPath() method does NOT call check(), so it still must be
153 called to verify the InheritanceTree.
155 class PEGASUS_REPOSITORY_LINKAGE InheritanceTree
159 /** Default constructor. */
165 /** Inserts a class-subclass relationship into the inheritance three.
166 Note that a class CAN be inserted before its superclass, in which case
167 a provisional entry is made for the superclass and flagged as such;
168 when the superclass is later inserted, the provisional flag is cleared.
169 @param className - name of class being inserted.
170 @param superClassName - name of super class of class.
172 void insert(const String& className, const String& superClassName);
174 /** Scan directory for file names of the form <ClassName>.<SuperClass> and
175 call insert on insert for each one. Note that root classes (classes with
176 no superclass) will use "#" for a SuperClass name.
177 @param path - directory that contains files describing inheritance
179 @exception throws CannotOpenDirectory is invalid path specifies an
182 void insertFromPath(const String& path);
184 /** Checks that every superClassName passed to insert() was also passed
185 as a className argument to insert(). In other words, it checks that
186 there are no provisional entries as described in the insert() method.
187 @exception InvalidInheritanceTree
191 /** Get subclass names of the given class.
192 @param className - class whose subclass names will be gotten. If
193 className is empty, all classnames are returned.
194 @param deepInheritance - if true all descendent classes of class
195 are returned. If className is empty, only root classes are returned.
196 @param subClassNames - output argument to hold subclass names.
197 @return true on success. False if no such class.
199 Boolean getSubClassNames(
200 const CIMName& className,
201 Boolean deepInheritance,
202 Array<CIMName>& subClassNames) const;
204 /** Returns true if class1 is a subclass of class2.
206 Boolean isSubClass(const CIMName& class1, const CIMName& class2) const;
208 /** Get the names of all superclasses of this class (direct and indirect).
210 Boolean getSuperClassNames(
211 const CIMName& className,
212 Array<CIMName>& subClassNames) const;
214 /** Get the superclass of the given class.
215 @param className name of class.
216 @param superClassName name of superclass upon return.
217 @return true if class was found; false otherwise.
219 Boolean getSuperClass(
220 const CIMName& className,
221 CIMName& superClassName) const;
223 /** Returns true if the given class has sub-classes. */
224 Boolean hasSubClasses(
225 const CIMName& className,
226 Boolean& hasSubClasses) const;
228 /** Returns true if this inhertance tree contains the given class. */
229 Boolean containsClass(const CIMName& className) const;
231 /** Removes the given class from the class graph.
232 @exception CIMException(CIM_ERR_CLASS_HAS_CHILDREN)
233 @exception CIMException(CIM_ERR_INVALID_CLASS)
235 void remove(const CIMName& className);
237 /** Prints the class */
238 void print(PEGASUS_STD(ostream)& os) const;
242 InheritanceTree(const InheritanceTree&) { }
244 InheritanceTree& operator=(const InheritanceTree&) { return *this; }
246 InheritanceTreeRep* _rep;
249 /** The InvalidInheritanceTree exception is thrown when the
250 InheritanceTreeRep::check() method determines that an inheritance tree
251 was not fully specified (when any class was passed as a superClassName
252 argument to insert() but never as a className argument.
254 class InvalidInheritanceTree : public Exception
258 //InvalidInheritanceTree(const String& className)
259 //: Exception("Invalid inheritance tree: unknown class: " + className) { }
260 InvalidInheritanceTree(const String& className)
261 : Exception(MessageLoaderParms("Repository.InheritanceTree.INVALID_INHERITANCE_TREE",
262 "Invalid inheritance tree: unknown class: $0", className)) { }
266 PEGASUS_NAMESPACE_END
268 #endif /* Pegasus_InheritanceTree_h */