org.openmobileis.common.util
Class PropertiesManager

java.lang.Object
  extended byorg.openmobileis.common.util.PropertiesManager

public class PropertiesManager
extends java.lang.Object

Use to manage application properties. Application properties files should be stored in a folder called "properties" inside the classpath. Not mandatory but its a project practice. Otherwise the manager looks in the classpath for file properties Implements singleton pattern. Use getManager method to get access to the application resource manager Propertie file can contain fields that begin with $. These fields are replaced when loaded by system property first that PropertiesManager property For exemple if you define in the propery file the following property : if system user.dir is /home/application myproperty=$user.dir/somepath/file The property loaded will be myproperty=/home/application/somepath/file

Since:
JDK 1.1
Version:
1.0
Author:
Philippe Delrieu

Field Summary
 java.util.Properties globalProperties
           
static PropertiesManager instance
           
 
Constructor Summary
protected PropertiesManager()
           
 
Method Summary
 void addPropertiesFile(java.lang.String filename)
          load a property file inside the classpath.
 void addPropertiesFileFromFilePath(java.lang.String filename)
          load a property file from the file system If not found throw IOException
 void addProperty(java.lang.String key, java.lang.String value)
          add the specified key,value to the manager properties
protected  java.io.InputStream convertPropertiesFile(java.io.InputStream inStream)
           
static PropertiesManager getManager()
          main method to get ResourceManager
 java.util.Properties getProperties()
          return all the loaded properties
 java.util.Properties getProperties(java.lang.String prop_file)
          read the property file inside the classpath.
 java.util.Properties getPropertiesFromPath(java.lang.String prop_file)
          read the property file from the file system Does not load it
 java.lang.String getProperty(java.lang.String key)
          return the property with specified key from loaded properties.
 java.lang.String getProperty(java.lang.String key, java.lang.String defaultValue)
          return the property with specified key from loaded properties.
 java.io.InputStream getRessourceAsStream(java.lang.String name)
           
static void registerInstance(PropertiesManager manager)
          Use to register another ResourceManager.
 void removeAllProperties()
          remove all resource manager properties
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instance

public static PropertiesManager instance

globalProperties

public java.util.Properties globalProperties
Constructor Detail

PropertiesManager

protected PropertiesManager()
Method Detail

removeAllProperties

public void removeAllProperties()
remove all resource manager properties


getManager

public static PropertiesManager getManager()
main method to get ResourceManager

Returns:
application properties manager

registerInstance

public static void registerInstance(PropertiesManager manager)
Use to register another ResourceManager.

Parameters:
manager - : properties manager to register

getRessourceAsStream

public java.io.InputStream getRessourceAsStream(java.lang.String name)
                                         throws java.io.IOException
Throws:
java.io.IOException

addPropertiesFile

public void addPropertiesFile(java.lang.String filename)
                       throws java.io.IOException
load a property file inside the classpath. if the path is /org/openmobileis/file.properties First look in the classpath for /properties/org/openmobileis/file.properties then in /org/openmobileis/file.properties. If not found throw IOException

Parameters:
filename - : properties file name.
Throws:
java.io.IOException - : throws if the file is not found

addPropertiesFileFromFilePath

public void addPropertiesFileFromFilePath(java.lang.String filename)
                                   throws java.io.IOException
load a property file from the file system If not found throw IOException

Parameters:
filename - : properties file name.
Throws:
java.io.IOException - : throws if the file is not found

getProperties

public java.util.Properties getProperties(java.lang.String prop_file)
                                   throws java.io.IOException
read the property file inside the classpath. Does not load it if the path is /org/openmobileis/file.properties First looks in the classpath for /properties/org/openmobileis/file.properties then for /org/openmobileis/file.properties. If not found throw IOException

Throws:
java.io.IOException - : throws if the file is not found

getPropertiesFromPath

public java.util.Properties getPropertiesFromPath(java.lang.String prop_file)
                                           throws java.io.IOException
read the property file from the file system Does not load it

Throws:
java.io.IOException - : throws if the file is not found

getProperties

public java.util.Properties getProperties()
return all the loaded properties

Returns:
the loaded properties

getProperty

public java.lang.String getProperty(java.lang.String key,
                                    java.lang.String defaultValue)
return the property with specified key from loaded properties. return default value if not found.

Parameters:
key - : the property key to get
defaultValue - : default value if key is not found
Returns:
the property with specified key or default value if not found.

getProperty

public java.lang.String getProperty(java.lang.String key)
return the property with specified key from loaded properties. return null if not found.

Parameters:
key - : the property key to get
Returns:
the property with specified key or null if not found.

addProperty

public void addProperty(java.lang.String key,
                        java.lang.String value)
add the specified key,value to the manager properties

Parameters:
key - : the property key
value - : value of the property

convertPropertiesFile

protected java.io.InputStream convertPropertiesFile(java.io.InputStream inStream)
                                             throws java.io.IOException
Throws:
java.io.IOException


Copyright 2006 OpenMobileIS. All Rights Reserved.