javatools.util
Class Props

java.lang.Object
  |
  +--java.util.Dictionary
        |
        +--java.util.Hashtable
              |
              +--java.util.Properties
                    |
                    +--javatools.util.Props
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, Resetable, java.io.Serializable

public class Props
extends java.util.Properties
implements Resetable

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.

See Also:
Serialized Form

Nested Class Summary
(package private) static class Props.Key
           
 
Field Summary
(package private)  java.lang.ClassLoader cl
           
(package private)  java.lang.String fullName
           
(package private) static java.io.File localConfigDirFile
           
(package private)  java.io.File localConfigFile
           
(package private) static java.util.Hashtable map
           
(package private)  java.lang.String name
           
(package private)  boolean valid
           
 
Fields inherited from class java.util.Properties
defaults
 
Method Summary
 java.lang.ClassLoader getClassLoader()
           
 java.lang.String getFullName()
           
(package private) static java.lang.String getLocalConfigDir()
           
 java.util.List getPropertyList(java.lang.String propertyName)
           
 java.util.StringTokenizer getTokenizer(java.lang.String propertyName)
          Assumes that there is a property containing a list of things (probably, but not necessarily classes to load).
 void load()
           
 void loadLocalConfig()
           
(package private)  boolean loadOne(java.lang.ClassLoader cl, java.lang.String props)
           
 void loadResources()
           
static java.util.StringTokenizer makeTokenizer(java.lang.String names)
           
 void reset()
           
static Props singleton(java.lang.String name)
           
static Props singleton(java.lang.String name, java.lang.ClassLoader cl)
           
 void store()
           
 
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
 

Field Detail

map

static java.util.Hashtable map

localConfigDirFile

static java.io.File localConfigDirFile

localConfigFile

java.io.File localConfigFile

name

java.lang.String name

fullName

java.lang.String fullName

valid

boolean valid

cl

java.lang.ClassLoader cl
Method Detail

singleton

public static Props singleton(java.lang.String name)
                       throws java.io.IOException
java.io.IOException

singleton

public static Props singleton(java.lang.String name,
                              java.lang.ClassLoader cl)
                       throws java.io.IOException
java.io.IOException

makeTokenizer

public static java.util.StringTokenizer makeTokenizer(java.lang.String names)

getLocalConfigDir

static java.lang.String getLocalConfigDir()

getClassLoader

public java.lang.ClassLoader getClassLoader()

getFullName

public java.lang.String getFullName()

getTokenizer

public java.util.StringTokenizer getTokenizer(java.lang.String propertyName)
Assumes that there is a property containing a list of things (probably, but not necessarily classes to load). This returns a StringTokenizer for parsing that list.

Parameters:
propertyName - Description of Parameter
Returns:
The tokenizer value

getPropertyList

public java.util.List getPropertyList(java.lang.String propertyName)

reset

public void reset()
           throws ResetException
Specified by:
reset in interface Resetable
ResetException

load

public void load()
          throws java.io.IOException
java.io.IOException

store

public void store()
           throws java.io.IOException
java.io.IOException

loadLocalConfig

public void loadLocalConfig()
                     throws java.io.IOException
java.io.IOException

loadResources

public void loadResources()
                   throws java.io.IOException
java.io.IOException

loadOne

boolean loadOne(java.lang.ClassLoader cl,
                java.lang.String props)
          throws java.io.IOException
java.io.IOException