|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.melati.util.PropertiesUtils
public final class PropertiesUtils
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 |
---|
public static Properties fromFile(File path) throws IOException
Properties
object from a file.
path
- a File
path name
Properties
object
IOException
- if there is a problem loading the filepublic static Properties fromResource(Class<?> clazz, String name) throws IOException
Properties
object from a Class
.
clazz
- the Class
to look upname
- the property file name
Properties
object
IOException
- if the file cannot load or is not foundpublic static String getOrDie(Properties properties, String propertyName) throws NoSuchPropertyException
properties
- the Properties
object to look inpropertyName
- the property to get
NoSuchPropertyException
- if the property is not setpublic static String getOrDefault(Properties properties, String propertyName, String def)
properties
- the Properties
object to look inpropertyName
- the property to getdef
- the default to return if not found
public static int getOrDie_int(Properties properties, String propertyName) throws NoSuchPropertyException, FormatPropertyException
properties
- the Properties
object to look inpropertyName
- the property to get
NoSuchPropertyException
- if it is not found
FormatPropertyException
- if it is not an Integerpublic static int getOrDefault_int(Properties properties, String propertyName, int def) throws FormatPropertyException
Properties
object or make a fuss.
properties
- a Properties
propertyName
- the name of the propertydef
- cater for multiple definitions, with increment numbers
FormatPropertyException
- if it is not an Integerpublic static Object instanceOfNamedClass(String className, String interfaceClassName) throws InstantiationPropertyException
className
- the name of the classinterfaceClassName
- the interface Class name
InstantiationPropertyException
- if the named class does not descend from the interfacepublic static Object instanceOfNamedClass(Properties properties, String propertyName, String interfaceClassName, String defaultName) throws InstantiationPropertyException
properties
- a Properties
propertyName
- the name of the propertyinterfaceClassName
- the interface namedefaultName
- a default concrete class if the property is undefined
InstantiationPropertyException
- if there is a problem
|
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |