|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--bill.util.config.Configuration
This class controls the reading and accessing of configuration information stored in the equivalent of Windows "ini" files.
Field Summary | |
protected ConfigurationSection |
_currentSection
Internal pointer to the current section being manipulated when reading a configuration from a file. |
protected String |
_fileName
Name of the file associated with the configuration data |
protected Vector |
_sectionNames
A list of the section names for the configuration in the order they appear in the configuration. |
protected Hashtable |
_sections
The list of section in the configuration. |
static short |
ENTRY_CONFLICT_APPEND
Indicates that when a duplicate entry is added, the original will be left as is and another entry with the same name will be added as well. |
static short |
ENTRY_CONFLICT_DISCARD
Indicates that when a duplicate entry is added, it should be discarded (ignored) and the value of the existing one is left unchanged. |
static short |
ENTRY_CONFLICT_OVERWRITE
Indicates that when a duplicate entry is added, it should overwrite the value of the existing one. |
static short |
SECTION_CONFLICT_APPEND
Indicates that when a duplicate section is added, the original will be left as is and another section with the same name will be added as well. |
static short |
SECTION_CONFLICT_DISCARD
Indicates that when a duplicate section is added, it should be discarded (ignored) and the value of the existing one is left unchanged. |
static short |
SECTION_CONFLICT_INCLUDE
Indicates that when a duplicate section is added, the original will be left as is and and we will just add entries for this section to the existing section's entries. |
static short |
SECTION_CONFLICT_OVERWRITE
Indicates that when a duplicate section is added, it should overwrite the value of the existing one. |
Constructor Summary | |
Configuration()
Default creator, just sets our section list information to empty containers. |
|
Configuration(String fileName)
Class creator. |
Method Summary | |
ConfigurationSection |
addSection(String sectionName)
Adds a new section to this configuration. |
ConfigurationSection |
addSection(String sectionName,
int index)
Adds a new section to this configuration. |
ConfigurationEntry |
addSectionEntry(ConfigurationSection section,
ConfigurationEntry entry)
Adds a new entry to a section in this configuration. |
ConfigurationEntry |
addSectionEntry(String sectionName,
String entryName,
String entryValue)
Adds a new entry to a section in this configuration. |
Vector |
getEntryNames(String sectionName)
Used to retrieve a Vector of the entries contained in the specified section within this configuration. |
String |
getFileName()
Getter for the name of the file this configuration data belongs to. |
int |
getNumberOfEntries(String sectionName)
Determines the number of entries contained in specified section. |
int |
getNumberOfSections()
Determines the number of sections contained in this configuration. |
ConfigurationSection |
getSection(String sectionName)
Finds the requested ConfigurationSection entry in the list of sections the configuration file contains. |
ConfigurationSection |
getSection(String sectionName,
int sectionInstance)
Finds the requested instance of the ConfigurationSection entry in the list of sections the configuration file contains. |
short |
getSectionConflictMode()
Gets the section conflict mode a section uses to resolve duplicate section adds. |
ConfigurationEntry |
getSectionEntry(String sectionName,
int sectionInstance,
String entryName)
Finds the requested ConfigurationEntry class instance from the specified section. |
ConfigurationEntry |
getSectionEntry(String sectionName,
String entryName)
Finds the requested ConfigurationEntry class instance from the specified section. |
short |
getSectionEntryConflictMode(String sectionName)
Gets the entry conflict mode a section uses to resolve duplicate entry adds. |
int |
getSectionEntryQuantity(String sectionName,
int sectionInstance,
String entryName)
Determines how many entries of the specified name exist for the specified section. |
int |
getSectionEntryQuantity(String sectionName,
String entryName)
Determines how many entries of the specified name exist for the specified section. |
String |
getSectionEntryValue(String sectionName,
int sectionInstance,
String entryName)
Finds the requested entry's value from the specified section. |
String |
getSectionEntryValue(String sectionName,
int sectionInstance,
String entryName,
int entryInstance)
Finds the requested entry's value from the specified section. |
String |
getSectionEntryValue(String sectionName,
String entryName)
Finds the requested entry's value from the specified section. |
String |
getSectionEntryValue(String sectionName,
String entryName,
int entryInstance)
Finds the requested entry's value from the specified section. |
int |
getSectionEntryValueAsInteger(String sectionName,
int sectionInstance,
String entryName)
Finds the requested entry's value from the specified section. |
int |
getSectionEntryValueAsInteger(String sectionName,
int sectionInstance,
String entryName,
int entryInstance)
Retrieves the value of the specified entry from this section. |
int |
getSectionEntryValueAsInteger(String sectionName,
String entryName)
Finds the requested entry's value from the specified section. |
int |
getSectionEntryValueAsInteger(String sectionName,
String entryName,
int entryInstance)
Finds the requested entry's value from the specified section. |
Vector |
getSectionNames()
Used to retrieve a Vector of the sections contained in this configuration. |
int |
getSectionQuantity(String sectionName)
Determines how many sections of the specified name exist in this configuration. |
Hashtable |
getSections()
Getter for the hashtable of sections in a Configuration instance. |
int |
indexOf(String sectionName)
Determines the index of the first section with the specified name. |
int |
indexOf(String sectionName,
int index)
Determines the index of the first section with the specified name beginning the search at the specified index. |
boolean |
isSection(String sectionName)
Checks to see if this section exists in the configuration. |
boolean |
isSection(String sectionName,
int sectionInstance)
Checks to see if this section exists in the configuration. |
boolean |
isSectionEntry(String sectionName,
String entryName)
Checks to see if this section entry exists in the configuration. |
void |
merge(Configuration config)
Merges the sections from the specified configuration into the current configuration. |
void |
mergeSections(String target,
int targetInstance,
String source)
Merges the entries from one section with the entries from another. |
void |
mergeSections(String target,
int targetInstance,
String source,
int sourceInstance)
Merges the entries from one section with the entries from another. |
void |
mergeSections(String target,
String source)
Merges the entries from one section with the entries from another. |
void |
mergeSections(String target,
String source,
int sourceInstance)
Merges the entries from one section with the entries from another. |
boolean |
removeSection(ConfigurationSection section)
Removes a section from this configuration. |
boolean |
removeSection(String sectionName)
Removes a section from this configuration. |
boolean |
removeSectionEntry(String sectionName,
String entryName)
Removes an entry from a section in this configuration. |
ConfigurationSection |
renameSection(String oldName,
String newName)
Renames an existing section to the given new name. |
void |
save()
Method to save the configuration back to a file. |
boolean |
setFileName(String fileName)
Setter for the name of the file this configuration data belongs to. |
void |
setSectionConflictMode(short sectionConflictMode)
Sets the section conflict mode a section uses to resolve duplicate section adds. |
void |
setSectionEntryConflictMode(String sectionName,
short entryConflictMode)
Sets the entry conflict mode a section uses to resolve duplicate entry adds. |
void |
setSectionEntryValue(String sectionName,
String entryName,
String entryValue)
Adds a new entry to a section in this configuration. |
void |
swapSections(int first,
int second)
Swap the position of two sections in the ordered list of sections. |
void |
swapSections(String firstName,
String secondName)
Swap the position of two sections in the ordered list of sections. |
String |
toString()
Returns a string representation of the Configuration class. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final short SECTION_CONFLICT_OVERWRITE
public static final short SECTION_CONFLICT_DISCARD
public static final short SECTION_CONFLICT_APPEND
public static final short SECTION_CONFLICT_INCLUDE
public static final short ENTRY_CONFLICT_OVERWRITE
public static final short ENTRY_CONFLICT_DISCARD
public static final short ENTRY_CONFLICT_APPEND
protected String _fileName
protected Hashtable _sections
protected Vector _sectionNames
protected ConfigurationSection _currentSection
Constructor Detail |
public Configuration()
public Configuration(String fileName) throws FileNotFoundException, IOException, ConfigurationException
fileName
- Name of the configuration file to process.FileNotFoundException
- Indicates the file name passed in does
not exist or cannot be accessed.IOException
- File was found but an error occurred while reading it.ConfigurationException
- A processing error was encountered while
reading the configuration file, typically a syntax error.Method Detail |
public String getFileName()
public boolean setFileName(String fileName)
fileName
- Value to set the file name to.
true
, otherwise returns false
.public Hashtable getSections()
public ConfigurationSection getSection(String sectionName)
sectionName
- Name of the section to find
null
if the section does not exist.public ConfigurationSection getSection(String sectionName, int sectionInstance)
sectionName
- Name of the section to findsectionInstance
- Which instance of the section to retrieve. This is
a 0 based value, so the first instance is instance 0, the second is 1,
etc.
null
if the section does not exist.public ConfigurationEntry getSectionEntry(String sectionName, String entryName)
sectionName
- Name of the section to find entry inentryName
- Name of the entry to find
null
if the entry does not exist.public ConfigurationEntry getSectionEntry(String sectionName, int sectionInstance, String entryName)
sectionName
- Name of the section to find entry in.sectionInstance
- Which instance of the section to retrieve entry
from. This is a 0 based value, so the first instance is instance 0, the
second is 1, etc.entryName
- Name of the entry to find.
null
if the entry does not exist.public String getSectionEntryValue(String sectionName, String entryName)
sectionName
- Name of the section to find entry in.entryName
- Name of the entry to find value for.null
if the
entry does not exist.public int getSectionEntryValueAsInteger(String sectionName, String entryName)
sectionName
- Name of the section to find entry in.entryName
- Name of the entry to find value for.0
if the
entry does not exist.public String getSectionEntryValue(String sectionName, int sectionInstance, String entryName)
sectionName
- Name of the section to find entry in.sectionInstance
- Which instance of the section to get an entry value
for. This is a 0 based value, so the first instance is instance 0, the
second is 1, etc.entryName
- Name of the entry to find value for.null
if the
entry does not exist.public int getSectionEntryValueAsInteger(String sectionName, int sectionInstance, String entryName)
sectionName
- Name of the section to find entry in.sectionInstance
- Which instance of the section to get an entry value
for. This is a 0 based value, so the first instance is instance 0, the
second is 1, etc.entryName
- Name of the entry to find value for.0
if the
entry does not exist.public String getSectionEntryValue(String sectionName, String entryName, int entryInstance)
sectionName
- Name of the section to find entry in.entryName
- Name of the entry to find value for.entryInstance
- Which instance of the entry within the section to get
an value for. This is a 0 based value, so the first instance is instance
0, the second is 1, etc.null
if the
entry does not exist.public int getSectionEntryValueAsInteger(String sectionName, String entryName, int entryInstance)
sectionName
- Name of the section to find entry in.entryName
- Name of the entry to find value for.entryInstance
- Which instance of the entry within the section to get
an value for. This is a 0 based value, so the first instance is instance
0, the second is 1, etc.null
if the
entry does not exist.public String getSectionEntryValue(String sectionName, int sectionInstance, String entryName, int entryInstance)
sectionName
- Name of the section to find entry in.sectionInstance
- Which instance of the section to get an entry value
for. This is a 0 based value, so the first instance is instance 0, the
second is 1, etc.entryName
- Name of the entry to find value for.entryInstance
- Which instance of the entry within the section to get
an value for. This is a 0 based value.null
if the
entry does not exist.public int getSectionEntryValueAsInteger(String sectionName, int sectionInstance, String entryName, int entryInstance)
entryName
- Name of the entry whose value is to be retrievedentryInstance
- Which instance of the entry to retrieve. This is
a 0 based value, so the first instance is instance 0, the second is 1,
etc.null
if the entry could not
be found.public int getSectionQuantity(String sectionName)
sectionName
- Name of the section to find quantity of.public int getSectionEntryQuantity(String sectionName, String entryName)
sectionName
- Name of the section to find entry in.entryName
- Name of the entry to find quantity of.public int getSectionEntryQuantity(String sectionName, int sectionInstance, String entryName)
sectionName
- Name of the section to find entry in.sectionInstance
- Which instance of the section to get an entry
quantity for. This is a 0 based value, so the first instance is instance
0, the second is 1, etc.entryName
- Name of the entry to find quantity of.public void setSectionConflictMode(short sectionConflictMode)
sectionConflictMode
- The section conflict mode.public short getSectionConflictMode()
public void setSectionEntryConflictMode(String sectionName, short entryConflictMode) throws ConfigurationException
sectionName
- Name of the section to set the mode of.entryConflictMode
- The entry conflict mode.public short getSectionEntryConflictMode(String sectionName)
sectionName
- Name of the section to get the mode of.public void setSectionEntryValue(String sectionName, String entryName, String entryValue)
sectionName
- Name of the section to add or set an entry in.entryName
- Name of the new entry to add or set.entryValue
- Value to give the entry.public void swapSections(int first, int second)
first
- Index of the first section we are switchingsecond
- Index of the second section we are switchingpublic void swapSections(String firstName, String secondName) throws ConfigurationException
firstName
- Name of the first section we are switchingsecondName
- Name of the second section we are switchingConfigurationException
- Thrown when there is no section by one (or
both) of the section names.public int indexOf(String sectionName)
sectionName
- The name of the section to look for.public int indexOf(String sectionName, int index)
sectionName
- The name of the section to look for.index
- The index to start the search at.public int getNumberOfSections()
public int getNumberOfEntries(String sectionName) throws ConfigurationException
sectionName
- Name of the section to get the entry count forConfigurationException
- Thrown when the specified section does not
exist in the configuration.public boolean isSection(String sectionName)
true
if the section exists, false
otherwise.public boolean isSection(String sectionName, int sectionInstance)
sectionName
- Name of the section to check for.sectionInstance
- Which instance of the section to look for. This is
a 0 based value, so the first instance is instance 0, the second is 1, etc.true
if the section exists, false
otherwise.public boolean isSectionEntry(String sectionName, String entryName)
true
if the section entry exists, false
otherwise.public ConfigurationSection renameSection(String oldName, String newName)
oldName
- Name of the section being renamed.newName
- Value to rename the section to.
null
otherwise.public ConfigurationSection addSection(String sectionName) throws ConfigurationException
sectionName
- Name of the new section to add.null
otherwise.public ConfigurationSection addSection(String sectionName, int index) throws ConfigurationException
sectionName
- Name of the new section to add.null
otherwise.public boolean removeSection(String sectionName)
sectionName
- Name of the section to remove.true
on success, false
otherwise.public ConfigurationEntry addSectionEntry(String sectionName, String entryName, String entryValue) throws ConfigurationException
sectionName
- Name of the section to add an entry to.entryName
- Name of the new entry to add.entryValue
- Value to give the new entry.null
otherwise.ConfigurationException
- Thrown when there is already an existing
entry by this name and entry conflict resolution has been set to
Configuration.ENTRY_CONFLICT_DISCARD.
public ConfigurationEntry addSectionEntry(ConfigurationSection section, ConfigurationEntry entry) throws ConfigurationException
section
- The section to add the entry to.entry
- The configuration entry to add.null
otherwise.ConfigurationException
- Thrown when there is already an existing
entry by this name and entry conflict resolution has been set to
Configuration.ENTRY_CONFLICT_DISCARD.
public boolean removeSectionEntry(String sectionName, String entryName)
sectionName
- Name of the section the entry is in.entryName
- Name of the entry to remove.true
on success, false
otherwise.public boolean removeSection(ConfigurationSection section)
section
- The section to remove.true
on success, false
otherwise.public void merge(Configuration config) throws ConfigurationException
config
- The configuration to be merged in.ConfigurationException
- Thrown when one or more sections from the
specified configuration cannot be added to the current configuration. This
is typically caused by duplicate sections when the target configuration
has a Section Conflict Mode of
Configuration.SECTION_CONFLICT_DISCARD
.public void mergeSections(String target, String source) throws ConfigurationException
target
- Name of the section entries are being merged into.source
- Name of the section entries are being copied from.ConfigurationException
- Thrown when one or more entries from the
specified section cannot be added to the current section. This is
typically caused by duplicate entries when the target section as a
Entry Conflict Mode of Configuration.ENTRY_CONFLICT_DISCARD
.public void mergeSections(String target, int targetInstance, String source) throws ConfigurationException
target
- Name of the section entries are being merged into.targetInstance
- Which instance of the target section to retrieve.
This is a 0 based value, so the first instance is instance 0, the second
is 1, etc.source
- Name of the section entries are being copied from.ConfigurationException
- Thrown when one or more entries from the
specified section cannot be added to the current section. This is
typically caused by duplicate entries when the target section as a
Entry Conflict Mode of Configuration.ENTRY_CONFLICT_DISCARD
.public void mergeSections(String target, String source, int sourceInstance) throws ConfigurationException
target
- Name of the section entries are being merged into.source
- Name of the section entries are being copied from.sourceInstance
- Which instance of the source section to retrieve.
This is a 0 based value, so the first instance is instance 0, the second
is 1, etc.ConfigurationException
- Thrown when one or more entries from the
specified section cannot be added to the current section. This is
typically caused by duplicate entries when the target section as a
Entry Conflict Mode of Configuration.ENTRY_CONFLICT_DISCARD
.public void mergeSections(String target, int targetInstance, String source, int sourceInstance) throws ConfigurationException
target
- Name of the section entries are being merged into.targetInstance
- Which instance of the target section to retrieve.
This is a 0 based value, so the first instance is instance 0, the second
is 1, etc.source
- Name of the section entries are being copied from.sourceInstance
- Which instance of the source section to retrieve.
This is a 0 based value, so the first instance is instance 0, the second
is 1, etc.ConfigurationException
- Thrown when one or more entries from the
specified section cannot be added to the current section. This is
typically caused by duplicate entries when the target section as a
Entry Conflict Mode of Configuration.ENTRY_CONFLICT_DISCARD
.public Vector getSectionNames()
public Vector getEntryNames(String sectionName)
sectionName
- Name of the section to retrieve entry names for.null
is returned.public void save() throws Exception
Exception
- Thrown when the save file could not be opened or has
no sections.public String toString()
toString
in class Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |