EAF 7.4 API

org.enhydra.util
Class AbsConfigFile

java.lang.Object
  extended by org.enhydra.util.AbsConfigFile
All Implemented Interfaces:
ConfigFileInterface

public abstract class AbsConfigFile
extends java.lang.Object
implements ConfigFileInterface

AbsConfigFile is abstract class which contains methods used to manipulate application's configuration file to read its configuration parameters.

Version:
1.0
Author:
Tanja Jovanovic
See Also:
Config, ConfigFileInterface

Field Summary
protected  java.util.Hashtable comments
          Comments of configuration parameters.
protected  com.lutris.util.Config config
          The configuration object to which this configuration file belongs to.
protected  java.io.File file
          The associated file (if any).
protected  org.enhydra.util.JNDIAdapter jndiAdapt
          JNDI Adapter used for reading application's parameters.
protected  java.util.Hashtable jndiParameterNames
          Parameters from configuration file whose values are jndi names of resources.
protected  java.util.Vector order
          Order in which are configuration parameters added.
 
Fields inherited from interface org.enhydra.util.ConfigFileInterface
TRAILING_COMMENT
 
Constructor Summary
AbsConfigFile()
          Default constructor for an empty configuration file.
AbsConfigFile(java.io.File file)
          Constructor from a File.
AbsConfigFile(com.lutris.util.KeywordValueTable kvt)
          Constructor from a KeywordValueTable.
 
Method Summary
 void addEntry(java.lang.String key, java.lang.String[] values, java.lang.String comment)
          Adds an entry to the configuration.
 void addEntry(java.lang.String kkey, java.lang.String value, java.lang.String comment)
          Adds an entry to the configuration.
 java.lang.String getComment(java.lang.String key)
          Returns the comment associated with a given key, or null if there is no comment.
 com.lutris.util.Config getConfig()
          Returns the Config object representing the config data in the file.
 java.io.File getFile()
          Gets the associated file.
protected  void readJndi()
          Reads application configuration parameters using JNDI Context.
 void removeEntry(java.lang.String key)
          Removes an entry from the configuration.
 void setFile(java.io.File file)
          Sets the configuration file.
 void write()
          Writes this config to the associated configuration file.
abstract  void write(java.io.OutputStream outputStream)
          Writes out a configuration file to the OutputStream specified.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

config

protected com.lutris.util.Config config
The configuration object to which this configuration file belongs to.


order

protected java.util.Vector order
Order in which are configuration parameters added.


comments

protected java.util.Hashtable comments
Comments of configuration parameters.


file

protected java.io.File file
The associated file (if any).


jndiAdapt

protected org.enhydra.util.JNDIAdapter jndiAdapt
JNDI Adapter used for reading application's parameters.


jndiParameterNames

protected java.util.Hashtable jndiParameterNames
Parameters from configuration file whose values are jndi names of resources.

Constructor Detail

AbsConfigFile

public AbsConfigFile()
Default constructor for an empty configuration file.


AbsConfigFile

public AbsConfigFile(java.io.File file)
              throws ConfigException,
                     java.io.IOException
Constructor from a File. Allows to later write back the configuration to the same file.

Parameters:
file - The local file to parse.
Throws:
java.io.IOException
ConfigException

AbsConfigFile

public AbsConfigFile(com.lutris.util.KeywordValueTable kvt)
              throws ConfigException
Constructor from a KeywordValueTable.

Parameters:
kvt - A KeywordValueTable from which to populate the configuration file.
Throws:
ConfigException
Method Detail

readJndi

protected void readJndi()
                 throws ConfigException
Reads application configuration parameters using JNDI Context. Subclasses should override this method.

Throws:
ConfigException

getConfig

public com.lutris.util.Config getConfig()
Returns the Config object representing the config data in the file.

Specified by:
getConfig in interface ConfigFileInterface
Returns:
The Config object for this ConfigFile.

getComment

public java.lang.String getComment(java.lang.String key)
Returns the comment associated with a given key, or null if there is no comment. Pass in ConfigFileInterface.TRAILING_COMMENT to get the trailing comment.

Specified by:
getComment in interface ConfigFileInterface
Parameters:
key - the key to look up.
Returns:
the associated comment or null

addEntry

public void addEntry(java.lang.String key,
                     java.lang.String[] values,
                     java.lang.String comment)
              throws KeywordValueException
Adds an entry to the configuration.

Specified by:
addEntry in interface ConfigFileInterface
Parameters:
key - The config element name.
values - A string array of values.
comment - A string containing a properly commented configuration file comment.
Throws:
KeywordValueException

addEntry

public void addEntry(java.lang.String kkey,
                     java.lang.String value,
                     java.lang.String comment)
              throws KeywordValueException
Adds an entry to the configuration.

Specified by:
addEntry in interface ConfigFileInterface
Parameters:
key - The config element name.
value - A String value.
comment - A string containing a properly commented configuration file comment.
Throws:
KeywordValueException

removeEntry

public void removeEntry(java.lang.String key)
                 throws KeywordValueException
Removes an entry from the configuration.

Specified by:
removeEntry in interface ConfigFileInterface
Parameters:
key - The config element name.
Throws:
KeywordValueException

getFile

public java.io.File getFile()
Gets the associated file. If no file is associated with this config, null is returned.

Specified by:
getFile in interface ConfigFileInterface
Returns:
associated file

setFile

public void setFile(java.io.File file)
Sets the configuration file. This method can be useful in case when in construction of ConfigFile object is not defined associated file. After the file is set, Configuration parameters are read by using JNDI Context.

Specified by:
setFile in interface ConfigFileInterface
Parameters:
file - given reference to configuration file represented as File object.

write

public void write()
           throws java.io.IOException,
                  java.io.FileNotFoundException
Writes this config to the associated configuration file. If no file is associated with this config, throws a FileNotFoundException.

Specified by:
write in interface ConfigFileInterface
Throws:
java.io.IOException
java.io.FileNotFoundException

write

public abstract void write(java.io.OutputStream outputStream)
Writes out a configuration file to the OutputStream specified.

Specified by:
write in interface ConfigFileInterface
Parameters:
outputStream - The output stream on which to write the config file.

EAF 7.4 API