java.lang.Objectnet.sourceforge.jezxmlconfig.XmlConfig
This class provide an easy way to read, write and manage configuration parameters in a XML format file.
It is optimized to be very fast when accessing configuration parameters.
Description
For reading, defined parameter values will be directly accessible in following formats:
"#"
or "0x"
.
Named constants could be defined.
They could be used in parameter values with the ${constant_name}
format.
Note: Calling an unknown constant will not raise an error:
parameter value will simply appears "as is" (Without interpretation of "${}" syntax).
Only strings like "${existing_constant_name}
" will be replaced with constant values.
This syntax could also be used with system properties, exactly the same way as constants.
XML configuration file must be complient with following DTD:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!ELEMENT configuration (constants?,parameters)>
<!ELEMENT constants (constant+)>
<!ELEMENT constant EMPTY>
<!ATTLIST constant
name CDATA #REQUIRED
value CDATA #REQUIRED
>
<!ELEMENT parameters (section+)>
<!ELEMENT section (section*,param+)>
<!ATTLIST section
name CDATA #REQUIRED
>
<!ELEMENT param EMPTY>
<!ATTLIST param
name CDATA #REQUIRED
value CDATA #REQUIRED
>
Simple use example
XML configuration file:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE configuration SYSTEM "XmlConfig.dtd">
<configuration>
<constants>
<constant name="rootPath" value="/tmp" />
</constants>
<parameters>
<section name="machines">
<section name="gateway">
<param name="host" value="Jupiter" />
<param name="port" value="2222" />
</section>
<section name="comp">
<param name="host" value="Saturn" />
<param name="port" value="3333" />
</section>
<param name="netAdminName" value="James BOND" />
<param name="netAdminEmail" value="jbond@007.net" />
</section>
<section name="applications">
<section name="spaceNavigation">
<param name="localDir" value="${rootPath}/spaceNav" />
<param name="logFile" value="${rootPath}/spaceNav.log" />
<param name="units" value="parsec,light year,kilometer" />
</section>
<param name="numberInProd" value="0" />
</section>
</parameters>
</configuration>
At main program start
...
// Get configuration instance
XmlConfig config = XmlConfig.getInstance();
// Load an XML configuration file
try {
// Variable 'myConfigFile' of type java.io.File corresponds to my existing configuration file
config.loadFile(myConfigFile);
}
catch(XmlConfigException xce) {
// Load error (File not found, not accessible, bad format...)
xce.printStackTrace();
}
...
When using parameter values
...
// Get configuration instance
XmlConfig config = XmlConfig.getInstance(); // Or from JNDI: XmlConfig config = XmlConfig.jndiLookup("configJndiName");
// Read parameter values:
// Throw a XmlConfigException if a parameter is not found and a default value is not provided.
try {
// Computing machine name
String host = config.getStringParameter("machines.comp", "host");
// Communication port for computing machine
// No possible XmlConfigException: default value DEFAULT_PORT is provided if parameter is not found
int port = config.getIntParameter("machines.comp", "port", DEFAULT_PORT);
// Local work directory (XmlConfigException thrown if parameter is not found)
File localDirectory = (File)config.getObjectParameter(TYPE_DIR, "applications.spaceNavigation", "localDir");
// Log file (XmlConfigException thrown if parameter is not found)
File fichierLog = (File)config.getObjectParameter(TYPE_FILE, "applications.spaceNavigation", "logFile");
// Units ("units" array will have a length of 3, and elements will be: "parsec", "light year" et "kilometer")
String[] units = config.getMultiStringParameter("applications.spaceNavigation", "units");
}
catch(XmlConfigException xce) {
// Parameter not found (detail available in xce.getMessage())
xce.printStackTrace();
}
...
You can also build and update configuration at runtime:
// We have never access configuration: It will be initialized empty
XmlConfig config = XmlConfig.getInstance();
// Add a constant
config.addConstant("myConst", "toto");
// Add sections
config.addSection("general");
config.addSection("general.version");
config.addSection("general.detail");
// Add parameters
config.addParameter("general", "parametre1", "valeur1");
config.addParameter("general.version", "type", "release");
config.addParameter("general.version", "nom", "2.1");
config.addParameter("general.detail", "p2", "${myConst}"); // Utilisation d'une constante définie
config.addParameter("general.detail", "userName", "${user.name}"); // Utilisation d'une "system property"
// Move "general.detail" section to be the "detail" root section.
config.moveSection("general", null, "detail");
// Rename a constant: All references to this constant in parameter values will be updated indeed...
config.renameConstant("myConst", "newConstantName");
...
Field Summary | |
static java.lang.String |
CONSTANT_NAME_PREFIX
|
static java.lang.String |
CONSTANT_NAME_SUFFIX
|
static java.lang.String |
DEFAULT_SET
|
static int |
MODE_DEFAULT
|
static int |
MODE_READ_ONLY
|
static int |
MODE_THREAD_SAFE
|
static java.lang.String |
SECTION_SEPARATOR
|
static int |
TYPE_BIG_DECIMAL
|
static int |
TYPE_BIG_INTEGER
|
static int |
TYPE_BIT_SET
|
static int |
TYPE_BOOLEAN
|
static int |
TYPE_BYTE
|
static int |
TYPE_CHAR
|
static int |
TYPE_DIR
|
static int |
TYPE_DOUBLE
|
static int |
TYPE_FILE
|
static int |
TYPE_FLOAT
|
static int |
TYPE_INET_ADDRESS
|
static int |
TYPE_INT
|
static int |
TYPE_LONG
|
static int |
TYPE_SHORT
|
static int |
TYPE_UNKNOWN
|
static int |
TYPE_URL
|
Method Summary | |
void |
addConstant(java.lang.String name,
java.lang.String value)
Add a constant in configuration. |
void |
addParameter(java.lang.String section,
java.lang.String name,
java.lang.String value)
Add parameter in existing section. |
void |
addSection(java.lang.String name)
Add a section in configuration. |
void |
addSection(java.lang.String name,
boolean createParents)
Add a section in configuration. |
void |
dump(java.io.PrintStream out)
This method is provided for debug purpose. |
boolean |
getBooleanParameter(java.lang.String section,
java.lang.String key)
Give the boolean value of specified parameter. |
boolean |
getBooleanParameter(java.lang.String section,
java.lang.String key,
boolean defaultValue)
Give the boolean value of specified parameter. |
java.lang.String |
getBrutParameter(java.lang.String sectionPath,
java.lang.String paramName)
Give a parameter brut value (without constant replacement) for specified section. |
byte |
getByteParameter(java.lang.String section,
java.lang.String key)
Give the byte value of specified parameter. |
byte |
getByteParameter(java.lang.String section,
java.lang.String key,
byte defaultValue)
Give the byte value of specified parameter. |
char |
getCharParameter(java.lang.String section,
java.lang.String key)
Give the character value of specified parameter. |
char |
getCharParameter(java.lang.String section,
java.lang.String key,
char defaultValue)
Give the character value of specified parameter. |
java.lang.String |
getConfigPath()
Give loaded XML configuration path. |
java.lang.String |
getConstant(java.lang.String name)
Give a constant value. |
java.lang.String |
getConstant(java.lang.String name,
java.lang.String defaultValue)
Give a constant value, or a default value if constant does not exist. |
java.lang.String[] |
getConstantNames()
Give defined constant names in XML configuration file read order. |
java.io.File |
getCurrentFile()
Give the file corresponding to loaded configuration. |
int |
getDeepestParamLevel(java.lang.String key)
Test if a section contains parameters in itself or in its sub-sections recursively. |
double |
getDoubleParameter(java.lang.String section,
java.lang.String key)
Give the double precision float value of specified parameter. |
double |
getDoubleParameter(java.lang.String section,
java.lang.String key,
double defaultValue)
Give the double precision float value of specified parameter. |
float |
getFloatParameter(java.lang.String section,
java.lang.String key)
Give the float value of specified parameter. |
float |
getFloatParameter(java.lang.String section,
java.lang.String key,
float defaultValue)
Give the float value of specified parameter. |
static XmlConfig |
getInstance()
Give the only instance of default configuration set. |
static XmlConfig |
getInstance(java.lang.String configSet,
int mode)
Give the only instance of specified configuration set. |
int |
getIntParameter(java.lang.String section,
java.lang.String key)
Give the integer value of specified parameter. |
int |
getIntParameter(java.lang.String section,
java.lang.String key,
int defaultValue)
Give the integer value of specified parameter. |
javax.naming.Context |
getJndiContext()
Get JEZXmlConfig JNDI context. |
java.lang.String |
getJndiName()
Get JNDI name of current configuration. |
long |
getLongParameter(java.lang.String section,
java.lang.String key)
Give the long integer value of specified parameter. |
long |
getLongParameter(java.lang.String section,
java.lang.String key,
long defaultValue)
Give the long integer value of specified parameter. |
java.lang.Object[] |
getMultiObjectParameter(int type,
java.lang.String section,
java.lang.String key)
Give parameter multi-values for specified section. |
java.lang.Object[] |
getMultiObjectParameter(int type,
java.lang.String section,
java.lang.String key,
java.lang.Object[] defaultValues)
Give parameter multi-values for specified section. |
java.lang.Object[] |
getMultiObjectParameter(int type,
java.lang.String section,
java.lang.String key,
java.lang.Object[] defaultValues,
java.lang.String separator)
Give parameter multi-values for specified section. |
java.lang.Object[] |
getMultiObjectParameter(int type,
java.lang.String section,
java.lang.String key,
java.lang.String separator)
Give parameter multi-values for specified section. |
java.lang.String[] |
getMultiStringParameter(java.lang.String section,
java.lang.String paramName)
Give parameter multi-values for specified section. |
java.lang.String[] |
getMultiStringParameter(java.lang.String section,
java.lang.String paramName,
java.lang.String separator)
Give parameter multi-values for specified section. |
java.lang.String[] |
getMultiStringParameter(java.lang.String section,
java.lang.String paramName,
java.lang.String[] defaultValues)
Give parameter multi-values for specified section. |
java.lang.String[] |
getMultiStringParameter(java.lang.String section,
java.lang.String paramName,
java.lang.String[] defaultValues,
java.lang.String separator)
Give parameter multi-values for specified section. |
java.lang.Object |
getObjectParameter(int type,
java.lang.String section,
java.lang.String key)
Give a parameter value in specified object type. |
java.lang.Object |
getObjectParameter(int type,
java.lang.String section,
java.lang.String key,
java.lang.Object defaultValue)
Give a parameter value in specified object type. |
java.lang.String[] |
getParamNames(java.lang.String sectionName)
Give parameter names of specified section in XML configuration file read order. |
java.lang.String[] |
getRootSectionNames()
Give root section names. |
java.lang.String[] |
getSectionPaths()
Give section list in XML configuration file read order. |
short |
getShortParameter(java.lang.String section,
java.lang.String key)
Give the short integer value of specified parameter. |
short |
getShortParameter(java.lang.String section,
java.lang.String key,
short defaultValue)
Give the sort integer value of specified parameter. |
java.lang.String |
getStringParameter(java.lang.String sectionPath,
java.lang.String paramName)
Give a parameter value for specified section. |
java.lang.String |
getStringParameter(java.lang.String sectionPath,
java.lang.String paramName,
java.lang.String defaultValue)
Give a parameter value for specified section. |
java.lang.String[] |
getSubSectionNames(java.lang.String sectionName)
Give sub-section of specified section (non recursive). |
boolean |
getValidation()
Indicate if configuration is validated with DTD. |
void |
insertSection(java.lang.String before,
java.lang.String name)
Insert a new section before an other sibling one. |
boolean |
isConstantExist(java.lang.String key)
Test if a constant exists. |
boolean |
isParamExist(java.lang.String section,
java.lang.String key)
Test if a parameter exists in a section. |
boolean |
isSectionEmpty(java.lang.String key)
Test if a section is empty. |
boolean |
isSectionExist(java.lang.String section)
Test if a section exists. |
static java.util.List |
jndiList()
List available configurations from root directory of JEZXmlConfig JNDI service provider. |
static java.util.List |
jndiList(java.lang.String subdir)
List available configurations from specified subdirectory of JEZXmlConfig JNDI service provider. |
static java.util.List |
jndiListAll()
List all available configurations with full path from JEZXmlConfig JNDI service provider. |
static XmlConfig |
jndiLookup(java.lang.String jndiName)
Lookup given configuration from JEZXmlConfig JNDI service provider, and give an instance corresponding to it. |
void |
load(java.io.File configFile)
Load specified XML configuration file in memory. |
void |
load(java.io.InputStream inputStream,
java.lang.String path)
Load specified XML configuration in memory from given input stream. |
void |
load(java.lang.String path)
Load specified XML configuration in memory. |
void |
load(java.net.URL configFileUrl)
Load specified XML configuration in memory from a given URL. |
void |
loadProperties(java.io.File configFile)
Load specified property file in memory. |
void |
loadProperties(java.io.InputStream inputStream,
java.lang.String path)
Load specified properties in memory from given input stream. |
void |
loadProperties(java.lang.String path)
Load specified properties in memory. |
void |
loadProperties(java.net.URL configFileUrl)
Load specified properties in memory from a given URL. |
static void |
main(java.lang.String[] args)
FOR UNIT TESTS ONLY. |
void |
moveParameter(java.lang.String oldSection,
java.lang.String newSection,
java.lang.String name)
Move a parameter from a section to another one. |
void |
moveSection(java.lang.String oldParent,
java.lang.String newParent,
java.lang.String name)
Move a section. |
static void |
removeAllInstances()
|
void |
removeConstant(java.lang.String name)
Delete a constant. |
static void |
removeInstance(java.lang.String configSet)
|
void |
removeParameter(java.lang.String section,
java.lang.String name)
Delete a parameter. |
void |
removeSection(java.lang.String name)
Delete specified section including all its content recursively. |
void |
renameConstant(java.lang.String oldName,
java.lang.String newName)
Rename a constant. |
void |
renameParameter(java.lang.String section,
java.lang.String oldName,
java.lang.String newName)
Rename a parameter. |
void |
renameSection(java.lang.String parent,
java.lang.String simpleOldName,
java.lang.String simpleNewName)
Rename a section. |
void |
reset()
Completely empty the configuration. |
void |
save()
Save configuration in the same file it was loaded (or with same JNDI name if obtained from JNDI). |
void |
save(java.io.File outputFile)
Save configuration content in specified file. |
void |
save(java.lang.String path)
Save configuration content in specified file. |
void |
saveJndi()
Save configuration with same JNDI name. |
void |
saveJndi(java.lang.String jndiName)
Save configuration with given JNDI name. |
void |
saveJndi(java.lang.String jndiName,
boolean overwrite)
Save configuration with given JNDI name. |
void |
saveProperties(java.io.File outputFile)
Save configuration content in specified file with Java properties format. |
void |
setValidation(boolean validate)
Indicate if configuration content must be validated with DTD. |
void |
updateConstant(java.lang.String name,
java.lang.String value)
Change a constant value. |
void |
updateParameter(java.lang.String section,
java.lang.String name,
java.lang.String value)
Change a parameter value. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String SECTION_SEPARATOR
public static final java.lang.String CONSTANT_NAME_PREFIX
public static final java.lang.String CONSTANT_NAME_SUFFIX
public static final java.lang.String DEFAULT_SET
public static final int MODE_DEFAULT
public static final int MODE_THREAD_SAFE
public static final int MODE_READ_ONLY
public static final int TYPE_UNKNOWN
public static final int TYPE_BOOLEAN
public static final int TYPE_CHAR
public static final int TYPE_BYTE
public static final int TYPE_SHORT
public static final int TYPE_INT
public static final int TYPE_LONG
public static final int TYPE_FLOAT
public static final int TYPE_DOUBLE
public static final int TYPE_DIR
public static final int TYPE_FILE
public static final int TYPE_BIT_SET
public static final int TYPE_INET_ADDRESS
public static final int TYPE_URL
public static final int TYPE_BIG_INTEGER
public static final int TYPE_BIG_DECIMAL
Method Detail |
public boolean getValidation()
true
if configuration is validated with DTD.public javax.naming.Context getJndiContext()
null
if JNDI was never called.public java.lang.String getJndiName()
null/CODE> if configuration is neither obtained nor saved with JNDI.
public java.lang.String getConfigPath()
public java.io.File getCurrentFile()
null
if we have loaded a configuration from an URL or a classloader relative path.public java.lang.String[] getConstantNames()
public java.lang.String getConstant(java.lang.String name) throws net.sourceforge.jezxmlconfig.XmlConfigException
name
- Constant name.
XmlConfigException
- If specified constant does not exist.public java.lang.String getConstant(java.lang.String name, java.lang.String defaultValue)
name
- Constant name.defaultValue
- Default value.
public java.lang.String[] getSectionPaths()
public boolean isSectionExist(java.lang.String section)
section
- Full qualified section name.
true
if specified section exists.public boolean isSectionEmpty(java.lang.String key) throws net.sourceforge.jezxmlconfig.XmlConfigException
key
- Full qualified section name.
true
if specified section does not contains any sub-section or parameter.
net.sourceforge.jezxmlconfig.XmlConfigException
public boolean isConstantExist(java.lang.String key)
key
- Constant name.
true
if specified constant exists.public boolean isParamExist(java.lang.String section, java.lang.String key)
section
- Full qualified section name.key
- Parameter name.
true
if specified parameter exists.public int getDeepestParamLevel(java.lang.String key) throws net.sourceforge.jezxmlconfig.XmlConfigException
key
- Full qualified section name.
-1
if specified section does not contains any parameter at any level.0
if specified section contains parameters only at its level.
N
deepest level of sub-section that have parameters.
net.sourceforge.jezxmlconfig.XmlConfigException
public java.lang.String[] getRootSectionNames()
public java.lang.String[] getSubSectionNames(java.lang.String sectionName)
sectionName
- Full qualified section name.
null
if specified section does not exist.public java.lang.String[] getParamNames(java.lang.String sectionName)
null
if specified section does not exist.public java.lang.String getBrutParameter(java.lang.String sectionPath, java.lang.String paramName) throws net.sourceforge.jezxmlconfig.XmlConfigException
sectionPath
- Full qualified section name.paramName
- Parameter name.
XmlConfigException
- If specified parameter does not exist.public java.lang.String getStringParameter(java.lang.String sectionPath, java.lang.String paramName) throws net.sourceforge.jezxmlconfig.XmlConfigException
sectionPath
- Full qualified section name.paramName
- Parameter name.
XmlConfigException
- If specified parameter does not exist.public java.lang.String getStringParameter(java.lang.String sectionPath, java.lang.String paramName, java.lang.String defaultValue)
sectionPath
- Full qualified section name.paramName
- Parameter name.defaultValue
- Default value.
public java.lang.String[] getMultiStringParameter(java.lang.String section, java.lang.String paramName) throws net.sourceforge.jezxmlconfig.XmlConfigException
section
- Full qualified section name.paramName
- Parameter name.
XmlConfigException
- if parameter is not found.public java.lang.String[] getMultiStringParameter(java.lang.String section, java.lang.String paramName, java.lang.String[] defaultValues)
section
- Full qualified section name.paramName
- Parameter name.defaultValues
- Default values.
public java.lang.String[] getMultiStringParameter(java.lang.String section, java.lang.String paramName, java.lang.String separator) throws net.sourceforge.jezxmlconfig.XmlConfigException
section
- Full qualified section name.paramName
- Parameter name.separator
- The separator to be used when parsing values.
XmlConfigException
- if parameter is not found.public java.lang.String[] getMultiStringParameter(java.lang.String section, java.lang.String paramName, java.lang.String[] defaultValues, java.lang.String separator)
section
- Full qualified section name.paramName
- Parameter name.defaultValues
- Default values.separator
- The separator to be used when parsing values.
public char getCharParameter(java.lang.String section, java.lang.String key) throws net.sourceforge.jezxmlconfig.XmlConfigException
section
- Full qualified section name.key
- Parameter name.
XmlConfigException
- if parameter does not exist, or its value is not a valid character.public char getCharParameter(java.lang.String section, java.lang.String key, char defaultValue)
section
- Full qualified section name.key
- Parameter name.defaultValue
- Default value.
public byte getByteParameter(java.lang.String section, java.lang.String key) throws net.sourceforge.jezxmlconfig.XmlConfigException
Value can be negative. In this case, it must begin with the minus character '-'. It can be one of following formats:
"#"
or "0x"
.
section
- Full qualified section name.key
- Parameter name.
XmlConfigException
- if parameter is not found or its value is out of range or not in a valid format.public byte getByteParameter(java.lang.String section, java.lang.String key, byte defaultValue)
Value can be negative. In this case, it must begin with the minus character '-'. It can be one of following formats:
"#"
or "0x"
.
section
- Full qualified section name.key
- Parameter name.defaultValue
- Default value.
public short getShortParameter(java.lang.String section, java.lang.String key) throws net.sourceforge.jezxmlconfig.XmlConfigException
Value can be negative. In this case, it must begin with the minus character '-'. It can be one of following formats:
"#"
or "0x"
.
section
- Full qualified section name.key
- Parameter name.
XmlConfigException
- if parameter is not found or its value is out of range or not in a valid format.public short getShortParameter(java.lang.String section, java.lang.String key, short defaultValue)
Value can be negative. In this case, it must begin with the minus character '-'. It can be one of following formats:
"#"
or "0x"
.
section
- Full qualified section name.key
- Parameter name.defaultValue
- Default value.
public int getIntParameter(java.lang.String section, java.lang.String key) throws net.sourceforge.jezxmlconfig.XmlConfigException
Value can be negative. In this case, it must begin with the minus character '-'. It can be one of following formats:
"#"
or "0x"
.
section
- Full qualified section name.key
- Parameter name.
XmlConfigException
- if parameter is not found or its value is out of range or not in a valid format.public int getIntParameter(java.lang.String section, java.lang.String key, int defaultValue)
Value can be negative. In this case, it must begin with the minus character '-'. It can be one of following formats:
"#"
or "0x"
.
section
- Full qualified section name.key
- Parameter name.defaultValue
- Default value.
public long getLongParameter(java.lang.String section, java.lang.String key) throws net.sourceforge.jezxmlconfig.XmlConfigException
Value can be negative. In this case, it must begin with the minus character '-'. It can be one of following formats:
"#"
or "0x"
.
section
- Full qualified section name.key
- Parameter name.
XmlConfigException
- if parameter is not found or its value is out of range or not in a valid format.public long getLongParameter(java.lang.String section, java.lang.String key, long defaultValue)
Value can be negative. In this case, it must begin with the minus character '-'. It can be one of following formats:
"#"
or "0x"
.
section
- Full qualified section name.key
- Parameter name.defaultValue
- Default value.
public float getFloatParameter(java.lang.String section, java.lang.String key) throws net.sourceforge.jezxmlconfig.XmlConfigException
Value can be negative. In this case, it must begin with the minus character '-'. It can also be given in format supported by Float.parseFloat(String value) method.
If value is too large, no exception is thrown and return value is Float.POSITIVE_INFINITY or Float.NEGATIVE_INFINITY
depending on sign.
This case can be tested with following code: boolean isInfinite = new Float(result).isInfinite()
section
- Full qualified section name.key
- Parameter name.
XmlConfigException
- if parameter is not found or its value is not in a valid format.public float getFloatParameter(java.lang.String section, java.lang.String key, float defaultValue)
Value can be negative. In this case, it must begin with the minus character '-'. It can also be given in format supported by Float.parseFloat(String value) method.
If value is too large, no exception is thrown and return value is Float.POSITIVE_INFINITY or Float.NEGATIVE_INFINITY
depending on sign.
This case can be tested with following code: boolean isInfinite = new Float(result).isInfinite()
section
- Full qualified section name.key
- Parameter name.defaultValue
- Default value.
public double getDoubleParameter(java.lang.String section, java.lang.String key) throws net.sourceforge.jezxmlconfig.XmlConfigException
Value can be negative. In this case, it must begin with the minus character '-'. It can also be given in format supported by Double.parseDouble(String value) method.
If value is too large, no exception is thrown and return value is Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY
depending on sign.
This case can be tested with following code: boolean isInfinite = new Double(result).isInfinite()
section
- Full qualified section name.key
- Parameter name.
XmlConfigException
- if parameter is not found or its value is not in a valid format.public double getDoubleParameter(java.lang.String section, java.lang.String key, double defaultValue)
Value can be negative. In this case, it must begin with the minus character '-'. It can also be given in format supported by Double.parseDouble(String value) method.
If value is too large, no exception is thrown and return value is Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY
depending on sign.
This case can be tested with following code: boolean isInfinite = new Double(result).isInfinite()
section
- Full qualified section name.key
- Parameter name.defaultValue
- Default value.
public boolean getBooleanParameter(java.lang.String section, java.lang.String key) throws net.sourceforge.jezxmlconfig.XmlConfigException
section
- Full qualified section name.key
- Parameter name.
XmlConfigException
- If specified parameter does not exist.public boolean getBooleanParameter(java.lang.String section, java.lang.String key, boolean defaultValue)
section
- Full qualified section name.key
- Parameter name.defaultValue
- Default value.
public java.lang.Object getObjectParameter(int type, java.lang.String section, java.lang.String key) throws net.sourceforge.jezxmlconfig.XmlConfigException
type
- The wanted type for value (See class general documentation for more information).section
- Full qualified section name.key
- Parameter name.
XmlConfigException
- If specified parameter is not found or its value is not in a valid format.public java.lang.Object getObjectParameter(int type, java.lang.String section, java.lang.String key, java.lang.Object defaultValue)
type
- The wanted type for value (See class general documentation for more information).section
- Full qualified section name.key
- Parameter name.defaultValue
- Default value.
public java.lang.Object[] getMultiObjectParameter(int type, java.lang.String section, java.lang.String key) throws net.sourceforge.jezxmlconfig.XmlConfigException
type
- section
- Full qualified section name.key
- Parameter name.
XmlConfigException
- If specified parameter is not found or its value is not in a valid format.public java.lang.Object[] getMultiObjectParameter(int type, java.lang.String section, java.lang.String key, java.lang.Object[] defaultValues)
type
- section
- Full qualified section name.key
- Parameter name.defaultValues
- Default values.
public java.lang.Object[] getMultiObjectParameter(int type, java.lang.String section, java.lang.String key, java.lang.String separator) throws net.sourceforge.jezxmlconfig.XmlConfigException
type
- section
- Full qualified section name.key
- Parameter name.
XmlConfigException
- If specified parameter is not found or its value is not in a valid format.public java.lang.Object[] getMultiObjectParameter(int type, java.lang.String section, java.lang.String key, java.lang.Object[] defaultValues, java.lang.String separator)
type
- section
- Full qualified section name.key
- Parameter name.defaultValues
- Default values.
public void setValidation(boolean validate)
validate
- Must be true
to validate XML configuration file with DTD.public void addConstant(java.lang.String name, java.lang.String value) throws net.sourceforge.jezxmlconfig.XmlConfigException
name
- constant name.value
- Constant value.
XmlConfigException
- If a constant already exist with the same name.
java.lang.SecurityException
- If configuration is in readonly mode.public void addSection(java.lang.String name) throws net.sourceforge.jezxmlconfig.XmlConfigException
name
- Full qualified constant name.
XmlConfigException
- If section already exist or parent does not exist.
java.lang.SecurityException
- If configuration is in readonly mode.public void addSection(java.lang.String name, boolean createParents) throws net.sourceforge.jezxmlconfig.XmlConfigException
name
- Full qualified constant name.createParents
- Must be true
if you want non existing parents to be automaticaly created as well.
XmlConfigException
- If section already exist or parent does not exist.
java.lang.SecurityException
- If configuration is in readonly mode.public void insertSection(java.lang.String before, java.lang.String name) throws net.sourceforge.jezxmlconfig.XmlConfigException
before
- Full qualified section name of existing sibling (The new section will be inserted just before this one).name
- New section simple name.
XmlConfigException
- If section already exist, or specified sibling section does not exist.
java.lang.SecurityException
- If configuration is in readonly mode.public void addParameter(java.lang.String section, java.lang.String name, java.lang.String value) throws net.sourceforge.jezxmlconfig.XmlConfigException
section
- Full qualified section name.name
- Parameter name.value
- Parameter value
(can contain a reference to a constant or a system property with format ${constantName}
).
XmlConfigException
- If parameter already exist or if specified section does not exist.
java.lang.SecurityException
- If configuration is in readonly mode.public void removeConstant(java.lang.String name) throws net.sourceforge.jezxmlconfig.XmlConfigException
name
- Constant name.
XmlConfigException
- If specified constant does not exist.
java.lang.SecurityException
- If configuration is in readonly mode.public void removeSection(java.lang.String name) throws net.sourceforge.jezxmlconfig.XmlConfigException
name
- Full qualified section name.
XmlConfigException
- If specified section does not exist.
java.lang.SecurityException
- If configuration is in readonly mode.public void removeParameter(java.lang.String section, java.lang.String name) throws net.sourceforge.jezxmlconfig.XmlConfigException
section
- Full qualified section name.name
- Parameter name.
XmlConfigException
- If specified section or parameter does not exist.
java.lang.SecurityException
- If configuration is in readonly mode.public void renameConstant(java.lang.String oldName, java.lang.String newName) throws net.sourceforge.jezxmlconfig.XmlConfigException
oldName
- Old constant name.newName
- New constant name.
XmlConfigException
- If old constant does not exist or new constant already exist.
java.lang.SecurityException
- If configuration is in readonly mode.public void updateConstant(java.lang.String name, java.lang.String value) throws net.sourceforge.jezxmlconfig.XmlConfigException
name
- Constant name.value
- New constant value.
XmlConfigException
- If specified constant does not exist.
java.lang.SecurityException
- If configuration is in readonly mode.public void renameSection(java.lang.String parent, java.lang.String simpleOldName, java.lang.String simpleNewName) throws net.sourceforge.jezxmlconfig.XmlConfigException
Note: This method just rename a section and cannot move it in an other parent section. To do that, use moveSection() method.
parent
- Full qualified parent section name, or null
if you want to rename a root section.simpleOldName
- Old simple section name.simpleNewName
- New simple section name.
XmlConfigException
- If parent section or the section itself does not exist, or new section already exist.
java.lang.SecurityException
- If configuration is in readonly mode.public void moveSection(java.lang.String oldParent, java.lang.String newParent, java.lang.String name) throws net.sourceforge.jezxmlconfig.XmlConfigException
oldParent
- Full qualified olf parent section name, or null
if you want to move a root section.newParent
- Full qualified new parent section name, or null
if you want the section to become a root one.name
- Simple name of section you want to move.
XmlConfigException
- If one of these following case is true:
java.lang.SecurityException
- If configuration is in readonly mode.public void renameParameter(java.lang.String section, java.lang.String oldName, java.lang.String newName) throws net.sourceforge.jezxmlconfig.XmlConfigException
section
- Full qualified section name.oldName
- Old parameter name.newName
- New parameter name.
XmlConfigException
- If one of these following case is true:
java.lang.SecurityException
- If configuration is in readonly mode.public void moveParameter(java.lang.String oldSection, java.lang.String newSection, java.lang.String name) throws net.sourceforge.jezxmlconfig.XmlConfigException
oldSection
- Full qualified old section name.newSection
- Full qualified new section name.name
- Parameter name.
XmlConfigException
- If one of these following case is true:
java.lang.SecurityException
- If configuration is in readonly mode.public void updateParameter(java.lang.String section, java.lang.String name, java.lang.String value) throws net.sourceforge.jezxmlconfig.XmlConfigException
section
- Full qualified section name.name
- Parameter name.value
- New parameter value
(can contain a reference to a constant or a system property with format ${constantName}
).
XmlConfigException
- If section or parameter does not exist.
java.lang.SecurityException
- If configuration is in readonly mode.public void reset() throws net.sourceforge.jezxmlconfig.XmlConfigException
WARNING: All constants, sections and parameters will be permanetly delete.
XmlConfigException
- If the system cannot obtain an XML document factory (No XML parser found).
java.lang.SecurityException
- If configuration is in readonly mode.public void save() throws net.sourceforge.jezxmlconfig.XmlConfigException
XmlConfigException
- If file is readonly or an I/O exception occurs.public void saveJndi() throws net.sourceforge.jezxmlconfig.XmlConfigException
XmlConfigException
- if configuration was not obtained from JNDI or if cannot be saved.public void saveJndi(java.lang.String jndiName) throws net.sourceforge.jezxmlconfig.XmlConfigException
jndiName
- JNDI name for saving configuration
XmlConfigException
- if configuration cannot be saved, or if a configuration with specified JNDI name already exist.public void saveJndi(java.lang.String jndiName, boolean overwrite) throws net.sourceforge.jezxmlconfig.XmlConfigException
jndiName
- JNDI name for saving configuration.overwrite
- Must be true
to successfully update a configuration on an already existing JNDI name.
XmlConfigException
- if configuration cannot be saved.public void save(java.lang.String path) throws net.sourceforge.jezxmlconfig.XmlConfigException
path
- File (with path) where configuration must be saved.
XmlConfigException
- If file cannot be created or overwriten, or an I/O exception occurs.public void save(java.io.File outputFile) throws net.sourceforge.jezxmlconfig.XmlConfigException
outputFile
- File where configuration must be saved.
XmlConfigException
- If file cannot be created or overwriten, or an I/O exception occurs.public void saveProperties(java.io.File outputFile) throws net.sourceforge.jezxmlconfig.XmlConfigException
outputFile
- File where configuration must be saved.
XmlConfigException
- If file cannot be created or overwriten, or an I/O exception occurs.public void load(java.io.File configFile) throws net.sourceforge.jezxmlconfig.XmlConfigException
configFile
- Configuration file.
XmlConfigException
- If specified file does not exist or cannot be read, if an I/O exception occurs,
or if file content cannot be parsed correctly.
java.lang.SecurityException
- If configuration is in readonly mode and a load() method have already been called.public void load(java.net.URL configFileUrl) throws net.sourceforge.jezxmlconfig.XmlConfigException
configFileUrl
- An URL that provide an XML configuration.
XmlConfigException
- If an I/O exception occurs, or if file content cannot be parsed correctly.
java.lang.SecurityException
- If configuration is in readonly mode and a load() method have already been called.public void load(java.lang.String path) throws net.sourceforge.jezxmlconfig.XmlConfigException
path
- Configuration path.
Could be given with one of the following way (with priority order):
XmlConfigException
- If specified file does not exist or cannot be read, if an I/O exception occurs,
or if file content cannot be parsed correctly.
java.lang.SecurityException
- If configuration is in readonly mode and a load() method have already been called.public void load(java.io.InputStream inputStream, java.lang.String path) throws net.sourceforge.jezxmlconfig.XmlConfigException
inputStream
- Input stream from which configuration will be loaded.path
- The path associated to this configuration. It is only used for display purpose (never computed or interpreted).
XmlConfigException
- If an I/O exception occurs, or file content cannot be parsed correctly.
java.lang.SecurityException
- If configuration is in readonly mode and a load() method have already been called.public void loadProperties(java.io.File configFile) throws net.sourceforge.jezxmlconfig.XmlConfigException
Warning: A parameter is always in a section. Then, in your property file, things will be interpreted as the following:
word1.word2.word3=value1
word0=value2
configFile
- Property file.
XmlConfigException
- If specified file does not exist or cannot be read, if an I/O exception occurs,
or if file content cannot be parsed correctly.
java.lang.SecurityException
- If configuration is in readonly mode and a load() method have already been called.public void loadProperties(java.net.URL configFileUrl) throws net.sourceforge.jezxmlconfig.XmlConfigException
Warning: A parameter is always in a section. Then, in your property file, things will be interpreted as the following:
word1.word2.word3=value1
word0=value2
configFileUrl
- An URL that provide data in Java properties format.
XmlConfigException
- If an I/O exception occurs, or if file content cannot be parsed correctly.
java.lang.SecurityException
- If configuration is in readonly mode and a load() method have already been called.public void loadProperties(java.lang.String path) throws net.sourceforge.jezxmlconfig.XmlConfigException
Warning: A parameter is always in a section. Then, in your property file, things will be interpreted as the following:
word1.word2.word3=value1
word0=value2
path
- Configuration path.
Could be given with one of the following way (with priority order):
XmlConfigException
- If specified file does not exist or cannot be read, if an I/O exception occurs,
or if file content cannot be parsed correctly.
java.lang.SecurityException
- If configuration is in readonly mode and a load() method have already been called.public void loadProperties(java.io.InputStream inputStream, java.lang.String path) throws net.sourceforge.jezxmlconfig.XmlConfigException
Warning: A parameter is always in a section. Then, in your property file, things will be interpreted as the following:
word1.word2.word3=value1
word0=value2
inputStream
- Input stream from which configuration will be loaded.path
- The path associated to this configuration. It is only used for display purpose (never computed or interpreted).
XmlConfigException
- If an I/O exception occurs, or file content cannot be parsed correctly.
java.lang.SecurityException
- If configuration is in readonly mode and a load() method have already been called.public void dump(java.io.PrintStream out)
It displays whole configuration content as a readable text on the specified output.
out
- The output where configuration will be dumped.public static XmlConfig getInstance() throws net.sourceforge.jezxmlconfig.XmlConfigException
If this is the very first time this method is called, an empty configuration is built.
XmlConfigException
- Only at very first call and if XML document corresponding to
an empty configuration cannot be initialized.public static XmlConfig jndiLookup(java.lang.String jndiName) throws net.sourceforge.jezxmlconfig.XmlConfigException
XmlConfigException
- Only at very first call and if XML document corresponding to
an empty configuration cannot be initialized.public static java.util.List jndiList() throws net.sourceforge.jezxmlconfig.XmlConfigException
XmlConfigException
- If cannot access JNDI successfully.public static java.util.List jndiList(java.lang.String subdir) throws net.sourceforge.jezxmlconfig.XmlConfigException
subdir
- The subdirectory where we want to list configurations.
XmlConfigException
- If cannot access JNDI successfully.public static java.util.List jndiListAll() throws net.sourceforge.jezxmlconfig.XmlConfigException
XmlConfigException
- If cannot access JNDI successfully.public static XmlConfig getInstance(java.lang.String configSet, int mode) throws net.sourceforge.jezxmlconfig.XmlConfigException
If this is the very first time this method is called for this configuration set, an empty configuration is built.
configSet
- The configuration set name.mode
- This parameter is only used at very first time this method is called for the specified configuration set.
It will be ignored for other calls.XmlConfigException
- Only at very first call and if XML document corresponding to
an empty configuration cannot be initialized, or if given mode is unknown.public static void removeInstance(java.lang.String configSet)
public static void removeAllInstances()
public static void main(java.lang.String[] args)
This main method just load given file and displays its content on standard output using the dump() method.
One argument is needed: The file to load.