public final class Config extends Object
A class for accessing configuration information from a properties file or from the System properties. Properties defined in the file will override the properties set in the System properties. The properties file should be located somewhere on the class path for the class loader used to load this class.
The default file that properties will be fetched from is referred to by Config.CONFIG_FILE_NAME.
| Modifier and Type | Field and Description |
|---|---|
static String |
CONFIG_FILE_NAME
The name of the properties file used for configuration; "secretsmanager.properties".
|
| Modifier and Type | Method and Description |
|---|---|
String |
fullPropertyName(String propertyName)
Extends a property name to be the full version written in the configuration file.
|
Class |
getClassPropertyWithDefault(String propertyName,
Class defaultValue)
Returns a
Class property or a default value if the property is not set. |
int |
getIntPropertyWithDefault(String propertyName,
int defaultValue)
Returns a
int property or a default value if the property is not set. |
long |
getLongPropertyWithDefault(String propertyName,
long defaultValue)
Returns a
long property or a default value if the property is not set. |
Class |
getRequiredClassProperty(String propertyName)
Returns a
Class property or throws a NoSuchElementException if the property is not set. |
int |
getRequiredIntProperty(String propertyName)
Returns a
int property or throws a NoSuchElementException if the property is not set. |
long |
getRequiredLongProperty(String propertyName)
Returns a
long property or throws a NoSuchElementException if the property is not set. |
String |
getRequiredStringProperty(String propertyName)
Returns a
String property or throws a NoSuchElementException if the property is not
set. |
String |
getStringPropertyWithDefault(String propertyName,
String defaultValue)
Returns a
String property or a default value if the property is not set. |
Config |
getSubconfig(String subprefix)
Extracts all of the properties for a given subprefix into its own
Config object. |
static Config |
loadConfigFrom(String resourceName)
Loads a configuration from a specific configuration file.
|
static Config |
loadMainConfig()
Loads a configuration from
CONFIG_FILE_NAME. |
public static final String CONFIG_FILE_NAME
public static Config loadConfigFrom(String resourceName)
resourceName - The name of the config file to load from.Config with the properties from the
file and the system properties as defaults.public static Config loadMainConfig()
CONFIG_FILE_NAME. Will use the System properties as defaults.Config with the properties from the
CONFIG_FILE_NAME file and the system
properties as defaults.public Config getSubconfig(String subprefix)
Config object. The property
names will be changed to no longer have the subprefix.subprefix - The subprefix to get all of the properties for.public String fullPropertyName(String propertyName)
Config object.propertyName - The property name to extend.public String getStringPropertyWithDefault(String propertyName, String defaultValue)
String property or a default value if the property is not set.propertyName - The name of the property to retrieve.defaultValue - The default value to use.String property or a default value if
the property is not set.public int getIntPropertyWithDefault(String propertyName, int defaultValue)
int property or a default value if the property is not set.propertyName - The name of the property to retrieve.defaultValue - The default value to use.int property or a default value if
the property is not set.PropertyException - If the property value is not a decimal int.public long getLongPropertyWithDefault(String propertyName, long defaultValue)
long property or a default value if the property is not set.propertyName - The name of the property to retrieve.defaultValue - The default value to use.long property or a default value if
the property is not set.PropertyException - If the property value is not a decimal
long.public Class getClassPropertyWithDefault(String propertyName, Class defaultValue)
Class property or a default value if the property is not set.propertyName - The name of the property to retrieve.defaultValue - The default value to use.Class property or a default value if
the property is not set.PropertyException - If the class name does not exist in this class loader.public String getRequiredStringProperty(String propertyName)
String property or throws a NoSuchElementException if the property is not
set.propertyName - The name of the property to retrieve.String property or a default value if
the property is not set.NoSuchElementException - If the property is not set.public int getRequiredIntProperty(String propertyName)
int property or throws a NoSuchElementException if the property is not set.propertyName - The name of the property to retrieve.int property or a default value if
the property is not set.PropertyException - If the property value is not a decimal int.NoSuchElementException - If the property is not set.public long getRequiredLongProperty(String propertyName)
long property or throws a NoSuchElementException if the property is not set.propertyName - The name of the property to retrieve.long property or a default value if
the property is not set.PropertyException - If the property value is not a decimal
long.NoSuchElementException - If the property is not set.public Class getRequiredClassProperty(String propertyName)
Class property or throws a NoSuchElementException if the property is not set.propertyName - The name of the property to retrieve.Class property or a default value if
the property is not set.PropertyException - If the class name does not exist in this class loader.NoSuchElementException - If the property is not set.Copyright © 2023. All rights reserved.