Module org.refcodes.properties
Package org.refcodes.properties
Class PolyglotPropertiesBuilder.PolyglotPropertiesBuilderFactory
java.lang.Object
org.refcodes.properties.PolyglotPropertiesBuilder.PolyglotPropertiesBuilderFactory
- All Implemented Interfaces:
org.refcodes.mixin.FilenameSuffixesAccessor,ResourcePropertiesFactory,ResourcePropertiesFactory.ResourcePropertiesBuilderFactory
- Enclosing class:
- PolyglotPropertiesBuilder
public static class PolyglotPropertiesBuilder.PolyglotPropertiesBuilderFactory
extends Object
implements ResourcePropertiesFactory.ResourcePropertiesBuilderFactory
The
PolyglotPropertiesBuilder.PolyglotPropertiesBuilderFactory is a meta factory using a
collection of ResourcePropertiesFactory.ResourcePropertiesBuilderFactory instances to
deliver ResourceProperties.ResourcePropertiesBuilder instances. In case a properties
file for a filename was not found, then the according factories filename
extension
(FilenameSuffixesAccessor.getFilenameSuffixes()) is
append to the filename and probing is repeated. Any factory method such
as toProperties(Map), toProperties(Object),
toProperties(PropertiesBuilder) or
toProperties(PropertiesBuilder) will return
ResourceProperties.ResourcePropertiesBuilder created by the first added
ResourcePropertiesFactory.ResourcePropertiesBuilderFactory instance.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.refcodes.mixin.FilenameSuffixesAccessor
org.refcodes.mixin.FilenameSuffixesAccessor.FilenameSuffixesBuilder<B extends org.refcodes.mixin.FilenameSuffixesAccessor.FilenameSuffixesBuilder<B>>, org.refcodes.mixin.FilenameSuffixesAccessor.FilenameSuffixesMutator, org.refcodes.mixin.FilenameSuffixesAccessor.FilenameSuffixesPropertyNested classes/interfaces inherited from interface org.refcodes.properties.ResourcePropertiesFactory
ResourcePropertiesFactory.ResourcePropertiesBuilderFactory -
Constructor Summary
ConstructorsConstructorDescriptionInitializes thePolyglotPropertiesBuilder.PolyglotPropertiesBuilderFactorywith a predefined set ofResourcePropertiesFactory.ResourcePropertiesBuilderFactoryinstances.PolyglotPropertiesBuilderFactory(ResourcePropertiesFactory.ResourcePropertiesBuilderFactory... aFactories) Initializes thePolyglotPropertiesBuilder.PolyglotPropertiesBuilderFactorywith the givenResourcePropertiesFactory.ResourcePropertiesBuilderFactoryinstances. -
Method Summary
Modifier and TypeMethodDescriptionString[]Returns the filename extensions of the ResourcePropertiesFactory in the given order.static byte[]toByteArray(InputStream aInputStream) Converts a byte array from anInputStream.toProperties(File aFile, org.refcodes.runtime.ConfigLocator aConfigLocator, char... aDelimiters) Loads or seeks the properties from the givenFile.toProperties(InputStream aInputStream, char... aDelimiters) Reads the properties from the givenInputStream.toProperties(Class<?> aResourceClass, String aFilePath, org.refcodes.runtime.ConfigLocator aConfigLocator, char... aDelimiters) Loads the properties from the given file's path.toProperties(Object aObj) Will returnResourceProperties.ResourcePropertiesBuildercreated by the first addedResourcePropertiesFactory.ResourcePropertiesBuilderFactoryinstance.toProperties(String aFilePath, org.refcodes.runtime.ConfigLocator aConfigLocator, char... aDelimiters) Loads the properties from the given file's path.toProperties(URL aUrl, char... aDelimiters) Loads the properties from the givenURL.toProperties(Map<?, ?> aPropertiesBuilder) Will returnResourceProperties.ResourcePropertiesBuildercreated by the first addedResourcePropertiesFactory.ResourcePropertiesBuilderFactoryinstance.toProperties(Properties aProperties) Will returnResourceProperties.ResourcePropertiesBuildercreated by the first addedResourcePropertiesFactory.ResourcePropertiesBuilderFactoryinstance.toProperties(Properties.PropertiesBuilder aPropertiesBuilder) Will returnResourceProperties.ResourcePropertiesBuildercreated by the first addedResourcePropertiesFactory.ResourcePropertiesBuilderFactoryinstance.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.refcodes.properties.ResourcePropertiesFactory
hasFilenameSuffix, hasFilenameSuffixMethods inherited from interface org.refcodes.properties.ResourcePropertiesFactory.ResourcePropertiesBuilderFactory
toProperties, toProperties, toProperties, toProperties, toProperties, toProperties, toProperties, toProperties, toProperties, toProperties, toProperties
-
Constructor Details
-
PolyglotPropertiesBuilderFactory
public PolyglotPropertiesBuilderFactory()Initializes thePolyglotPropertiesBuilder.PolyglotPropertiesBuilderFactorywith a predefined set ofResourcePropertiesFactory.ResourcePropertiesBuilderFactoryinstances. -
PolyglotPropertiesBuilderFactory
public PolyglotPropertiesBuilderFactory(ResourcePropertiesFactory.ResourcePropertiesBuilderFactory... aFactories) Initializes thePolyglotPropertiesBuilder.PolyglotPropertiesBuilderFactorywith the givenResourcePropertiesFactory.ResourcePropertiesBuilderFactoryinstances. Them factories will be queried in the order being provided.- Parameters:
aFactories- The factories to be added.
-
-
Method Details
-
getFilenameSuffixes
Returns the filename extensions of the ResourcePropertiesFactory in the given order.- Specified by:
getFilenameSuffixesin interfaceorg.refcodes.mixin.FilenameSuffixesAccessor
-
toProperties
public ResourceProperties.ResourcePropertiesBuilder toProperties(Class<?> aResourceClass, String aFilePath, org.refcodes.runtime.ConfigLocator aConfigLocator, char... aDelimiters) throws IOException, ParseException Loads the properties from the given file's path. A providedConfigLocatordescribes 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:
toPropertiesin interfaceResourcePropertiesFactory- Specified by:
toPropertiesin interfaceResourcePropertiesFactory.ResourcePropertiesBuilderFactory- 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- TheConfigLocatordescribes 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:
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.
-
toProperties
public ResourceProperties.ResourcePropertiesBuilder toProperties(File aFile, org.refcodes.runtime.ConfigLocator aConfigLocator, char... aDelimiters) throws IOException, ParseException Loads or seeks the properties from the givenFile. A providedConfigLocatordescribes the locations to additional crawl for the desired file.- Specified by:
toPropertiesin interfaceResourcePropertiesFactory- Specified by:
toPropertiesin interfaceResourcePropertiesFactory.ResourcePropertiesBuilderFactory- Parameters:
aFile- TheFilefrom which to load the properties.aConfigLocator- TheConfigLocatordescribes 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:
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.
-
toProperties
public ResourceProperties.ResourcePropertiesBuilder toProperties(InputStream aInputStream, char... aDelimiters) throws IOException, ParseException Reads the properties from the givenInputStream.- Specified by:
toPropertiesin interfaceResourcePropertiesFactory- Specified by:
toPropertiesin interfaceResourcePropertiesFactory.ResourcePropertiesBuilderFactory- Parameters:
aInputStream- TheInputStreamfrom which to read the properties.aDelimiters- The path delimiters to be used when parsing the source's properties.- Returns:
- The accordingly constructed
ResourceProperties. - Throws:
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.
-
toProperties
Will returnResourceProperties.ResourcePropertiesBuildercreated by the first addedResourcePropertiesFactory.ResourcePropertiesBuilderFactoryinstance. Create aResourcePropertiesinstance containing the elements of the providedMapinstance using the path delimiter "/" (Delimiter.PATH) for the path declarations.- Specified by:
toPropertiesin interfaceResourcePropertiesFactory- Specified by:
toPropertiesin interfaceResourcePropertiesFactory.ResourcePropertiesBuilderFactory- Parameters:
aPropertiesBuilder- the properties to be added.- Returns:
- The accordingly constructed
ResourceProperties.
-
toProperties
Will returnResourceProperties.ResourcePropertiesBuildercreated by the first addedResourcePropertiesFactory.ResourcePropertiesBuilderFactoryinstance. Create aResourcePropertiesinstance 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,Collectionand arrays are identified and handled as of their type: The path for each value in aMapis appended with its according key. The path for each value in aCollectionor array is appended with its according index of occurrence (in case of aListor 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:
toPropertiesin interfaceResourcePropertiesFactory- Specified by:
toPropertiesin interfaceResourcePropertiesFactory.ResourcePropertiesBuilderFactory- Parameters:
aObj- The object from which the elements are to be added.- Returns:
- The accordingly constructed
ResourceProperties.
-
toProperties
Will returnResourceProperties.ResourcePropertiesBuildercreated by the first addedResourcePropertiesFactory.ResourcePropertiesBuilderFactoryinstance. Create aResourcePropertiesinstance containing the elements of the providedPropertiesinstance using the path delimiter "/" (Delimiter.PATH) for the path declarations.- Specified by:
toPropertiesin interfaceResourcePropertiesFactory- Specified by:
toPropertiesin interfaceResourcePropertiesFactory.ResourcePropertiesBuilderFactory- Parameters:
aProperties- the properties to be added.- Returns:
- The accordingly constructed
ResourceProperties.
-
toProperties
public ResourceProperties.ResourcePropertiesBuilder toProperties(Properties.PropertiesBuilder aPropertiesBuilder) Will returnResourceProperties.ResourcePropertiesBuildercreated by the first addedResourcePropertiesFactory.ResourcePropertiesBuilderFactoryinstance. Create aResourcePropertiesinstance containing the elements of the providedProperties.PropertiesBuilderinstance using the default path delimiter "/" (Delimiter.PATH) for the path declarations.- Specified by:
toPropertiesin interfaceResourcePropertiesFactory- Specified by:
toPropertiesin interfaceResourcePropertiesFactory.ResourcePropertiesBuilderFactory- Parameters:
aPropertiesBuilder- the properties to be added.- Returns:
- The accordingly constructed
ResourceProperties.
-
toProperties
public ResourceProperties.ResourcePropertiesBuilder toProperties(String aFilePath, org.refcodes.runtime.ConfigLocator aConfigLocator, char... aDelimiters) throws IOException, ParseException Loads the properties from the given file's path. A providedConfigLocatordescribes the locations to additional crawl for the desired file.- Specified by:
toPropertiesin interfaceResourcePropertiesFactory- Specified by:
toPropertiesin interfaceResourcePropertiesFactory.ResourcePropertiesBuilderFactory- Parameters:
aFilePath- The path to the file from which to load the properties.aConfigLocator- TheConfigLocatordescribes 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:
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.
-
toProperties
public ResourceProperties.ResourcePropertiesBuilder toProperties(URL aUrl, char... aDelimiters) throws IOException, ParseException Loads the properties from the givenURL.- Specified by:
toPropertiesin interfaceResourcePropertiesFactory- Specified by:
toPropertiesin interfaceResourcePropertiesFactory.ResourcePropertiesBuilderFactory- Parameters:
aUrl- TheURLfrom which to read the properties.aDelimiters- The path delimiters to be used when parsing the source's properties.- Returns:
- The accordingly constructed
ResourceProperties. - Throws:
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.
-
toByteArray
Converts a byte array from anInputStream.- Parameters:
aInputStream- TheInputStreamto be converted.- Returns:
- The byte array from the
InputStream. - Throws:
IOException- Thrown in case there were problems reading theInputStream.
-