|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.shimari.framework.Config
This class is a replacement for java.util.Properties. It establishes an application's configuration based on a properties file that is loaded from the classpath, or a URL, or a supplied SortedMap. It provides a range of methods to parse the properties as various specific types. .properties files. Unlike java.util.Properties it does not expose a modifiable interface; it throws better error messages; it does the loading from the classpath for you; it is capable of translating properties into objects; and it does strict checking on values.
Field Summary | |
static java.text.SimpleDateFormat |
DATE_FORMAT
|
static char |
SEPARATOR
|
Constructor Summary | |
Config(java.lang.String propertyResource)
Create a new config from a file on the current context class loader. |
|
Config(java.net.URL configurationSource)
Create a new config loading from the supplied URL. |
Method Summary | |
boolean |
containsKey(java.lang.String key)
Return true if the key is defined in this Config |
java.net.InetSocketAddress |
getAddress(java.lang.String key)
Return the value as an inet socket address. |
java.net.InetSocketAddress |
getAddress(java.lang.String key,
java.net.InetSocketAddress defaultValue)
If the key does not exist in the configuration, return the default value instead. |
java.lang.Object |
getBean(java.lang.String key)
Equivalent to getBean(key,Object.class) |
java.lang.Object |
getBean(java.lang.String key,
java.lang.Class type)
Get a property as an Object. |
java.lang.Object[] |
getBeanArray(java.lang.String key)
Equivalent to getBeanArray(key,Object.class) |
java.lang.Object[] |
getBeanArray(java.lang.String key,
java.lang.Class type)
The key denotes a prefix; all the roots under this prefix will be loaded as beans and returned as an array. |
java.lang.Class |
getClass(java.lang.String key)
Return the value as a Class. |
java.lang.Class |
getClass(java.lang.String key,
java.lang.Class defaultValue)
If the key does not exist in the configuration, return the default value instead. |
java.lang.Class[] |
getClassArray(java.lang.String key)
Get a property as a Class[]. |
Registry |
getComponentRegistry()
Return the components created under this configuration |
Config |
getConfig(java.lang.String key)
Get a copy of the Config, only operating on the subset of keys beginning with the supplied prefix. |
java.util.Date |
getDate(java.lang.String key)
Return the value as a date. |
java.util.Date |
getDate(java.lang.String key,
java.util.Date defaultValue)
If the key does not exist in the configuration, return the default value instead. |
java.io.File |
getDirectory(java.lang.String key)
Return the value as a File, checking that it is also a directory. |
java.io.File |
getDirectory(java.lang.String key,
java.io.File defaultValue)
If the key does not exist in the configuration, return the default value instead. |
double |
getDouble(java.lang.String key)
Return the value as a double. |
double |
getDouble(java.lang.String key,
double defaultValue)
If the configuration does not contain the key return the default value instead. |
double[] |
getDoubleArray(java.lang.String key)
Get a property as a double[]. |
java.io.File |
getFile(java.lang.String key)
Return the value as a File. |
java.io.File |
getFile(java.lang.String key,
java.io.File defaultValue)
If the key does not exist in the configuration, return the default value instead. |
int |
getInteger(java.lang.String key)
Return the value as an int. |
int |
getInteger(java.lang.String key,
int defaultValue)
If the configuration does not contain the supplied key, return the default value. |
int[] |
getIntegerArray(java.lang.String key)
Get a property as an int[]. |
long |
getLong(java.lang.String key)
Return the value as a long. |
long |
getLong(java.lang.String key,
long defaultValue)
If the configuration does not contain the supplied key, return the default value instead. |
long[] |
getLongArray(java.lang.String key)
Get a property as an int[]. |
java.util.regex.Pattern |
getPattern(java.lang.String key)
Return a regular expression pattern. |
java.util.regex.Pattern |
getPattern(java.lang.String key,
java.util.regex.Pattern defaultValue)
If the key does not exist in the configuration, return the default value instead. |
java.net.URL |
getSource()
Return the source of the configuration |
java.lang.String |
getString(java.lang.String key)
Get a property as a String. |
java.lang.String |
getString(java.lang.String key,
java.lang.String defaultValue)
Instead of throwing a ConfigException, return the default value if the string is not in the configuration. |
java.lang.String[] |
getStringArray(java.lang.String key)
Get a property as a String[]. |
java.lang.String[] |
getStringarray(java.lang.String key,
java.lang.String regx)
Similar to getStringArray(key) but you get to choose the splitting regular expression |
java.net.URL |
getURL(java.lang.String key)
Return the value as a URL. |
java.net.URL |
getURL(java.lang.String key,
java.net.URL defaultValue)
If the key does not exist in the configuration, return the default value instead. |
boolean |
isEmpty()
Return true if the Config contains no values |
java.util.Iterator |
keys()
Get the keys. |
java.util.Set |
keySet()
Get a set containing the keys of this configuration. |
java.util.Set |
rootSet()
Get the root keys. |
int |
size()
Return the number of keys in this Config. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final char SEPARATOR
public static final java.text.SimpleDateFormat DATE_FORMAT
Constructor Detail |
public Config(java.net.URL configurationSource) throws ConfigException
public Config(java.lang.String propertyResource) throws ConfigException
Method Detail |
public final java.lang.String getString(java.lang.String key) throws ConfigException
ConfigException
public java.lang.String getString(java.lang.String key, java.lang.String defaultValue)
public java.lang.String[] getStringArray(java.lang.String key) throws ConfigException
ConfigException
public java.lang.String[] getStringarray(java.lang.String key, java.lang.String regx) throws ConfigException
ConfigException
public int getInteger(java.lang.String key) throws ConfigException
ConfigException
public int getInteger(java.lang.String key, int defaultValue) throws ConfigException
ConfigException
public int[] getIntegerArray(java.lang.String key) throws ConfigException
ConfigException
public long getLong(java.lang.String key) throws ConfigException
ConfigException
public long getLong(java.lang.String key, long defaultValue) throws ConfigException
ConfigException
public long[] getLongArray(java.lang.String key) throws ConfigException
ConfigException
public double getDouble(java.lang.String key) throws ConfigException
ConfigException
public double getDouble(java.lang.String key, double defaultValue) throws ConfigException
ConfigException
public double[] getDoubleArray(java.lang.String key) throws ConfigException
ConfigException
public java.lang.Object getBean(java.lang.String key, java.lang.Class type) throws ConfigException
ConfigException
public java.lang.Object getBean(java.lang.String key) throws ConfigException
ConfigException
public java.lang.Object[] getBeanArray(java.lang.String key, java.lang.Class type) throws ConfigException
ConfigException
public java.lang.Object[] getBeanArray(java.lang.String key) throws ConfigException
ConfigException
public java.util.Date getDate(java.lang.String key) throws ConfigException
ConfigException
public java.util.Date getDate(java.lang.String key, java.util.Date defaultValue) throws ConfigException
ConfigException
public java.net.URL getURL(java.lang.String key) throws ConfigException
ConfigException
public java.net.URL getURL(java.lang.String key, java.net.URL defaultValue) throws ConfigException
ConfigException
public java.io.File getFile(java.lang.String key) throws ConfigException
ConfigException
public java.io.File getFile(java.lang.String key, java.io.File defaultValue) throws ConfigException
ConfigException
public java.io.File getDirectory(java.lang.String key) throws ConfigException
ConfigException
public java.io.File getDirectory(java.lang.String key, java.io.File defaultValue) throws ConfigException
ConfigException
public java.lang.Class getClass(java.lang.String key) throws ConfigException
ConfigException
public java.lang.Class getClass(java.lang.String key, java.lang.Class defaultValue) throws ConfigException
ConfigException
public java.lang.Class[] getClassArray(java.lang.String key) throws ConfigException
ConfigException
public java.net.InetSocketAddress getAddress(java.lang.String key) throws ConfigException
ConfigException
public java.net.InetSocketAddress getAddress(java.lang.String key, java.net.InetSocketAddress defaultValue) throws ConfigException
ConfigException
public java.util.regex.Pattern getPattern(java.lang.String key) throws ConfigException
ConfigException
public java.util.regex.Pattern getPattern(java.lang.String key, java.util.regex.Pattern defaultValue) throws ConfigException
ConfigException
public java.util.Iterator keys()
public java.util.Set rootSet()
public java.util.Set keySet()
rootSet().
public Config getConfig(java.lang.String key) throws ConfigException
ConfigException
rootSet()
public boolean containsKey(java.lang.String key)
public int size()
public boolean isEmpty()
public java.net.URL getSource()
public Registry getComponentRegistry()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |