Example usage for org.apache.commons.configuration.tree UnionCombiner UnionCombiner

List of usage examples for org.apache.commons.configuration.tree UnionCombiner UnionCombiner

Introduction

In this page you can find the example usage for org.apache.commons.configuration.tree UnionCombiner UnionCombiner.

Prototype

UnionCombiner

Source Link

Usage

From source file:com.shanke.common.conf.CustomConfigurationBuilder.java

/**
 * Returns the configuration provided by this builder. If the boolean
 * parameter is <b>true</b>, the configuration definition file will be
 * loaded. It will then be parsed, and instances for the declared
 * configurations will be created.//  w  w w . j  a va2  s  .c  o m
 * 
 * @param load
 *            a flag whether the configuration definition file should be
 *            loaded; a value of <b>false</b> would make sense if the file
 *            has already been created or its content was manipulated using
 *            some of the property accessor methods
 * @return the configuration
 * @throws ConfigurationException
 *             if an error occurs
 */
public Configuration getConfiguration(boolean load) throws ConfigurationException {
    if (load) {
        load();
    }

    Configuration result = createResultConfiguration();
    constructedConfiguration = result;

    List overrides = configurationsAt(KEY_OVERRIDE1);
    overrides.addAll(configurationsAt(KEY_OVERRIDE2));
    initCombinedConfiguration(result, overrides, KEY_OVERRIDE_LIST);

    List additionals = configurationsAt(KEY_UNION);
    if (!additionals.isEmpty()) {
        CombinedConfiguration addConfig = new CombinedConfiguration(new UnionCombiner());
        result.addConfiguration(addConfig, ADDITIONAL_NAME);
        initCombinedConfiguration(addConfig, additionals, KEY_ADDITIONAL_LIST);
    }

    return result;
}

From source file:org.ambraproject.configuration.ConfigurationStore.java

/**
 * Load/Reload the configuration from the factory config url.
 *
 * @param configURL URL to the config file for ConfigurationFactory
 * @throws ConfigurationException when the config factory configuration has an error
 *//*from   w w w . j ava2  s .c  om*/
public void loadConfiguration(URL configURL) throws ConfigurationException {
    root = new CombinedConfiguration(new OverrideCombiner());

    // System properties override everything
    root.addConfiguration(new SystemConfiguration());

    // Load from ambra.configuration -- /etc/... (optional)
    if (configURL != null) {
        try {
            root.addConfiguration(getConfigurationFromUrl(configURL));
            log.info("Added URL '" + configURL + "'");
        } catch (ConfigurationException ce) {
            if (!(ce.getCause() instanceof FileNotFoundException))
                throw ce;
            log.info("Unable to open '" + configURL + "'");
        }
    }

    // Add ambra.configuration.overrides (if defined)
    String overrides = System.getProperty(OVERRIDES_URL);
    if (overrides != null) {
        try {
            root.addConfiguration(getConfigurationFromUrl(new URL(overrides)));
            log.info("Added override URL '" + overrides + "'");
        } catch (MalformedURLException mue) {
            // Must not be a URL, so it must be a resource
            addResources(root, overrides);
        }
    }

    CombinedConfiguration defaults = new CombinedConfiguration(new UnionCombiner());
    // Add defaults.xml from classpath
    addResources(defaults, DEFAULTS_RESOURCE);
    // Add journal.xml from journals/journal-name/configuration/journal.xml
    addJournalResources(root, defaults, JOURNAL_DIRECTORY);
    root.addConfiguration(defaults);

    // Add global-defaults.xml (presumably found in this jar)
    addResources(root, GLOBAL_DEFAULTS_RESOURCE);

    if (log.isDebugEnabled())
        log.debug("Configuration dump: " + System.getProperty("line.separator")
                + ConfigurationUtils.toString(root));

    /**
     * This prefix is needed by the AmbraIdGenerator to create prefixes for object IDs.
     * Because of the way the AmbraIdGenerator class is created by hibernate, passing in values
     * is very difficult.  If a better method is discovered... by all means use that.  Until that time
     * I've created a system level property to store this prefix.
     */
    String objectIDPrefix = root.getString("ambra.platform.guid-prefix");

    if (objectIDPrefix == null) {
        throw new RuntimeException(
                "ambra.platform.guid-prefix node is not found in the defined configuration file.");
    }

    System.setProperty(SYSTEM_OBJECT_ID_PREFIX, objectIDPrefix);
}

From source file:org.ssh.comm.conf.CustomConfigurationBuilder.java

/**
 * Creates the {@code Configuration} for the configuration sources in the
 * <code>&lt;additional&gt;</code> section. This method is called when the
 * builder constructs the final configuration. It creates a new
 * {@code Configuration} and initializes some properties from the result
 * configuration./*from www . j  a va 2  s.c  om*/
 * 
 * @param resultConfig
 *            the result configuration (this is the configuration that will
 *            be returned by the builder)
 * @return the {@code Configuration} for the additional configuration
 *         sources
 * @since 1.7
 */
protected Configuration createAdditionalsConfiguration(Configuration resultConfig) {
    Configuration addConfig = new Configuration(new UnionCombiner());
    addConfig.setDelimiterParsingDisabled(resultConfig.isDelimiterParsingDisabled());
    addConfig.setForceReloadCheck(resultConfig.isForceReloadCheck());
    addConfig.setIgnoreReloadExceptions(resultConfig.isIgnoreReloadExceptions());
    return addConfig;
}

From source file:org.ssh.test.conf.IConfigurationBuilder.java

/**
 * Creates the {@code Configuration} for the configuration sources in the
 * <code>&lt;additional&gt;</code> section. This method is called when the
 * builder constructs the final configuration. It creates a new
 * {@code Configuration} and initializes some properties from the result
 * configuration./*from   w w w  .j  a  va2  s .c o  m*/
 * 
 * @param resultConfig
 *            the result configuration (this is the configuration that will
 *            be returned by the builder)
 * @return the {@code Configuration} for the additional configuration
 *         sources
 * @since 1.7
 */
protected IConfiguration createAdditionalsConfiguration(IConfiguration resultConfig) {
    IConfiguration addConfig = new IConfiguration(new UnionCombiner());
    addConfig.setDelimiterParsingDisabled(resultConfig.isDelimiterParsingDisabled());
    addConfig.setForceReloadCheck(resultConfig.isForceReloadCheck());
    addConfig.setIgnoreReloadExceptions(resultConfig.isIgnoreReloadExceptions());
    return addConfig;
}