Java Code Examples for org.apache.commons.configuration2.CombinedConfiguration#addConfiguration()
The following examples show how to use
org.apache.commons.configuration2.CombinedConfiguration#addConfiguration() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CombinedConfigurationBuilder.java From commons-configuration with Apache License 2.0 | 6 votes |
/** * Creates a new configuration using the specified builder and adds it * to the resulting combined configuration. * * @param ccResult the resulting combined configuration * @param decl the current {@code ConfigurationDeclaration} * @param builder the configuration builder * @throws ConfigurationException if an error occurs */ private void addChildConfiguration(final CombinedConfiguration ccResult, final ConfigurationDeclaration decl, final ConfigurationBuilder<? extends Configuration> builder) throws ConfigurationException { try { ccResult.addConfiguration( builder.getConfiguration(), decl.getName(), decl.getAt()); } catch (final ConfigurationException cex) { // ignore exceptions for optional configurations if (!decl.isOptional()) { throw cex; } } }
Example 2
Source File: AliceRecognition.java From carina with Apache License 2.0 | 6 votes |
private AliceRecognition() { try { CombinedConfiguration config = new CombinedConfiguration(new MergeCombiner()); config.addConfiguration(new SystemConfiguration()); config.addConfiguration(new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(new Parameters().properties().setFileName(ALICE_PROPERTIES)).getConfiguration()); this.enabled = config.getBoolean(ALICE_ENABLED, false); String url = config.getString(ALICE_SERVICE_URL, null); String accessToken = config.getString(ALICE_ACCESS_TOKEN, null); String command = config.getString(ALICE_COMMAND, null); if (enabled && !StringUtils.isEmpty(url) && !StringUtils.isEmpty(accessToken)) { this.client = new AliceClient(url, command); this.client.setAuthToken(accessToken); this.enabled = this.client.isAvailable(); } } catch (Exception e) { LOGGER.error("Unable to initialize Alice: " + e.getMessage(), e); } }
Example 3
Source File: PlatformConfigReader.java From obevo with Apache License 2.0 | 5 votes |
public ImmutableHierarchicalConfiguration readPlatformProperties(RichIterable<String> configPackages) { MutableList<PropertyInput> prioritizedProperties = readConfigPackages(configPackages); validate(prioritizedProperties); // order properties by priority: higher-numbered files will replace properties of lower-numbered files prioritizedProperties.sortThisBy(new Function<PropertyInput, Integer>() { @Override public Integer valueOf(PropertyInput propertyInput1) { return propertyInput1.getPriority(); } }).reverseThis(); // needs to be reversed as CombinedConfiguration takes the higher-priority files first // merge properties CombinedConfiguration combinedConfiguration = new CombinedConfiguration(new OverrideCombiner()); for (HierarchicalConfiguration<ImmutableNode> properties : prioritizedProperties.collect(new Function<PropertyInput, HierarchicalConfiguration<ImmutableNode>>() { @Override public HierarchicalConfiguration<ImmutableNode> valueOf(PropertyInput propertyInput) { return propertyInput.getProps(); } })) { combinedConfiguration.addConfiguration(properties); } // remove the configPriority property combinedConfiguration.clearTree(PROP_CONFIG_PRIORITY); return combinedConfiguration; }
Example 4
Source File: ProtocolHandlerChainImpl.java From james-project with Apache License 2.0 | 5 votes |
private void registerHandlersPackage(HandlersPackage handlersPackage, HierarchicalConfiguration<ImmutableNode> handlerConfig, List<HierarchicalConfiguration<ImmutableNode>> children) throws ConfigurationException { List<String> c = handlersPackage.getHandlers(); for (String cName : c) { CombinedConfiguration conf = new CombinedConfiguration(); HierarchicalConfiguration<ImmutableNode> cmdConf = addHandler(cName); conf.addConfiguration(cmdConf); if (handlerConfig != null) { conf.addConfiguration(handlerConfig); } children.add(conf); } }
Example 5
Source File: StudioConfigurationImpl.java From studio with GNU General Public License v3.0 | 5 votes |
private HierarchicalConfiguration<ImmutableNode> loadGlobalRepoConfig() { if (config.containsKey(STUDIO_CONFIG_GLOBAL_REPO_OVERRIDE_CONFIG)) { Path globalRepoOverrideConfigLocation = Paths.get(config.getString(REPO_BASE_PATH), config.getString(GLOBAL_REPO_PATH), config.getString(STUDIO_CONFIG_GLOBAL_REPO_OVERRIDE_CONFIG)); FileSystemResource fsr = new FileSystemResource(globalRepoOverrideConfigLocation.toFile()); if (fsr.exists()) { ZonedDateTime lastModified = null; try { lastModified = Instant.ofEpochMilli(fsr.lastModified()).atZone(UTC); if ((lastModifiedGlobalRepoConfig == null) || lastModified.isAfter(lastModifiedGlobalRepoConfig)) { YamlConfiguration globalRepoOverrideConfig = new YamlConfiguration(); try (InputStream in = fsr.getInputStream()) { globalRepoOverrideConfig.setExpressionEngine(getExpressionEngine()); globalRepoOverrideConfig.read(in); if (!globalRepoOverrideConfig.isEmpty()) { logger.debug("Loaded additional configuration from location: {0} \n {1}", fsr.getPath(), globalRepoOverrideConfig); } globalRepoConfig = globalRepoOverrideConfig; } if (!globalRepoConfig.isEmpty()) { CombinedConfiguration combinedConfig = new CombinedConfiguration(new OverrideCombiner()); combinedConfig.setExpressionEngine(getExpressionEngine()); combinedConfig.addConfiguration(globalRepoConfig); combinedConfig.addConfiguration(systemConfig); config = combinedConfig; } lastModifiedGlobalRepoConfig = lastModified; } } catch (IOException | ConfigurationException e) { logger.error("Failed to load studio configuration from: " + fsr.getPath(), e); } } } return config; }
Example 6
Source File: TestOverrideCombiner.java From commons-configuration with Apache License 2.0 | 5 votes |
/** * Tests a combine operation of non-hierarchical properties. This test is * related to CONFIGURATION-604. */ @Test public void testCombineProperties() { final PropertiesConfiguration c1 = new PropertiesConfiguration(); c1.addProperty("x.y.simpleCase", false); c1.addProperty("x.y.between", false); c1.addProperty("x.y.isDistinctFrom",false); c1.addProperty("x.y",false); final PropertiesConfiguration c2 = new PropertiesConfiguration(); c2.addProperty("x.y", true); c2.addProperty("x.y.between",true); c2.addProperty("x.y.comparison",true); c2.addProperty("x.y.in",true); c2.addProperty("x.y.isDistinctFrom",true); c2.addProperty("x.y.simpleCase", true); final CombinedConfiguration config = new CombinedConfiguration(new OverrideCombiner()); config.addConfiguration(c1); config.addConfiguration(c2); assertFalse("Wrong value for x.y", config.getBoolean("x.y")); assertFalse("Wrong value for x.y.between", config.getBoolean("x.y.between")); assertFalse("Wrong value for x.y.isDistinctFrom", config.getBoolean("x.y.isDistinctFrom")); assertFalse("Wrong value for x.y.simpleCase", config.getBoolean("x.y.simpleCase")); assertTrue("Wrong value for x.y.in", config.getBoolean("x.y.in")); assertTrue("Wrong value for x.y.comparison", config.getBoolean("x.y.comparison")); assertEquals("Wrong size", 6, config.size()); }
Example 7
Source File: MailRepositoryStoreBeanFactory.java From james-project with Apache License 2.0 | 4 votes |
/** * This method accept a Configuration object as hint and return the * corresponding MailRepository. The Configuration must be in the form of: * <p/> * <pre> * <repository destinationURL="[URL of this mail repository]" * type="[repository type ex. OBJECT or STREAM or MAIL etc.]" * model="[repository model ex. PERSISTENT or CACHE etc.]"> * [addition configuration] * </repository> * </pre> * * @param destination the destinationURL used to look up the repository * @return the selected repository * @throws MailRepositoryStoreException if any error occurs while parsing the Configuration or * retrieving the MailRepository */ @Override @SuppressWarnings("deprecation") public synchronized MailRepository select(MailRepositoryUrl destination) throws MailRepositoryStoreException { MailRepository reply = repositories.get(destination); if (reply != null) { LOGGER.debug("obtained repository: {},{}", destination, reply.getClass()); return reply; } else { String repClass = classes.get(destination.getProtocol()); LOGGER.debug("obtained repository: {} to handle: {}", repClass, destination.getProtocol().getValue()); // If default values have been set, create a new repository // configuration element using the default values // and the values in the selector. // If no default values, just use the selector. final CombinedConfiguration config = new CombinedConfiguration(); HierarchicalConfiguration<ImmutableNode> defConf = defaultConfigs.get(destination.getProtocol()); if (defConf != null) { config.addConfiguration(defConf); } HierarchicalConfiguration<ImmutableNode> builder = new BaseHierarchicalConfiguration(); builder.addProperty("[@destinationURL]", destination.asString()); config.addConfiguration(builder); try { // Use the classloader which is used for bean instance stuff @SuppressWarnings("unchecked") Class<MailRepository> clazz = (Class<MailRepository>) getBeanFactory().getBeanClassLoader().loadClass(repClass); reply = (MailRepository) getBeanFactory().autowire(clazz, ConfigurableListableBeanFactory.AUTOWIRE_AUTODETECT, false); if (reply instanceof Configurable) { ((Configurable) reply).configure(config); } reply = (MailRepository) getBeanFactory().initializeBean(reply, destination.getProtocol().getValue()); repositories.put(destination, reply); LOGGER.info("added repository: {}->{}", defConf, repClass); return reply; } catch (Exception e) { LOGGER.warn("Exception while creating repository: {}", e.getMessage(), e); throw new UnsupportedRepositoryStoreException("Cannot find or init repository", e); } } }
Example 8
Source File: CombinedConfigurationBuilder.java From commons-configuration with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} This implementation processes the definition configuration * in order to * <ul> * <li>initialize the resulting {@code CombinedConfiguration}</li> * <li>determine the builders for all configuration sources</li> * <li>populate the resulting {@code CombinedConfiguration}</li> * </ul> */ @Override protected void initResultInstance(final CombinedConfiguration result) throws ConfigurationException { super.initResultInstance(result); currentConfiguration = result; final HierarchicalConfiguration<?> config = getDefinitionConfiguration(); if (config.getMaxIndex(KEY_COMBINER) < 0) { // No combiner defined => set default result.setNodeCombiner(new OverrideCombiner()); } setUpCurrentParameters(); initNodeCombinerListNodes(result, config, KEY_OVERRIDE_LIST); registerConfiguredProviders(config); setUpCurrentXMLParameters(); currentXMLParameters.setFileSystem(initFileSystem(config)); initSystemProperties(config, getBasePath()); registerConfiguredLookups(config, result); configureEntityResolver(config, currentXMLParameters); setUpParentInterpolator(currentConfiguration, config); final ConfigurationSourceData data = getSourceData(); final boolean createBuilders = data.getChildBuilders().isEmpty(); final List<ConfigurationBuilder<? extends Configuration>> overrideBuilders = data.createAndAddConfigurations(result, data.getOverrideSources(), data.overrideBuilders); if (createBuilders) { data.overrideBuilders.addAll(overrideBuilders); } if (!data.getUnionSources().isEmpty()) { final CombinedConfiguration addConfig = createAdditionalsConfiguration(result); result.addConfiguration(addConfig, ADDITIONAL_NAME); initNodeCombinerListNodes(addConfig, config, KEY_ADDITIONAL_LIST); final List<ConfigurationBuilder<? extends Configuration>> unionBuilders = data.createAndAddConfigurations(addConfig, data.unionDeclarations, data.unionBuilders); if (createBuilders) { data.unionBuilders.addAll(unionBuilders); } } result.isEmpty(); // this sets up the node structure currentConfiguration = null; }