Package com.germinus.easyconf
Class ComponentProperties
- java.lang.Object
-
- com.germinus.easyconf.ComponentProperties
-
public class ComponentProperties extends java.lang.ObjectPart 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 theConfigurationinterface 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.ListEMPTY_LISTprivate static Loglogstatic java.lang.StringNULL_STRING(package private) AggregatedPropertiesproperties
-
Constructor Summary
Constructors Constructor Description ComponentProperties(AggregatedProperties conf)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsKey(java.lang.String key)booleanequals(java.lang.Object obj)java.math.BigDecimalgetBigDecimal(java.lang.String key)java.math.BigDecimalgetBigDecimal(java.lang.String key, Filter filter)java.math.BigDecimalgetBigDecimal(java.lang.String key, Filter filter, java.math.BigDecimal defaultValue)java.math.BigDecimalgetBigDecimal(java.lang.String key, java.math.BigDecimal defaultValue)java.math.BigIntegergetBigInteger(java.lang.String key)java.math.BigIntegergetBigInteger(java.lang.String key, Filter filter)java.math.BigIntegergetBigInteger(java.lang.String key, Filter filter, java.math.BigInteger defaultValue)java.math.BigIntegergetBigInteger(java.lang.String key, java.math.BigInteger defaultValue)booleangetBoolean(java.lang.String key)booleangetBoolean(java.lang.String key, boolean defaultValue)booleangetBoolean(java.lang.String key, Filter filter)booleangetBoolean(java.lang.String key, Filter filter, boolean defaultValue)java.lang.BooleangetBoolean(java.lang.String key, Filter filter, java.lang.Boolean defaultValue)java.lang.BooleangetBoolean(java.lang.String key, java.lang.Boolean defaultValue)bytegetByte(java.lang.String key)bytegetByte(java.lang.String key, byte defaultValue)bytegetByte(java.lang.String key, Filter filter)bytegetByte(java.lang.String key, Filter filter, byte defaultValue)java.lang.BytegetByte(java.lang.String key, Filter filter, java.lang.Byte defaultValue)java.lang.BytegetByte(java.lang.String key, java.lang.Byte defaultValue)java.lang.ClassgetClass(java.lang.String key)Get theClassrepresentation of the class name specified in the given propertyjava.lang.ClassgetClass(java.lang.String key, Filter filter)Similar to the previous methods but complementing the property key with the given filterjava.lang.ClassgetClass(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.ClassgetClass(java.lang.String key, java.lang.Class defaultValue)Get theClassrepresentation of the class name specified in the given property.java.lang.Class[]getClassArray(java.lang.String key)Get an array ofClassobjects 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 ofClassobjects for the class names specified in the given property.java.lang.StringgetComponentName()java.lang.LonggetDelayPeriod()Returned the configured delay period for this component or null if reloading is not being performeddoublegetDouble(java.lang.String key)doublegetDouble(java.lang.String key, double defaultValue)doublegetDouble(java.lang.String key, Filter filter)doublegetDouble(java.lang.String key, Filter filter, double defaultValue)java.lang.DoublegetDouble(java.lang.String key, Filter filter, java.lang.Double defaultValue)java.lang.DoublegetDouble(java.lang.String key, java.lang.Double defaultValue)floatgetFloat(java.lang.String key)floatgetFloat(java.lang.String key, float defaultValue)floatgetFloat(java.lang.String key, Filter filter)floatgetFloat(java.lang.String key, Filter filter, float defaultValue)java.lang.FloatgetFloat(java.lang.String key, Filter filter, java.lang.Float defaultValue)java.lang.FloatgetFloat(java.lang.String key, java.lang.Float defaultValue)intgetInt(java.lang.String key)intgetInt(java.lang.String key, int defaultValue)intgetInt(java.lang.String key, Filter filter)intgetInt(java.lang.String key, Filter filter, int defaultValue)java.lang.IntegergetInteger(java.lang.String key, Filter filter, java.lang.Integer defaultValue)java.lang.IntegergetInteger(java.lang.String key, java.lang.Integer defaultValue)java.util.IteratorgetKeys()java.util.IteratorgetKeys(java.lang.String prefix)java.util.ListgetList(java.lang.String key)java.util.ListgetList(java.lang.String key, Filter filter)java.util.ListgetList(java.lang.String key, Filter filter, java.util.List defaultValue)java.util.ListgetList(java.lang.String key, java.util.List defaultValue)java.util.ListgetLoadedSources()Get a list of the sources which have been loaded for this componentlonggetLong(java.lang.String key)longgetLong(java.lang.String key, long defaultValue)longgetLong(java.lang.String key, Filter filter)longgetLong(java.lang.String key, Filter filter, long defaultValue)java.lang.LonggetLong(java.lang.String key, Filter filter, java.lang.Long defaultValue)java.lang.LonggetLong(java.lang.String key, java.lang.Long defaultValue)java.util.PropertiesgetProperties()Returns a copy of the configuration into a java.util.Properties class.java.lang.ObjectgetProperty(java.lang.String key)protected java.lang.ObjectgetPropertyWithFilter(java.lang.String key, Filter filter, java.lang.Class theClass, java.lang.Object defaultValue)shortgetShort(java.lang.String key)shortgetShort(java.lang.String key, short defaultValue)shortgetShort(java.lang.String key, Filter filter)shortgetShort(java.lang.String key, Filter filter, short defaultValue)java.lang.ShortgetShort(java.lang.String key, Filter filter, java.lang.Short defaultValue)java.lang.ShortgetShort(java.lang.String key, java.lang.Short defaultValue)java.lang.StringgetString(java.lang.String key)Get the String value of the given key.java.lang.StringgetString(java.lang.String key, Filter filter)java.lang.StringgetString(java.lang.String key, Filter filter, java.lang.String defaultValue)java.lang.StringgetString(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.ObjectgetTypedPropertyWithDefault(java.lang.String key, java.lang.Class theClass, Configuration properties, java.lang.Object defaultValue)booleanhasBaseConfiguration()inthashCode()booleanisEmpty()booleanisThrowExceptionOnMissing()protected java.lang.StringlistToString(java.util.List list)voidsetProperty(java.lang.String key, java.lang.Object value)voidsetThrowExceptionOnMissing(boolean throwExceptionOnMissing)Set the flag throwExceptionOnMissing.Configurationsubset(java.lang.String prefix)ConfigurationtoConfiguration()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.DataConfigurationtoDataConfiguration()Returns a decorator of the configuration of type org.apache.commons.configuration.DataConfiguration.DynaBeantoDynaBean()Returns a decorator of the configuration that can be used as a DynaBean.java.util.MaptoMap()Returns a decorator of the configuration that implements the Map interface.java.lang.StringtoString()protected voidvalidateValue(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.Mapinstance
-
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
DynaBeaninstance
-
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
Configurationinstance
-
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
DataConfigurationinstance
-
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
Propertiesinstance
-
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:
equalsin classjava.lang.Object
-
getKeys
public java.util.Iterator getKeys()
-
getKeys
public java.util.Iterator getKeys(java.lang.String prefix)
-
hashCode
public int hashCode()
- Overrides:
hashCodein 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:
toStringin 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.ClassNotFoundExceptionGet theClassrepresentation 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.ClassNotFoundExceptionGet theClassrepresentation of the class name specified in the given property. Or thedefaultValueif 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.ClassNotFoundExceptionSimilar 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.ClassNotFoundExceptionEquivalent 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.ClassNotFoundExceptionGet an array ofClassobjects 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.ClassNotFoundExceptionGet an array ofClassobjects for the class names specified in the given property. Or thedefaultValueif 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.ClassNotFoundExceptionSimilar 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.ClassNotFoundExceptionEquivalent 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)
-
-