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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2