Search in sources :

Example 1 with CatFactory

use of org.opennms.netmgt.config.api.CatFactory in project opennms by OpenNMS.

the class RTCUtils method createCategoriesMap.

/**
	 * Creates the categories map. Reads the categories from the categories.xml
	 * and creates the 'RTCCategory's map
	 */
public static HashMap<String, RTCCategory> createCategoriesMap() {
    CatFactory cFactory = null;
    try {
        CategoryFactory.init();
        cFactory = CategoryFactory.getInstance();
    } catch (IOException ex) {
        LOG.error("Failed to load categories information", ex);
        throw new UndeclaredThrowableException(ex);
    }
    HashMap<String, RTCCategory> retval = new HashMap<String, RTCCategory>();
    cFactory.getReadLock().lock();
    try {
        for (CategoryGroup cg : cFactory.getConfig().getCategoryGroups()) {
            final String commonRule = cg.getCommon().getRule();
            for (final org.opennms.netmgt.config.categories.Category cat : cg.getCategories()) {
                RTCCategory rtcCat = new RTCCategory(cat, commonRule);
                retval.put(rtcCat.getLabel(), rtcCat);
            }
        }
    } finally {
        cFactory.getReadLock().unlock();
    }
    return retval;
}
Also used : HashMap(java.util.HashMap) CatFactory(org.opennms.netmgt.config.api.CatFactory) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) IOException(java.io.IOException) RTCCategory(org.opennms.netmgt.rtc.datablock.RTCCategory) CategoryGroup(org.opennms.netmgt.config.categories.CategoryGroup)

Aggregations

IOException (java.io.IOException)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 HashMap (java.util.HashMap)1 CatFactory (org.opennms.netmgt.config.api.CatFactory)1 CategoryGroup (org.opennms.netmgt.config.categories.CategoryGroup)1 RTCCategory (org.opennms.netmgt.rtc.datablock.RTCCategory)1