org.kohsuke.stapler.config
Class ConfigurationLoader

java.lang.Object
  extended by 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 the MyConfig 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 to new 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 named getRootDir().

Author:
Kohsuke Kawaguchi

Method Summary
<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 specified Properties object.
static ConfigurationLoader fromEnvironmentVariables()
          Creates ConfigurationLoader that uses environment variables as the source.
static ConfigurationLoader fromSystemProperties()
          Creates ConfigurationLoader that uses all the system properties as the source.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 specified Properties object.

Throws:
IOException

from

public static ConfigurationLoader from(Map<String,String> props)
                                throws IOException
Throws:
IOException

fromSystemProperties

public static ConfigurationLoader fromSystemProperties()
                                                throws IOException
Creates ConfigurationLoader that uses all the system properties as the source.

Throws:
IOException

fromEnvironmentVariables

public static ConfigurationLoader fromEnvironmentVariables()
                                                    throws IOException
Creates ConfigurationLoader 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.



Copyright © 2013. All Rights Reserved.