pt.digitalis.utils.config
Interface IConfigurations

All Known Implementing Classes:
AbstractConfigurationsImpl, ConfigurationsPreferencesImpl

public interface IConfigurations

Interface that provides a common interface for configuration persistence purposes. It provides a structure for configurations in the following form: configID -> sectionID -> List of "key = value"

Author:
Pedro Viegas pviegas@digitalis.pt

Method Summary
 Map<String,Class<?>> getCacheConfigurationPoints()
          Returns the previously cached configuration points.
 List<ConfigItem> getConfigItemsMap(Class<?> clazz)
          The list of the methods and keys read from the ConfigKeyID annotated methods or other getters as long as not ConfigIgnore annotated.
 String getGeneralPrefix()
           
 void readAllConfigurationsPoints()
          Parses all classes for configuration points and build a map of all configurations found
<T> T
readConfiguration(Class<T> clazz)
          Reads configurations from the persistence layer.
 Properties readConfiguration(String configID, String sectionID)
          Reads configurations from the persistence layer
<T> T
readConfiguration(String configID, String sectionID, Class<T> clazz)
          Reads configurations from the persistence layer.
 Map<String,String> readConfigurationAsMap(String configID, String sectionID)
          Reads configurations from the persistence layer
 void readConfigurationsPointsForPackage(String basePackage)
          Parses all classes of the given package for configuration points and build a map of all configurations found
 boolean removeConfiguration(Object bean)
          Removes configurations from the persistence layer.
 boolean removeConfiguration(String configID, String sectionID)
          Removes configurations from the persistence layer
 boolean writeConfiguration(String configID, String sectionID, Object bean)
          Writes configurations to the persistence layer.
 boolean writeConfiguration(String configID, String sectionID, Properties values)
          Writes configurations to the persistence layer
<T> boolean
writeConfiguration(T annotatedPojo)
          Writes configurations to the persistence layer.
 boolean writeConfigurationFromMap(String configID, String sectionID, Map<String,String> values)
          Writes configurations to the persistence layer
 

Method Detail

getCacheConfigurationPoints

Map<String,Class<?>> getCacheConfigurationPoints()
Returns the previously cached configuration points. Will call cacheAllConfigurations method if no configurations are yet in cache.

Returns:
the configuration map with configuration path and corresponding class

getConfigItemsMap

List<ConfigItem> getConfigItemsMap(Class<?> clazz)
The list of the methods and keys read from the ConfigKeyID annotated methods or other getters as long as not ConfigIgnore annotated. Note: Only setters that receives a class argument that has a String constructor will be supported. In order to have a custom class supported just implement a constructor(String) and the toString method to provide conversion to/from your own class object. Some types are automatically converted to classes: int, long, double, boolean

Parameters:
clazz - the class to parse
Returns:
the list of ConfigItems

getGeneralPrefix

String getGeneralPrefix()
Returns:
Returns the common configuration prefix

readAllConfigurationsPoints

void readAllConfigurationsPoints()
Parses all classes for configuration points and build a map of all configurations found


readConfiguration

<T> T readConfiguration(Class<T> clazz)
Reads configurations from the persistence layer. It will scan the given class for annotations that instruct how to read the values. The annotations are the ones present in "pt.digitalis.dif.config.annotations" If not available a simple conversion of attributes to key name will be used, as in: "method: getFullName -> key FullName" Note: The ConfigID and ConfigSectionID annotations are mandatory for this method to succeed

Type Parameters:
T - the Type to create
Parameters:
clazz - the class that defines the object that represents the properties to read
Returns:
an instance of class with the read values

readConfiguration

Properties readConfiguration(String configID,
                             String sectionID)
Reads configurations from the persistence layer

Parameters:
configID - the identifier of the configuration group
sectionID - the identifier of the section within the group
Returns:
a Properties object with the key value pairs

readConfiguration

<T> T readConfiguration(String configID,
                        String sectionID,
                        Class<T> clazz)
Reads configurations from the persistence layer. It will scan the given class for annotations that instruct how to read the values. The annotations are the ones present in "pt.digitalis.utils.config.annotations" If not available a simple conversion of attributes to key name will be used, as in: "method: getFullName -> key FullName"

Type Parameters:
T - the Type to create
Parameters:
configID - the identifier of the configuration group
sectionID - the identifier of the section within the group
clazz - the class that defines the object that represents the properties to read
Returns:
an instance of class with the read values

readConfigurationAsMap

Map<String,String> readConfigurationAsMap(String configID,
                                          String sectionID)
Reads configurations from the persistence layer

Parameters:
configID - the identifier of the configuration group
sectionID - the identifier of the section within the group
Returns:
a Properties object with the key value pairs

readConfigurationsPointsForPackage

void readConfigurationsPointsForPackage(String basePackage)
Parses all classes of the given package for configuration points and build a map of all configurations found

Parameters:
basePackage - the base package to search configurations classes on

removeConfiguration

boolean removeConfiguration(Object bean)
                            throws Exception
Removes configurations from the persistence layer. It will scan the given class for annotations that instruct what configurations it should remove. The annotations are the ones present in "pt.digitalis.dif.config.annotations" Note: The ConfigID and ConfigSectionID annotations are mandatory for this method to succeed

Parameters:
bean - the object (JavaBean) that will be read and saved
Returns:
T if successful
Throws:
Exception - if the return object cannot be created

removeConfiguration

boolean removeConfiguration(String configID,
                            String sectionID)
Removes configurations from the persistence layer

Parameters:
configID - the identifier of the configuration group
sectionID - the identifier of the section within the group
Returns:
T if successful

writeConfiguration

boolean writeConfiguration(String configID,
                           String sectionID,
                           Object bean)
Writes configurations to the persistence layer. A simple conversion of attributes to key name will be used, as in: "method: getFullName -> key FullName"

Parameters:
configID - the identifier of the configuration group
sectionID - the identifier of the section within the group
bean - the object (JavaBean) that will be read and saved
Returns:
T if the operation was successful

writeConfiguration

boolean writeConfiguration(String configID,
                           String sectionID,
                           Properties values)
Writes configurations to the persistence layer

Parameters:
configID - the identifier of the configuration group
sectionID - the identifier of the section within the group
values - a Properties object with the key value pairs
Returns:
T if the operation was successful

writeConfiguration

<T> boolean writeConfiguration(T annotatedPojo)
                           throws Exception
Writes configurations to the persistence layer. It will scan the given class for annotations that instruct how to read the values. The annotations are the ones present in "pt.digitalis.dif.config.annotations" If not available a simple conversion of attributes to key name will be used, as in: "method: getFullName -> key FullName"

Type Parameters:
T - the Type to create
Parameters:
annotatedPojo - the annotated class object with the values to be saved
Returns:
T if the operation was successful
Throws:
Exception - if the bean class is not found

writeConfigurationFromMap

boolean writeConfigurationFromMap(String configID,
                                  String sectionID,
                                  Map<String,String> values)
Writes configurations to the persistence layer

Parameters:
configID - the identifier of the configuration group
sectionID - the identifier of the section within the group
values - a Properties object with the key value pairs
Returns:
T if the operation was successful


Copyright © 2012 Digitalis Informática Lda. All Rights Reserved.