Java 类org.apache.commons.configuration2.CombinedConfiguration 实例源码

项目:beadledom    文件:BeadledomConfigurationModule.java   
@Provides
@Singleton
ImmutableHierarchicalConfiguration providesConfiguration(
    Set<ConfigurationSource> configurationSources) {
  CombinedConfiguration config = new CombinedConfiguration();

  List<ConfigurationSource> sortedConfigurations = new ArrayList<ConfigurationSource>();
  sortedConfigurations.addAll(configurationSources);
  Collections.sort(sortedConfigurations);

  ConfigurationSource previousConfigSource = null;
  for (ConfigurationSource configSource : sortedConfigurations) {
    if (previousConfigSource != null) {
      warnIfEqualPriority(previousConfigSource, configSource);
    }
    config.addConfiguration(configSource.getConfig());
    previousConfigSource = configSource;
  }
  config.setNodeCombiner(new OverrideCombiner());
  return config;
}
项目:sponge    文件:DefaultConfigurationManager.java   
protected CommonsConfiguration createRootConfig() {
    MergeCombiner combiner = new MergeCombiner();
    combiner.addListNode(PluginManagerConstants.CFG_PLUGIN);

    CombinedConfiguration cc = new CombinedConfiguration(combiner);

    // Try to add explicit configuration
    if (configurationFilename != null) {
        logger.info("Loading configuration file {}...", configurationFilename);
        Pair<XMLConfiguration, URL> configurationPair = createXmlConfiguration(configurationFilename);

        cc.addConfiguration(configurationPair.getLeft());
        configurationFileUrl = configurationPair.getRight();
    }

    // Add default configuration
    cc.addConfiguration(createXmlConfiguration(ConfigurationConstants.DEFAULT_CONFIG).getLeft());

    // if (configurationFilename != null && logger.isDebugEnabled()) {
    // logger.debug("Initial XML configuration:\n{}", Utils.dumpConfiguration(cc));
    // }

    return new CommonsConfiguration(cc);
}
项目:carina    文件:AliceRecognition.java   
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());
    }
}
项目:commons-configuration2-jackson    文件:JsonConfigurationTests.java   
@Test
public void readCombinedConfig() throws ConfigurationException {
    // Arrange
    final ConfigurationBuilderProvider provider = new JacksonConfigurationBuilderProvider<>(JsonConfiguration.class);

    final Parameters params = new Parameters();
    final CombinedBuilderParameters combinedBuilderParameters = params.combined()
            .setDefinitionBuilderParameters(
                    params.fileBased().setFileName(Resources.getResource("combined.xml").toString())
            )
            .registerProvider("json", provider);

    // Act
    final CombinedConfigurationBuilder builder = new CombinedConfigurationBuilder();
    final CombinedConfiguration sut = builder.configure(combinedBuilderParameters).getConfiguration();

    // Assert
    assertThat(sut.getString("someFolder"), is("default"));
    assertThat(sut.getString("name"), is("testName"));
    assertThat(sut.getString("obj.name"), is("test"));
    assertThat(sut.getInt("obj.value"), is(1));
    assertThat(sut.getString("listOfObjs(0).name"), is("testname"));
    assertThat(sut.getInt("listOfObjs(0).value"), is(4));
    assertThat(sut.getString("listOfObjs(1).name"), is("other"));
    assertThat(sut.getInt("listOfObjs(1).value"), is(20));
    assertThat(sut.getStringArray("listOfObjs.name"), is(new String[]{"testname", "other"}));
    assertThat(sut.getProperty("nullValue"), is(nullValue()));
    assertThat(sut.getProperty("emptyList"), is(nullValue()));
}
项目:sponge    文件:CommonsConfiguration.java   
@Override
public CommonsConfiguration getChildConfiguration(String child) {
    return new CommonsConfiguration(
            hasChildConfiguration(child) ? (BaseHierarchicalConfiguration) config.configurationAt(child) : new CombinedConfiguration());
}