|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectorg.mbari.siam.configt.ConfigFile
public abstract class ConfigFile
The ConfigFile class is a base class representing common properties and behavior of a configuration file. ConfigFiles are created and managed by a PlatformConfigServlet, which gets the location and type of the config file from it's own properties file. The name and type information are used to get the appropriate ConfigFile subclass from a ConfigFileFactory instance. Each configuration file contains a collection (Vector) of ConfigItems (configuration items) that are managed within it. These configuration items are defined in a properties file. The ConfigFile is responsible for reading the config item definitions and creating the appropriate ConfigItem objects (see method loadProperties()). Once the configuration items are created, the readAll() method is used to initialize the ConfigItems with the values currently stored in the configuration file. The ConfigItem objects are requested by the PlatformConfigServlet, which manages their organization and presentation in the user interface. The ConfigFile is also responsible for using the present value of it's configuration items to generate the actual configuration file; subclasses generally override the default method for this, writeTemp(), to implement file-specific logic. When the PlatformConfigServlet is ready to write settings to the configuration files, it first calls the createBackup() method to backup the current contents of the configuration file. It then invokes writeTemp() for each ConfigFile, which writes a temporary copy of the config file, followed by replaceFile(), which replaces the original file with the temporary copy just created. The configuration files may be generated in different ways. Some files (siamPort.cfg, siamEnv) are edited in place, using regular expressions to find and replace configuration items with their current values. Other files (system files like rc.local, hosts, etc.) are generated using templates, with HTML-style tags that represent places where configuration item values should be inserted. This allows the content of these files to be changed without recompiling the configuration tool.
| Field Summary | |
|---|---|
boolean |
_appendUnwrittenItems
used by writeTempFindReplace() to look for unwritten config items and append them to the file |
protected java.util.Vector |
_configItems
Collection of configuration items managed through this ConfigFile |
boolean |
_getDisplayValue
used by writeTempFindReplace() to use the display value for config items or use mapped (itemRef) values of configItems |
protected java.util.Hashtable |
_layoutParameters
Used to set up parameters for laying out HTML controls (e.g. |
protected static org.apache.log4j.Logger |
_log4j
Log4J logger |
boolean |
_mapNull
used by writeTempFindReplace() to map null characters to _nullMapString if true |
java.lang.String |
_nullMapString
|
protected ConfigTool |
_parent
PlatformConfigServlet managing this ConfigFile. |
protected java.util.Properties |
_properties
Java Properties |
protected java.lang.String |
_propertiesPath
Location of properties file defining |
protected java.lang.String |
_templatePath
Location of template used to regenerate this config file |
protected java.io.File |
_theFile
The actual file represented by this ConfigFile. |
static int |
FIND_REPLACE
|
static int |
SIMPLE
WriteTemp variant selectors |
static int |
TAG_REPLACE
|
| Constructor Summary | |
|---|---|
ConfigFile(java.lang.String path,
java.lang.String propertiesPath)
Constructor |
|
| Method Summary | |
|---|---|
protected void |
appendTempFile(java.io.BufferedWriter bw)
Append additional contents, templates, etc. |
boolean |
createBackup(java.lang.String backupType,
java.io.File backupDir)
Backup this file to a new name, optionally overwrite the existing backup, or keep multiple copies (file.bak.mmddyy[-n]) |
java.util.Vector |
getAll()
Return a vector of all ConfigItems |
java.util.Vector |
getAttributes(java.util.Properties properties,
HTMLControl htc,
java.lang.String itemName)
getAttributes - get attributes for the specified ConfigItem |
int |
getCols(java.lang.String group)
Return max number of columns called for by ConfigItem's layout parameters |
ConfigItem |
getItem(java.lang.String name)
Return an configuration item with the specified name; note that names may not be shared among config files, i.e., the same item may not be managed by more than one config file. |
java.lang.String |
getItemValue(java.lang.String name)
Get the current value of the specified ConfigItem |
protected int |
getLayoutParameter(java.lang.String key)
|
java.lang.String |
getName()
Return configuration file name |
java.util.Hashtable |
getOutputMappings(java.util.Properties properties,
HTMLControl htc,
java.lang.String itemName)
getOutputMappings - get output value mappings for the specified ConfigItem |
java.lang.String |
getPath()
Return path to this ConfigFile |
int |
getRows(java.lang.String group)
Return max number of rows called for by ConfigItem's layout parameters |
boolean |
initFile(java.io.File file)
Create a file if it doesn't already exist |
boolean |
initFile(java.lang.String fileName)
Wrapper for initFile; creates a new file from fileName and passes it to initFile |
protected void |
initWriteFlags(boolean value)
Intialize write flags for all config items |
protected void |
loadProperties()
Load properties and ConfigItem definitions from properties file. |
static void |
main(java.lang.String[] args)
|
protected java.lang.String |
mapOutputValue(java.lang.String s)
mapOutputValue() allows subclasses a mechanism for mapping the value of Strings used for presentation to a different value for output(e.g. |
void |
newLine(java.io.BufferedWriter bw)
Override BufferedWriter's newLine() method, which varies the newline character(s) according to platform. |
java.util.Vector |
readAll()
Read the configuration file and assign the values read from the file to the ConfigItems managed by this ConfigFile. |
void |
replaceFile(java.io.File tempFile)
replaceFile replaces the configuration file with the new version (created by a call to writeTemp()). |
void |
setParent(ConfigTool parent)
Set parent PlatformConfigServlet |
protected void |
updateConfigItems()
Update value of ConfigItems, possibly using values of global items. |
boolean |
validateItem(java.lang.String name)
Validates a configuration item (not implemented) |
protected void |
writeLine(java.lang.String line,
java.io.BufferedWriter bw)
Write line, newline and flush |
abstract java.io.File |
writeTemp()
Write the current value of all configuration items to a temporary file. |
java.io.File |
writeTemp(int method)
|
java.io.File |
writeTempFindReplace()
there are a couple of parameters that must be set before calling this this method:getDisplayValue and appendUnwrittenItems |
java.io.File |
writeTempSimple()
|
java.io.File |
writeTempTagReplace()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static org.apache.log4j.Logger _log4j
protected java.util.Vector _configItems
protected java.util.Properties _properties
protected java.lang.String _propertiesPath
protected java.lang.String _templatePath
protected java.util.Hashtable _layoutParameters
public static final int SIMPLE
public static final int TAG_REPLACE
public static final int FIND_REPLACE
public boolean _appendUnwrittenItems
public boolean _getDisplayValue
public boolean _mapNull
public java.lang.String _nullMapString
protected ConfigTool _parent
protected java.io.File _theFile
| Constructor Detail |
|---|
public ConfigFile(java.lang.String path,
java.lang.String propertiesPath)
| Method Detail |
|---|
public void setParent(ConfigTool parent)
public ConfigItem getItem(java.lang.String name)
public java.lang.String getItemValue(java.lang.String name)
public java.util.Vector readAll()
public int getRows(java.lang.String group)
public int getCols(java.lang.String group)
protected int getLayoutParameter(java.lang.String key)
public boolean createBackup(java.lang.String backupType,
java.io.File backupDir)
public void replaceFile(java.io.File tempFile)
public abstract java.io.File writeTemp()
public java.io.File writeTemp(int method)
public java.io.File writeTempSimple()
public java.io.File writeTempTagReplace()
public java.io.File writeTempFindReplace()
protected void updateConfigItems()
throws java.lang.Exception
java.lang.Exception
protected void appendTempFile(java.io.BufferedWriter bw)
throws java.io.IOException
java.io.IOExceptionprotected void initWriteFlags(boolean value)
public java.util.Vector getAll()
protected void writeLine(java.lang.String line,
java.io.BufferedWriter bw)
throws java.io.IOException
java.io.IOException
public void newLine(java.io.BufferedWriter bw)
throws java.io.IOException
java.io.IOException
public boolean initFile(java.io.File file)
throws java.io.IOException
java.io.IOException
public boolean initFile(java.lang.String fileName)
throws java.io.IOException
java.io.IOExceptionpublic boolean validateItem(java.lang.String name)
public java.util.Vector getAttributes(java.util.Properties properties,
HTMLControl htc,
java.lang.String itemName)
public java.util.Hashtable getOutputMappings(java.util.Properties properties,
HTMLControl htc,
java.lang.String itemName)
protected void loadProperties()
throws java.lang.Exception
java.lang.Exceptionpublic java.lang.String getPath()
public java.lang.String getName()
public static void main(java.lang.String[] args)
protected java.lang.String mapOutputValue(java.lang.String s)
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||