|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object
|
+--java.util.Dictionary
|
+--java.util.Hashtable
|
+--java.util.Properties
|
+--javatools.util.Props
An extended version of Properties class. It allows reading Properties files from the classpath or resource file. It uses ClassLoader.getResourceAsStream to find a properties file, so that means it either has to be on the classpath or bundled into the jar.
It is intended that you only pass a single string to find the properties like "foo". That will cause Props to search for a file called foo.properties. The directory it searches in will be by default the "res/" directory. That means that it will search your classpath or jar file for a file res/foo.properties. If you run your software in different environments you can pass a system property to the java virtual machine called "environment". In that case the searching will descend another directory level. e.g. if you pass -Denvironment=development, then it will first look for a file res/development/foo.properties. If you are using servlets your servlet engine should have a means to pass in system variables.
This makes it easy to integrate properties into your code. All you do is use Props to find a certain class of property, like "foo" and it will take care of where to physically find the file. And you can set up different properties for different environments.
TODO: make it combine the environment and non-environment specific properties into the one set.
| Field Summary |
| Fields inherited from class java.util.Properties |
defaults |
| Method Summary | |
java.lang.String |
getFullName()
Returns the full name for this Props. |
static java.lang.String |
getLocalConfigDir()
Returns the local configuration directory. |
void |
load()
Loads properties. |
void |
loadLocalConfig()
Loads local configuration file. |
void |
loadResources()
Loads resources (aka properties). |
void |
reset()
Resets all this Props. |
static Props |
singleton(java.lang.String name)
Returns a brand new Props object referencing properties of the given name. |
void |
store()
Stores properties in a file. |
| Methods inherited from class java.util.Properties |
getProperty, getProperty, list, list, load, propertyNames, save, setProperty, store |
| Methods inherited from class java.util.Hashtable |
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values |
| Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Method Detail |
public static Props singleton(java.lang.String name)
throws java.io.IOException
name - The name of properties file to load.
java.io.IOException - If they cannot be loaded.public static java.lang.String getLocalConfigDir()
public java.lang.String getFullName()
public void reset()
throws ResetException
reset in interface ResetableResetException - If something goes wrong.
public void load()
throws java.io.IOException
java.io.IOException - If properties cannot be loaded.
public void store()
throws java.io.IOException
java.io.IOException - If properties cannot be stored.
public void loadLocalConfig()
throws java.io.IOException
java.io.IOException - If file cannot be found.
public void loadResources()
throws java.io.IOException
java.io.IOException - If properties cannot be loaded.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||