List of usage examples for org.apache.commons.configuration CompositeConfiguration CompositeConfiguration
public CompositeConfiguration()
From source file:io.nuun.plugin.configuration.common.NuunCommonConfigurationPlugin.java
@Override public InitState init(InitContext initContext) { // find all properties classes in the classpath Collection<String> propertiesFiles = initContext.propertiesFiles(); configuration = new CompositeConfiguration(); for (String propertiesFile : propertiesFiles) { logger.info("adding {} to module", propertiesFile); configuration.addConfiguration(configuration(propertiesFile)); }//w w w . j a v a 2s . c om for (Configuration additionalConfiguration : additionalConfigurations) { logger.info("adding additionnal configuration {} to module", additionalConfiguration); configuration.addConfiguration(additionalConfiguration); } return InitState.INITIALIZED; }
From source file:com.runwaysdk.configuration.CommonsConfigurationTest.java
@Test public void testCommonsConfigOverride() { BaseConfiguration bc = new BaseConfiguration(); BaseConfiguration bc2 = new BaseConfiguration(); bc2.addProperty("test.prop", 52); CompositeConfiguration cconfig = new CompositeConfiguration(); cconfig.addConfiguration(bc);/*from w w w . ja v a 2s . c o m*/ cconfig.addConfiguration(bc2); bc.addProperty("test.prop", 112); Assert.assertEquals(112, cconfig.getInt("test.prop")); }
From source file:com.dattack.dbtools.drules.engine.ThreadContext.java
/** * Sets the initial configuration to use. * * @param configuration/*from ww w. ja v a2s . 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:ffx.algorithms.XeonProtonate.java
private static void main(String args[]) { System.setProperty("polarization", "none"); System.setProperty("gkterm", "true"); System.setProperty("cav_model", "born_solv"); /**//w w w . j a v a 2 s. c o m * Load the test system. */ String testFile = System.getProperty("testFile"); if (testFile != null) { structure = new File(testFile); } else { structure = new File("1omu.pdb"); } PotentialsFileOpener opener = new PotentialsFileOpener(structure); opener.run(); molecularAssembly = opener.getAssembly(); nAtoms = molecularAssembly.getAtomArray().length; forceFieldEnergy = molecularAssembly.getPotentialEnergy(); logger.info(String.format("\n Running protonate: ")); // default CLI options for 1omu.pdb int nSteps = 1000000; double timeStep = 1.0; double printInterval = 0.01; double saveInterval = 1.0; double temperature = 298.15; Thermostats thermostat = null; Integrators integrator = null; boolean initVelocities = true; double restartFrequency = 1000; String fileType = "PDB"; int mcStepFrequency = 100; int rotamerStepFrequency = 995; double pH = 4.0; CompositeConfiguration properties = new CompositeConfiguration(); // Single-residue titration option. ArrayList<String> resList = new ArrayList<>(); resList.add("P7"); resList.add("P10"); resList.add("P13"); resList.add("P19"); resList.add("P27"); resList.add("P29"); resList.add("P34"); resList.add("P55"); // create the MD object MolecularDynamics molDyn = new MolecularDynamics(molecularAssembly, molecularAssembly.getPotentialEnergy(), properties, null, thermostat, integrator); molDyn.setFileType(fileType); molDyn.setRestartFrequency(restartFrequency); // create the Monte-Carlo listener and connect it to the MD Protonate mcProt = new Protonate(molecularAssembly, mcStepFrequency, rotamerStepFrequency, pH, molDyn.getThermostat()); molDyn.setMonteCarloListener(mcProt); mcProt.addMolDyn(molDyn); // set residues to be titrated mcProt.chooseResID(resList); // finalize the Multi-Residue machinery mcProt.readyup(); // and away we go! molDyn.dynamic(nSteps, timeStep, printInterval, saveInterval, temperature, initVelocities, null); }
From source file:edu.utexas.cs.tactex.core.BrokerPropertiesService.java
void recycle() { // set up the config instance config = new CompositeConfiguration(); configurator = new Configurator(); initialized = false; }
From source file:net.elsched.utils.SettingsBinder.java
/** * Bind configuration parameters into Guice Module. * /*from w w w . ja va2s . c om*/ * @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.yahoo.bard.webservice.config.LayeredFileSystemConfig.java
/** * Build a Layered File System Configuration, using first the environment and an application configuration source, * then drill down into available modules and load each of them in package dependency order. *//*from w ww . j a v a2s . c o m*/ @SuppressWarnings(value = "unchecked") public LayeredFileSystemConfig() { masterConfiguration = new CompositeConfiguration(); masterConfiguration.setThrowExceptionOnMissing(true); runtimeProperties = new Properties(); try { List<Configuration> userConfig = loader.loadConfigurations(USER_CONFIG_FILE_NAME); // User configuration provides overrides for configuration on a specific environment or specialized role if (userConfig.size() > 1) { List<Resource> resources = loader.loadResourcesWithName(USER_CONFIG_FILE_NAME) .collect(Collectors.toList()); LOG.error(TOO_MANY_USER_CONFIGS.logFormat(resources.toString())); throw new SystemConfigException(TOO_MANY_USER_CONFIGS.format(resources.size())); } // Test application configuration provides overrides for configuration in a testing environment List<Configuration> testApplicationConfig = loader.loadConfigurationsNoJars(TEST_CONFIG_FILE_NAME); // Application configuration defines configuration at an application level for a bard instance List<Configuration> applicationConfig = loader.loadConfigurations(APPLICATION_CONFIG_FILE_NAME); if (applicationConfig.size() > 1) { List<Resource> resources = loader.loadResourcesWithName(APPLICATION_CONFIG_FILE_NAME) .collect(Collectors.toList()); LOG.error(TOO_MANY_APPLICATION_CONFIGS.logFormat(resources.toString())); throw new SystemConfigException(TOO_MANY_APPLICATION_CONFIGS.format(resources.size())); } // Environment config has higher priority than java system properties // Java system properties have higher priority than file based configuration // Also, a runtime map is maintained to support on-the-fly configuration changes // Load the rest of the config "top down" through the layers, in highest to lowest precedence Stream.of(Stream.of(new MapConfiguration(runtimeProperties)), Stream.of(new EnvironmentConfiguration()), Stream.of(new SystemConfiguration()), userConfig.stream(), testApplicationConfig.stream(), applicationConfig.stream()).flatMap(Function.identity()).filter(Objects::nonNull) .forEachOrdered(masterConfiguration::addConfiguration); // Use the config which has been loaded to identify module dependencies List<String> dependentModules = (List<String>) masterConfiguration .getList(ConfigurationGraph.DEPENDENT_MODULE_KEY, Collections.<String>emptyList()); // Add module dependencies to the master configuration new ModuleLoader(loader).getConfigurations(dependentModules) .forEach(masterConfiguration::addConfiguration); } catch (IOException e) { throw new SystemConfigException(e); } }
From source file:com.runwaysdk.configuration.CommonsConfigurationTest.java
@Test public void testCommonsConfigOverrideSetVsAdd() { BaseConfiguration bc = new BaseConfiguration(); BaseConfiguration bc2 = new BaseConfiguration(); bc2.addProperty("test.prop", 52); CompositeConfiguration cconfig = new CompositeConfiguration(); cconfig.addConfiguration(bc);// w w w . j a va2 s . c o m cconfig.addConfiguration(bc2); bc.setProperty("test.prop", 112); Assert.assertEquals(112, cconfig.getInt("test.prop")); }
From source file:com.manydesigns.portofino.i18n.ResourceBundleManager.java
public ResourceBundle getBundle(Locale locale) { ConfigurationResourceBundle bundle = resourceBundles.get(locale); if (bundle == null) { CompositeConfiguration configuration = new CompositeConfiguration(); Iterator<String> iterator = searchPaths.descendingIterator(); while (iterator.hasNext()) { String path = iterator.next(); int index = path.lastIndexOf('/') + 1; String basePath = path.substring(0, index); int suffixIndex = path.length() - ".properties".length(); String resourceBundleBaseName = path.substring(index, suffixIndex); String bundleName = getBundleFileName(resourceBundleBaseName, locale); PropertiesConfiguration conf; try { conf = new PropertiesConfiguration(); conf.setFileName(basePath + bundleName); conf.setDelimiterParsingDisabled(true); conf.load();// w w w.j av a 2s .co m } catch (ConfigurationException e) { logger.debug("Couldn't load resource bundle for locale " + locale + " from " + basePath, e); //Fall back to default .properties without _locale try { String defaultBundleName = basePath + resourceBundleBaseName + ".properties"; conf = new PropertiesConfiguration(); conf.setFileName(defaultBundleName); conf.setDelimiterParsingDisabled(true); conf.load(); } catch (ConfigurationException e1) { logger.debug("Couldn't load default resource bundle from " + basePath, e1); conf = null; } } if (conf != null) { FileChangedReloadingStrategy reloadingStrategy = new FileChangedReloadingStrategy(); conf.setReloadingStrategy(reloadingStrategy); configuration.addConfiguration(conf); } } bundle = new ConfigurationResourceBundle(configuration, locale); //TODO setParent? resourceBundles.put(locale, bundle); } return bundle; }
From source file:br.com.ingenieux.mojo.jbake.GenerateMojo.java
protected CompositeConfiguration createConfiguration() throws ConfigurationException { final CompositeConfiguration config = new CompositeConfiguration(); config.addConfiguration(ConfigUtil.load(inputDirectory)); config.addConfiguration(new MapConfiguration(this.project.getProperties())); return config; }