Package space.arim.dazzleconf.factory
Class AbstractConfigurationFactory<C>
java.lang.Object
space.arim.dazzleconf.factory.AbstractConfigurationFactory<C>
- Type Parameters:
C- the type of the configuration
- All Implemented Interfaces:
ConfigurationFactory<C>
Deprecated.
Abstract implementation of
ConfigurationFactory which takes care of IO boilerplate as well as
configuration loading from a map. Only the required methods need be implemented.- Author:
- A248
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractConfigurationFactory(Class<C> configClass, ConfigurationOptions options) Deprecated.Creates from a config class and config options -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract Charsetcharset()Deprecated.The charset used by this factoryGets the configuration class this factory is forDeprecated.Gets the comment header on the top level configurationGets the configuration options this factory usesload(InputStream inputStream) Reads configuration data from an input streamload(InputStream inputStream, C auxiliaryEntries) Reads configuration data from an input stream with the given auxiliary configuration instance.load(ReadableByteChannel readChannel) Reads configuration data from a readable channelload(ReadableByteChannel readChannel, C auxiliaryEntries) Reads configuration data from a readable channel with the given auxiliary configuration instance.Reads the default configuration data from annotations inConfDefault
If any config entry is missing a default value annotation, or the default values cannot be deserialised to the appropriate config value,IllDefinedConfigExceptionis thrownloadMapFromReader(Reader reader) Deprecated.Loads a raw map of nested values from the specified reader.protected StringDeprecated.If the configuration format does not natively support comments, it is possible to attach a "comment" as a string value before the configuration entry which is to be commented, with the use of some key suffix.protected booleanDeprecated.Whether this implementation actively supports comments by recognisingCommentedWrapperin config values.voidwrite(C configData, OutputStream outputStream) Writes configuration data to an output streamvoidwrite(C configData, WritableByteChannel writableChannel) Writes configuration data to a writable byte channelprotected abstract voidwriteMapToWriter(Map<String, Object> config, Writer writer) Deprecated.Writes a raw map of nested values to the specified writer.
-
Constructor Details
-
AbstractConfigurationFactory
Deprecated.Creates from a config class and config options- Parameters:
configClass- the config classoptions- configuration options- Throws:
NullPointerException- ifconfigClassoroptionsis nullIllegalArgumentException- ifconfigClassis not an interfaceIllDefinedConfigException- if the configuration entries defined in the config class are invalid
-
-
Method Details
-
charset
Deprecated.The charset used by this factory- Returns:
- the charset to use
-
loadMapFromReader
protected abstract Map<String,Object> loadMapFromReader(Reader reader) throws IOException, ConfigFormatSyntaxException Deprecated.Loads a raw map of nested values from the specified reader. The map returned is a hierarchical map of nested maps.- Parameters:
reader- the reader- Returns:
- the raw map of values
- Throws:
IOException- if an I/O error occursConfigFormatSyntaxException- if the configuration format syntax is incorrect
-
writeMapToWriter
protected abstract void writeMapToWriter(Map<String, Object> config, Writer writer) throws IOExceptionDeprecated.Writes a raw map of nested values to the specified writer. Inverse operation ofloadMapFromReader(Reader).
For implementations returningtrueinsupportsCommentsThroughWrapper(), special treatment is required in the implementation of this method. Namely, configuration values may be commented or uncommented. If uncommented, they are an everyday object. If commented, they are wrapped inCommentedWrapper, which includes the config value itself as well as the comments which are placed before it. Comments may also apply to config sections, thereforeCommentWrappermay also wrap nested maps.- Parameters:
config- the raw map of nested values (and possibly comments)writer- the writer- Throws:
IOException- if an I/O error occurs
-
supportsCommentsThroughWrapper
protected boolean supportsCommentsThroughWrapper()Deprecated.Whether this implementation actively supports comments by recognisingCommentedWrapperin config values. It is insufficient for the underlying format to support comments; the implementation of this config factory must also recogniseCommentedWrappervalues. SeewriteMapToWriter(Map, Writer)for more information.- Returns:
- true if comments supported by recognising
CommentedWrapper, false otherwise
-
pseudoCommentsSuffix
Deprecated.If the configuration format does not natively support comments, it is possible to attach a "comment" as a string value before the configuration entry which is to be commented, with the use of some key suffix.
If this method returns a non empty string, this feature is enabled. For example, if this returns '-comment', using the Json configuration language, comments will be written as shown:retries-comment: "determines the amount of retries" retries: 3
- Returns:
- an empty string if disabled, otherwise the suffix to append to form the keys of comments
-
getHeader
Deprecated.Gets the comment header on the top level configuration- Returns:
- the comment header
-
getConfigClass
Description copied from interface:ConfigurationFactoryGets the configuration class this factory is for- Specified by:
getConfigClassin interfaceConfigurationFactory<C>- Returns:
- the configuration class
-
getOptions
Description copied from interface:ConfigurationFactoryGets the configuration options this factory uses- Specified by:
getOptionsin interfaceConfigurationFactory<C>- Returns:
- the configuration options
-
load
Description copied from interface:ConfigurationFactoryReads configuration data from a readable channel- Specified by:
loadin interfaceConfigurationFactory<C>- Parameters:
readChannel- the channel from which to read the data- Returns:
- the read config data
- Throws:
IOException- if an I/O error occursInvalidConfigException- if the configuration is invalid. Where possible, more specific subclasses are thrown
-
load
Description copied from interface:ConfigurationFactoryReads configuration data from an input stream- Specified by:
loadin interfaceConfigurationFactory<C>- Parameters:
inputStream- the stream from which to read the data- Returns:
- the read config data
- Throws:
IOException- if an I/O error occursInvalidConfigException- if the configuration is invalid. Where possible, more specific subclasses are thrown
-
load
public C load(ReadableByteChannel readChannel, C auxiliaryEntries) throws IOException, InvalidConfigException Description copied from interface:ConfigurationFactoryReads configuration data from a readable channel with the given auxiliary configuration instance. Any keys missing in the loaded config data will be supplanted by the config instance's corresponding entry.
By checking if the returned configuration implementsAuxiliaryKeys, the caller can determine whether any of the auxiliary entries were used.- Specified by:
loadin interfaceConfigurationFactory<C>- Parameters:
readChannel- the channel from which to read the dataauxiliaryEntries- the auxiliary configuration instance- Returns:
- the read config data
- Throws:
IOException- if an I/O error occursInvalidConfigException- if the configuration is invalid. Where possible, more specific subclasses are thrown
-
load
public C load(InputStream inputStream, C auxiliaryEntries) throws IOException, InvalidConfigException Description copied from interface:ConfigurationFactoryReads configuration data from an input stream with the given auxiliary configuration instance. Any keys missing in the loaded config data will be supplanted by the config instance's corresponding entry.
By checking if the returned configuration implementsAuxiliaryKeys, the caller can determine whether any of the auxiliary entries were used.- Specified by:
loadin interfaceConfigurationFactory<C>- Parameters:
inputStream- the stream from which to read the dataauxiliaryEntries- the auxiliary configuration instance- Returns:
- the read config data
- Throws:
IOException- if an I/O error occursInvalidConfigException- if the configuration is invalid. Where possible, more specific subclasses are thrown
-
loadDefaults
Description copied from interface:ConfigurationFactoryReads the default configuration data from annotations inConfDefault
If any config entry is missing a default value annotation, or the default values cannot be deserialised to the appropriate config value,IllDefinedConfigExceptionis thrown- Specified by:
loadDefaultsin interfaceConfigurationFactory<C>- Returns:
- the read config data
-
write
Description copied from interface:ConfigurationFactoryWrites configuration data to a writable byte channel- Specified by:
writein interfaceConfigurationFactory<C>- Parameters:
configData- the configuration datawritableChannel- the channel to which to write the data- Throws:
IOException- if an I/O error occurs
-
write
Description copied from interface:ConfigurationFactoryWrites configuration data to an output stream- Specified by:
writein interfaceConfigurationFactory<C>- Parameters:
configData- the configuration dataoutputStream- the stream to which to write the data- Throws:
IOException- if an I/O error occurs
-
HumanReadableConfigurationFactory