Package com.germinus.easyconf
Class ComponentProperties
- java.lang.Object
-
- com.germinus.easyconf.ComponentProperties
-
public class ComponentProperties extends java.lang.Object
Part of a component configuration which contains its properties. The properties can be accessed by type and automatic conversion will be performed. The supported types are: BigDecimal, BigInteger, Boolean, Byte, Double, Float, Integer, List, Long, Short, String and StringArray It is based on theConfiguration
interface from Jakarta Commons Configuration but it is given a different name which makes more sense inside EasyConf. The boolean flag throwExceptionOnMissing controls the behaviour of this class when a property that does not exist is queried. If set to true (the default) a NoSuchElementException will be thrown if the given key does not exist and no default was provided. If set to false, null will be returned except for the method getList() which will return an empty unmodifyiable list.- Version:
- $Revision: 1.23 $
- Author:
- Jorge Ferrer
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.List
EMPTY_LIST
private static Log
log
static java.lang.String
NULL_STRING
(package private) AggregatedProperties
properties
-
Constructor Summary
Constructors Constructor Description ComponentProperties(AggregatedProperties conf)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
containsKey(java.lang.String key)
boolean
equals(java.lang.Object obj)
java.math.BigDecimal
getBigDecimal(java.lang.String key)
java.math.BigDecimal
getBigDecimal(java.lang.String key, Filter filter)
java.math.BigDecimal
getBigDecimal(java.lang.String key, Filter filter, java.math.BigDecimal defaultValue)
java.math.BigDecimal
getBigDecimal(java.lang.String key, java.math.BigDecimal defaultValue)
java.math.BigInteger
getBigInteger(java.lang.String key)
java.math.BigInteger
getBigInteger(java.lang.String key, Filter filter)
java.math.BigInteger
getBigInteger(java.lang.String key, Filter filter, java.math.BigInteger defaultValue)
java.math.BigInteger
getBigInteger(java.lang.String key, java.math.BigInteger defaultValue)
boolean
getBoolean(java.lang.String key)
boolean
getBoolean(java.lang.String key, boolean defaultValue)
boolean
getBoolean(java.lang.String key, Filter filter)
boolean
getBoolean(java.lang.String key, Filter filter, boolean defaultValue)
java.lang.Boolean
getBoolean(java.lang.String key, Filter filter, java.lang.Boolean defaultValue)
java.lang.Boolean
getBoolean(java.lang.String key, java.lang.Boolean defaultValue)
byte
getByte(java.lang.String key)
byte
getByte(java.lang.String key, byte defaultValue)
byte
getByte(java.lang.String key, Filter filter)
byte
getByte(java.lang.String key, Filter filter, byte defaultValue)
java.lang.Byte
getByte(java.lang.String key, Filter filter, java.lang.Byte defaultValue)
java.lang.Byte
getByte(java.lang.String key, java.lang.Byte defaultValue)
java.lang.Class
getClass(java.lang.String key)
Get theClass
representation of the class name specified in the given propertyjava.lang.Class
getClass(java.lang.String key, Filter filter)
Similar to the previous methods but complementing the property key with the given filterjava.lang.Class
getClass(java.lang.String key, Filter filter, java.lang.Class defaultValue)
Equivalent to the previous method but giving a default value which will be used if no value has been specified in the configurations filejava.lang.Class
getClass(java.lang.String key, java.lang.Class defaultValue)
Get theClass
representation of the class name specified in the given property.java.lang.Class[]
getClassArray(java.lang.String key)
Get an array ofClass
objects for the class names specified in the given propertyjava.lang.Class[]
getClassArray(java.lang.String key, Filter filter)
Similar to the previous methods but complementing the property key with the given filterjava.lang.Class[]
getClassArray(java.lang.String key, Filter filter, java.lang.Class[] defaultValue)
Equivalent to the previous method but giving a default value which will be used if no value has been specified in the configurations filejava.lang.Class[]
getClassArray(java.lang.String key, java.lang.Class[] defaultValue)
Get an array ofClass
objects for the class names specified in the given property.java.lang.String
getComponentName()
java.lang.Long
getDelayPeriod()
Returned the configured delay period for this component or null if reloading is not being performeddouble
getDouble(java.lang.String key)
double
getDouble(java.lang.String key, double defaultValue)
double
getDouble(java.lang.String key, Filter filter)
double
getDouble(java.lang.String key, Filter filter, double defaultValue)
java.lang.Double
getDouble(java.lang.String key, Filter filter, java.lang.Double defaultValue)
java.lang.Double
getDouble(java.lang.String key, java.lang.Double defaultValue)
float
getFloat(java.lang.String key)
float
getFloat(java.lang.String key, float defaultValue)
float
getFloat(java.lang.String key, Filter filter)
float
getFloat(java.lang.String key, Filter filter, float defaultValue)
java.lang.Float
getFloat(java.lang.String key, Filter filter, java.lang.Float defaultValue)
java.lang.Float
getFloat(java.lang.String key, java.lang.Float defaultValue)
int
getInt(java.lang.String key)
int
getInt(java.lang.String key, int defaultValue)
int
getInt(java.lang.String key, Filter filter)
int
getInt(java.lang.String key, Filter filter, int defaultValue)
java.lang.Integer
getInteger(java.lang.String key, Filter filter, java.lang.Integer defaultValue)
java.lang.Integer
getInteger(java.lang.String key, java.lang.Integer defaultValue)
java.util.Iterator
getKeys()
java.util.Iterator
getKeys(java.lang.String prefix)
java.util.List
getList(java.lang.String key)
java.util.List
getList(java.lang.String key, Filter filter)
java.util.List
getList(java.lang.String key, Filter filter, java.util.List defaultValue)
java.util.List
getList(java.lang.String key, java.util.List defaultValue)
java.util.List
getLoadedSources()
Get a list of the sources which have been loaded for this componentlong
getLong(java.lang.String key)
long
getLong(java.lang.String key, long defaultValue)
long
getLong(java.lang.String key, Filter filter)
long
getLong(java.lang.String key, Filter filter, long defaultValue)
java.lang.Long
getLong(java.lang.String key, Filter filter, java.lang.Long defaultValue)
java.lang.Long
getLong(java.lang.String key, java.lang.Long defaultValue)
java.util.Properties
getProperties()
Returns a copy of the configuration into a java.util.Properties class.java.lang.Object
getProperty(java.lang.String key)
protected java.lang.Object
getPropertyWithFilter(java.lang.String key, Filter filter, java.lang.Class theClass, java.lang.Object defaultValue)
short
getShort(java.lang.String key)
short
getShort(java.lang.String key, short defaultValue)
short
getShort(java.lang.String key, Filter filter)
short
getShort(java.lang.String key, Filter filter, short defaultValue)
java.lang.Short
getShort(java.lang.String key, Filter filter, java.lang.Short defaultValue)
java.lang.Short
getShort(java.lang.String key, java.lang.Short defaultValue)
java.lang.String
getString(java.lang.String key)
Get the String value of the given key.java.lang.String
getString(java.lang.String key, Filter filter)
java.lang.String
getString(java.lang.String key, Filter filter, java.lang.String defaultValue)
java.lang.String
getString(java.lang.String key, java.lang.String defaultValue)
java.lang.String[]
getStringArray(java.lang.String key)
java.lang.String[]
getStringArray(java.lang.String key, Filter filter)
java.lang.String[]
getStringArray(java.lang.String key, Filter filter, java.lang.String[] defaultValue)
java.lang.String[]
getStringArray(java.lang.String key, java.lang.String[] defaultValue)
protected static java.lang.Object
getTypedPropertyWithDefault(java.lang.String key, java.lang.Class theClass, Configuration properties, java.lang.Object defaultValue)
boolean
hasBaseConfiguration()
int
hashCode()
boolean
isEmpty()
boolean
isThrowExceptionOnMissing()
protected java.lang.String
listToString(java.util.List list)
void
setProperty(java.lang.String key, java.lang.Object value)
void
setThrowExceptionOnMissing(boolean throwExceptionOnMissing)
Set the flag throwExceptionOnMissing.Configuration
subset(java.lang.String prefix)
Configuration
toConfiguration()
Returns a decorator of the configuration of type org.apache.commons.configuration.Configuration Note that any changes made to this decorator will be made to the original configuration and viceversa.DataConfiguration
toDataConfiguration()
Returns a decorator of the configuration of type org.apache.commons.configuration.DataConfiguration.DynaBean
toDynaBean()
Returns a decorator of the configuration that can be used as a DynaBean.java.util.Map
toMap()
Returns a decorator of the configuration that implements the Map interface.java.lang.String
toString()
protected void
validateValue(java.lang.String key, java.lang.Object value)
-
-
-
Field Detail
-
NULL_STRING
public static final java.lang.String NULL_STRING
-
EMPTY_LIST
private static final java.util.List EMPTY_LIST
-
log
private static final Log log
-
properties
AggregatedProperties properties
-
-
Constructor Detail
-
ComponentProperties
ComponentProperties(AggregatedProperties conf)
-
-
Method Detail
-
toMap
public java.util.Map toMap()
Returns a decorator of the configuration that implements the Map interface. Note that any changes made to this decorator will be made to the original configuration and viceversa.- Returns:
- a
java.util.Map
instance
-
toDynaBean
public DynaBean toDynaBean()
Returns a decorator of the configuration that can be used as a DynaBean. Note that any changes made to this decorator will be made to the original configuration and viceversa.- Returns:
- a
DynaBean
instance
-
toConfiguration
public Configuration toConfiguration()
Returns a decorator of the configuration of type org.apache.commons.configuration.Configuration Note that any changes made to this decorator will be made to the original configuration and viceversa.- Returns:
- a
Configuration
instance
-
toDataConfiguration
public DataConfiguration toDataConfiguration()
Returns a decorator of the configuration of type org.apache.commons.configuration.DataConfiguration. This decorator has many extra methods for retrieving typed properties such as color, URL, locale, Calendar and lists and array of any of these types. Note that any changes made to this decorator will be made to the original configuration and viceversa.- Returns:
- a
DataConfiguration
instance
-
getProperties
public java.util.Properties getProperties()
Returns a copy of the configuration into a java.util.Properties class. Multivalued properties will be converted to comma-separated strings. Any changes made to the configuration will not be available to the Properties and viceversa.- Returns:
- a
Properties
instance
-
getProperty
public java.lang.Object getProperty(java.lang.String key)
-
containsKey
public boolean containsKey(java.lang.String key)
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
getKeys
public java.util.Iterator getKeys()
-
getKeys
public java.util.Iterator getKeys(java.lang.String prefix)
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
isEmpty
public boolean isEmpty()
-
setProperty
public void setProperty(java.lang.String key, java.lang.Object value)
-
subset
public Configuration subset(java.lang.String prefix)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getBigDecimal
public java.math.BigDecimal getBigDecimal(java.lang.String key)
-
getBigDecimal
public java.math.BigDecimal getBigDecimal(java.lang.String key, java.math.BigDecimal defaultValue)
-
getBigDecimal
public java.math.BigDecimal getBigDecimal(java.lang.String key, Filter filter)
-
getBigDecimal
public java.math.BigDecimal getBigDecimal(java.lang.String key, Filter filter, java.math.BigDecimal defaultValue)
-
getBigInteger
public java.math.BigInteger getBigInteger(java.lang.String key)
-
getBigInteger
public java.math.BigInteger getBigInteger(java.lang.String key, java.math.BigInteger defaultValue)
-
getBigInteger
public java.math.BigInteger getBigInteger(java.lang.String key, Filter filter)
-
getBigInteger
public java.math.BigInteger getBigInteger(java.lang.String key, Filter filter, java.math.BigInteger defaultValue)
-
getBoolean
public boolean getBoolean(java.lang.String key)
-
getBoolean
public boolean getBoolean(java.lang.String key, boolean defaultValue)
-
getBoolean
public java.lang.Boolean getBoolean(java.lang.String key, java.lang.Boolean defaultValue) throws java.lang.NoClassDefFoundError
- Throws:
java.lang.NoClassDefFoundError
-
getBoolean
public boolean getBoolean(java.lang.String key, Filter filter)
-
getBoolean
public java.lang.Boolean getBoolean(java.lang.String key, Filter filter, java.lang.Boolean defaultValue) throws java.lang.NoClassDefFoundError
- Throws:
java.lang.NoClassDefFoundError
-
getBoolean
public boolean getBoolean(java.lang.String key, Filter filter, boolean defaultValue)
-
getByte
public byte getByte(java.lang.String key)
-
getByte
public byte getByte(java.lang.String key, byte defaultValue)
-
getByte
public java.lang.Byte getByte(java.lang.String key, java.lang.Byte defaultValue)
-
getByte
public byte getByte(java.lang.String key, Filter filter)
-
getByte
public java.lang.Byte getByte(java.lang.String key, Filter filter, java.lang.Byte defaultValue)
-
getByte
public byte getByte(java.lang.String key, Filter filter, byte defaultValue)
-
getDouble
public double getDouble(java.lang.String key)
-
getDouble
public double getDouble(java.lang.String key, double defaultValue)
-
getDouble
public java.lang.Double getDouble(java.lang.String key, java.lang.Double defaultValue)
-
getDouble
public double getDouble(java.lang.String key, Filter filter)
-
getDouble
public java.lang.Double getDouble(java.lang.String key, Filter filter, java.lang.Double defaultValue)
-
getDouble
public double getDouble(java.lang.String key, Filter filter, double defaultValue)
-
getClass
public java.lang.Class getClass(java.lang.String key) throws java.lang.ClassNotFoundException
Get theClass
representation of the class name specified in the given property- Throws:
java.lang.ClassNotFoundException
- if the specified class is not found
-
getClass
public java.lang.Class getClass(java.lang.String key, java.lang.Class defaultValue) throws java.lang.ClassNotFoundException
Get theClass
representation of the class name specified in the given property. Or thedefaultValue
if no value has been given to the property.- Throws:
java.lang.ClassNotFoundException
- if a class has been configured but it is not found
-
getClass
public java.lang.Class getClass(java.lang.String key, Filter filter) throws java.lang.ClassNotFoundException
Similar to the previous methods but complementing the property key with the given filter- Throws:
java.lang.ClassNotFoundException
-
getClass
public java.lang.Class getClass(java.lang.String key, Filter filter, java.lang.Class defaultValue) throws java.lang.ClassNotFoundException
Equivalent to the previous method but giving a default value which will be used if no value has been specified in the configurations file- Throws:
java.lang.ClassNotFoundException
-
getClassArray
public java.lang.Class[] getClassArray(java.lang.String key) throws java.lang.ClassNotFoundException
Get an array ofClass
objects for the class names specified in the given property- Throws:
java.lang.ClassNotFoundException
- if the any of the configured classes is not found
-
getClassArray
public java.lang.Class[] getClassArray(java.lang.String key, java.lang.Class[] defaultValue) throws java.lang.ClassNotFoundException
Get an array ofClass
objects for the class names specified in the given property. Or thedefaultValue
if no value has been given to the property.- Throws:
java.lang.ClassNotFoundException
- if the any of the configured classes is not found
-
getClassArray
public java.lang.Class[] getClassArray(java.lang.String key, Filter filter) throws java.lang.ClassNotFoundException
Similar to the previous methods but complementing the property key with the given filter- Throws:
java.lang.ClassNotFoundException
-
getClassArray
public java.lang.Class[] getClassArray(java.lang.String key, Filter filter, java.lang.Class[] defaultValue) throws java.lang.ClassNotFoundException
Equivalent to the previous method but giving a default value which will be used if no value has been specified in the configurations file- Throws:
java.lang.ClassNotFoundException
-
getFloat
public float getFloat(java.lang.String key)
-
getFloat
public float getFloat(java.lang.String key, float defaultValue)
-
getFloat
public java.lang.Float getFloat(java.lang.String key, java.lang.Float defaultValue)
-
getFloat
public float getFloat(java.lang.String key, Filter filter)
-
getFloat
public java.lang.Float getFloat(java.lang.String key, Filter filter, java.lang.Float defaultValue)
-
getFloat
public float getFloat(java.lang.String key, Filter filter, float defaultValue)
-
getInt
public int getInt(java.lang.String key)
-
getInt
public int getInt(java.lang.String key, int defaultValue)
-
getInteger
public java.lang.Integer getInteger(java.lang.String key, java.lang.Integer defaultValue)
-
getInt
public int getInt(java.lang.String key, Filter filter)
-
getInteger
public java.lang.Integer getInteger(java.lang.String key, Filter filter, java.lang.Integer defaultValue)
-
getInt
public int getInt(java.lang.String key, Filter filter, int defaultValue)
-
getList
public java.util.List getList(java.lang.String key)
-
getList
public java.util.List getList(java.lang.String key, java.util.List defaultValue)
-
getList
public java.util.List getList(java.lang.String key, Filter filter)
-
getList
public java.util.List getList(java.lang.String key, Filter filter, java.util.List defaultValue)
-
getLong
public long getLong(java.lang.String key)
-
getLong
public java.lang.Long getLong(java.lang.String key, java.lang.Long defaultValue)
-
getLong
public long getLong(java.lang.String key, long defaultValue)
-
getLong
public long getLong(java.lang.String key, Filter filter)
-
getLong
public java.lang.Long getLong(java.lang.String key, Filter filter, java.lang.Long defaultValue)
-
getLong
public long getLong(java.lang.String key, Filter filter, long defaultValue)
-
getShort
public short getShort(java.lang.String key)
-
getShort
public java.lang.Short getShort(java.lang.String key, java.lang.Short defaultValue)
-
getShort
public short getShort(java.lang.String key, short defaultValue)
-
getShort
public short getShort(java.lang.String key, Filter filter)
-
getShort
public java.lang.Short getShort(java.lang.String key, Filter filter, java.lang.Short defaultValue)
-
getShort
public short getShort(java.lang.String key, Filter filter, short defaultValue)
-
getString
public java.lang.String getString(java.lang.String key)
Get the String value of the given key. If it contains a list of values, they will be serialized to a comma-separated format (use getList or getStringArray if you want separated list items)
-
getString
public java.lang.String getString(java.lang.String key, java.lang.String defaultValue)
-
getString
public java.lang.String getString(java.lang.String key, Filter filter)
-
getString
public java.lang.String getString(java.lang.String key, Filter filter, java.lang.String defaultValue)
-
getStringArray
public java.lang.String[] getStringArray(java.lang.String key)
-
getStringArray
public java.lang.String[] getStringArray(java.lang.String key, Filter filter)
-
getStringArray
public java.lang.String[] getStringArray(java.lang.String key, Filter filter, java.lang.String[] defaultValue)
-
getStringArray
public java.lang.String[] getStringArray(java.lang.String key, java.lang.String[] defaultValue)
-
hasBaseConfiguration
public boolean hasBaseConfiguration()
-
getLoadedSources
public java.util.List getLoadedSources()
Get a list of the sources which have been loaded for this component
-
setThrowExceptionOnMissing
public void setThrowExceptionOnMissing(boolean throwExceptionOnMissing)
Set the flag throwExceptionOnMissing. See the class documentation for more details.
-
isThrowExceptionOnMissing
public boolean isThrowExceptionOnMissing()
-
getDelayPeriod
public java.lang.Long getDelayPeriod()
Returned the configured delay period for this component or null if reloading is not being performed
-
getComponentName
public java.lang.String getComponentName()
-
getPropertyWithFilter
protected java.lang.Object getPropertyWithFilter(java.lang.String key, Filter filter, java.lang.Class theClass, java.lang.Object defaultValue)
-
getTypedPropertyWithDefault
protected static java.lang.Object getTypedPropertyWithDefault(java.lang.String key, java.lang.Class theClass, Configuration properties, java.lang.Object defaultValue)
-
validateValue
protected void validateValue(java.lang.String key, java.lang.Object value)
-
listToString
protected java.lang.String listToString(java.util.List list)
-
-