(file) Return to InheritanceTree.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Repository

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2