Class CategoryFactory

  • All Implemented Interfaces:
    CatFactory

    public final class CategoryFactory
    extends java.lang.Object
    implements CatFactory
    This is the singleton class used to load the configuration from the categories.xml. This provides convenience methods to get the configured categories and their information, add/delete categories from category groups. Note: Users of this class should make sure the init() is called before calling any other method to ensure the config is loaded before accessing other convenience methods.
    Author:
    Sowmya Nataraj , OpenNMS
    • Constructor Summary

      Constructors 
      Constructor Description
      CategoryFactory​(org.springframework.core.io.Resource resource)
      Constructor for CategoryFactory.
    • Constructor Detail

      • CategoryFactory

        public CategoryFactory​(org.springframework.core.io.Resource resource)
                        throws java.io.IOException

        Constructor for CategoryFactory.

        Parameters:
        resource - a Resource object.
        Throws:
        java.io.IOException - if any.
    • Method Detail

      • getReadLock

        public java.util.concurrent.locks.Lock getReadLock()
        Specified by:
        getReadLock in interface CatFactory
      • getWriteLock

        public java.util.concurrent.locks.Lock getWriteLock()
        Specified by:
        getWriteLock in interface CatFactory
      • init

        public static void init()
                         throws java.io.IOException
        Load the config from the default config file and create the singleton instance of this factory.
        Throws:
        java.io.IOException - Thrown if the specified config file cannot be read
        java.io.IOException - if any.
      • reload

        public static void reload()
                           throws java.io.IOException
        Reload the config from the default config file
        Throws:
        java.io.IOException - Thrown if the specified config file cannot be read/loaded
        java.io.IOException - if any.
      • getInstance

        public static CatFactory getInstance()
        Return the singleton instance of this factory.
        Returns:
        The current factory instance.
        Throws:
        java.lang.IllegalStateException - Thrown if the factory has not yet been initialized.
      • setInstance

        public static void setInstance​(CatFactory singleton)

        setInstance

        Parameters:
        singleton - a CatFactory object.
      • getConfig

        public Catinfo getConfig()
        Return the categories configuration.
        Specified by:
        getConfig in interface CatFactory
        Returns:
        the categories configuration
      • addCategoryGroup

        public void addCategoryGroup​(CategoryGroup group)
        Add a categorygroup.
        Parameters:
        group - category group to be added
      • replaceCategoryGroup

        public boolean replaceCategoryGroup​(CategoryGroup group)
        Replace categorygroup.
        Parameters:
        group - category group to be replaced
        Returns:
        true if categorygroup is successfully replaced
      • deleteCategoryGroup

        public boolean deleteCategoryGroup​(CategoryGroup group)
        Delete a categorygroup.
        Parameters:
        group - category group to be removed
        Returns:
        true if categorygroup is successfully deleted
      • deleteCategoryGroup

        public boolean deleteCategoryGroup​(java.lang.String groupname)
        Delete a categorygroup.
        Parameters:
        groupname - category group to be removed
        Returns:
        true if categorygroup is successfully deleted
      • addCategory

        public boolean addCategory​(java.lang.String groupname,
                                   Category cat)
        Add category to a categorygroup.
        Parameters:
        groupname - category group to which category is to be added
        cat - category to be added
        Returns:
        true if category is successfully added to the specified category group
      • replaceCategory

        public boolean replaceCategory​(java.lang.String groupname,
                                       Category cat)
        Replace category in a categorygroup.
        Parameters:
        groupname - category group to which category is to be added
        cat - category to be replaced
        Returns:
        true if category is successfully replaced in the specified category group
      • deleteCategory

        public boolean deleteCategory​(java.lang.String groupname,
                                      Category cat)
        Delete category from a categorygroup.
        Parameters:
        groupname - category group from which category is to be removed
        cat - category to be deleted
        Returns:
        true if category is successfully deleted from the specified category group
      • deleteCategory

        public boolean deleteCategory​(java.lang.String groupname,
                                      java.lang.String catlabel)
        Delete category from a categorygroup.
        Parameters:
        groupname - category group from which category is to be removed
        catlabel - label of the category to be deleted
        Returns:
        true if category is successfully deleted from the specified category group
      • getCategory

        public Category getCategory​(java.lang.String name)

        getCategory

        Return the category specified by name.
        Specified by:
        getCategory in interface CatFactory
        Parameters:
        name - a String object.
        Returns:
        a Category object.
      • getNormal

        public double getNormal​(java.lang.String catlabel)

        getNormal

        Return the normal value for the specified category.
        Specified by:
        getNormal in interface CatFactory
        Parameters:
        catlabel - a String object.
        Returns:
        a double.
      • getWarning

        public double getWarning​(java.lang.String catlabel)

        getWarning

        Return the warning value for the specified category.
        Specified by:
        getWarning in interface CatFactory
        Parameters:
        catlabel - a String object.
        Returns:
        a double.
      • getServices

        public java.lang.String[] getServices​(java.lang.String catlabel)
        Return the services list for the specified category.
        Parameters:
        catlabel - the label for the category whose services list is needed
        Returns:
        the services list for the specified category, null if category is not found
      • getRule

        public java.lang.String getRule​(java.lang.String catlabel)
        Return the rule for the specified category.
        Parameters:
        catlabel - the label for the category whose services list is needed
        Returns:
        the rule for the specified category, null if the category is not found
      • getEffectiveRule

        public java.lang.String getEffectiveRule​(java.lang.String catlabel)

        getEffectiveRule

        Return the effective rule for the specified category. The category rule ANDed with the rule of the category group that the category belongs to.
        Specified by:
        getEffectiveRule in interface CatFactory
        Parameters:
        catlabel - a String object.
        Returns:
        a String object.