Package org.kohsuke.stapler.config
Class ConfigurationLoader
- java.lang.Object
-
- org.kohsuke.stapler.config.ConfigurationLoader
-
public class ConfigurationLoader extends Object
Provides a type-safe access to the configuration of the application.Often web applications need to load configuration from outside. T
Typical usage would be
MyConfig config=ConfigurationLoad.from(...).as(MyConfig.class)
where theMyConfig
interface defines a bunch of methods named after the property name:interface MyConfig { File rootDir(); int retryCount(); String domainName(); ... }
Method calls translate to respective property lookup. For example,
config.rootDir()
would be equivalent tonew File(properties.get("rootDir"))
.The method name can include common prefixes, such as "get", "is", and "has", and those portions will be excluded from the property name. Thus the
rootDir()
could have been namedgetRootDir()
.- Author:
- Kohsuke Kawaguchi
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> T
as(Class<T> type)
Creates a type-safe proxy that reads from the source specified by one of the fromXyz methods.static ConfigurationLoader
from(File configPropertyFile)
Loads the configuration from the specified property file.static ConfigurationLoader
from(Map<String,String> props)
static ConfigurationLoader
from(Properties props)
Loads the configuration from the specifiedProperties
object.static ConfigurationLoader
fromEnvironmentVariables()
CreatesConfigurationLoader
that uses environment variables as the source.static ConfigurationLoader
fromSystemProperties()
CreatesConfigurationLoader
that uses all the system properties as the source.
-
-
-
Method Detail
-
from
public static ConfigurationLoader from(File configPropertyFile) throws IOException
Loads the configuration from the specified property file.- Throws:
IOException
-
from
public static ConfigurationLoader from(Properties props) throws IOException
Loads the configuration from the specifiedProperties
object.- Throws:
IOException
-
from
public static ConfigurationLoader from(Map<String,String> props) throws IOException
- Throws:
IOException
-
fromSystemProperties
public static ConfigurationLoader fromSystemProperties() throws IOException
CreatesConfigurationLoader
that uses all the system properties as the source.- Throws:
IOException
-
fromEnvironmentVariables
public static ConfigurationLoader fromEnvironmentVariables() throws IOException
CreatesConfigurationLoader
that uses environment variables as the source. Since environment variables are often by convention all caps, while system properties and other properties tend to be camel cased, this method creates a case-insensitive configuration (that allows retrievals by both "path" and "PATH" to fill this gap.- Throws:
IOException
-
as
public <T> T as(Class<T> type)
Creates a type-safe proxy that reads from the source specified by one of the fromXyz methods.
-
-