Example usage for org.apache.commons.configuration CompositeConfiguration CompositeConfiguration

List of usage examples for org.apache.commons.configuration CompositeConfiguration CompositeConfiguration

Introduction

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

Prototype

public CompositeConfiguration() 

Source Link

Document

Creates an empty CompositeConfiguration object which can then be added some other Configuration files

Usage

From source file:com.yahoo.sshd.server.settings.SshdSettingsBuilder.java

protected Configuration createConfiguration(final String overriddenPath) {
    try {//from   w  ww.  j  a v a2  s  .c  om

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("got overriddenPath {}", overriddenPath);
        }

        CompositeConfiguration compositeConfig = new CompositeConfiguration();
        // TODO: see how Systems and properties interact.
        compositeConfig.addConfiguration(new SystemConfiguration());
        compositeConfig.addConfiguration(findPropertiesConfiguration(overriddenPath));

        return compositeConfig;
    } catch (ConfigurationException e) {
        throw new RuntimeException(e);
    }
}

From source file:io.fluo.api.config.FluoConfiguration.java

/**
 * Returns configuration with all Fluo properties set to their
 * default. NOTE - some properties do not have defaults and 
 * will not be set.//from  w  w  w .  java2 s .  co  m
 */
public static Configuration getDefaultConfiguration() {
    Configuration config = new CompositeConfiguration();
    setDefaultConfiguration(config);
    return config;
}

From source file:cross.Factory.java

/**
 * Return the current configuration./*from  w  w  w  .jav a  2s . c om*/
 *
 * @return the current configuration
 */
protected Configuration getConfigurationMe() {
    if (this.configuration == null) {
        this.log.warn("Configuration not set, creating empty one!");
        this.configuration = new CompositeConfiguration();
    }
    // EvalTools.notNull(this.objconfig,
    // "ArrayFactory has not been configured yet!", this);
    // throw new RuntimeException("ArrayFactory has not been configured
    // yet!");
    return this.configuration;
}

From source file:com.nridge.core.app.mgr.AppMgr.java

/**
 * Loads the default property files ("application.properties" and
 * "logback.xml") from the file system and assigns default application
 * properties.// w ww. ja  v a 2  s  .co m
 * <p>
 * <b>Note:</b>&nbsp;This method will establish a default 5 minute reloading
 * policy for the "application.properties" file.  Therefore, any
 * changes to this property file while the application is running
 * will be recognized within a 5 minute period.
 * </p>
 *
 * @throws NSException Typically thrown for I/O related issues.
 */
public void loadPropertyFiles() throws NSException {
    String logFileName;

    try {

        // First, we will read our application properties.

        mConfiguration = new CompositeConfiguration();
        mConfiguration.setDelimiterParsingDisabled(true);
        mConfiguration.addConfiguration(new SystemConfiguration());
        mConfiguration.addConfiguration(new EnvironmentConfiguration());
        PropertiesConfiguration propertyCfg = new PropertiesConfiguration(deriveCfgPathFileName());
        FileChangedReloadingStrategy reloadingStrategy = new FileChangedReloadingStrategy();
        reloadingStrategy.setRefreshDelay(DateUtils.MILLIS_PER_MINUTE * 2L);
        propertyCfg.setReloadingStrategy(reloadingStrategy);
        mConfiguration.addConfiguration(propertyCfg);

        // Next, we will load our Logback properties file and configure our application logger.

        if (mCmdLine == null)
            logFileName = LOG_PROPERTY_FILE_NAME;
        else
            logFileName = mCmdLine.getOptionValue("logfile", LOG_PROPERTY_FILE_NAME);
        File logFile = new File(logFileName);
        if (!logFile.exists()) {
            String logPathFileName = String.format("%s%c%s", deriveCfgPathName(), File.separatorChar,
                    logFileName);
            logFile = new File(logPathFileName);
            if (logFile.exists())
                logFileName = logPathFileName;
            else
                throw new NSException("Unable to locate logging properties file: " + logFileName);
        }

        if (StringUtils.isEmpty(getString(APP_PROPERTY_INS_PATH)))
            mConfiguration.addProperty(APP_PROPERTY_INS_PATH, getInsPathName());
        if (StringUtils.isEmpty(getString(APP_PROPERTY_CFG_PATH)))
            mConfiguration.addProperty(APP_PROPERTY_CFG_PATH, deriveCfgPathName());
        if (StringUtils.isEmpty(getString(APP_PROPERTY_LOG_PATH)))
            mConfiguration.addProperty(APP_PROPERTY_LOG_PATH, deriveLogPathName());
        if (StringUtils.isEmpty(getString(APP_PROPERTY_DS_PATH)))
            mConfiguration.addProperty(APP_PROPERTY_DS_PATH, deriveDSPathName());
        if (StringUtils.isEmpty(getString(APP_PROPERTY_RDB_PATH)))
            mConfiguration.addProperty(APP_PROPERTY_RDB_PATH, deriveRDBMSPathName());
        if (StringUtils.isEmpty(getString(APP_PROPERTY_GDB_PATH)))
            mConfiguration.addProperty(APP_PROPERTY_GDB_PATH, deriveGraphPathName());

        LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
        JoranConfigurator joranConfigurator = new JoranConfigurator();
        joranConfigurator.setContext(loggerContext);
        loggerContext.reset();
        joranConfigurator.doConfigure(logFileName);
    } catch (ConfigurationException e) {
        throw new NSException("Configuration parsing error: " + e.getMessage());
    } catch (JoranException e) {
        throw new NSException("Logback parsing error: " + e.getMessage());
    } catch (ClassCastException ignored) {

        /* Note that a WARNING related to java.lang.ClassCastException will trigger due to
        Smart GWT and NSD being dependent on different releases of the same logging
        framework.  http://www.slf4j.org/codes.html */

    }
}

From source file:maltcms.ui.nb.pipelineRunner.ui.PipelineRunnerTopComponent.java

private Configuration buildCompositeConfiguration(Configuration cfg) {
    final CompositeConfiguration ccfg = new CompositeConfiguration();
    ccfg.addConfiguration(cfg);/*from  w  w  w .j  av  a 2  s . c om*/
    URL defaultConfigLocation = null;
    defaultConfigLocation = getClass().getClassLoader().getResource("cfg/default.properties");
    try {
        PropertiesConfiguration defaultConfig = new PropertiesConfiguration(defaultConfigLocation);
        ccfg.addConfiguration(defaultConfig);
        Logger.getLogger(getClass().getName()).log(Level.INFO, "Using default config location: {0}",
                defaultConfigLocation.toString());
    } catch (Exception e) {
        Logger.getLogger(getClass().getName()).warning(e.getLocalizedMessage());
    }

    ccfg.addConfiguration(new SystemConfiguration());
    return ccfg;
}

From source file:com.germinus.easyconf.ComponentProperties.java

protected Object getPropertyWithFilter(String key, Filter filter, Class theClass, Object defaultValue) {
    CompositeConfiguration filteredConf = properties;
    Object value = null;//from  w w w  .  ja  v a 2 s  . c  o m
    for (int i = filter.numOfSelectors(); (i >= 0) && (value == null); i--) {
        MapConfiguration varsConf = null;
        if (filter.hasVariables()) {
            varsConf = new MapConfiguration(filter.getVariables());
            filteredConf = new CompositeConfiguration();
            filteredConf.addConfiguration(varsConf);
            filteredConf.addConfiguration(properties);
        }
        value = getTypedPropertyWithDefault(key + filter.getFilterSuffix(i), theClass, filteredConf, null);
        if (varsConf != null) {
            properties.removeConfiguration(varsConf);
        }
        log.debug("Value for " + key + filter.getFilterSuffix(i) + "=" + value);
    }
    if (value == null) {
        value = defaultValue;
    }
    return value;
}

From source file:ffx.ui.MainPanel.java

/**
 * Attempts to load the supplied file/*from www. j a v a 2  s  .  c o m*/
 *
 * @param file File to open
 * @param commandDescription Description of the command that created this
 * file.
 * @return a {@link java.lang.Thread} object.
 */
private UIFileOpener openInit(File file, String commandDescription) {
    if (file == null || !file.isFile() || !file.canRead()) {
        return null;
    }
    file = new File(FilenameUtils.normalize(file.getAbsolutePath()));
    // Set the Current Working Directory based on this file.
    setCWD(file.getParentFile());

    // Get "filename" from "filename.extension".
    String name = file.getName();
    String extension = FilenameUtils.getExtension(name);

    /**
     * Run a Force Field X script.
     */
    if (extension.equalsIgnoreCase("ffx") || extension.equalsIgnoreCase("groovy")) {
        ModelingShell shell = getModelingShell();
        shell.runFFXScript(file);
        boolean shutDown = Boolean.parseBoolean(System.getProperty("ffx.shutDown", "true"));
        if (java.awt.GraphicsEnvironment.isHeadless() && shutDown) {
            exit();
        } else {
            return null;
        }
    }

    // Create the CompositeConfiguration properties.
    CompositeConfiguration properties = Keyword.loadProperties(file);
    // Create an FFXSystem for this file.
    FFXSystem newSystem = new FFXSystem(file, commandDescription, properties);
    // Create a Force Field.
    forceFieldFilter = new ForceFieldFilter(properties);
    ForceField forceField = forceFieldFilter.parse();
    String patches[] = properties.getStringArray("patch");
    for (String patch : patches) {
        logger.info(" Attempting to read force field patch from " + patch + ".");
        CompositeConfiguration patchConfiguration = new CompositeConfiguration();
        patchConfiguration.addProperty("parameters", patch);
        forceFieldFilter = new ForceFieldFilter(patchConfiguration);
        ForceField patchForceField = forceFieldFilter.parse();
        forceField.append(patchForceField);
        if (RotamerLibrary.addRotPatch(patch)) {
            logger.info(String.format(" Loaded rotamer definitions from patch %s.", patch));
        }
    }
    newSystem.setForceField(forceField);
    SystemFilter systemFilter = null;

    // Decide what parser to use.
    if (xyzFileFilter.acceptDeep(file)) {
        // Use the TINKER Cartesian Coordinate File Parser.
        systemFilter = new XYZFilter(file, newSystem, forceField, properties);
    } else if (intFileFilter.acceptDeep(file)) {
        // Use the TINKER Internal Coordinate File Parser.
        systemFilter = new INTFilter(file, newSystem, forceField, properties);
    } else {
        // Use the PDB File Parser.
        systemFilter = new PDBFilter(file, newSystem, forceField, properties);
    }

    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    activeFilter = systemFilter;
    UIFileOpener fileOpener = new UIFileOpener(systemFilter, this);
    if (fileOpenerThreads > 0) {
        fileOpener.setNThreads(fileOpenerThreads);
    }
    return fileOpener;
    //return new UIFileOpener(systemFilter, this);
}

From source file:ffx.ui.MainPanel.java

/**
 * Attempts to load from the supplied data structure
 *
 * @param data Data structure to load from
 * @param file Source file//www.ja  v a 2 s.c o  m
 * @param commandDescription Description of the command that created this
 * file.
 * @return A thread-based UIDataConverter
 */
private UIDataConverter convertInit(Object data, File file, String commandDescription) {
    if (data == null) {
        return null;
    }

    // Create the CompositeConfiguration properties.
    CompositeConfiguration properties = Keyword.loadProperties(file);
    // Create an FFXSystem for this file.
    FFXSystem newSystem = new FFXSystem(file, commandDescription, properties);
    // Create a Force Field.
    forceFieldFilter = new ForceFieldFilter(properties);
    ForceField forceField = forceFieldFilter.parse();
    String patches[] = properties.getStringArray("patch");
    for (String patch : patches) {
        logger.info(" Attempting to read force field patch from " + patch + ".");
        CompositeConfiguration patchConfiguration = new CompositeConfiguration();
        patchConfiguration.addProperty("parameters", patch);
        forceFieldFilter = new ForceFieldFilter(patchConfiguration);
        ForceField patchForceField = forceFieldFilter.parse();
        forceField.append(patchForceField);
        if (RotamerLibrary.addRotPatch(patch)) {
            logger.info(String.format(" Loaded rotamer definitions from patch %s.", patch));
        }
    }
    newSystem.setForceField(forceField);
    ConversionFilter convFilter = null;

    // Decide what parser to use.
    if (biojavaDataFilter.accept(data)) {
        convFilter = new BiojavaFilter((Structure) data, newSystem, forceField, properties);
    } else {
        throw new IllegalArgumentException("Not a recognized data structure.");
    }

    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    activeConvFilter = convFilter;
    return new UIDataConverter(data, file, convFilter, this);
}

From source file:ffx.ui.MainPanel.java

/**
 * Attempts to load the supplied file/*from   w  w w  .  j  av  a 2 s  . c om*/
 *
 * @param files Files to open
 * @param commandDescription Description of the command that created this
 * file.
 * @return a {@link java.lang.Thread} object.
 */
private UIFileOpener openInit(List<File> files, String commandDescription) {
    if (files == null) {
        return null;
    }
    File file = new File(FilenameUtils.normalize(files.get(0).getAbsolutePath()));
    // Set the Current Working Directory based on this file.
    setCWD(file.getParentFile());

    // Get "filename" from "filename.extension".
    String name = file.getName();
    String extension = FilenameUtils.getExtension(name);

    // Create the CompositeConfiguration properties.
    CompositeConfiguration properties = Keyword.loadProperties(file);
    forceFieldFilter = new ForceFieldFilter(properties);
    ForceField forceField = forceFieldFilter.parse();

    // Create an FFXSystem for this file.
    FFXSystem newSystem = new FFXSystem(file, commandDescription, properties);
    String patches[] = properties.getStringArray("patch");
    for (String patch : patches) {
        logger.info(" Attempting to read force field patch from " + patch + ".");
        CompositeConfiguration patchConfiguration = new CompositeConfiguration();
        patchConfiguration.addProperty("parameters", patch);
        forceFieldFilter = new ForceFieldFilter(patchConfiguration);
        ForceField patchForceField = forceFieldFilter.parse();
        forceField.append(patchForceField);
        if (RotamerLibrary.addRotPatch(patch)) {
            logger.info(String.format(" Loaded rotamer definitions from patch %s.", patch));
        }
    }
    newSystem.setForceField(forceField);
    // Decide what parser to use.
    SystemFilter systemFilter = null;
    if (xyzFileFilter.acceptDeep(file)) {
        // Use the TINKER Cartesian Coordinate File Parser.
        systemFilter = new XYZFilter(files, newSystem, forceField, properties);
    } else if (intFileFilter.acceptDeep(file)) {
        // Use the TINKER Internal Coordinate File Parser.
        systemFilter = new INTFilter(files, newSystem, forceField, properties);
    } else {
        // Use the PDB File Parser.
        systemFilter = new PDBFilter(files, newSystem, forceField, properties);
    }

    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    activeFilter = systemFilter;
    //return new UIFileOpener(systemFilter, this);
    UIFileOpener fileOpener = new UIFileOpener(systemFilter, this);
    if (fileOpenerThreads > 0) {
        fileOpener.setNThreads(fileOpenerThreads);
    }
    return fileOpener;
}

From source file:ninja.i18n.MessagesImpl.java

/**
 * Does all the loading of message files.
 * /*from   ww w .  ja v  a2  s. c  o  m*/
 * Only registered messages in application.conf are loaded.
 * 
 */
private Map<String, Configuration> loadAllMessageFilesForRegisteredLanguages() {

    Map<String, Configuration> langToKeyAndValuesMappingMutable = Maps.newHashMap();

    // Load default messages:
    Configuration defaultLanguage = loadLanguageConfiguration("conf/messages.properties");

    // Make sure we got the file.
    // Everything else does not make much sense.
    if (defaultLanguage == null) {
        throw new RuntimeException(
                "Did not find conf/messages.properties. Please add a default language file.");
    } else {
        langToKeyAndValuesMappingMutable.put("", defaultLanguage);
    }

    // Get the languages from the application configuration.
    String[] applicationLangs = ninjaProperties.getStringArray(NinjaConstant.applicationLanguages);

    // If we don't have any languages declared we just return.
    // We'll use the default messages.properties file.
    if (applicationLangs == null) {
        return ImmutableMap.copyOf(langToKeyAndValuesMappingMutable);
    }

    // Load each language into the HashMap containing the languages:
    for (String lang : applicationLangs) {

        // First step: Load complete language eg. en-US
        Configuration configuration = loadLanguageConfiguration(
                String.format("conf/messages_%s.properties", lang));

        Configuration configurationLangOnly = null;

        // If the language has a country code load the default values for
        // the language, too. For instance missing variables in en-US will
        // be
        // Overwritten by the default languages.
        if (lang.contains("-")) {
            // get the lang
            String langOnly = lang.split("-")[0];

            // And load the configuraion
            configurationLangOnly = loadLanguageConfiguration(
                    String.format("conf/messages_%s.properties", langOnly));

        }

        // This is strange. If you defined the language in application.conf
        // it should be there propably.
        if (configuration == null) {
            logger.info(
                    "Did not find conf/messages_{}.properties but it was specified in application.conf. Using default language instead.",
                    lang);

        } else {

            // add new language, but combine with default language if stuff
            // is missing...
            CompositeConfiguration compositeConfiguration = new CompositeConfiguration();
            // Add eg. "en-US"
            compositeConfiguration.addConfiguration(configuration);

            // Add eg. "en"
            if (configurationLangOnly != null) {
                compositeConfiguration.addConfiguration(configurationLangOnly);
            }
            // Add messages.conf (default pack)
            compositeConfiguration.addConfiguration(defaultLanguage);

            // and add the composed configuration to the hashmap with the
            // mapping.
            langToKeyAndValuesMappingMutable.put(lang, (Configuration) compositeConfiguration);
        }

    }

    return ImmutableMap.copyOf(langToKeyAndValuesMappingMutable);

}