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

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

Introduction

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

Prototype

String getString(String key);

Source Link

Document

Get a string associated with the given configuration key.

Usage

From source file:com.boozallen.cognition.ingest.storm.bolt.geo.TwoFishesGeocodeBolt.java

@Override
public void configure(Configuration conf) throws ConfigurationException {
    _server = conf.getString(SERVER);
    coordinatesField = conf.getString(COORDINATES_FIELD, "geo.coordinates");
    _locationFields = new ArrayList<>();
    conf.getList(LOCATION_FIELDS).forEach(x -> _locationFields.add(x.toString()));
    _successCount = 0;/*from  w ww .  j  av a 2s .  c om*/
    _failCount = 0;
    _exceptionCount = 0;
    _useMultipleLocations = conf.getBoolean(USE_MULTIPLE_LOCATIONS, false);
}

From source file:es.udc.gii.common.eaf.algorithm.operator.reproduction.mutation.de.DEMutationOperator.java

@Override
public void configure(Configuration conf) {
    try {//from w  ww .  ja  v  a  2s.  co m

        if (conf.containsKey("MutationStrategy.Class")) {
            this.mutationStrategy = (DEMutationStrategy) Class.forName(conf.getString("MutationStrategy.Class"))
                    .newInstance();
            this.mutationStrategy.configure(conf.subset("MutationStrategy"));
        } else {
            ConfWarning w = new ConfWarning("MutationStrategy", this.getClass().getSimpleName());
            w.warn();
        }
        if (conf.containsKey("CrossOverScheme.Class")) {
            this.crossOverScheme = (CrossOverScheme) Class.forName(conf.getString("CrossOverScheme.Class"))
                    .newInstance();
            this.crossOverScheme.configure(conf.subset("CrossOverScheme"));
        } else {
            ConfWarning w = new ConfWarning("CrossOverScheme", this.crossOverScheme.getClass().getSimpleName());
            w.warn();
        }

    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
        throw new ConfigurationException(this.getClass(), ex);
    }

}

From source file:com.cisco.oss.foundation.message.HornetQMessageConsumer.java

private String createQueueIfNeeded() {

    Configuration subset = configuration.subset(consumerName);
    queueName = subset.getString("queue.name");

    String filter = subset.getString("queue.filter", "");
    boolean isDurable = subset.getBoolean("queue.isDurable", true);
    boolean isSubscription = subset.getBoolean("queue.isSubscription", false);
    String subscribedTo = isSubscription ? subset.getString("queue.subscribedTo", "") : queueName;

    if (isSubscription) {
        if (StringUtils.isBlank(subscribedTo)) {
            throw new QueueException(
                    "Check Configuration - missing required subscribedTo name for consumerThreadLocal["
                            + consumerName + "] as it is marked as isSubscription=true");
        }//w ww.j  a  v  a  2s  .  c o  m
        //            subscribedTo = "foundation." + subscribedTo;
    }

    if (StringUtils.isBlank(queueName)) {

        String rpmSoftwareName = System.getenv("_RPM_SOFTWARE_NAME");
        String artifactId = System.getenv("_ARTIFACT_ID");
        String componentName = "";

        if (StringUtils.isNoneBlank(rpmSoftwareName)) {
            componentName = rpmSoftwareName;
        } else {
            if (StringUtils.isNoneBlank(artifactId)) {
                componentName = artifactId;
            }
        }

        if (StringUtils.isNoneBlank(componentName)) {
            queueName = componentName + "_" + subscribedTo;
        }

        if (StringUtils.isBlank(queueName)) {
            throw new QueueException(
                    "Check Configuration - missing required queue name for consumerThreadLocal: "
                            + consumerName);
        }
    }

    String realQueueName = /*"foundation." + */queueName;

    boolean queueExists = false;

    for (Pair<ClientSession, SessionFailureListener> clientSessionSessionFailureListenerPair : HornetQMessagingFactory
            .getSession(FoundationQueueConsumerFailureListener.class)) {
        ClientSession clientSession = clientSessionSessionFailureListenerPair.getLeft();
        try {
            queueExists = clientSession.queueQuery(new SimpleString(realQueueName)).isExists();
            if (!queueExists) {
                clientSession.createQueue(isSubscription ? subscribedTo : realQueueName, realQueueName, filter,
                        isDurable);
            }
        } catch (HornetQException e) {
            try {
                clientSession.createQueue(isSubscription ? subscribedTo : realQueueName, realQueueName, filter,
                        isDurable);
            } catch (HornetQException e1) {
                throw new QueueException("Can't create queue: " + realQueueName + ". Error: " + e1, e1);
            }
        }
    }

    return realQueueName;

}

From source file:es.udc.gii.common.eaf.algorithm.parallel.migration.acceptance.GenerationBasedAcceptance.java

/**
 * Configures this class with a given {@link Configuration}.<p>
 *
 * Configuration example://  w  w w. j  a va  2 s . co  m
 *
 * <pre>
 * ...
 * &lt;AcceptancePolicy&gt;
 *     &lt;Class&gt;...parallel.migration.GenerationBasedAcceptance&lt;/Class&gt;
 *     &lt;AcceptIndividualsFrom&gt;ANY_GENERATION&lt;/AcceptIndividualsFrom&gt;
 * &lt;/AcceptancePolicy&gt;
 * ...
 * </pre><p>
 *
 * This configures this class for accepting any individual from any
 * generation. The following values are allowed for <code>AcceptIndividualsFrom</code>:
 *
 * <pre>
 *    ANY_GENERATION
 *    OLDER_GENERATION
 *    NEWER_GENERATION
 *    SAME_GENERATION
 * </pre>
 */
@Override
public void configure(Configuration conf) {
    String acceptFrom = conf.getString("AcceptIndividualsFrom");

    if (acceptFrom.equals("ANY_GENERATION")) {
        setAcceptIndividualsFrom(ANY_GENERATION);
    } else if (acceptFrom.equals("OLDER_GENERATION")) {
        setAcceptIndividualsFrom(OLDER_GENERATION);
    } else if (acceptFrom.equals("SAME_GENERATION")) {
        setAcceptIndividualsFrom(SAME_GENERATION);
    } else if (acceptFrom.equals("NEWER_GENERATION")) {
        setAcceptIndividualsFrom(NEWER_GENERATION);
    } else {
        throw new RuntimeException("GenerationBasedAcceptance (configure" + "): Wrong parameter " + acceptFrom
                + ". Only "
                + "ANY_GENERATION, SAME_GENERATION, OLDER_GENERATION and NEWER_GENERATION are allowed.");
    }
}

From source file:com.nesscomputing.migratory.maven.MigrateMojo.java

@Override
protected void doExecute(Migratory migratory) throws Exception {
    Configuration c = new SystemConfiguration().subset(CONTEXT_PROPERTIES);

    for (Iterator<?> it = c.getKeys(); it.hasNext();) {
        final String key = (String) it.next();
        migratory.addDefine(key, c.getString(key));
    }//from   w ww .j a v  a  2 s  . c om

    final MigrationPlan plan = createMigrationPlan(migrations);
    migratory.addLocator(new MojoLocator(migratory, locationUrl.toURI()));

    migratory.dbMigrate(plan, optionList);

    final Map<String, List<MetadataInfo>> results = migratory.dbHistory(null, optionList);
    for (Map.Entry<String, List<MetadataInfo>> personality : results.entrySet()) {
        HistoryMojo.dump(verbose, personality.getKey(), personality.getValue());
    }
}

From source file:io.mindmaps.graql.internal.analytics.DegreeAndPersistVertexProgram.java

@Override
public void loadState(final Graph graph, final Configuration configuration) {
    this.selectedTypes = new HashSet<>();
    configuration.getKeys(TYPE).forEachRemaining(key -> selectedTypes.add(configuration.getString(key)));
    keySpace = configuration.getString(KEYSPACE);
}

From source file:com.linkedin.pinot.filesystem.HadoopPinotFS.java

@Override
public void init(Configuration config) {
    try {//www .jav a2  s. c  om
        retryCount = config.getInt(RETRY, retryCount);
        retryWaitMs = config.getInt(RETRY_WAITIME_MS, retryWaitMs);
        hadoopConf = getConf(config.getString(HADOOP_CONF_PATH));
        authenticate(hadoopConf, config);
        hadoopFS = org.apache.hadoop.fs.FileSystem.get(hadoopConf);
        LOGGER.info("successfully initialized HadoopPinotFS");
    } catch (IOException e) {
        throw new RuntimeException("Could not initialize HadoopPinotFS", e);
    }
}

From source file:net.sf.jclal.classifier.MOAClassifier.java

/**
 * Method to read the object's configuration
 * @param configuration//from w w  w.  jav  a  2s  .  c o  m
 *            The configuration of MOA classifier.
 *
 *            The XML labels supported are:
 *
 *            <ul>
 *            <li>
 *            <b>classifier type= class</b>
 *            <p>
 *            Package:
 *            </p>
 *            moa.classifiers
 *            <p>
 *            Class: All
 *            </p>
 *            </li>
 *            </ul>
 */
@Override
public void configure(Configuration configuration) {

    String classifierError = "classifier type= ";
    try {

        // classifier classname
        String classifierClassname = configuration.getString("classifier[@type]");

        classifierError += classifierClassname;

        // classifier class
        Class<? extends Classifier> classifierClass = (Class<? extends Classifier>) Class
                .forName(classifierClassname);

        // Add this classifier
        setClassifier(new MOAWrapper(classifierClass.newInstance()));

    } catch (ClassNotFoundException e) {
        throw new ConfigurationRuntimeException("\nIllegal classifier classname: " + classifierError, e);
    } catch (InstantiationException e) {
        throw new ConfigurationRuntimeException("\nIllegal classifier classname: " + classifierError, e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationRuntimeException("\nIllegal classifier classname: " + classifierError, e);
    }
}

From source file:de.klemp.middleware.controller.Controller.java

/**
 * This method creates a connection to the postgresql database. After done
 * the requests the method closeDBConnection() has to be used. This is a
 * local method which is only used by other methods of the controller.
 *//*  w w  w.ja  v  a  2  s . c om*/
private static synchronized void createDBConnection() {

    Configuration config;
    try {
        config = new PropertiesConfiguration("GUIconf.properties");
        String databaseDriver = config.getString("databaseDriver");
        Class.forName(databaseDriver);

        if (conn == null || conn.isClosed()) {

            String urlDatabase = config.getString("urlDatabase");
            conn = DriverManager.getConnection(urlDatabase, "middleware", "queryDatabase");
        }
    } catch (ConfigurationException | ClassNotFoundException | SQLException e) {
        logger.error("Could not create a database connection", e);
    }

}

From source file:com.evolveum.midpoint.init.ConfigurablePrismContextFactory.java

@Override
protected void registerExtensionSchemas(SchemaRegistry schemaRegistry) throws SchemaException {
    Configuration config = configuration.getConfiguration(CONFIGURATION_GLOBAL);
    if (config == null) {
        LOGGER.warn("Global part 'midpoint.global' is not defined in configuration file.");
        return;//from   w  w  w.  j  av a2  s. c o m
    }
    String extensionDir = config.getString(EXTENSION_DIR);

    if (StringUtils.isEmpty(extensionDir)) {
        if (StringUtils.isNotEmpty(configuration.getMidpointHome())) {
            extensionDir = configuration.getMidpointHome() + "/schema";
        }
    }

    if (StringUtils.isNotEmpty(extensionDir)) {
        LOGGER.info("Loading extension schemas from folder '{}'.", new Object[] { extensionDir });
    } else {
        LOGGER.warn("Not loading extension schemas, extensionDir or even midpoint.home is not defined.");
        return;
    }

    try {
        File file = new File(extensionDir);
        if (!file.exists() || !file.isDirectory()) {
            LOGGER.warn("Extension dir '{}' does not exist, or is not a directory, skipping extension loading.",
                    new Object[] { extensionDir });
            return;
        }

        schemaRegistry.registerPrismSchemasFromDirectory(file);
    } catch (Exception ex) {
        throw new SchemaException(ex.getMessage(), ex);
    }
}