org.igfay.jfig
Class JFig

java.lang.Object
  extended byorg.igfay.jfig.JFig
All Implemented Interfaces:
JFigIF

public class JFig
extends java.lang.Object
implements JFigIF

The JFig package provides very simple, flexible and powerful functionality for managing one or more configurations in a java environment.

It allows for a combination of a hierarchy of configuration files, substitution variables and property variables. Methods are provided to get values stored in a configuration dictionary with a variety of types (String, array, integer, float, boolean, etc) and default values.

Usage:
To get an instance of the JFig singleton, use: JFig. getInstance();

There are a number of helper methods to retrieve configuration values. The most common is:
String value = JFig. getInstance().getValue ("aSection","aKey","aDefaultValue");

See the javadocs for additional helper methods to retrieve values as different java types and with different exception handling.

Author:
bconrad

Method Summary
 void addConfigEventListener(JFigListener listener)
          Add JFig listeners to list so they can be notified when there is a significant change in the configuration.
protected  void fireConfigUpdateEvent()
          Notify registered listeners when configuration is updated.
protected  java.util.Map getAllConfigFiles()
          Returns the list of all config files that have been processed.
 java.lang.String[] getArrayValue(java.lang.String section, java.lang.String key)
          Convenience method for getting values as array.
 java.lang.String[] getArrayValue(java.lang.String section, java.lang.String key, java.lang.String notFoundValue)
          Convenience method for getting values as array with default value.
 boolean getBooleanValue(java.lang.String section, java.lang.String key, java.lang.String notFoundValue)
          Convenience method for getting values as boolean
 JFigDictionary getConfigDictionary()
          return the ConfigurationDictionary Made public so we can access this from a jsp and show the configuration via html.
protected  java.lang.String getConfigFileName()
           
protected  java.util.List getConfigListeners()
          Lazily initialize and return listeners
protected  JFigLocatorIF getConfigLocator()
           
 java.util.Map getEntriesStartingWith(java.lang.String section, java.lang.String key)
          Return a map of all values starting with "key" in the scetcion.
 float getFloatValue(java.lang.String section, java.lang.String key, java.lang.String notFoundValue)
          Convenience method for getting values as float
static JFigIF getInstance()
          Return the config singleton
static JFigIF getInstance(int dummy)
          Deprecated. - Use initialize
static JFigIF getInstance(int dummy, JFigLocatorIF locator)
          Deprecated. - Use initialize
static JFigIF getInstance(JFigLocatorIF jfigLocator)
          Return the config singleton passing a JFigLocator
 int getIntegerValue(java.lang.String section, java.lang.String key)
          Convenience method for getting values as int
 int getIntegerValue(java.lang.String section, java.lang.String key, java.lang.String notFoundValue)
          Convenience method for getting values as int, with default value
protected  JFigParser getParser()
          Return the JFig parser
 java.util.Map getSection(java.lang.String section)
          Return an entire section as a Map
 java.util.Properties getSectionAsProperties(java.lang.String section)
          Return a section as a Properties object
 java.util.Properties getSectionAsProperties(java.lang.String section, java.util.Properties properties)
          Return a section populated in a supplied Properties object.
 java.lang.String getValue(java.lang.String section, java.lang.String key)
          Call configParser to get the value for a key in a given section.
 java.lang.String getValue(java.lang.String section, java.lang.String key, java.lang.String defaultValue)
          Return the value for this section and key.
 java.util.List getValuesStartingWith(java.lang.String section, java.lang.String key)
          Return a list of all values starting with "key" in the section.
static JFigIF initialize()
          Initialize configuration
static JFigIF initialize(JFigLocator locator)
          Initialize configuration.
protected  boolean isXML()
          Is the configuration file in XML format or ini format.
static void main(java.lang.String[] args)
           
 void print()
          Print the values in the JFig dictionary.
 void printConfigurationDictionary()
          Deprecated.  
protected  void processConfig()
          Call parser to process required config
 void reprocessConfiguration()
          Reprocess the configuration creating a new config dictionary
 void reprocessConfiguration(JFigLocator locator)
          Reprocess the configuration with the specified JFigLocator, creating a new config dictionary
protected  void setAllConfigFiles(java.util.HashMap map)
           
protected  void setConfigDictionary(JFigDictionary configDictionary)
          Sets the configDictionary.
 void setConfigurationValue(java.lang.String sectionName, java.lang.String keyString, java.lang.String valueString)
          Set a configuration value.
static void setInstance(JFigIF jfig)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

main

public static void main(java.lang.String[] args)

getInstance

public static JFigIF getInstance()
Return the config singleton

Returns:

setInstance

public static void setInstance(JFigIF jfig)

getInstance

public static JFigIF getInstance(int dummy)
                          throws JFigException
Deprecated. - Use initialize

Return the config singleton. If the configuration file is not found, throw an exception.

Returns:
Throws:
JFigException

getInstance

public static JFigIF getInstance(int dummy,
                                 JFigLocatorIF locator)
                          throws JFigException
Deprecated. - Use initialize

Return the config singleton passing a JFigLocator. If the configuration file is not found, throw an exception.

Returns:
Throws:
JFigException

getInstance

public static JFigIF getInstance(JFigLocatorIF jfigLocator)
Return the config singleton passing a JFigLocator

Returns:

addConfigEventListener

public void addConfigEventListener(JFigListener listener)
Add JFig listeners to list so they can be notified when there is a significant change in the configuration.

Specified by:
addConfigEventListener in interface JFigIF
Parameters:
listener - The feature to be added to the ConfigEventListener attribute

getConfigListeners

protected java.util.List getConfigListeners()
Lazily initialize and return listeners


fireConfigUpdateEvent

protected void fireConfigUpdateEvent()
Notify registered listeners when configuration is updated.


print

public void print()
Print the values in the JFig dictionary.

Specified by:
print in interface JFigIF

printConfigurationDictionary

public void printConfigurationDictionary()
Deprecated.  

Print the values in the JFig dictionary.

Specified by:
printConfigurationDictionary in interface JFigIF

processConfig

protected void processConfig()
                      throws JFigException
Call parser to process required config

Throws:
JFigException

reprocessConfiguration

public void reprocessConfiguration()
                            throws JFigException
Reprocess the configuration creating a new config dictionary

Specified by:
reprocessConfiguration in interface JFigIF
Throws:
JFigException

reprocessConfiguration

public void reprocessConfiguration(JFigLocator locator)
                            throws JFigException
Reprocess the configuration with the specified JFigLocator, creating a new config dictionary

Specified by:
reprocessConfiguration in interface JFigIF
Throws:
JFigException

initialize

public static JFigIF initialize()
                         throws JFigException
Initialize configuration

Throws:
JFigException

initialize

public static JFigIF initialize(JFigLocator locator)
                         throws JFigException
Initialize configuration. It is recommended that JFig is explicitly initialized by this method. The alternative is to let getInstance() lazily initialize. The difference is that this will throw a JFigException if there is a problem in the initialization process while getInstance() will not.

Throws:
JFigException

getConfigDictionary

public JFigDictionary getConfigDictionary()
return the ConfigurationDictionary Made public so we can access this from a jsp and show the configuration via html.

Specified by:
getConfigDictionary in interface JFigIF

getArrayValue

public java.lang.String[] getArrayValue(java.lang.String section,
                                        java.lang.String key)
                                 throws JFigException
Convenience method for getting values as array. The value is tokenized depending on the first token found in the following order: comma, semicolon, colon, space

Specified by:
getArrayValue in interface JFigIF
Throws:
JFigException

getBooleanValue

public boolean getBooleanValue(java.lang.String section,
                               java.lang.String key,
                               java.lang.String notFoundValue)
Convenience method for getting values as boolean

Specified by:
getBooleanValue in interface JFigIF

getFloatValue

public float getFloatValue(java.lang.String section,
                           java.lang.String key,
                           java.lang.String notFoundValue)
                    throws JFigException
Convenience method for getting values as float

Specified by:
getFloatValue in interface JFigIF
Parameters:
section - Description of Parameter
key - Description of Parameter
notFoundValue - Description of Parameter
Returns:
The FloatValue value
Throws:
JFigException - Description of Exception

getIntegerValue

public int getIntegerValue(java.lang.String section,
                           java.lang.String key)
                    throws JFigException
Convenience method for getting values as int

Specified by:
getIntegerValue in interface JFigIF
Throws:
JFigException

getIntegerValue

public int getIntegerValue(java.lang.String section,
                           java.lang.String key,
                           java.lang.String notFoundValue)
Convenience method for getting values as int, with default value

Specified by:
getIntegerValue in interface JFigIF

getParser

protected JFigParser getParser()
Return the JFig parser


isXML

protected boolean isXML()
Is the configuration file in XML format or ini format.

Returns:
boolean

getValue

public java.lang.String getValue(java.lang.String section,
                                 java.lang.String key,
                                 java.lang.String defaultValue)
Return the value for this section and key. If none found, return the default value.

Specified by:
getValue in interface JFigIF
Parameters:
section - Description of Parameter
key - Description of Parameter
defaultValue - Description of Parameter
Returns:
The Value value

getValuesStartingWith

public java.util.List getValuesStartingWith(java.lang.String section,
                                            java.lang.String key)
Return a list of all values starting with "key" in the section. If section xxx contains x.1, x.2, and x.3, getValuesStartingWith("xxx", "x.") returns a list containing x.1, x.2, and x.3.

Specified by:
getValuesStartingWith in interface JFigIF
Parameters:
section -
key -
Returns:
List

getEntriesStartingWith

public java.util.Map getEntriesStartingWith(java.lang.String section,
                                            java.lang.String key)
Return a map of all values starting with "key" in the scetcion. If section xxx contains x.1=a, x.2=b, and x.3=c, getValuesStartingWith("xxx", "x.") returns a map containing x.1,a x.2,b and x.3,c.

Specified by:
getEntriesStartingWith in interface JFigIF
Parameters:
section -
key -
Returns:
List

getSection

public java.util.Map getSection(java.lang.String section)
Return an entire section as a Map

Specified by:
getSection in interface JFigIF
Parameters:
section -
Returns:

getSectionAsProperties

public java.util.Properties getSectionAsProperties(java.lang.String section)
Return a section as a Properties object

Specified by:
getSectionAsProperties in interface JFigIF
Parameters:
section -
Returns:

getSectionAsProperties

public java.util.Properties getSectionAsProperties(java.lang.String section,
                                                   java.util.Properties properties)
Return a section populated in a supplied Properties object.

Specified by:
getSectionAsProperties in interface JFigIF
Parameters:
section -
Returns:

getValue

public java.lang.String getValue(java.lang.String section,
                                 java.lang.String key)
                          throws JFigException
Call configParser to get the value for a key in a given section.

Specified by:
getValue in interface JFigIF
Throws:
JFigException

setConfigurationValue

public void setConfigurationValue(java.lang.String sectionName,
                                  java.lang.String keyString,
                                  java.lang.String valueString)
Set a configuration value. Most values are set during initial parsing so this is rarely used.

Specified by:
setConfigurationValue in interface JFigIF

getArrayValue

public java.lang.String[] getArrayValue(java.lang.String section,
                                        java.lang.String key,
                                        java.lang.String notFoundValue)
Convenience method for getting values as array with default value.

Specified by:
getArrayValue in interface JFigIF

setConfigDictionary

protected void setConfigDictionary(JFigDictionary configDictionary)
Sets the configDictionary.

Parameters:
configDictionary -

getAllConfigFiles

protected java.util.Map getAllConfigFiles()
Returns the list of all config files that have been processed. Used to prevent processing the same file multiple times esp in case of circular includes.

Returns:
List

setAllConfigFiles

protected void setAllConfigFiles(java.util.HashMap map)

getConfigLocator

protected JFigLocatorIF getConfigLocator()
Returns:

getConfigFileName

protected java.lang.String getConfigFileName()