diff options
author | Pavel Aharoni <pa0916@att.com> | 2017-06-11 14:33:57 +0300 |
---|---|---|
committer | Pavel Aharoni <pa0916@att.com> | 2017-06-11 14:33:57 +0300 |
commit | 04387deeab820e75c6d37d2ddd5b514cb7bcfd9e (patch) | |
tree | 2f4dfacba74ec390c4371c62dc96af2b1d5f19ef /sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/ConfigurationManager.java | |
parent | fff70fce14ebe7dec3a4d52b7b90cee4414d0562 (diff) |
[SDC-32] separate Tosca Parser from DC
Change-Id: I7e7f31ff2bd92fec22031f75b7051d129a21d01b
Signed-off-by: Pavel Aharoni <pa0916@att.com>
Diffstat (limited to 'sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/ConfigurationManager.java')
-rw-r--r-- | sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/ConfigurationManager.java | 110 |
1 files changed, 0 insertions, 110 deletions
diff --git a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/ConfigurationManager.java b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/ConfigurationManager.java deleted file mode 100644 index e83e6aa..0000000 --- a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/ConfigurationManager.java +++ /dev/null @@ -1,110 +0,0 @@ -package org.openecomp.sdc.tosca.parser.config; - -import com.google.common.base.Charsets; -import com.google.common.io.Resources; -import org.openecomp.sdc.tosca.parser.utils.YamlToObjectConverter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; - - -public class ConfigurationManager { - - private static Logger log = LoggerFactory.getLogger(ConfigurationManager.class.getName()); - - private static final String CONFIGURATION_DIR = "config/"; - private static volatile ConfigurationManager instance; -// private Configuration configuration; -// private ErrorConfiguration errorConfiguration; - - Map<String, Object> configurations = new HashMap<String, Object>(); - - - - private ConfigurationManager() { - initialConfigObjectsFromFiles(); - } - - private void initialConfigObjectsFromFiles() { - loadConfigurationClass(ErrorConfiguration.class); - loadConfigurationClass(Configuration.class); - } - - private <T> void loadConfigurationClass(Class<T> clazz) { - T object = getObjectFromYaml(clazz); - configurations.put(clazz.getSimpleName(), object); - } - - - public <T> T getObjectFromYaml(Class<T> className) { - - - String configFileName = calculateFileName(className); - - URL url = Resources.getResource(CONFIGURATION_DIR + configFileName); - String configFileContents = null; - try { - configFileContents = Resources.toString(url, Charsets.UTF_8); - } catch (IOException e) { - log.error("ConfigurationManager - Failed to load configuration file"); - } - YamlToObjectConverter yamlToObjectConverter = new YamlToObjectConverter(); - T object = yamlToObjectConverter.convertFromString(configFileContents, className); - - return object; - } - - - public static ConfigurationManager getInstance() { - if (instance == null) { - synchronized (ConfigurationManager.class) { - if (instance == null) { - instance = new ConfigurationManager(); - } - } - } - return instance; - } - - private static <T> String calculateFileName(Class<T> className) { - - String[] words = className.getSimpleName().split("(?=\\p{Upper})"); - - StringBuilder builder = new StringBuilder(); - - // There cannot be a null value returned from "split" - words != null is - // redundant - // if (words != null) { - boolean isFirst = true; - for (int i = 0; i < words.length; i++) { - - String word = words[i]; - if (word != null && !word.isEmpty()) { - if (!isFirst) { - builder.append("-"); - } else { - isFirst = false; - } - builder.append(words[i].toLowerCase()); - } - } - return builder.toString() + ".yaml"; - - /* - * } else { return className.getSimpleName().toLowerCase() + Constants.YAML_SUFFIX; } - */ - - } - - public ErrorConfiguration getErrorConfiguration() { - return (ErrorConfiguration) configurations.get((ErrorConfiguration.class.getSimpleName())); - } - - public Configuration getConfiguration() { - return (Configuration) configurations.get((Configuration.class.getSimpleName())); - } -} |