Class Configuration

  • All Implemented Interfaces:
    Serializable

    @ApplicationScoped
    public class Configuration
    extends Object
    implements Serializable
    An application-scoped CDI managed bean named which serves as an injectable component for managing configuration parameters.
    Author:
    Phillip Ross
    See Also:
    Serialized Form
    • Field Detail

      • DEFAULT_CONFIG_FILE_PATH_PROPERTY_NAME

        public static final String DEFAULT_CONFIG_FILE_PATH_PROPERTY_NAME
        The default name of the system property referencing to the location of the configuration file.
        See Also:
        Constant Field Values
    • Constructor Detail

      • Configuration

        public Configuration()
        Instantiates a new configuration object.
    • Method Detail

      • getProperties

        public Properties getProperties()
        Gets the properties.
        Returns:
        the properties
      • getPropertiesWithPrefix

        public Properties getPropertiesWithPrefix​(String prefix)
        Gets the properties that begin with a specified prefix.
        Parameters:
        prefix - the prefix
        Returns:
        the properties
      • setProperties

        public void setProperties​(Properties properties)
        Clears existing configuration properties replaces with the specified properties.
        Parameters:
        properties - the properties
      • setProperty

        public void setProperty​(String propertyName,
                                String propertyValue)
        Sets the specified property to the specified value.
        Parameters:
        propertyName - the property name to be set
        propertyValue - the property value to set the property to
      • getProperty

        public String getProperty​(String propertyName)
        Gets the property value with the specified name.
        Parameters:
        propertyName - the name of the property to get
        Returns:
        the value of the property retrieved
      • getProperty

        public String getProperty​(String propertyName,
                                  String defaultValue)
        Gets the property value with the specified name. If the property does not exist, the specified default value is returned.
        Parameters:
        propertyName - the name of the property to get
        defaultValue - the value returned if the property does not exist
        Returns:
        the value of the property retrieved
      • get

        public Object get​(Object key)
        Parameters:
        key - the key whose associated value is to be returned
        Returns:
        the value to which the specified key is mapped, or null if this map contains no mapping for the key
        Throws:
        NullPointerException - if the specified key is null
      • getOrDefault

        public Object getOrDefault​(Object key,
                                   Object defaultValue)
        Parameters:
        key - the key whose associated value is to be returned
        defaultValue - the value to be returned if the associated property value is null
        Returns:
        the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key
      • readProperties

        @PostConstruct
        public void readProperties()
        Reads in the configuration properties. If the co.luminositylabs.configFile system property exists, the value of this property is used as the path to read the configuration from. If the property does not exist, a path named co.luminositylabs.config.properties is used.

        If the configuration pathname does NOT represent an absolute path, the pathname will be treated as a relative path, and the file will be searched for in a series of relative locations:

        1. First, the file will be searched for at the path relative to the current working directory.
        2. Second, the file will be searched for at the path relative to the home directory.
        3. Lastly, the file will be searched for at the path relative to the classpath.

        If the configuration file is not found, an IOException is thrown.