net.sf.mybatchfwk.utils
Class PropertiesLoader

java.lang.Object
  extended by net.sf.mybatchfwk.utils.PropertiesLoader

public class PropertiesLoader
extends java.lang.Object

The PropertiesLoader class is used to load a configuration from a file, and initialize all the fields of an object using the annotations.

Author:
Jérôme Bertèche (cyberteche@users.sourceforge.net)

Constructor Summary
PropertiesLoader(java.util.Properties properties)
           
 
Method Summary
 void addProperty(java.lang.String key, java.lang.String value)
          Add the given property
 void assignProperties(java.lang.Object object)
          Assign the configuration properties to an object using the annotations.
 boolean getBooleanProperty(java.lang.String key)
          Retrieve a boolean from a string property
 java.text.DateFormat getDateFormat()
           
 java.util.Date getDateProperty(java.lang.String key)
          Retrieve a date from a string property
 int getIntegerProperty(java.lang.String key)
          Retrieve an integer from a string property
 long getLongProperty(java.lang.String key)
          Retrieve a long from a string property
 java.util.Properties getProperties()
           
static java.util.Properties getProperties(java.lang.String fileName)
          Load properties stored into a properties configuration file
 java.lang.String getProperty(java.lang.String key)
          Return the property designed by the given key
static java.lang.reflect.Field[] getPropertyFields(java.lang.Class clazz)
          Return the fields that owns an annotation of type Property
 short getShortProperty(java.lang.String key)
          Retrieve a short from a string property
 void setDateFormat(java.text.DateFormat dateFormat)
           
 void setProperties(java.util.Properties properties)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertiesLoader

public PropertiesLoader(java.util.Properties properties)
Parameters:
properties -
Method Detail

getProperties

public static java.util.Properties getProperties(java.lang.String fileName)
                                          throws java.io.IOException
Load properties stored into a properties configuration file

Returns:
the properties of the configuration file
Throws:
java.io.IOException - if the configuration file cannot be find into the classpath or if it cannot be parsed (not a properties file)

getPropertyFields

public static java.lang.reflect.Field[] getPropertyFields(java.lang.Class clazz)
Return the fields that owns an annotation of type Property

Parameters:
clazz -
Returns:

assignProperties

public void assignProperties(java.lang.Object object)
                      throws java.lang.IllegalArgumentException,
                             java.lang.IllegalAccessException,
                             java.text.ParseException
Assign the configuration properties to an object using the annotations.
For each field that own an annotation of type Property, we retrieve the key of this annotation. Next we retrieve the value into the configuration that corresponds to this key. Finally, this value is assigned to the field of the object.

Parameters:
object -
Throws:
java.lang.IllegalArgumentException
java.lang.IllegalAccessException
java.text.ParseException

getBooleanProperty

public boolean getBooleanProperty(java.lang.String key)
Retrieve a boolean from a string property

Parameters:
key -
Returns:

getIntegerProperty

public int getIntegerProperty(java.lang.String key)
Retrieve an integer from a string property

Parameters:
key -
Returns:

getShortProperty

public short getShortProperty(java.lang.String key)
Retrieve a short from a string property

Parameters:
key -
Returns:

getLongProperty

public long getLongProperty(java.lang.String key)
Retrieve a long from a string property

Parameters:
key -
Returns:

getDateProperty

public java.util.Date getDateProperty(java.lang.String key)
                               throws java.text.ParseException
Retrieve a date from a string property

Parameters:
key -
Returns:
Throws:
java.text.ParseException

getProperty

public java.lang.String getProperty(java.lang.String key)
Return the property designed by the given key

Parameters:
key -
Returns:

addProperty

public void addProperty(java.lang.String key,
                        java.lang.String value)
Add the given property

Parameters:
key -
value -

getDateFormat

public java.text.DateFormat getDateFormat()
Returns:
the dateFormat

setDateFormat

public void setDateFormat(java.text.DateFormat dateFormat)
Parameters:
dateFormat - the dateFormat to set

getProperties

public java.util.Properties getProperties()
Returns:
the properties

setProperties

public void setProperties(java.util.Properties properties)
Parameters:
properties - the properties to set


Copyright © 2006 null. All Rights Reserved.