Package org.refcodes.configuration
Class PolyglotProperties.PolyglotPropertiesFactory
- java.lang.Object
-
- org.refcodes.configuration.PolyglotProperties.PolyglotPropertiesFactory
-
- All Implemented Interfaces:
ResourcePropertiesFactory
,org.refcodes.mixin.FilenameExtensionsAccessor
- Enclosing class:
- PolyglotProperties
public static class PolyglotProperties.PolyglotPropertiesFactory extends java.lang.Object implements ResourcePropertiesFactory
ThePolyglotProperties.PolyglotPropertiesFactory
is a meta factory using a collection ofResourcePropertiesFactory
instances to deliverResourceProperties
instances. In case a properties file for a filename was not found, then the according factories filename extension (FilenameExtensionsAccessor.getFilenameExtensions()
) is append to the filename and probing is repeated. Any factory method such astoProperties(Map)
,toProperties(Object)
,toProperties(Properties)
ortoProperties(PropertiesBuilder)
will returnResourceProperties
created by the first addedResourcePropertiesFactory
instance.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.FilenameExtensionsAccessor
org.refcodes.mixin.FilenameExtensionsAccessor.FilenameExtensionsBuilder<B extends org.refcodes.mixin.FilenameExtensionsAccessor.FilenameExtensionsBuilder<B>>, org.refcodes.mixin.FilenameExtensionsAccessor.FilenameExtensionsMutator, org.refcodes.mixin.FilenameExtensionsAccessor.FilenameExtensionsProperty
-
Nested classes/interfaces inherited from interface org.refcodes.configuration.ResourcePropertiesFactory
ResourcePropertiesFactory.ResourcePropertiesBuilderFactory
-
-
Constructor Summary
Constructors Constructor Description PolyglotPropertiesFactory()
Initializes thePolyglotProperties.PolyglotPropertiesFactory
with a predefined set ofResourcePropertiesFactory
instances.PolyglotPropertiesFactory(ResourcePropertiesFactory... aFactories)
Initializes thePolyglotProperties.PolyglotPropertiesFactory
with the givenResourcePropertiesFactory
instances.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String[]
getFilenameExtensions()
Returns the filename extensions of the ResourcePropertiesFactory in the given order.static byte[]
toByteArray(java.io.InputStream aInputStream)
Converts a byte array from anInputStream
.ResourceProperties
toProperties(java.io.File aFile, org.refcodes.runtime.ConfigLocator aConfigLocator, char... aDelimiters)
Loads or seeks the properties from the givenFile
.ResourceProperties
toProperties(java.io.InputStream aInputStream, char... aDelimiters)
Reads the properties from the givenInputStream
.ResourceProperties
toProperties(java.lang.Class<?> aResourceClass, java.lang.String aFilePath, org.refcodes.runtime.ConfigLocator aConfigLocator, char... aDelimiters)
Loads the properties from the given file's path.ResourceProperties
toProperties(java.lang.Object aObj)
Will returnResourceProperties
created by the first addedResourcePropertiesFactory
instance.ResourceProperties
toProperties(java.lang.String aFilePath, org.refcodes.runtime.ConfigLocator aConfigLocator, char... aDelimiters)
Loads the properties from the given file's path.ResourceProperties
toProperties(java.net.URL aUrl, char... aDelimiters)
Loads the properties from the givenURL
.ResourceProperties
toProperties(java.util.Map<?,?> aProperties)
Will returnResourceProperties
created by the first addedResourcePropertiesFactory
instance.ResourceProperties
toProperties(Properties aProperties)
Will returnResourceProperties
created by the first addedResourcePropertiesFactory
instance.ResourceProperties
toProperties(Properties.PropertiesBuilder aProperties)
Will returnResourceProperties
created by the first addedResourcePropertiesFactory
instance.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.refcodes.configuration.ResourcePropertiesFactory
toProperties, toProperties, toProperties, toProperties, toProperties, toProperties, toProperties, toProperties, toProperties, toProperties, toProperties
-
-
-
-
Constructor Detail
-
PolyglotPropertiesFactory
public PolyglotPropertiesFactory()
Initializes thePolyglotProperties.PolyglotPropertiesFactory
with a predefined set ofResourcePropertiesFactory
instances.
-
PolyglotPropertiesFactory
public PolyglotPropertiesFactory(ResourcePropertiesFactory... aFactories)
Initializes thePolyglotProperties.PolyglotPropertiesFactory
with the givenResourcePropertiesFactory
instances. Them factories will be queried in the order being provided.- Parameters:
aFactories
- The factories to be added.
-
-
Method Detail
-
getFilenameExtensions
public java.lang.String[] getFilenameExtensions()
Returns the filename extensions of the ResourcePropertiesFactory in the given order.- Specified by:
getFilenameExtensions
in interfaceorg.refcodes.mixin.FilenameExtensionsAccessor
-
toProperties
public ResourceProperties toProperties(java.lang.Class<?> aResourceClass, java.lang.String aFilePath, org.refcodes.runtime.ConfigLocator aConfigLocator, char... aDelimiters) throws java.io.IOException, java.text.ParseException
Loads the properties from the given file's path. A providedConfigLocator
describes the locations to additional crawl for the desired file. 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).- Specified by:
toProperties
in interfaceResourcePropertiesFactory
- Parameters:
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.aConfigLocator
- TheConfigLocator
describes the locations to additional crawl for the desired file.aDelimiters
- The path delimiters to be used when parsing the source's properties.- Returns:
- The accordingly constructed
ResourceProperties
. - Throws:
java.io.IOException
- thrown in case accessing or processing the properties file failed.java.text.ParseException
- Signals that an error has been reached unexpectedly while parsing the data to be loaded.
-
toProperties
public ResourceProperties toProperties(java.io.File aFile, org.refcodes.runtime.ConfigLocator aConfigLocator, char... aDelimiters) throws java.io.IOException, java.text.ParseException
Loads or seeks the properties from the givenFile
. A providedConfigLocator
describes the locations to additional crawl for the desired file.- Specified by:
toProperties
in interfaceResourcePropertiesFactory
- Parameters:
aFile
- TheFile
from which to load the properties.aConfigLocator
- TheConfigLocator
describes the locations to additional crawl for the desired file.aDelimiters
- The path delimiters to be used when parsing the source's properties.- Returns:
- The accordingly constructed
ResourceProperties
. - Throws:
java.io.IOException
- thrown in case accessing or processing the properties file failed.java.text.ParseException
- Signals that an error has been reached unexpectedly while parsing the data to be loaded.
-
toProperties
public ResourceProperties toProperties(java.io.InputStream aInputStream, char... aDelimiters) throws java.io.IOException, java.text.ParseException
Reads the properties from the givenInputStream
.- Specified by:
toProperties
in interfaceResourcePropertiesFactory
- Parameters:
aInputStream
- TheInputStream
from which to read the properties.aDelimiters
- The path delimiters to be used when parsing the source's properties.- Returns:
- The accordingly constructed
ResourceProperties
. - Throws:
java.io.IOException
- thrown in case accessing or processing the properties file failed.java.text.ParseException
- Signals that an error has been reached unexpectedly while parsing the data to be loaded.
-
toProperties
public ResourceProperties toProperties(java.util.Map<?,?> aProperties)
Will returnResourceProperties
created by the first addedResourcePropertiesFactory
instance. Create aResourceProperties
instance containing the elements of the providedMap
instance using the path delimiter "/" (Delimiter.PATH
) for the path declarations- Specified by:
toProperties
in interfaceResourcePropertiesFactory
- Parameters:
aProperties
- the properties to be added.- Returns:
- The accordingly constructed
ResourceProperties
.
-
toProperties
public ResourceProperties toProperties(java.lang.Object aObj)
Will returnResourceProperties
created by the first addedResourcePropertiesFactory
instance. Create aResourceProperties
instance containing the elements as ofPathMap.MutablePathMap.insert(Object)
using the path delimiter "/" (Delimiter.PATH
) for the path declarations: "Inspects the given object and adds all elements found in the given object. Elements of typeMap
,Collection
and arrays are identified and handled as of their type: The path for each value in aMap
is appended with its according key. The path for each value in aCollection
or array is appended with its according index of occurrence (in case of aList
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."- Specified by:
toProperties
in interfaceResourcePropertiesFactory
- Parameters:
aObj
- The object from which the elements are to be added.- Returns:
- The accordingly constructed
ResourceProperties
.
-
toProperties
public ResourceProperties toProperties(Properties aProperties)
Will returnResourceProperties
created by the first addedResourcePropertiesFactory
instance. Create aResourceProperties
instance containing the elements of the providedProperties
instance using the path delimiter "/" (Delimiter.PATH
) for the path declarations- Specified by:
toProperties
in interfaceResourcePropertiesFactory
- Parameters:
aProperties
- the properties to be added.- Returns:
- The accordingly constructed
ResourceProperties
.
-
toProperties
public ResourceProperties toProperties(Properties.PropertiesBuilder aProperties)
Will returnResourceProperties
created by the first addedResourcePropertiesFactory
instance. Create aResourceProperties
instance containing the elements of the providedProperties.PropertiesBuilder
instance using the default path delimiter "/" (Delimiter.PATH
) for the path declarations- Specified by:
toProperties
in interfaceResourcePropertiesFactory
- Parameters:
aProperties
- the properties to be added.- Returns:
- The accordingly constructed
ResourceProperties
.
-
toProperties
public ResourceProperties toProperties(java.lang.String aFilePath, org.refcodes.runtime.ConfigLocator aConfigLocator, char... aDelimiters) throws java.io.IOException, java.text.ParseException
Loads the properties from the given file's path. A providedConfigLocator
describes the locations to additional crawl for the desired file.- Specified by:
toProperties
in interfaceResourcePropertiesFactory
- Parameters:
aFilePath
- The path to the file from which to load the properties.aConfigLocator
- TheConfigLocator
describes the locations to additional crawl for the desired file.aDelimiters
- The path delimiters to be used when parsing the source's properties.- Returns:
- The accordingly constructed
ResourceProperties
. - Throws:
java.io.IOException
- thrown in case accessing or processing the properties file failed.java.text.ParseException
- Signals that an error has been reached unexpectedly while parsing the data to be loaded.
-
toProperties
public ResourceProperties toProperties(java.net.URL aUrl, char... aDelimiters) throws java.io.IOException, java.text.ParseException
Loads the properties from the givenURL
.- Specified by:
toProperties
in interfaceResourcePropertiesFactory
- Parameters:
aUrl
- TheURL
from which to read the properties.aDelimiters
- The path delimiters to be used when parsing the source's properties.- Returns:
- The accordingly constructed
ResourceProperties
. - Throws:
java.io.IOException
- thrown in case accessing or processing the properties file failed.java.text.ParseException
- Signals that an error has been reached unexpectedly while parsing the data to be loaded.
-
toByteArray
public static byte[] toByteArray(java.io.InputStream aInputStream) throws java.io.IOException
Converts a byte array from anInputStream
.- Parameters:
aInputStream
- TheInputStream
to be converted.- Returns:
- The byte array from the
InputStream
. - Throws:
java.io.IOException
- Thrown in case there were problems reading theInputStream
.
-
-