Class ComponentProperties

java.lang.Object
com.germinus.easyconf.ComponentProperties

public class ComponentProperties extends 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 the Configuration 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 Details

    • NULL_STRING

      public static final String NULL_STRING
    • EMPTY_LIST

      private static final List EMPTY_LIST
    • log

      private static final Log log
    • properties

  • Constructor Details

  • Method Details

    • toMap

      public 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 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 Object getProperty(String key)
    • containsKey

      public boolean containsKey(String key)
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • getKeys

      public Iterator getKeys()
    • getKeys

      public Iterator getKeys(String prefix)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • isEmpty

      public boolean isEmpty()
    • setProperty

      public void setProperty(String key, Object value)
    • subset

      public Configuration subset(String prefix)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getBigDecimal

      public BigDecimal getBigDecimal(String key)
    • getBigDecimal

      public BigDecimal getBigDecimal(String key, BigDecimal defaultValue)
    • getBigDecimal

      public BigDecimal getBigDecimal(String key, Filter filter)
    • getBigDecimal

      public BigDecimal getBigDecimal(String key, Filter filter, BigDecimal defaultValue)
    • getBigInteger

      public BigInteger getBigInteger(String key)
    • getBigInteger

      public BigInteger getBigInteger(String key, BigInteger defaultValue)
    • getBigInteger

      public BigInteger getBigInteger(String key, Filter filter)
    • getBigInteger

      public BigInteger getBigInteger(String key, Filter filter, BigInteger defaultValue)
    • getBoolean

      public boolean getBoolean(String key)
    • getBoolean

      public boolean getBoolean(String key, boolean defaultValue)
    • getBoolean

      public Boolean getBoolean(String key, Boolean defaultValue) throws NoClassDefFoundError
      Throws:
      NoClassDefFoundError
    • getBoolean

      public boolean getBoolean(String key, Filter filter)
    • getBoolean

      public Boolean getBoolean(String key, Filter filter, Boolean defaultValue) throws NoClassDefFoundError
      Throws:
      NoClassDefFoundError
    • getBoolean

      public boolean getBoolean(String key, Filter filter, boolean defaultValue)
    • getByte

      public byte getByte(String key)
    • getByte

      public byte getByte(String key, byte defaultValue)
    • getByte

      public Byte getByte(String key, Byte defaultValue)
    • getByte

      public byte getByte(String key, Filter filter)
    • getByte

      public Byte getByte(String key, Filter filter, Byte defaultValue)
    • getByte

      public byte getByte(String key, Filter filter, byte defaultValue)
    • getDouble

      public double getDouble(String key)
    • getDouble

      public double getDouble(String key, double defaultValue)
    • getDouble

      public Double getDouble(String key, Double defaultValue)
    • getDouble

      public double getDouble(String key, Filter filter)
    • getDouble

      public Double getDouble(String key, Filter filter, Double defaultValue)
    • getDouble

      public double getDouble(String key, Filter filter, double defaultValue)
    • getClass

      public Class getClass(String key) throws ClassNotFoundException
      Get the Class representation of the class name specified in the given property
      Throws:
      ClassNotFoundException - if the specified class is not found
    • getClass

      public Class getClass(String key, Class defaultValue) throws ClassNotFoundException
      Get the Class representation of the class name specified in the given property. Or the defaultValue if no value has been given to the property.
      Throws:
      ClassNotFoundException - if a class has been configured but it is not found
    • getClass

      public Class getClass(String key, Filter filter) throws ClassNotFoundException
      Similar to the previous methods but complementing the property key with the given filter
      Throws:
      ClassNotFoundException
    • getClass

      public Class getClass(String key, Filter filter, Class defaultValue) throws 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:
      ClassNotFoundException
    • getClassArray

      public Class[] getClassArray(String key) throws ClassNotFoundException
      Get an array of Class objects for the class names specified in the given property
      Throws:
      ClassNotFoundException - if the any of the configured classes is not found
    • getClassArray

      public Class[] getClassArray(String key, Class[] defaultValue) throws ClassNotFoundException
      Get an array of Class objects for the class names specified in the given property. Or the defaultValue if no value has been given to the property.
      Throws:
      ClassNotFoundException - if the any of the configured classes is not found
    • getClassArray

      public Class[] getClassArray(String key, Filter filter) throws ClassNotFoundException
      Similar to the previous methods but complementing the property key with the given filter
      Throws:
      ClassNotFoundException
    • getClassArray

      public Class[] getClassArray(String key, Filter filter, Class[] defaultValue) throws 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:
      ClassNotFoundException
    • getFloat

      public float getFloat(String key)
    • getFloat

      public float getFloat(String key, float defaultValue)
    • getFloat

      public Float getFloat(String key, Float defaultValue)
    • getFloat

      public float getFloat(String key, Filter filter)
    • getFloat

      public Float getFloat(String key, Filter filter, Float defaultValue)
    • getFloat

      public float getFloat(String key, Filter filter, float defaultValue)
    • getInt

      public int getInt(String key)
    • getInt

      public int getInt(String key, int defaultValue)
    • getInteger

      public Integer getInteger(String key, Integer defaultValue)
    • getInt

      public int getInt(String key, Filter filter)
    • getInteger

      public Integer getInteger(String key, Filter filter, Integer defaultValue)
    • getInt

      public int getInt(String key, Filter filter, int defaultValue)
    • getList

      public List getList(String key)
    • getList

      public List getList(String key, List defaultValue)
    • getList

      public List getList(String key, Filter filter)
    • getList

      public List getList(String key, Filter filter, List defaultValue)
    • getLong

      public long getLong(String key)
    • getLong

      public Long getLong(String key, Long defaultValue)
    • getLong

      public long getLong(String key, long defaultValue)
    • getLong

      public long getLong(String key, Filter filter)
    • getLong

      public Long getLong(String key, Filter filter, Long defaultValue)
    • getLong

      public long getLong(String key, Filter filter, long defaultValue)
    • getShort

      public short getShort(String key)
    • getShort

      public Short getShort(String key, Short defaultValue)
    • getShort

      public short getShort(String key, short defaultValue)
    • getShort

      public short getShort(String key, Filter filter)
    • getShort

      public Short getShort(String key, Filter filter, Short defaultValue)
    • getShort

      public short getShort(String key, Filter filter, short defaultValue)
    • getString

      public String getString(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 String getString(String key, String defaultValue)
    • getString

      public String getString(String key, Filter filter)
    • getString

      public String getString(String key, Filter filter, String defaultValue)
    • getStringArray

      public String[] getStringArray(String key)
    • getStringArray

      public String[] getStringArray(String key, Filter filter)
    • getStringArray

      public String[] getStringArray(String key, Filter filter, String[] defaultValue)
    • getStringArray

      public String[] getStringArray(String key, String[] defaultValue)
    • hasBaseConfiguration

      public boolean hasBaseConfiguration()
    • getLoadedSources

      public 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 Long getDelayPeriod()
      Returned the configured delay period for this component or null if reloading is not being performed
    • getComponentName

      public String getComponentName()
    • getPropertyWithFilter

      protected Object getPropertyWithFilter(String key, Filter filter, Class theClass, Object defaultValue)
    • getTypedPropertyWithDefault

      protected static Object getTypedPropertyWithDefault(String key, Class theClass, Configuration properties, Object defaultValue)
    • validateValue

      protected void validateValue(String key, Object value)
    • listToString

      protected String listToString(List list)