Using The HierarchyManager API

The class NetworkedPlanet.TME.Utils.HierarchyManager provides access to all of the hierarchies contained in a single topic map. The constructor for the class takes a single ITopicMap parameter which defines the topic map which the manager should process. During the constructor, the topic map is interrogated for all facets and the HierarchyManager will attempt to process each of those facets as a hierarchy. If the the subject identifiers specified in Table 8.1, “Topic PSIs for Topic Hierarchies” are not all found in the topic map, a ERROR level message will be written to the HierarchyManager log (see Chapter 14, Logging for more details); a TopicMapProcessingException will be thrown and no hierarchies will be loaded. If some of the facets do not conform to the structure required for a hierarchical facet, a WARNING level message will be written to the HierarchyManager log, but the correctly structure facets will all be processed. The constructor code caches the hierarchy in memory to provide rapid access to the entire tree.

Once the HierarchyManager constructor returns, the hierarchies found can be accessed through the Hierarchies property. This returns an unmodifiable IList of NetworkedPlanet.TME.Utils.Hierarchy instances. A Hierarchy instance represents the meta-data for a hierarchy. This includes the ITopic that defines the hierarchy and the ITopic that defines the hierarchy association type. In addition, the root node of the hierarchy can be accessed through the Root property.

The Root property returns an instance of NetworkedPlanet.TME.Utils.HierarchyNode. This class is used to represent a single node in the hierarchy tree. The property Topic provides access to the underlying ITopic in the topic map and the property Children returns an unmodifiable IList of HierarchyNode instances representing all of the children of this node in the hierarchy. The properties Parent and Hierarchy allow direct access to the parent node in the hierarchy and the hierarchy definition respectively.