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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2