Package org.opennms.netmgt.config
Class CategoryFactory
- java.lang.Object
-
- org.opennms.netmgt.config.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.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addCategory(java.lang.String groupname, Category cat)
Add category to a categorygroup.void
addCategoryGroup(CategoryGroup group)
Add a categorygroup.boolean
deleteCategory(java.lang.String groupname, java.lang.String catlabel)
Delete category from a categorygroup.boolean
deleteCategory(java.lang.String groupname, Category cat)
Delete category from a categorygroup.boolean
deleteCategoryGroup(java.lang.String groupname)
Delete a categorygroup.boolean
deleteCategoryGroup(CategoryGroup group)
Delete a categorygroup.Category
getCategory(java.lang.String name)
getCategoryCatinfo
getConfig()
Return the categories configuration.java.lang.String
getEffectiveRule(java.lang.String catlabel)
getEffectiveRulestatic CatFactory
getInstance()
Return the singleton instance of this factory.double
getNormal(java.lang.String catlabel)
getNormaljava.util.concurrent.locks.Lock
getReadLock()
java.lang.String
getRule(java.lang.String catlabel)
Return the rule for the specified category.java.lang.String[]
getServices(java.lang.String catlabel)
Return the services list for the specified category.double
getWarning(java.lang.String catlabel)
getWarningjava.util.concurrent.locks.Lock
getWriteLock()
static void
init()
Load the config from the default config file and create the singleton instance of this factory.static void
reload()
Reload the config from the default config fileboolean
replaceCategory(java.lang.String groupname, Category cat)
Replace category in a categorygroup.boolean
replaceCategoryGroup(CategoryGroup group)
Replace categorygroup.static void
setInstance(CatFactory singleton)
setInstance
-
-
-
Method Detail
-
getReadLock
public java.util.concurrent.locks.Lock getReadLock()
- Specified by:
getReadLock
in interfaceCatFactory
-
getWriteLock
public java.util.concurrent.locks.Lock getWriteLock()
- Specified by:
getWriteLock
in interfaceCatFactory
-
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 readjava.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/loadedjava.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
- aCatFactory
object.
-
getConfig
public Catinfo getConfig()
Return the categories configuration.- Specified by:
getConfig
in interfaceCatFactory
- 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 addedcat
- 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 addedcat
- 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 removedcat
- 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 removedcatlabel
- 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 interfaceCatFactory
- Parameters:
name
- aString
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 interfaceCatFactory
- Parameters:
catlabel
- aString
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 interfaceCatFactory
- Parameters:
catlabel
- aString
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 interfaceCatFactory
- Parameters:
catlabel
- aString
object.- Returns:
- a
String
object.
-
-