public class XmlProperties extends Object implements ResourceProperties
ResourceProperties
interface with support of so
called "XML properties".
For XML properties, see "https://en.wikipedia.org/wiki/XML"ResourceProperties.MutableResoureProperties, ResourceProperties.ResourcePropertiesBuilder
Properties.MutableProperties, Properties.PropertiesBuilder
org.refcodes.structure.CanonicalMap.CanonicalMapBuilder, org.refcodes.structure.CanonicalMap.MutableCanonicalMap
org.refcodes.structure.PathMap.MutablePathMap<T>, org.refcodes.structure.PathMap.PathMapBuilder<T>
org.refcodes.structure.Dictionary.MutableDictionary<K,V>
org.refcodes.structure.Keys.MutableKeys<K,V>, org.refcodes.structure.Keys.MutableValues<K,V>
org.refcodes.mixin.DelimiterAccessor.DelimiterBuilder<B extends org.refcodes.mixin.DelimiterAccessor.DelimiterBuilder<B>>, org.refcodes.mixin.DelimiterAccessor.DelimiterMutator, org.refcodes.mixin.DelimiterAccessor.DelimiterProperty
org.refcodes.mixin.TypeAccessor.TypeMutator<T>, org.refcodes.mixin.TypeAccessor.TypeProperty<T>
org.refcodes.structure.PropertiesAccessorMixin.PropertiesBuilderMixin<T>, org.refcodes.structure.PropertiesAccessorMixin.PropertiesMixin, org.refcodes.structure.PropertiesAccessorMixin.PropertiesMutatorMixin
Modifier and Type | Field and Description |
---|---|
protected ResourceProperties.ResourcePropertiesBuilder |
_properties |
DEFAULT_COMMENT
Constructor and Description |
---|
XmlProperties(Class<?> aResourceClass,
String aFilePath)
Loads the XML Properties from the given file's path.
|
XmlProperties(Class<?> aResourceClass,
String aFilePath,
boolean isSeekFile)
Loads the XML Properties from the given file's path.
|
XmlProperties(Class<?> aResourceClass,
String aFilePath,
boolean isSeekFile,
char... aDelimiters)
Loads the XML Properties from the given file's path.
|
XmlProperties(Class<?> aResourceClass,
String aFilePath,
char... aDelimiters)
Loads the XML Properties from the given file's path.
|
XmlProperties(File aFile)
Loads the XML Properties from the given
File . |
XmlProperties(File aFile,
boolean isSeekFile)
Loads or seeks the XML Properties from the given
File . |
XmlProperties(File aFile,
boolean isSeekFile,
char... aDelimiters)
Loads or seeks the XML Properties from the given
File . |
XmlProperties(File aFile,
char... aDelimiters)
Loads the XML Properties from the given
File . |
XmlProperties(InputStream aInputStream)
Reads the XML Properties from the given
InputStream . |
XmlProperties(InputStream aInputStream,
char... aDelimiters)
Reads the XML Properties from the given
InputStream . |
XmlProperties(Map<?,?> aProperties)
Create a
XmlProperties instance containing the
elements of the provided Map instance using the default path
delimiter "/" (Delimiter.PATH ) for the path declarations |
XmlProperties(Object aObj)
Create a
XmlProperties instance containing the
elements as of PathMap.MutablePathMap.insert(Object) using the default
path delimiter "/" (Delimiter.PATH ) for the path declarations:
"Inspects the given object and adds all elements found in the given
object. |
XmlProperties(Properties.PropertiesBuilder aProperties)
Create a
XmlProperties instance containing the
elements of the provided Properties.PropertiesBuilder instance using the
default path delimiter "/" (Delimiter.PATH ) for the path
declarations |
XmlProperties(Properties aProperties)
Create a
XmlProperties instance containing the
elements of the provided Properties instance using the default
path delimiter "/" (Delimiter.PATH ) for the path declarations |
XmlProperties(String aFilePath)
Loads the XML Properties from the given file's path.
|
XmlProperties(String aFilePath,
boolean isSeekFile)
Loads the XML Properties from the given file's path.
|
XmlProperties(String aFilePath,
boolean isSeekFile,
char... aDelimiters)
Loads the XML Properties from the given file's path.
|
XmlProperties(String aFilePath,
char... aDelimiters)
Loads the XML Properties from the given file's path.
|
XmlProperties(URL aUrl)
Loads the XML Properties from the given
URL . |
XmlProperties(URL aUrl,
char... aDelimiters)
Loads the XML Properties from the given
URL . |
Modifier and Type | Method and Description |
---|---|
boolean |
containsKey(Object aKey) |
String |
get(Object aKey) |
char |
getDelimiter() |
Class<String> |
getType() |
boolean |
isEmpty() |
Set<String> |
keySet() |
Properties |
reload()
Reloads the
ResourceProperties from the resource to which the
ResourceProperties are attached to (such as a File as of
ResourceProperties.MutableResoureProperties.loadFrom(File) or
ResourceProperties.saveTo(File) ). |
Properties |
reload(ReloadMode aReloadMode)
Reloads the
ResourceProperties from the resource to which the
ResourceProperties are attached to (such as a File as of
ResourceProperties.MutableResoureProperties.loadFrom(File) or
ResourceProperties.saveTo(File) ). |
Properties |
retrieveFrom(String aFromPath) |
Properties |
retrieveTo(String aToPath) |
File |
saveTo(File aFile,
String aComment,
char aDelimiter)
Saves the properties to the given
File using the provided
delimiter as the destination's path delimiter. |
void |
saveTo(OutputStream aOutputStream,
String aComment,
char aDelimiter)
Saves the properties to the given
OutputStream using the provided
delimiter as the destination's path delimiter. |
int |
size() |
Object |
toDataStructure(String aPath) |
Collection<String> |
values() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
fileTo, fileTo, fileTo, fileTo, fileTo, fileTo, fileTo, fileTo, saveTo, saveTo, saveTo, saveTo, saveTo, saveTo, saveTo, saveTo, saveTo, saveTo, toSerialized, toSerialized
containsValue, retrieve, toMap, toProperties, toPropertyPath
toInstance, toInstance, toType, toType
directories, directories, entries, entries, fromExternalKey, getArray, getArray, hasParentPath, isArray, isArray, isDirectory, isEntry, isRecord, isRootPath, keySet, paths, paths, records, records, toDataStructure, toExternalKey, toMap, toNormalizedPath, toNormalizedPath, toParentPath, toRootPath
containsKey, get, getBoolean, getBoolean, getByte, getByte, getCharacter, getCharacter, getDouble, getDouble, getFloat, getFloat, getInteger, getInteger, getLong, getLong, getShort, getShort, use, useBoolean, useBoolean, useByte, useByte, useDouble, useDouble, useFloat, useFloat, useInteger, useInteger, useLong, useLong, useShort, useShort
protected ResourceProperties.ResourcePropertiesBuilder _properties
public XmlProperties(Object aObj)
XmlProperties
instance containing the
elements as of PathMap.MutablePathMap.insert(Object)
using the default
path delimiter "/" (Delimiter.PATH
) for the path declarations:
"Inspects the given object and adds all elements found in the given
object. Elements of type Map
, Collection
and arrays are
identified and handled as of their type: The path for each value in a
Map
is appended with its according key. The path for each value
in a Collection
or array is appended with its according index of
occurrence (in case of a List
or an array, its actual index). In
case of reflection, the path for each member is appended with its
according mamber's name. All elements (e.g. the members and values) are
inspected recursively which results in the according paths of the
terminating values."aObj
- The object from which the elements are to be added.public XmlProperties(Properties aProperties)
XmlProperties
instance containing the
elements of the provided Properties
instance using the default
path delimiter "/" (Delimiter.PATH
) for the path declarationsaProperties
- the properties to be added.public XmlProperties(Properties.PropertiesBuilder aProperties)
XmlProperties
instance containing the
elements of the provided Properties.PropertiesBuilder
instance using the
default path delimiter "/" (Delimiter.PATH
) for the path
declarationsaProperties
- the properties to be added.public XmlProperties(Map<?,?> aProperties)
XmlProperties
instance containing the
elements of the provided Map
instance using the default path
delimiter "/" (Delimiter.PATH
) for the path declarationsaProperties
- the properties to be added.public XmlProperties(File aFile) throws IOException, ParseException
File
.aFile
- The File
from which to load the properties.IOException
- thrown in case accessing or processing the properties
file failed.ParseException
- Signals that an error has been reached
unexpectedly while parsing the data to be loaded.public XmlProperties(File aFile, char... aDelimiters) throws IOException, ParseException
File
.aFile
- The File
from which to load the properties.aDelimiters
- The path delimiters to be used when parsing the
source's properties.IOException
- thrown in case accessing or processing the properties
file failed.ParseException
- Signals that an error has been reached
unexpectedly while parsing the data to be loaded.public XmlProperties(File aFile, boolean isSeekFile) throws IOException, ParseException
File
.
In case you enable the "seek" argument and directly loading from the
File
does not succeed, then loads from the first folder
containing such a file as of the specification for the method
RuntimeUtility.toConfigDirs()
.aFile
- The File
from which to load the properties.isSeekFile
- When true, then the properties are loaded as of the
"seek" functionality described above.IOException
- thrown in case accessing or processing the properties
file failed.ParseException
- Signals that an error has been reached
unexpectedly while parsing the data to be loaded.public XmlProperties(File aFile, boolean isSeekFile, char... aDelimiters) throws IOException, ParseException
File
.
In case you enable the "seek" argument and directly loading from the
File
does not succeed, then loads from the first folder
containing such a file as of the specification for the method
RuntimeUtility.toConfigDirs()
.aFile
- The File
from which to load the properties.isSeekFile
- When true, then the properties are loaded as of the
"seek" functionality described above.aDelimiters
- The path delimiters to be used when parsing the
source's properties.IOException
- thrown in case accessing or processing the properties
file failed.ParseException
- Signals that an error has been reached
unexpectedly while parsing the data to be loaded.public XmlProperties(String aFilePath) throws IOException, ParseException
aFilePath
- The path to the file from which to load the properties.IOException
- thrown in case accessing or processing the properties
file failed.ParseException
- Signals that an error has been reached
unexpectedly while parsing the data to be loaded.public XmlProperties(String aFilePath, char... aDelimiters) throws IOException, ParseException
aFilePath
- The path to the file from which to load the properties.aDelimiters
- The path delimiters to be used when parsing the
source's properties.IOException
- thrown in case accessing or processing the properties
file failed.ParseException
- Signals that an error has been reached
unexpectedly while parsing the data to be loaded.public XmlProperties(Class<?> aResourceClass, String aFilePath) throws IOException, ParseException
aResourceClass
- The class which's class loader is to take care of
loading the properties (from inside a JAR).aFilePath
- The file path of the class's resources from which to
load the properties.IOException
- thrown in case accessing or processing the properties
file failed.ParseException
- Signals that an error has been reached
unexpectedly while parsing the data to be loaded.public XmlProperties(Class<?> aResourceClass, String aFilePath, char... aDelimiters) throws IOException, ParseException
aResourceClass
- The class which's class loader is to take care of
loading the properties (from inside a JAR).aFilePath
- The file path of the class's resources from which to
load the properties.aDelimiters
- The path delimiters to be used when parsing the
source's properties.IOException
- thrown in case accessing or processing the properties
file failed.ParseException
- Signals that an error has been reached
unexpectedly while parsing the data to be loaded.public XmlProperties(String aFilePath, boolean isSeekFile) throws IOException, ParseException
File
does not succeed, then loads from the first folder
containing such a file as of the specification for the method
RuntimeUtility.toConfigDirs()
.aFilePath
- The path to the file from which to load the properties.isSeekFile
- When true, then the properties are loaded as of the
"seek" functionality described above.IOException
- thrown in case accessing or processing the properties
file failed.ParseException
- Signals that an error has been reached
unexpectedly while parsing the data to be loaded.public XmlProperties(String aFilePath, boolean isSeekFile, char... aDelimiters) throws IOException, ParseException
File
does not succeed, then loads from the first folder
containing such a file as of the specification for the method
RuntimeUtility.toConfigDirs()
.aFilePath
- The path to the file from which to load the properties.isSeekFile
- When true, then the properties are loaded as of the
"seek" functionality described above.aDelimiters
- The path delimiters to be used when parsing the
source's properties.IOException
- thrown in case accessing or processing the properties
file failed.ParseException
- Signals that an error has been reached
unexpectedly while parsing the data to be loaded.public XmlProperties(Class<?> aResourceClass, String aFilePath, boolean isSeekFile) throws IOException, ParseException
File
does not succeed, then loads from the first folder
containing such a file as of the specification for the method
RuntimeUtility.toConfigDirs()
.
Finally (if nothing else succeeds) the properties are loaded by the
provided class's class loader which takes care of loading the properties
(in case the file path is a relative path, also the absolute path with a
prefixed path delimiter "/" is probed).aResourceClass
- The class which's class loader is to take care of
loading the properties (from inside a JAR).aFilePath
- The file path of the class's resources from which to
load the properties.isSeekFile
- When true, then the properties are loaded as of the
"seek" functionality described above.IOException
- thrown in case accessing or processing the properties
file failed.ParseException
- Signals that an error has been reached
unexpectedly while parsing the data to be loaded.public XmlProperties(Class<?> aResourceClass, String aFilePath, boolean isSeekFile, char... aDelimiters) throws IOException, ParseException
File
does not succeed, then loads from the first folder
containing such a file as of the specification for the method
RuntimeUtility.toConfigDirs()
.
Finally (if nothing else succeeds) the properties are loaded by the
provided class's class loader which takes care of loading the properties
(in case the file path is a relative path, also the absolute path with a
prefixed path delimiter "/" is probed).aResourceClass
- The class which's class loader is to take care of
loading the properties (from inside a JAR).aFilePath
- The file path of the class's resources from which to
load the properties.isSeekFile
- When true, then the properties are loaded as of the
"seek" functionality described above.aDelimiters
- The path delimiters to be used when parsing the
source's properties.IOException
- thrown in case accessing or processing the properties
file failed.ParseException
- Signals that an error has been reached
unexpectedly while parsing the data to be loaded.public XmlProperties(URL aUrl) throws IOException, ParseException
URL
.aUrl
- The URL
from which to read the properties.IOException
- thrown in case accessing or processing the properties
file failed.ParseException
- Signals that an error has been reached
unexpectedly while parsing the data to be loaded.public XmlProperties(URL aUrl, char... aDelimiters) throws IOException, ParseException
URL
.aUrl
- The URL
from which to read the properties.aDelimiters
- The path delimiters to be used when parsing the
source's properties.IOException
- thrown in case accessing or processing the properties
file failed.ParseException
- Signals that an error has been reached
unexpectedly while parsing the data to be loaded.public XmlProperties(InputStream aInputStream) throws IOException, ParseException
InputStream
.aInputStream
- The InputStream
from which to read the
properties.IOException
- thrown in case accessing or processing the properties
file failed.ParseException
- Signals that an error has been reached
unexpectedly while parsing the data to be loaded.public XmlProperties(InputStream aInputStream, char... aDelimiters) throws IOException, ParseException
InputStream
.aInputStream
- The InputStream
from which to read the
properties.aDelimiters
- The path delimiters to be used when parsing the
source's properties.IOException
- thrown in case accessing or processing the properties
file failed.ParseException
- Signals that an error has been reached
unexpectedly while parsing the data to be loaded.public boolean containsKey(Object aKey)
public Collection<String> values()
public int size()
size
in interface org.refcodes.structure.Containable
public boolean isEmpty()
isEmpty
in interface org.refcodes.structure.Containable
public Properties retrieveFrom(String aFromPath)
retrieveFrom
in interface Properties
retrieveFrom
in interface org.refcodes.structure.CanonicalMap
retrieveFrom
in interface org.refcodes.structure.PathMap<String>
public Properties retrieveTo(String aToPath)
retrieveTo
in interface Properties
retrieveTo
in interface org.refcodes.structure.CanonicalMap
retrieveTo
in interface org.refcodes.structure.PathMap<String>
public char getDelimiter()
getDelimiter
in interface org.refcodes.mixin.DelimiterAccessor
public Class<String> getType()
getType
in interface Properties
getType
in interface org.refcodes.mixin.TypeAccessor<String>
public Object toDataStructure(String aPath)
toDataStructure
in interface org.refcodes.structure.PathMap<String>
public void saveTo(OutputStream aOutputStream, String aComment, char aDelimiter) throws IOException
OutputStream
using the provided
delimiter as the destination's path delimiter. Load them via
ResourceProperties.MutableResoureProperties.loadFrom(InputStream, char...)
This is the hook-method of the default implementation for writing
(saving) the properties. In case you want to implement
ResourceProperties
which support other notations than the
properties notation (path=value
), then you overwrite this
method in your implementation accordingly.saveTo
in interface ResourceProperties
aOutputStream
- The OutputStream
to which to save the
properties to.aComment
- The description for the properties file.aDelimiter
- The path delimiter to be used when writing out the
properties to the destination (in case the the serialized format
supports / requires the such).IOException
- thrown in case saving the properties failedpublic Properties reload() throws IOException, IllegalStateException, ParseException
ResourceProperties
from the resource to which the
ResourceProperties
are attached to (such as a File
as of
ResourceProperties.MutableResoureProperties.loadFrom(File)
or
ResourceProperties.saveTo(File)
).
In case the resource (such as an InputStream
) does not support
reloading, then an IllegalStateException
is thrown.
Properties existing in the attached resource as well in the
Properties
itself are replaced. Properties existing in the
attached resource but not(!) in the Properties
itself are not(!)
removed. Use ResourceProperties.reload(ReloadMode)
with an argument of
true
(~ orphan removal) to remove properties not existing in
the resource.reload
in interface ResourceProperties
Properties
as loaded from the resource and applied to
this instance.IOException
- thrown in case accessing the resource encountered an
I/O problem.IllegalStateException
- in case the attached resource does not
support reloading.ParseException
- Signals that an error has been reached
unexpectedly while parsing the data to be loaded.public Properties reload(ReloadMode aReloadMode) throws IOException, IllegalStateException, ParseException
ResourceProperties
from the resource to which the
ResourceProperties
are attached to (such as a File
as of
ResourceProperties.MutableResoureProperties.loadFrom(File)
or
ResourceProperties.saveTo(File)
).
In case the resource (such as an InputStream
) does not support
reloading, then an IllegalStateException
is thrown.
Properties existing in the attached resource as well in the
Properties
itself are replaced.
When "orphan removal" is set to false
, then properties
existing in the attached resource but not(!) in the Properties
itself are not(!) removed. When "orphan removal" is set to
true
, then properties existing in the attached resource but
not(!) in the Properties
itself are(!) removed.reload
in interface ResourceProperties
aReloadMode
- when set to ReloadMode.ORPHAN_REMOVAL
, then
properties existing in the attached resource but not(!) in the
Properties
itself are(!) removed. Else properties not
existing in the attached resource are kept.Properties
as loaded from the resource and applied to
this instance.IOException
- thrown in case accessing the resource encountered an
I/O problem.IllegalStateException
- in case the attached resource does not
support reloading.ParseException
- Signals that an error has been reached
unexpectedly while parsing the data to be loaded.public File saveTo(File aFile, String aComment, char aDelimiter) throws IOException
File
using the provided
delimiter as the destination's path delimiter. Load them via
ResourceProperties.MutableResoureProperties.loadFrom(File, char...)
.
The default implementation uses the hook method
ResourceProperties.saveTo(OutputStream, String, char)
to finally format and write
the properties.saveTo
in interface ResourceProperties
aFile
- The File
from which to load the properties.aComment
- The description for the properties file.aDelimiter
- The path delimiter to be used when writing out the
properties to the destination (in case the the serialized format
supports / requires the such).File
representing the actual location where the
properties have been saved to.IOException
- thrown in case saving the properties failedCopyright © 2018. All rights reserved.