diff options
Diffstat (limited to 'eaaf_core_utils')
-rw-r--r-- | eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/ConfigurationUtils.java | 62 | ||||
-rw-r--r-- | eaaf_core_utils/src/main/resources/messages/eaaf_utils_message.properties | 2 |
2 files changed, 64 insertions, 0 deletions
diff --git a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/ConfigurationUtils.java b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/ConfigurationUtils.java new file mode 100644 index 00000000..2e6d53c9 --- /dev/null +++ b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/ConfigurationUtils.java @@ -0,0 +1,62 @@ +package at.gv.egiz.eaaf.core.impl.utils; + +import at.gv.egiz.eaaf.core.api.idp.IConfiguration; +import at.gv.egiz.eaaf.core.exceptions.EaafConfigurationException; +import lombok.extern.slf4j.Slf4j; + +/** + * Utils for configuration value mapping. + * + * @author tlenz + * + */ +@Slf4j +public class ConfigurationUtils { + + + /** + * Parse Integer value from configuration. + * + * @param basicConfig Configuration object + * @param propertyKey Configuration key + * @return Configuration value + * @throws EaafConfigurationException If configuration value is not an Integer + */ + public static int parseInteger(IConfiguration basicConfig, String propertyKey) + throws EaafConfigurationException { + try { + return Integer.parseInt(basicConfig.getBasicConfiguration(propertyKey)); + + } catch (NumberFormatException e) { + log.error("Can not read Integer value from configuration: {}", propertyKey, e); + throw new EaafConfigurationException("internal.configuration.02", + new Object[] { propertyKey, Integer.class.getSimpleName() }, e); + + } + } + + /** + * Parse Long value from configuration. + * + * @param basicConfig Configuration object + * @param propertyKey Configuration key + * @return Configuration value + * @throws EaafConfigurationException If configuration value is not an Long + */ + public static long parseLong(IConfiguration basicConfig, String propertyKey) + throws EaafConfigurationException { + try { + return Long.parseLong(basicConfig.getBasicConfiguration(propertyKey)); + + } catch (NumberFormatException e) { + log.error("Can not read Long value from configuration: {}", propertyKey, e); + throw new EaafConfigurationException("internal.configuration.02", + new Object[] { propertyKey, Long.class.getSimpleName() }, e); + + } + } + + private ConfigurationUtils() { + + } +} diff --git a/eaaf_core_utils/src/main/resources/messages/eaaf_utils_message.properties b/eaaf_core_utils/src/main/resources/messages/eaaf_utils_message.properties index 2cc4e22e..6c29a57c 100644 --- a/eaaf_core_utils/src/main/resources/messages/eaaf_utils_message.properties +++ b/eaaf_core_utils/src/main/resources/messages/eaaf_utils_message.properties @@ -1,5 +1,7 @@ internal.configuration.00=Wrong configuration. Missing property: {0} internal.configuration.01=Wrong configuration property: {0}. Reason: {1} +internal.configuration.02=Wrong configuration property: {0}. Reason: Invalid {1} value + internal.keystore.00=HSM-Facade NOT INITIALIZED. KeyStore:{0} initialization failed internal.keystore.01=KeyStore:{0} configuration has an unsupported type in configuration. |