org.melati.util
Class PropertiesUtils

Package class diagram package PropertiesUtils
java.lang.Object
  extended by org.melati.util.PropertiesUtils

public final class PropertiesUtils
extends Object

Useful things to do with properties files.


Method Summary
static Properties fromFile(File path)
          Get a Properties object from a file.
static Properties fromResource(Class<?> clazz, String name)
          Get a Properties object from a Class.
static int getOrDefault_int(Properties properties, String propertyName, int def)
          Get an Integer property from a Properties object or make a fuss.
static String getOrDefault(Properties properties, String propertyName, String def)
          Get a property or return the supplied default.
static int getOrDie_int(Properties properties, String propertyName)
          Get an Integer property.
static String getOrDie(Properties properties, String propertyName)
          Return a property.
static Object instanceOfNamedClass(Properties properties, String propertyName, String interfaceClassName, String defaultName)
          Instantiate a Class.
static Object instanceOfNamedClass(String className, String interfaceClassName)
          Instantiate an interface.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

fromFile

public static Properties fromFile(File path)
                           throws IOException
Get a Properties object from a file.

Parameters:
path - a File path name
Returns:
a Properties object
Throws:
IOException - if there is a problem loading the file

fromResource

public static Properties fromResource(Class<?> clazz,
                                      String name)
                               throws IOException
Get a Properties object from a Class.

Parameters:
clazz - the Class to look up
name - the property file name
Returns:
a Properties object
Throws:
IOException - if the file cannot load or is not found

getOrDie

public static String getOrDie(Properties properties,
                              String propertyName)
                       throws NoSuchPropertyException
Return a property.

Parameters:
properties - the Properties object to look in
propertyName - the property to get
Returns:
the property value
Throws:
NoSuchPropertyException - if the property is not set

getOrDefault

public static String getOrDefault(Properties properties,
                                  String propertyName,
                                  String def)
Get a property or return the supplied default.

Parameters:
properties - the Properties object to look in
propertyName - the property to get
def - the default to return if not found
Returns:
the property value

getOrDie_int

public static int getOrDie_int(Properties properties,
                               String propertyName)
                        throws NoSuchPropertyException,
                               FormatPropertyException
Get an Integer property.

Parameters:
properties - the Properties object to look in
propertyName - the property to get
Returns:
the int property value
Throws:
NoSuchPropertyException - if it is not found
FormatPropertyException - if it is not an Integer

getOrDefault_int

public static int getOrDefault_int(Properties properties,
                                   String propertyName,
                                   int def)
                            throws FormatPropertyException
Get an Integer property from a Properties object or make a fuss.

Parameters:
properties - a Properties
propertyName - the name of the property
def - cater for multiple definitions, with increment numbers
Returns:
the property as an int
Throws:
FormatPropertyException - if it is not an Integer

instanceOfNamedClass

public static Object instanceOfNamedClass(String className,
                                          String interfaceClassName)
                                   throws InstantiationPropertyException
Instantiate an interface.

Parameters:
className - the name of the class
interfaceClassName - the interface Class name
Returns:
a new object
Throws:
InstantiationPropertyException - if the named class does not descend from the interface

instanceOfNamedClass

public static Object instanceOfNamedClass(Properties properties,
                                          String propertyName,
                                          String interfaceClassName,
                                          String defaultName)
                                   throws InstantiationPropertyException
Instantiate a Class.

Parameters:
properties - a Properties
propertyName - the name of the property
interfaceClassName - the interface name
defaultName - a default concrete class if the property is undefined
Returns:
a new Object
Throws:
InstantiationPropertyException - if there is a problem


Copyright © 2000-2010 PanEris. All Rights Reserved.