org.opennms.netmgt.config
Class CategoryFactory

java.lang.Object
  extended by org.opennms.netmgt.config.CategoryFactory
All Implemented Interfaces:
CatFactory

public final class CategoryFactory
extends 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.

Version:
$Id: $
Author:
Sowmya Nataraj , OpenNMS , Sowmya Nataraj , OpenNMS

Constructor Summary
CategoryFactory(org.springframework.core.io.Resource resource)
          Constructor for CategoryFactory.
 
Method Summary
 boolean addCategory(String groupname, Category cat)
          Add category to a categorygroup.
 void addCategoryGroup(Categorygroup group)
          Add a categorygroup.
 boolean deleteCategory(String groupname, Category cat)
          Delete category from a categorygroup.
 boolean deleteCategory(String groupname, String catlabel)
          Delete category from a categorygroup.
 boolean deleteCategoryGroup(Categorygroup group)
          Delete a categorygroup.
 boolean deleteCategoryGroup(String groupname)
          Delete a categorygroup.
 Category getCategory(String name)
          getCategory
 Catinfo getConfig()
          Return the categories configuration.
 String getEffectiveRule(String catlabel)
          getEffectiveRule
static CatFactory getInstance()
          Return the singleton instance of this factory.
 double getNormal(String catlabel)
          getNormal
 String getRule(String catlabel)
          Return the rule for the specified category.
 String[] getServices(String catlabel)
          Return the services list for the specified category.
 double getWarning(String catlabel)
          getWarning
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 file
 boolean replaceCategory(String groupname, Category cat)
          Replace category in a categorygroup.
 boolean replaceCategoryGroup(Categorygroup group)
          Replace categorygroup.
static void setInstance(CatFactory singleton)
          setInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CategoryFactory

public CategoryFactory(org.springframework.core.io.Resource resource)
                throws IOException,
                       org.exolab.castor.xml.MarshalException,
                       org.exolab.castor.xml.ValidationException

Constructor for CategoryFactory.

Parameters:
resource - a Resource object.
Throws:
IOException - if any.
org.exolab.castor.xml.MarshalException - if any.
org.exolab.castor.xml.ValidationException - if any.
Method Detail

init

public static void init()
                 throws IOException,
                        org.exolab.castor.xml.MarshalException,
                        org.exolab.castor.xml.ValidationException
Load the config from the default config file and create the singleton instance of this factory.

Throws:
IOException - Thrown if the specified config file cannot be read
org.exolab.castor.xml.MarshalException - Thrown if the file does not conform to the schema.
org.exolab.castor.xml.ValidationException - Thrown if the contents do not match the required schema.
IOException - if any.
org.exolab.castor.xml.MarshalException - if any.
org.exolab.castor.xml.ValidationException - if any.

reload

public static void reload()
                   throws IOException,
                          org.exolab.castor.xml.MarshalException,
                          org.exolab.castor.xml.ValidationException
Reload the config from the default config file

Throws:
IOException - Thrown if the specified config file cannot be read/loaded
org.exolab.castor.xml.MarshalException - Thrown if the file does not conform to the schema.
org.exolab.castor.xml.ValidationException - Thrown if the contents do not match the required schema.
IOException - if any.
org.exolab.castor.xml.MarshalException - if any.
org.exolab.castor.xml.ValidationException - if any.

getInstance

public static CatFactory getInstance()
Return the singleton instance of this factory.

Returns:
The current factory instance.
Throws:
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(String groupname)
Delete a categorygroup.

Parameters:
groupname - category group to be removed
Returns:
true if categorygroup is successfully deleted

addCategory

public boolean addCategory(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(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(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(String groupname,
                              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(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(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(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 String[] getServices(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 String getRule(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 String getEffectiveRule(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.


Copyright © 2011. All Rights Reserved.