-
Notifications
You must be signed in to change notification settings - Fork 0
Icecode Config Documentation
Having worked with many java configuration libraries. I have not found one that did what I wanted. This library addresses issue I found missing in other config libs
A ConfigurationService is basically a String to String Map with facilities to manage conversion, validation,defaults, monitoring, and loading of values of that map.
value key = Key("key",stringConverter);
value config = createFromFile("test.properties",{key})
value val = config.getValueAs<String>("key");
value val2 = config.getValue(key);
A Key is object that contains all information related to managing a Property in the ConfigurationService
The key to match on in the ConfigurationService can be anything accept a '='
The PropertyConverter to convert the value from a String to the type defined in the converter. The default converter is String Converter.
- String Converter
- ex.
hello
- Integer Converter
- ex.
5
- Float Converter
- ex.
5.5
- DateTime Converter
- ex.
2016-10-05T18:29:58.185
- Boolean Converter
- ex.
true
Used to describe what the Key is used for. Defaults to no description
A default value if the property can't be converted
A function used to validate the value after it has been converted
Validation is a follow on step after conversion to make sure the value of the property is valid. If validation fails the internal map will not be updated. Additionally, an error event will be sent to all listners of the ConfigurationService. Validation is only applied to properties that have a defined Key associated with it. The default validator just checks for existence. Example of a Key with an Empty String Validator:
value key1 = Key {
key = "key";
converter = stringConverter;
validator = (String key, String val) => if (!val.empty) then null else ErrorMessage("String is empty");
};
Clients can observer changes to the ConfigurationService by implementing the Listener and subscribing to the service.
object listener1 satisfies Listener {
shared actual void onChange(String key, String? val, ChangeType changeType) {
if (changeType == changed) {
print("key ``key`` changed to ``val``")
}
}
}
configService.addListener(listener1);
configService.reload(...);
- added
- if the property didn't exist and now exists
- changed
- if the property exists but the value changed
- removed
- if the property existed but has been removed
- error
- if validation failed on reloading a given property