Example usage for org.apache.commons.configuration Configuration containsKey

List of usage examples for org.apache.commons.configuration Configuration containsKey

Introduction

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

Prototype

boolean containsKey(String key);

Source Link

Document

Check if the configuration contains the specified key.

Usage

From source file:eu.sisob.uma.restserver.SystemManager.java

/**
 * Intialice de system//from  w w w.ja  v  a2 s .  c o  m
 * @throws SQLException 
 */
public void setup() throws SQLException {
    if (!this.is_running) {
        try {
            //Database
            //TheDBPool.getInstance();
            //ProjectLogger.LOGGER.info("Connection with H2 database done.");

            //Crawler

            Configuration config = TheConfig.getInstance();

            H2DBCredentials credentials_systemdb = new H2DBCredentials(
                    System.getProperty("com.sun.aas.instanceRoot") + File.separator + "docroot" + File.separator
                            + "data-extractor-system-db",
                    "system", "sa", "sa");
            this.systemdbpool = new H2DBPool(credentials_systemdb);

            if (config.containsKey(TheConfig.SERVICES_CRAWLER)
                    && config.getString(TheConfig.SERVICES_CRAWLER).equals("enabled")) {

                File local_crawler_data_path = new File(System.getProperty("com.sun.aas.instanceRoot")
                        + File.separator + "docroot" + File.separator + "crawler-data-service");

                boolean traceUrls = config.containsKey(TheConfig.SERVICES_CRAWLER_TRACEURLS)
                        && config.getString(TheConfig.SERVICES_CRAWLER_TRACEURLS).equals("true");
                boolean traceSearch = config.containsKey(TheConfig.SERVICES_CRAWLER_TRACESEARCH)
                        && config.getString(TheConfig.SERVICES_CRAWLER_TRACESEARCH).equals("true");
                ResearchersCrawlerService.setServiceSettings(
                        local_crawler_data_path.getAbsolutePath(), Thread.currentThread()
                                .getContextClassLoader().getResource("eu/sisob/uma/crawler/keywords"),
                        traceUrls, traceSearch);

                ResearchersCrawlerService.createInstance();
                ProjectLogger.LOGGER.info("Crawler service initialiced.");
            }

            if (config.containsKey(TheConfig.SERVICES_WEBSEARCHER)
                    && config.getString(TheConfig.SERVICES_WEBSEARCHER).equals("enabled")) {
                WebSearchersExtractorService.createInstance();
            }

            if (config.containsKey(TheConfig.SERVICES_INTERNAL_CV_FILES)
                    && config.getString(TheConfig.SERVICES_INTERNAL_CV_FILES).equals("enabled")) {
                InternalCVFilesExtractorService.createInstance();
            }

            if (config.containsKey(TheConfig.SERVICES_EMAIL)
                    && config.getString(TheConfig.SERVICES_EMAIL).equals("enabled")) {
                EmailExtractorService.createInstance();
            }

            if (TheConfig.getInstance().getString(TheConfig.SERVICES_GATE).equals("enabled")) {
                //Gate                 
                File local_gate_path = new File(System.getProperty("com.sun.aas.instanceRoot") + File.separator
                        + "docroot" + File.separator + "gate-data-extractor-service");
                local_gate_path.mkdirs();

                File gate_content = new File(local_gate_path.getAbsolutePath() + File.separator + "GATE-6.0");
                if (!gate_content.exists())
                    gate_content.mkdirs();

                File keywords = new File(local_gate_path.getAbsolutePath() + File.separator + "KEYWORDS");
                if (!keywords.exists())
                    keywords.mkdirs();

                ProjectLogger.LOGGER.info("Copying gate files");
                FileFootils.copyResourcesRecursively(Thread.currentThread().getContextClassLoader()
                        .getResource("eu/sisob/uma/NPL/Researchers/GATE-6.0/"), local_gate_path);
                FileFootils.copyResourcesRecursively(Thread.currentThread().getContextClassLoader()
                        .getResource("eu/sisob/uma/NPL/Researchers/KEYWORDS/"), local_gate_path);
                ProjectLogger.LOGGER.info("Gate files copied");

                {
                    H2DBCredentials credentials_resolver = new H2DBCredentials(
                            System.getProperty("com.sun.aas.instanceRoot") + File.separator + "docroot"
                                    + File.separator + "data-extractor-system-db",
                            "locations", "sa", "sa");

                    H2DBCredentials credentials_trad_tables_academic = new H2DBCredentials(
                            System.getProperty("com.sun.aas.instanceRoot") + File.separator + "docroot"
                                    + File.separator + "data-extractor-system-db",
                            "academic_tables_traductions", "sa", "sa");

                    GateDataExtractorService.setServiceSettings(
                            local_gate_path.getAbsolutePath() + File.separator + "GATE-6.0",
                            local_gate_path.getAbsolutePath() + File.separator + "KEYWORDS", 1, 5,
                            credentials_trad_tables_academic, credentials_resolver);

                    GateDataExtractorService.createInstance();
                    ProjectLogger.LOGGER.info("Gate service initialiced.");
                }

            }

            is_running = true;
        } finally {
            if (!is_running) {
                ProjectLogger.LOGGER.error("Something has failed in initialization. Going to release objects.");

                if (TheConfig.getInstance().getString(TheConfig.SERVICES_CRAWLER).equals("enabled")) {
                    //Crawler
                    ResearchersCrawlerService.releaseInstance();
                    ProjectLogger.LOGGER.info("Crawler service initialiced.");
                }

                if (TheConfig.getInstance().getString(TheConfig.SERVICES_GATE).equals("enabled")) {
                    //Gate                
                    GateDataExtractorService.releaseInstance();
                    ProjectLogger.LOGGER.info("Gate service release.");
                }

                //DB
                this.systemdbpool = null;
                ProjectLogger.LOGGER.info("System db pool initialiced.");

                this.is_running = false;
            } else {
                ProjectLogger.LOGGER.info("System initialized!");
            }
        }
    }
}

From source file:es.udc.gii.common.eaf.algorithm.EvolutionaryAlgorithm.java

@Override
public void configure(Configuration conf) {
    try {//from   w ww.jav  a 2  s. c  o  m
        setComparator((FitnessComparator) Class.forName(conf.getString("Comparator")).newInstance());

        setUseCustomInitPopulation(conf.containsKey("UseCustomRandomInitPopulation"));

        setDebug(conf.containsKey("Debug"));

        if (conf.containsKey("FitnessHistoryCapacity")) {
            this.fitness_history_capacity = conf.getInt("FitnessHistoryCapacity");
            this.fitness_history = new ArrayList<Individual>();

        } else {
            this.fitness_history = null;
        }

    } catch (Exception ex) {

        System.exit(0);
    }
}

From source file:com.vmware.qe.framework.datadriven.config.DDConfig.java

/**
 * Uses the current configuration data passed in as argument and does the following: <br>
 * 1. Look for config.properties file on class path and load it if present.<br>
 * 2. Look for config.path in CLI params. If present, load it and overwrite any existing
 * properties.<br>// w w  w  . j  av a 2 s  .  co  m
 * 3. Overwrite existing data with whatever was specified via cli. <br>
 * 
 * @param testData test configuration data
 * @return processed test configuration data
 */
private synchronized Configuration prepareData(Configuration testData) {
    Configuration resultData = null;
    // step 1. config.properties on classpath
    URL cfgFile = this.getClass().getResource(DD_CONFIG_FILE_NAME);
    if (cfgFile != null) {
        log.info("Loading Configuration File: {}", cfgFile);
        resultData = getConfigFileData(cfgFile.getFile());
    } else {
        log.warn("Config file not found! " + DD_CONFIG_FILE_NAME);
    }
    if (resultData != null) {
        log.debug("Loaded data from " + DD_CONFIG_FILE_NAME + " on classpath");
    }
    // step 2. config file specified on cli
    if (testData.containsKey(TESTINPUT_CONFIG_PATH)) {
        String filePath = testData.getString(TESTINPUT_CONFIG_PATH);
        if (checkFilePath(filePath)) {
            Configuration tmpData = getConfigFileData(filePath);
            resultData = overrideConfigProperties(resultData, tmpData);
            log.debug("Loaded data from config file '{}'", filePath);
        }
    }
    log.debug("Overriding using properties specified via commandline arguments");
    resultData = overrideConfigProperties(resultData, testData);
    if (resultData == null) {
        String error = "Configuration data can not be null. Please specify test "
                + "configuration information via config file on classpath or filesystem or via cli";
        log.error(error);
        throw new DDException(error);
    }
    log.debug("DDConfig: {}", ConfigurationUtils.toString(resultData));
    return resultData;
}

From source file:com.impetus.kundera.ycsb.runner.YCSBRunner.java

public YCSBRunner(final String propertyFile, final Configuration config) {
    this.propertyFile = propertyFile;
    ycsbJarLocation = config.getString("ycsbjar.location");
    clientjarlocation = config.getString("clientjar.location");
    host = config.getString("hosts");
    schema = config.getString("schema");
    columnFamilyOrTable = config.getString("columnfamilyOrTable");
    releaseNo = config.getDouble("release.no");
    runType = config.getString("run.type", "load");
    port = config.getInt("port");
    password = config.getString("password");
    clients = config.getStringArray("clients");
    isUpdate = config.containsKey("update");
    crudUtils = new HibernateCRUDUtils();
}

From source file:com.nesscomputing.quartz.NessQuartzModule.java

private void configureJob(final String jobName, final Configuration jobConfig) {
    try {//from   w  ww.ja v  a2  s .  c  o  m
        final String className = jobConfig.getString("class");
        Preconditions.checkState(className != null, "No class key found (but it existed earlier!");
        final Class<? extends Job> jobClass = Class.forName(className).asSubclass(Job.class);

        // Bind the class. if it needs to be a singleton, annotate accordingly. Do not add
        // in(Scopes.SINGLETON) here, because then it is not possible to undo that.
        bind(jobClass);

        final QuartzJobBinder binder = QuartzJobBinder.bindQuartzJob(binder(), jobClass);
        binder.name(jobName);

        if (jobConfig.containsKey("delay")) {
            binder.delay(parseDuration(jobConfig, "delay"));
        }

        if (jobConfig.containsKey("startTime")) {
            binder.startTime(parseStartTime(jobConfig, "startTime"), new TimeSpan("60s"));
        }

        if (jobConfig.containsKey("repeat")) {
            binder.repeat(parseDuration(jobConfig, "repeat"));
        }

        if (jobConfig.containsKey("group")) {
            binder.group(jobConfig.getString("group"));
        }

        if (jobConfig.containsKey("cronExpression")) {
            binder.cronExpression(jobConfig.getString("cronExpression"));
        }

        if (jobConfig.containsKey("enabled")) {
            binder.enabled(jobConfig.getBoolean("enabled"));
        } else {
            LOG.warn("Found job %s but no key for enabling!", jobName);
        }

        LOG.info("Registered %s", binder);
        binder.register();
    } catch (ClassCastException cce) {
        addError(cce);
    } catch (ClassNotFoundException cnfe) {
        addError(cnfe);
    }
}

From source file:com.evolveum.midpoint.model.impl.controller.ModelDiagController.java

private File getLogFile() throws SchemaException {
    Configuration c = midpointConfiguration
            .getConfiguration(MidpointConfiguration.SYSTEM_CONFIGURATION_SECTION);
    if (c == null || !c.containsKey(LOG_FILE_CONFIG_KEY)) {
        throw new SchemaException(
                "No log file specified in system configuration. Please set logFile in <midpoint><system> section.");
    }//  w  w w. j  a  v a  2s . c  o m
    return new File(c.getString(LOG_FILE_CONFIG_KEY));
}

From source file:com.netflix.config.ConcurrentCompositeConfiguration.java

/**
 * Check if the any of the sub configurations contains the specified key.
 *
 * @param key the key whose presence in this configuration is to be tested
 *
 * @return <code>true</code> if the configuration contains a value for this
 *         key, <code>false</code> otherwise
 * /*from   ww w  .j a  va  2s  .c  o  m*/
 */
@Override
public boolean containsKey(String key) {
    if (overrideProperties.containsKey(key)) {
        return true;
    }
    for (Configuration config : configList) {
        if (config.containsKey(key)) {
            return true;
        }
    }
    return false;
}

From source file:com.netflix.config.ConcurrentCompositeConfiguration.java

/**
 * Returns the configuration source, in which the specified key is defined.
 * This method will iterate over all existing child configurations and check
 * whether they contain the specified key. The following constellations are
 * possible:/*from  w  w  w  .  ja v a2  s .com*/
 * <ul>
 * <li>If the child configurations contains this key, the first one is returned.</li>
 * <li>If none of the child configurations contain the key, <b>null</b> is
 * returned.</li>
 * </ul>
 *
 * @param key the key to be checked
 * @return the source configuration of this key
 */
public Configuration getSource(String key) {
    if (key == null) {
        throw new IllegalArgumentException("Key must not be null!");
    }

    if (overrideProperties.containsKey(key)) {
        return overrideProperties;
    }

    for (Configuration conf : configList) {
        if (conf.containsKey(key)) {
            return conf;
        }
    }
    return null;
}

From source file:com.netflix.config.ConcurrentCompositeConfiguration.java

/**
 * Read property from underlying composite. It first checks if the property has been overridden
 * by {@link #setOverrideProperty(String, Object)} and if so return the overriding value.
 * Otherwise, it iterates through the list of sub configurations until it finds one that contains the
 * property and return the value from that sub configuration. It returns null of the property does
 * not exist.//  w ww.  ja va 2 s  . co m
 *
 * @param key key to use for mapping
 *
 * @return object associated with the given configuration key. null if it does not exist.
 */
public Object getProperty(String key) {
    if (overrideProperties.containsKey(key)) {
        return overrideProperties.getProperty(key);
    }
    Configuration firstMatchingConfiguration = null;
    for (Configuration config : configList) {
        if (config.containsKey(key)) {
            firstMatchingConfiguration = config;
            break;
        }
    }

    if (firstMatchingConfiguration != null) {
        return firstMatchingConfiguration.getProperty(key);
    } else {
        return null;
    }
}

From source file:cross.ObjectFactory.java

@Override
public void configure(final Configuration cfg) {
    this.cfg = cfg;
    String[] contextLocations = null;
    if (this.cfg.containsKey(CONTEXT_LOCATION_KEY)) {
        log.debug("Using user-defined location: {}", (Object[]) this.cfg.getStringArray(CONTEXT_LOCATION_KEY));
        contextLocations = cfg.getStringArray(CONTEXT_LOCATION_KEY);
    }/*from   w  w w . j a v  a2  s  .c  om*/
    if (contextLocations == null) {
        log.debug("No pipeline configuration found! Please define! Example: -c cfg/pipelines/chroma.mpl");
        return;
    }
    log.debug("Using context locations: {}", Arrays.toString(contextLocations));
    try {
        if (cfg.containsKey("maltcms.home")) {
            File f = new File(new File(cfg.getString("maltcms.home")),
                    "cfg/pipelines/xml/workflowDefaults.xml");
            if (f.exists()) {
                log.info("Using workflow defaults at: {}", f);
                cfg.setProperty("cross.applicationContext.workflowDefaults",
                        cfg.getString("cross.applicationContext.workflowDefaults.file"));
            }
        } else {
            log.info("Using workflow defaults from classpath.");
        }
        String[] defaultLocations = cfg.getStringArray("cross.applicationContext.defaultLocations");
        log.debug("Using default context locations: {}", Arrays.toString(defaultLocations));
        LinkedList<String> applicationContextLocations = new LinkedList<>(Arrays.asList(defaultLocations));
        applicationContextLocations.addAll(Arrays.asList(contextLocations));
        context = new DefaultApplicationContextFactory(applicationContextLocations, this.cfg)
                .createApplicationContext();
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}