List of usage examples for org.apache.commons.configuration SystemConfiguration SystemConfiguration
public SystemConfiguration()
From source file:com.joe.utilities.core.configuration.admin.repository.ConfigurationRepositoryImpl.java
/** * *///from ww w . j a v a2 s .c o m public ConfigurationRepositoryImpl() throws GlobalConfigurationException { this.systemProperty = new SystemConfiguration(); this.defaultProperty = Globals.loadDefaultProperties(); PropertiesConfiguration customerGlobalProperties = Globals.loadCustomerGlobalProperties(); if (customerGlobalProperties != null) { this.overrideProperty = customerGlobalProperties; } else { this.overrideProperty = new PropertiesConfiguration(); } this.overrideProperty.setAutoSave(true); }
From source file:com.dattack.dbtools.drules.engine.ThreadContext.java
/** * Sets the initial configuration to use. * * @param configuration//w ww . jav a 2s .c o m * the initial configuration */ public void setInitialConfiguration(final Configuration configuration) { if (internalConfiguration != null) { LOGGER.warn("InitialConfiguration "); } final CompositeConfiguration compositeConfiguration = new CompositeConfiguration(); compositeConfiguration.setDelimiterParsingDisabled(true); compositeConfiguration.addConfiguration(new SystemConfiguration()); if (configuration != null) { compositeConfiguration.addConfiguration(configuration); } internalConfiguration = new MapConfiguration(new HashMap<String, Object>()); internalConfiguration.copy(compositeConfiguration); }
From source file:net.elsched.utils.SettingsBinder.java
/** * Bind configuration parameters into Guice Module. * //from w w w . ja v a 2 s. co m * @return a Guice module configured with setting support. * @throws ConfigurationException * on configuration error */ public static Module bindSettings(String propertiesFileKey, Class<?>... settingsArg) throws ConfigurationException { final CompositeConfiguration config = new CompositeConfiguration(); config.addConfiguration(new SystemConfiguration()); String propertyFile = config.getString(propertiesFileKey); if (propertyFile != null) { config.addConfiguration(new PropertiesConfiguration(propertyFile)); } List<Field> fields = new ArrayList<Field>(); for (Class<?> settings : settingsArg) { fields.addAll(Arrays.asList(settings.getDeclaredFields())); } // Reflect on settings class and absorb settings final Map<Setting, Field> settings = new LinkedHashMap<Setting, Field>(); for (Field field : fields) { if (!field.isAnnotationPresent(Setting.class)) { continue; } // Validate target type SettingTypeValidator typeHelper = supportedSettingTypes.get(field.getType()); if (typeHelper == null || !typeHelper.check(field.getGenericType())) { throw new IllegalArgumentException(field.getType() + " is not one of the supported setting types"); } Setting setting = field.getAnnotation(Setting.class); settings.put(setting, field); } // Now validate them List<String> missingProperties = new ArrayList<String>(); for (Setting setting : settings.keySet()) { if (setting.defaultValue().isEmpty()) { if (!config.containsKey(setting.name())) { missingProperties.add(setting.name()); } } } if (missingProperties.size() > 0) { StringBuilder error = new StringBuilder(); error.append("The following required properties are missing from the server configuration: "); error.append(Joiner.on(", ").join(missingProperties)); } // bundle everything up in an injectable guice module return new AbstractModule() { @Override protected void configure() { // We must iterate the settings a third time when binding. // Note: do not collapse these loops as that will damage // early error detection. The runtime is still O(n) in setting // count. for (Map.Entry<Setting, Field> entry : settings.entrySet()) { Class<?> type = entry.getValue().getType(); Setting setting = entry.getKey(); if (int.class.equals(type)) { Integer defaultValue = null; if (!setting.defaultValue().isEmpty()) { defaultValue = Integer.parseInt(setting.defaultValue()); } bindConstant().annotatedWith(Names.named(setting.name())) .to(config.getInteger(setting.name(), defaultValue)); } else if (boolean.class.equals(type)) { Boolean defaultValue = null; if (!setting.defaultValue().isEmpty()) { defaultValue = Boolean.parseBoolean(setting.defaultValue()); } bindConstant().annotatedWith(Names.named(setting.name())) .to(config.getBoolean(setting.name(), defaultValue)); } else if (String.class.equals(type)) { bindConstant().annotatedWith(Names.named(setting.name())) .to(config.getString(setting.name(), setting.defaultValue())); } else { String[] value = config.getStringArray(setting.name()); if (value.length == 0 && !setting.defaultValue().isEmpty()) { value = setting.defaultValue().split(","); } bind(new TypeLiteral<List<String>>() { }).annotatedWith(Names.named(setting.name())).toInstance(ImmutableList.copyOf(value)); } } } }; }
From source file:com.opentable.config.ConfigFactory.java
private CombinedConfiguration loadOTStrategy() throws ConfigurationException { final String[] configPaths = StringUtils.stripAll(StringUtils.split(configName, ",")); final CombinedConfiguration cc = new CombinedConfiguration(new OverrideCombiner()); // All properties can be overridden by the System properties. cc.addConfiguration(new SystemConfiguration(), "systemProperties"); LOG.info("Configuration source: SYSTEM"); for (int i = configPaths.length - 1; i >= 0; i--) { final String configPath = configPaths[i]; final AbstractConfiguration subConfig = configStrategy.load(configPath, configPath); if (subConfig == null) { throw new IllegalStateException(String.format("Configuration '%s' does not exist!", configPath)); }/*from ww w.j a va 2 s . c o m*/ cc.addConfiguration(subConfig, configPath); LOG.info("New-style configuration source: {}", configPath); } return cc; }
From source file:com.github.anba.es6draft.util.Resources.java
/** * Loads the configuration file./*from www . j a va 2s. c o m*/ */ public static Configuration loadConfiguration(Class<?> clazz) { TestConfiguration config = clazz.getAnnotation(TestConfiguration.class); String file = config.file(); String name = config.name(); try { PropertiesConfiguration properties = new PropertiesConfiguration(); // entries are mandatory unless an explicit default value was given properties.setThrowExceptionOnMissing(true); properties.getInterpolator().setParentInterpolator(MISSING_VAR); properties.load(resource(file), "UTF-8"); Configuration configuration = new CompositeConfiguration( Arrays.asList(new SystemConfiguration(), properties)); return configuration.subset(name); } catch (ConfigurationException | IOException e) { throw new RuntimeException(e); } catch (NoSuchElementException e) { throw e; } }
From source file:io.servicecomb.config.archaius.sources.TestYAMLConfigurationSource.java
@Test public void testFullOperation() { // configuration from system properties ConcurrentMapConfiguration configFromSystemProperties = new ConcurrentMapConfiguration( new SystemConfiguration()); // configuration from yaml file DynamicConfiguration configFromYamlFile = new DynamicConfiguration(yamlConfigSource(), new NeverStartPollingScheduler()); // create a hierarchy of configuration that makes // 1) dynamic configuration source override system properties ConcurrentCompositeConfiguration finalConfig = new ConcurrentCompositeConfiguration(); finalConfig.addConfiguration(configFromYamlFile, "yamlConfig"); finalConfig.addConfiguration(configFromSystemProperties, "systemEnvConfig"); Assert.assertEquals(0.5, finalConfig.getDouble("trace.handler.sampler.percent"), 0.5); // DynamicStringListProperty property = new DynamicStringListProperty("trace.handler.tlist", "|", DynamicStringListProperty.DEFAULT_DELIMITER); // List<String> ll = property.get(); // for (String s : ll) { // System.out.println(s); // }//from w w w .ja va 2 s . c om Object o = finalConfig.getProperty("zq"); @SuppressWarnings("unchecked") List<Map<String, Object>> listO = (List<Map<String, Object>>) o; Assert.assertEquals(3, listO.size()); }
From source file:io.servicecomb.config.ConfigUtil.java
public static ConcurrentCompositeConfiguration createLocalConfig(List<ConfigModel> configModelList) { ConcurrentCompositeConfiguration config = new ConcurrentCompositeConfiguration(); duplicateServiceCombConfigToCse(config, new ConcurrentMapConfiguration(new SystemConfiguration()), "configFromSystem"); duplicateServiceCombConfigToCse(config, new ConcurrentMapConfiguration(new EnvironmentConfiguration()), "configFromEnvironment"); duplicateServiceCombConfigToCse(config, new DynamicConfiguration(new MicroserviceConfigurationSource(configModelList), new NeverStartPollingScheduler()), "configFromYamlFile"); return config; }
From source file:cc.kune.wave.server.CustomSettingsBinder.java
/** * Bind configuration parameters into Guice Module. * * @param propertyFile the property file * @param settingsArg the settings arg//from w w w . j ava2 s . c o m * @return a Guice module configured with setting support. * @throws ConfigurationException on configuration error */ public static Module bindSettings(String propertyFile, Class<?>... settingsArg) throws ConfigurationException { final CompositeConfiguration config = new CompositeConfiguration(); config.addConfiguration(new SystemConfiguration()); config.addConfiguration(new PropertiesConfiguration(propertyFile)); List<Field> fields = new ArrayList<Field>(); for (Class<?> settings : settingsArg) { fields.addAll(Arrays.asList(settings.getDeclaredFields())); } // Reflect on settings class and absorb settings final Map<Setting, Field> settings = new LinkedHashMap<Setting, Field>(); for (Field field : fields) { if (!field.isAnnotationPresent(Setting.class)) { continue; } // Validate target type SettingTypeValidator typeHelper = supportedSettingTypes.get(field.getType()); if (typeHelper == null || !typeHelper.check(field.getGenericType())) { throw new IllegalArgumentException(field.getType() + " is not one of the supported setting types"); } Setting setting = field.getAnnotation(Setting.class); settings.put(setting, field); } // Now validate them List<String> missingProperties = new ArrayList<String>(); for (Setting setting : settings.keySet()) { if (setting.defaultValue().isEmpty()) { if (!config.containsKey(setting.name())) { missingProperties.add(setting.name()); } } } if (missingProperties.size() > 0) { StringBuilder error = new StringBuilder(); error.append("The following required properties are missing from the server configuration: "); error.append(Joiner.on(", ").join(missingProperties)); throw new ConfigurationException(error.toString()); } // bundle everything up in an injectable guice module return new AbstractModule() { @Override protected void configure() { // We must iterate the settings a third time when binding. // Note: do not collapse these loops as that will damage // early error detection. The runtime is still O(n) in setting count. for (Map.Entry<Setting, Field> entry : settings.entrySet()) { Class<?> type = entry.getValue().getType(); Setting setting = entry.getKey(); if (int.class.equals(type)) { Integer defaultValue = null; if (!setting.defaultValue().isEmpty()) { defaultValue = Integer.parseInt(setting.defaultValue()); } bindConstant().annotatedWith(Names.named(setting.name())) .to(config.getInteger(setting.name(), defaultValue)); } else if (boolean.class.equals(type)) { Boolean defaultValue = null; if (!setting.defaultValue().isEmpty()) { defaultValue = Boolean.parseBoolean(setting.defaultValue()); } bindConstant().annotatedWith(Names.named(setting.name())) .to(config.getBoolean(setting.name(), defaultValue)); } else if (String.class.equals(type)) { bindConstant().annotatedWith(Names.named(setting.name())) .to(config.getString(setting.name(), setting.defaultValue())); } else { String[] value = config.getStringArray(setting.name()); if (value.length == 0 && !setting.defaultValue().isEmpty()) { value = setting.defaultValue().split(","); } bind(new TypeLiteral<List<String>>() { }).annotatedWith(Names.named(setting.name())).toInstance(ImmutableList.copyOf(value)); } } } }; }
From source file:com.nesscomputing.config.ConfigFactory.java
CombinedConfiguration load() { // Allow foo/bar/baz and foo:bar:baz final String[] configNames = StringUtils.stripAll(StringUtils.split(configName, "/:")); final CombinedConfiguration cc = new CombinedConfiguration(new OverrideCombiner()); // All properties can be overridden by the System properties. cc.addConfiguration(new SystemConfiguration(), "systemProperties"); boolean loadedConfig = false; for (int i = 0; i < configNames.length; i++) { final String configFileName = configNames[configNames.length - i - 1]; final String configFilePath = StringUtils.join(configNames, "/", 0, configNames.length - i); try {/*from w w w. j a v a 2s. c om*/ final AbstractConfiguration subConfig = configStrategy.load(configFileName, configFilePath); if (subConfig == null) { LOG.debug("Configuration '%s' does not exist, skipping", configFileName); } else { cc.addConfiguration(subConfig, configFileName); loadedConfig = true; } } catch (ConfigurationException ce) { LOG.error(String.format("While loading configuration '%s'", configFileName), ce); } } if (!loadedConfig && configNames.length > 0) { LOG.warn("Config name '%s' was given but no config file could be found, this looks fishy!", configName); } return cc; }
From source file:gda.configuration.properties.JakartaPropertiesConfig.java
/** * Constructor for JakartaPropertiesConfig objects. Creates a new composite configuration and adds a system * configuration to it./*from ww w . ja v a 2s . co m*/ */ public JakartaPropertiesConfig() { // create global composite to store all loaded property config data config = new CompositeConfiguration(); // create a system properties configuration - grabs all system // properties. Configuration sysConfig = new SystemConfiguration(); config.addConfiguration(sysConfig); // create map to store individual configs configMap = new HashMap<String, Configuration>(); // put system properties in the map configMap.put("system", sysConfig); }