dist1.acb.common
Class ConfigManager

java.lang.Object
  extended bydist1.acb.common.ConfigManager

public class ConfigManager
extends java.lang.Object

Config Manager See documentation of java.util.Properties

Version:
$Revision: 1.19 $
Author:
Alexander Stasiv

Method Summary
 java.lang.String constructFullPath(java.lang.String relativePath)
          Getter for property appWorkPath.
protected  void finalize()
           
static ConfigManager getInstance()
          Get instance of the manager
 int getIntProperty(java.lang.String key)
          Get value of a integer property
 int getIntProperty(java.lang.String key, int defaultValue)
          Get value of a integer property.
 java.lang.String getLogProperty(java.lang.String key)
          Get value of a property of the Log System
 java.lang.String getLogProperty(java.lang.String key, java.lang.String defaultValue)
          Get value of a property of the Log System.
 java.lang.String getProperty(java.lang.String key)
          Get value of a property
 java.lang.String getProperty(java.lang.String key, java.lang.String defaultValue)
          Get value of a property.
 java.io.InputStream getResource(java.lang.String resourceName)
          Returns input stream to a resource
 java.net.URL getResourceURL(java.lang.String resourceName)
          Returns input stream to a resource
 void init(java.lang.String sysPath, java.lang.String appPath, java.lang.String resourcesPath)
          Initialize the Config Manager.
 void load()
          Binds working directory fo the application to the directory and load configuration
 void loadDefaults(java.io.InputStream mainConfigStream, java.io.InputStream logConfigStream)
          Used for loading default configuration.
 java.util.Enumeration logPropertyNames()
          Returns an enumeration of all the keys in the property list of log system, including distinct keys in the default property list if a key of the same name has not already been found from the main properties list.
 java.util.Enumeration propertyNames()
          Returns an enumeration of all the keys in the property list of main configuration, including distinct keys in the default property list if a key of the same name has not already been found from the main properties list.
 void setAppWorkPath(java.lang.String appWorkPath)
          Setter for property appWorkPath.
 void setIntProperty(java.lang.String key, int property)
          Set value of a integer property
 void setLogProperty(java.lang.String key, java.lang.String property)
          Set value of a property of the Log System
 void setProperty(java.lang.String key, java.lang.String property)
          Set value of a property
 void store()
          Store the configuration
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static ConfigManager getInstance()
Get instance of the manager

Returns:
The manager

setAppWorkPath

public void setAppWorkPath(java.lang.String appWorkPath)
Setter for property appWorkPath.

Parameters:
appWorkPath - New value of property appWorkPath.

setIntProperty

public void setIntProperty(java.lang.String key,
                           int property)
Set value of a integer property

Parameters:
key - key of the property
property - Value

getIntProperty

public int getIntProperty(java.lang.String key,
                          int defaultValue)
Get value of a integer property. The method returns the default value argument if the property is not found or it can cast the vale to int.

Parameters:
key - key of the property
defaultValue - a default value.
Returns:
Value of the the property
Throws:
java.lang.NumberFormatException - internal exception

getIntProperty

public int getIntProperty(java.lang.String key)
                   throws java.util.NoSuchElementException,
                          java.lang.NumberFormatException
Get value of a integer property

Parameters:
key - key of the property
Returns:
Value of the the property
Throws:
java.util.NoSuchElementException - if the property with key was not found
java.lang.NumberFormatException - if the value can't be casted to a integer

setLogProperty

public void setLogProperty(java.lang.String key,
                           java.lang.String property)
Set value of a property of the Log System

Parameters:
key - key of the property
property - Value

getLogProperty

public java.lang.String getLogProperty(java.lang.String key,
                                       java.lang.String defaultValue)
Get value of a property of the Log System. The method returns the default value argument if the property is not found.

Parameters:
key - key of the property
defaultValue - a default value.
Returns:
Value of the the property

getLogProperty

public java.lang.String getLogProperty(java.lang.String key)
                                throws java.util.NoSuchElementException
Get value of a property of the Log System

Parameters:
key - key of the property
Returns:
Value of the the property
Throws:
java.util.NoSuchElementException - if the property with key was not found

setProperty

public void setProperty(java.lang.String key,
                        java.lang.String property)
Set value of a property

Parameters:
key - key of the property
property - Value

getProperty

public java.lang.String getProperty(java.lang.String key,
                                    java.lang.String defaultValue)
Get value of a property. The method returns the default value argument if the property is not found.

Parameters:
key - key of the property
defaultValue - a default value.
Returns:
Value of the the property

getProperty

public java.lang.String getProperty(java.lang.String key)
                             throws java.util.NoSuchElementException
Get value of a property

Parameters:
key - key of the property
Returns:
Value of the the property
Throws:
java.util.NoSuchElementException - - if the property with key was not found

getResource

public java.io.InputStream getResource(java.lang.String resourceName)
                                throws java.lang.RuntimeException
Returns input stream to a resource

Parameters:
resourceName - name of file with resource
Returns:
input stream to read the resource
Throws:
java.lang.RuntimeException - if resource was not found

getResourceURL

public java.net.URL getResourceURL(java.lang.String resourceName)
                            throws java.lang.RuntimeException
Returns input stream to a resource

Parameters:
resourceName - name of file with resource
Returns:
input stream to read the resource
Throws:
java.lang.RuntimeException - if resource was not found

constructFullPath

public java.lang.String constructFullPath(java.lang.String relativePath)
Getter for property appWorkPath.

Parameters:
relativePath - A relative path (from application directory)
Returns:
Value of property appWorkPath.

init

public void init(java.lang.String sysPath,
                 java.lang.String appPath,
                 java.lang.String resourcesPath)
          throws java.lang.SecurityException,
                 java.io.IOException
Initialize the Config Manager. Two steps are executed:

1. Call to setAppWorkPath(System.getProperty("user.home") + '/' + sysPath + '/' + appPath);

2. Call to load();

Parameters:
sysPath - The system dir (for example 'acb')
appPath - The application dir (for example 'cbl')
resourcesPath - path to application resources (may be applied to a jar or to a file system)
Throws:
java.io.IOException - if there are problems reading from the stream
java.lang.SecurityException - inner exception

load

public void load()
          throws java.lang.SecurityException,
                 java.io.IOException
Binds working directory fo the application to the directory and load configuration

Throws:
java.lang.SecurityException - if a security manager exists and if the caller does not have LoggingPermission("control")
java.io.IOException - if there are problems reading from the stream

loadDefaults

public void loadDefaults(java.io.InputStream mainConfigStream,
                         java.io.InputStream logConfigStream)
                  throws java.lang.SecurityException,
                         java.io.IOException
Used for loading default configuration. Load configuration from a stream and call to store() then to load()

Parameters:
mainConfigStream - Stream of main configuration
logConfigStream - Stream of configuration of logger
Throws:
java.lang.SecurityException - if a security manager exists and if the caller does not have LoggingPermission("control")
java.io.IOException - if there are problems reading from the stream

logPropertyNames

public java.util.Enumeration logPropertyNames()
Returns an enumeration of all the keys in the property list of log system, including distinct keys in the default property list if a key of the same name has not already been found from the main properties list.

Returns:
Returns an enumeration of all the keys in the property list of log system, including distinct keys in the default property list if a key of the same name has not already been found from the main properties list.

propertyNames

public java.util.Enumeration propertyNames()
Returns an enumeration of all the keys in the property list of main configuration, including distinct keys in the default property list if a key of the same name has not already been found from the main properties list.

Returns:
Returns an enumeration of all the keys in the property list of main configuration, including distinct keys in the default property list if a key of the same name has not already been found from the main properties list.

store

public void store()
           throws java.lang.SecurityException,
                  java.io.IOException
Store the configuration

Throws:
java.lang.SecurityException - if a security manager exists and if the caller does not have LoggingPermission("control")
java.io.IOException - if there are problems reading from the stream

finalize

protected void finalize()
                 throws java.lang.Throwable
Throws:
java.lang.Throwable


Copyright © 2004 Phoenix Team (CMU/AIT). All Rights Reserved.