Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

javatools.util
Class Props  view Props download Props.java

java.lang.Object
  extended byjava.util.Dictionary
      extended byjava.util.Hashtable
          extended byjava.util.Properties
              extended byjavatools.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. Last modification: 16/02/2003 12.49

Version:
0.2.0

Nested Class Summary
 
Nested classes inherited from class java.util.Hashtable
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Field Summary
(package private) static java.lang.String defaultLocalConfigDir
          The local configuration file for this Props.
(package private)  java.lang.String fullName
          The complete name for this Props.
(package private) static java.io.File localConfigDirFile
          Contains a file representing where is the local configuration directory.
(package private)  java.io.File localConfigFile
           
(package private) static java.util.Hashtable map
          Contains a map for the keys.
(package private)  java.lang.String name
          The name for this Props.
(package private)  boolean openAsResource
           
(package private)  java.lang.String propsURL
           
(package private)  boolean valid
          Contains a flag indicating if this Props is valid.
 
Fields inherited from class java.util.Properties
defaults
 
Fields inherited from class java.util.Hashtable
 
Constructor Summary
private Props(java.lang.String name, boolean openAsResource)
           
private Props(java.lang.String name, boolean load, boolean openAsResource)
           
 
Method Summary
 java.lang.String getFullName()
          Returns the full name for this Props.
static java.lang.String getLocalConfigDir()
          Returns the local configuration directory.
static java.lang.String getLocalDir()
           
 void load()
           
 void load(boolean openAsResource)
          Loads properties.
protected  void loadAsFile(java.lang.String props)
           
 void loadLocalConfig()
          Loads local configuration file.
(package private)  boolean loadOne(java.lang.ClassLoader cl, java.lang.String props)
          Loads one properties file.
 void loadResources(boolean openAsResource)
          Loads resources (aka properties).
 void reset()
          Resets all this Props.
static void setDefaultLocalConfigDir(java.lang.String defaultLocalConfigDir)
           
static Props singleton(java.lang.String name)
           
static Props singleton(java.lang.String name, boolean openAsResource)
          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, loadFromXML, propertyNames, save, setProperty, store, storeToXML, storeToXML
 
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
Contains a map for the keys.


localConfigDirFile

static java.io.File localConfigDirFile
Contains a file representing where is the local configuration directory.


defaultLocalConfigDir

static java.lang.String defaultLocalConfigDir
The local configuration file for this Props.


localConfigFile

java.io.File localConfigFile

name

java.lang.String name
The name for this Props.


fullName

java.lang.String fullName
The complete name for this Props.


valid

boolean valid
Contains a flag indicating if this Props is valid.


openAsResource

boolean openAsResource

propsURL

java.lang.String propsURL
Constructor Detail

Props

private Props(java.lang.String name,
              boolean openAsResource)
       throws java.io.IOException

Props

private Props(java.lang.String name,
              boolean load,
              boolean openAsResource)
       throws java.io.IOException
Method Detail

singleton

public static Props singleton(java.lang.String name,
                              boolean openAsResource)
                       throws java.io.IOException
Returns a brand new Props object referencing properties of the given name.


singleton

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

setDefaultLocalConfigDir

public static void setDefaultLocalConfigDir(java.lang.String defaultLocalConfigDir)

getLocalConfigDir

public static java.lang.String getLocalConfigDir()
Returns the local configuration directory.


getLocalDir

public static java.lang.String getLocalDir()

getFullName

public java.lang.String getFullName()
Returns the full name for this Props.


reset

public void reset()
           throws ResetException
Resets all this Props.

Specified by:
reset in interface Resetable

load

public void load()
          throws java.io.IOException

load

public void load(boolean openAsResource)
          throws java.io.IOException
Loads properties.


store

public void store()
           throws java.io.IOException
Stores properties in a file.


loadLocalConfig

public void loadLocalConfig()
                     throws java.io.IOException
Loads local configuration file.


loadResources

public void loadResources(boolean openAsResource)
                   throws java.io.IOException
Loads resources (aka properties).


loadOne

boolean loadOne(java.lang.ClassLoader cl,
                java.lang.String props)
          throws java.io.IOException
Loads one properties file.


loadAsFile

protected void loadAsFile(java.lang.String props)
                   throws java.io.IOException