|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sibvisions.rad.server.config.UpToDateConfigFile
public class UpToDateConfigFile
The UpToDateConfigFile
encapsulates the access to a xml configuration
file. It's guaranteed that the access to the properties of the file is up-to-date.
That means that changes will be detected automatically.
Constructor Summary | |
---|---|
UpToDateConfigFile(java.io.File pConfig)
Creates a new instance of UpToDateConfigFile for a
xml configuration file. |
|
UpToDateConfigFile(java.io.File pDirectory,
java.lang.String pConfig)
Creates a new instance of UpToDateConfigFile for a
xml configuration file. |
Method Summary | |
---|---|
java.lang.Object |
clone()
|
protected XmlWorker |
createXmlWorker()
Creates the default XmlWorker for reading the file. |
java.io.File |
getFile()
Gets the configuration file. |
XmlNode |
getNode(java.lang.String pName)
Gets the value for a property as xml representation. |
java.util.List<XmlNode> |
getNodes(java.lang.String pName)
Gets the value for a property as xml representation. |
java.util.List<java.lang.String> |
getProperties(java.lang.String pName)
Gets a list of values for a property which exists more than once. |
java.lang.String |
getProperty(java.lang.String pName)
Gets the value of a property from the application configuration file. |
java.lang.String |
getProperty(java.lang.String pName,
java.lang.String pDefault)
Gets the value of a property from the application configuration file. |
boolean |
isCloneNodes()
Gets whether xml nodes should be cloned before returning. |
boolean |
isFile()
Gets whether the config is a physical file. |
boolean |
isSaveImmediate()
Gets it immediate save of changes is enabled. |
boolean |
isStream()
Gets whether the config was read from an external stream. |
boolean |
isUpdateEnabled()
Gets whether the up-to-date option is enabled. |
boolean |
isValid()
Checks if the configuration file exists. |
boolean |
isVirtual()
Gets whether the config is virtual. |
protected void |
prepareIncludeNodes(XmlNode pNode)
Prepares the include nodes <include>... |
void |
reload()
Discards all changes and loads the configuration file. |
protected java.lang.String |
replacePlaceholder(java.lang.String pValue,
java.util.Properties pImportedProperties,
java.util.Properties pSystemProperties,
java.util.Map<java.lang.String,java.lang.String> pEnvironmentProperties)
Replaces all placeholder with the desired properties. |
protected boolean |
replacePlaceholder(XmlNode pNode,
java.util.Properties pImportedProperties,
java.util.Properties pSystemProperties,
java.util.Map<java.lang.String,java.lang.String> pEnvironmentProperties)
Replaces all property placeholder ${x.y.z} with
the corresponding value in the properties, recursively. |
void |
save()
Saves the changes to the file. |
void |
setCloneNodes(boolean pClone)
Sets whether xml nodes should be cloned before returning. |
protected void |
setContent(XmlNode pNode)
Sets the internal data node. |
void |
setNode(java.lang.String pName,
XmlNode pNode)
Sets a specific node to the application configuration file. |
void |
setProperty(java.lang.String pName,
java.lang.String pValue)
Sets the value of a property to the application configuration file. |
void |
setSaveImmediate(boolean pEnabled)
Sets the save immediate option. |
void |
setUpdateEnabled(boolean pEnabled)
Sets the up-to-date option of the configuration. |
protected void |
update()
Loads the configuration from the filesystem. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public UpToDateConfigFile(java.io.File pDirectory, java.lang.String pConfig) throws java.lang.Exception
UpToDateConfigFile
for a
xml configuration file. The configuration will read immediately.
pDirectory
- the directory where to find the configuration filepConfig
- the configuration file name
java.lang.Exception
- if it is not possible to read the configuration
from the filesystem or the xml content is not validpublic UpToDateConfigFile(java.io.File pConfig) throws java.lang.Exception
UpToDateConfigFile
for a
xml configuration file. The configuration will read immediately.
pConfig
- the configuration file
java.lang.Exception
- if it is not possible to read the configuration
from the filesystem or the xml content is not validMethod Detail |
---|
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
public java.io.File getFile()
public boolean isValid()
true
if the configuration file exists otherwise false
protected void update() throws java.lang.Exception
java.lang.Exception
- if it is not possible to read the configuration
from the filesystem or the xml content is not validpublic void setProperty(java.lang.String pName, java.lang.String pValue) throws java.lang.Exception
pName
- the property name (e.g. /application/securitymanager/class)pValue
- the value
java.lang.Exception
- if the configuration is invalidpublic void setNode(java.lang.String pName, XmlNode pNode) throws java.lang.Exception
pName
- the property namepNode
- the new node or null
to remove the property
java.lang.Exception
- if the configuration is invalidpublic java.lang.String getProperty(java.lang.String pName) throws java.lang.Exception
pName
- the property name (e.g /application/securitymanager/class)
java.lang.Exception
- if the configuration is invalidpublic java.lang.String getProperty(java.lang.String pName, java.lang.String pDefault) throws java.lang.Exception
pName
- the property name (e.g /application/securitymanager/class)pDefault
- the default value if the property is not available
pDefault
if the property is not available
java.lang.Exception
- if the configuration is invalidpublic java.util.List<java.lang.String> getProperties(java.lang.String pName) throws java.lang.Exception
pName
- the property name
null
if the property is not available
java.lang.Exception
- if the configuration is invalidpublic java.util.List<XmlNode> getNodes(java.lang.String pName) throws java.lang.Exception
pName
- the property name
null
if the property is not available
java.lang.Exception
- if the configuration is invalidpublic XmlNode getNode(java.lang.String pName) throws java.lang.Exception
pName
- the property name
null
is the property is not available
java.lang.Exception
- if the configuration is invalidpublic void setUpdateEnabled(boolean pEnabled)
pEnabled
- true
doesn't update the configuration when
next accessing; false
always keeps the configuration
up-to-datepublic boolean isUpdateEnabled()
true
if the current configuration will be read before
accessing a property, false
if the configuration won't
be read againpublic void setSaveImmediate(boolean pEnabled)
pEnabled
- true
to enable immediate save changes, false
otherwisepublic boolean isSaveImmediate()
true
if changes will saved immediate, false
otherwisepublic void save() throws java.io.IOException
java.io.IOException
- if the file access failed or the content was modified by <include> declarationspublic void reload() throws java.lang.Exception
java.lang.Exception
- if an exception occurs during loadingprotected XmlWorker createXmlWorker()
XmlWorker
for reading the file.
protected void setContent(XmlNode pNode)
pNode
- the data nodepublic final boolean isFile()
true
if config is a physical filepublic final boolean isVirtual()
true
if config is virtualpublic final boolean isStream()
true
if config was read from streampublic void setCloneNodes(boolean pClone)
pClone
- true
to clone nodes, false
otherwisepublic boolean isCloneNodes()
true
if nodes will be cloned, false
otherwiseprotected void prepareIncludeNodes(XmlNode pNode) throws java.io.IOException
<include>...</include>
.
The value of the include node is used as file path to load the resource
over the classpath or filesystem if it is available.
All loaded properties are inserted under the first founded root node.
In addition, all property place holders ${x.y.z}
are replaced with
the loaded values of the properties.
pNode
- the node to prepare
java.io.IOException
- if an error occurred when reading from the property file input stream.protected boolean replacePlaceholder(XmlNode pNode, java.util.Properties pImportedProperties, java.util.Properties pSystemProperties, java.util.Map<java.lang.String,java.lang.String> pEnvironmentProperties)
${x.y.z}
with
the corresponding value in the properties, recursively.
pNode
- the node to replace the property place holderspImportedProperties
- the import propertiespSystemProperties
- the system propertiespEnvironmentProperties
- the environment properties
true
if one node value was modifiedprotected java.lang.String replacePlaceholder(java.lang.String pValue, java.util.Properties pImportedProperties, java.util.Properties pSystemProperties, java.util.Map<java.lang.String,java.lang.String> pEnvironmentProperties)
pValue
- the value of an nodepImportedProperties
- the import propertiespSystemProperties
- the system propertiespEnvironmentProperties
- the environment properties
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |