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:org.janusgraph.graphdb.management.ConfigurationManagementGraph.java

/**
 * Create a configuration according to the supplied {@link Configuration}; you must include
 * the property "graph.graphname" with a value in the configuration; you can then
 * open your graph using graph.graphname without having to supply the
 * Configuration or File each time using the {@link org.janusgraph.core.ConfiguredGraphFactory}.
 *//*  ww w . j  a v a 2 s  .c  om*/
public void createConfiguration(final Configuration config) {
    Preconditions.checkArgument(config.containsKey(PROPERTY_GRAPH_NAME),
            String.format("Please include the property \"%s\" in your configuration.", PROPERTY_GRAPH_NAME));
    final Map<Object, Object> map = ConfigurationConverter.getMap(config);
    final Vertex v = graph.addVertex(T.label, VERTEX_LABEL);
    map.forEach((key, value) -> v.property((String) key, value));
    v.property(PROPERTY_TEMPLATE, false);
    graph.tx().commit();
}

From source file:org.janusgraph.graphdb.management.ConfigurationManagementGraph.java

/**
 * Create a template configuration according to the supplied {@link Configuration}; if
 * you already created a template configuration or the supplied {@link Configuration}
 * contains the property "graph.graphname", we throw a {@link RuntimeException}; you can then use
 * this template configuration to create a graph using the
 * ConfiguredGraphFactory create signature and supplying a new graphName.
 *//*  w ww  .j ava 2  s  . co m*/
public void createTemplateConfiguration(final Configuration config) {
    Preconditions.checkArgument(!config.containsKey(PROPERTY_GRAPH_NAME), String
            .format("Your template configuration may not contain the property \"%s\".", PROPERTY_GRAPH_NAME));
    Preconditions.checkState(null == getTemplateConfiguration(),
            "You may only have one template configuration and one exists already.");
    final Map<Object, Object> map = ConfigurationConverter.getMap(config);
    final Vertex v = graph.addVertex();
    v.property(PROPERTY_TEMPLATE, true);
    map.forEach((key, value) -> v.property((String) key, value));
    graph.tx().commit();

}

From source file:org.janusgraph.graphdb.management.ConfigurationManagementGraph.java

/**
 * Update configuration corresponding to supplied graphName; we update supplied existing
 * properties and add new ones to the {@link Configuration}; The supplied {@link Configuration} must include a
 * property "graph.graphname" and it must match supplied graphName;
 * NOTE: The updated configuration is only guaranteed to take effect if the {@link Graph} corresponding to
 * graphName has been closed and reopened on every JanusGraph Node.
 *///from  www .jav  a 2  s  .c o  m
public void updateConfiguration(final String graphName, final Configuration config) {
    final Map<Object, Object> map = ConfigurationConverter.getMap(config);
    if (config.containsKey(PROPERTY_GRAPH_NAME)) {
        final String graphNameOnConfig = (String) map.get(PROPERTY_GRAPH_NAME);
        Preconditions.checkArgument(graphName.equals(graphNameOnConfig),
                String.format("Supplied graphName %s does not match property value supplied on config: %s.",
                        graphName, graphNameOnConfig));
    } else {
        map.put(PROPERTY_GRAPH_NAME, graphName);
    }
    log.warn(
            "Configuration {} is only guaranteed to take effect when graph {} has been closed and reopened on all Janus Graph Nodes.",
            graphName, graphName);
    updateVertexWithProperties(PROPERTY_GRAPH_NAME, graphName, map);
}

From source file:org.janusgraph.graphdb.management.ConfigurationManagementGraph.java

/**
 * Update template configuration by updating supplied existing properties and adding new ones to the
* {@link Configuration}; your updated Configuration may not contain the property "graph.graphname";
 * NOTE: Any graph using a configuration that was created using the template configuration must--
 * 1) be closed and reopened on every JanusGraph Node 2) have its corresponding Configuration removed
 * and 3) recreate the graph-- before the update is guaranteed to take effect.
 *///from w  w w.j a v a 2s .com
public void updateTemplateConfiguration(final Configuration config) {
    Preconditions.checkArgument(!config.containsKey(PROPERTY_GRAPH_NAME), String.format(
            "Your updated template configuration may not contain the property \"%s\".", PROPERTY_GRAPH_NAME));
    log.warn(
            "Any graph configuration created using the template configuration are only guaranteed to have their configuration updated "
                    + "according to this new template configuration when the graph in question has been closed on every Janus Graph Node, its "
                    + "corresponding Configuration has been removed, and the graph has been recreated.");
    updateVertexWithProperties(PROPERTY_TEMPLATE, true, ConfigurationConverter.getMap(config));
}

From source file:org.jpac.configuration.Property.java

public Property(Object owningObject, String key, Object defaultValue, String comment, boolean classProperty)
        throws ConfigurationException {
    this.classProperty = classProperty;
    Configuration configuration = Configuration.getInstance();
    //compute key
    if (classProperty) {
        //if it is a class property, prefix its key with the canonical name of the class
        this.key = owningObject.getClass().getCanonicalName().replace(".", "..").concat(".").concat(key);
    } else if (owningObject instanceof AbstractModule) {
        //if it is a module, prefix its key with the qualified name of the module
        this.key = ((AbstractModule) owningObject).getQualifiedName().concat(".").concat(key);
    } else {//  w  ww  .  j  a  v  a  2s . c o m
        //otherwise, take the given key itself
        this.key = key;
    }
    //add property, if not already part of the configuration
    if (!configuration.containsKey(this.key)) {
        configuration.addProperty(this.key, defaultValue == null ? "" : defaultValue);
    }
    if (comment != null) {
        String commentKey = this.key + "[@comment]";
        if (!configuration.containsKey(commentKey)) {
            //add it to the property
            configuration.addProperty(commentKey, comment);
        }
        //mark this comment as been touched during actual session
        configuration.getTouchedProperties().add(commentKey);
    }
    //mark this property as been touched during actual session
    configuration.getTouchedProperties().add(this.key);
}

From source file:org.jpac.configuration.Property.java

public Property(String key) throws ConfigurationException {
    Configuration configuration = Configuration.getInstance();
    this.key = key;
    // check if the property exists inside configuration
    if (!configuration.containsKey(this.key)) {
        //if not found, check if is a class property
        int lastPunktIndex = this.key.lastIndexOf(".");
        this.key = this.key.substring(0, lastPunktIndex).replace(".", "..")
                + this.key.substring(lastPunktIndex);
        if (!configuration.containsKey(this.key)) {
            throw new ConfigurationException("property " + key + " does not exist!");
        } else {//from w ww  . java 2s.  com
            this.classProperty = true;
        }
    }
}

From source file:org.lable.oss.dynamicconfig.core.commonsconfiguration.ConcurrentConfigurationTest.java

@Test
public void testMethodWrappers() {
    CombinedConfiguration mockConfiguration = mock(CombinedConfiguration.class);
    Configuration concurrentConfiguration = new ConcurrentConfiguration(mockConfiguration, null);

    concurrentConfiguration.subset("subset");
    concurrentConfiguration.isEmpty();//from  w w w .j  a  v  a2  s .  co  m
    concurrentConfiguration.containsKey("key");
    concurrentConfiguration.getProperty("getprop");
    concurrentConfiguration.getKeys("getkeys");
    concurrentConfiguration.getKeys();
    concurrentConfiguration.getProperties("getprops");
    concurrentConfiguration.getBoolean("getboolean1");
    concurrentConfiguration.getBoolean("getboolean2", true);
    concurrentConfiguration.getBoolean("getboolean3", Boolean.FALSE);
    concurrentConfiguration.getByte("getbyte1");
    concurrentConfiguration.getByte("getbyte2", (byte) 0);
    concurrentConfiguration.getByte("getbyte3", Byte.valueOf((byte) 0));
    concurrentConfiguration.getDouble("getdouble1");
    concurrentConfiguration.getDouble("getdouble2", 0.2);
    concurrentConfiguration.getDouble("getdouble3", Double.valueOf(0.2));
    concurrentConfiguration.getFloat("getfloat1");
    concurrentConfiguration.getFloat("getfloat2", 0f);
    concurrentConfiguration.getFloat("getfloat3", Float.valueOf(0f));
    concurrentConfiguration.getInt("getint1");
    concurrentConfiguration.getInt("getint2", 0);
    concurrentConfiguration.getInteger("getint3", 0);
    concurrentConfiguration.getLong("getlong1");
    concurrentConfiguration.getLong("getlong2", 0L);
    concurrentConfiguration.getLong("getlong3", Long.valueOf(0L));
    concurrentConfiguration.getShort("getshort1");
    concurrentConfiguration.getShort("getshort2", (short) 0);
    concurrentConfiguration.getShort("getshort3", Short.valueOf((short) 0));
    concurrentConfiguration.getBigDecimal("getbigd1");
    concurrentConfiguration.getBigDecimal("getbigd2", BigDecimal.valueOf(0.4));
    concurrentConfiguration.getBigInteger("getbigi1");
    concurrentConfiguration.getBigInteger("getbigi2", BigInteger.valueOf(2L));
    concurrentConfiguration.getString("getstring1");
    concurrentConfiguration.getString("getstring2", "def");
    concurrentConfiguration.getStringArray("stringarray");
    concurrentConfiguration.getList("getlist1");
    concurrentConfiguration.getList("getlist2", Arrays.asList("a", "b"));

    verify(mockConfiguration, times(1)).subset("subset");
    verify(mockConfiguration, times(1)).isEmpty();
    verify(mockConfiguration, times(1)).containsKey("key");
    verify(mockConfiguration, times(1)).getProperty("getprop");
    verify(mockConfiguration, times(1)).getKeys("getkeys");
    verify(mockConfiguration, times(1)).getKeys();
    verify(mockConfiguration, times(1)).getProperties("getprops");
    verify(mockConfiguration, times(1)).getBoolean("getboolean1");
    verify(mockConfiguration, times(1)).getBoolean("getboolean2", true);
    verify(mockConfiguration, times(1)).getBoolean("getboolean3", Boolean.FALSE);
    verify(mockConfiguration, times(1)).getByte("getbyte1");
    verify(mockConfiguration, times(1)).getByte("getbyte2", (byte) 0);
    verify(mockConfiguration, times(1)).getByte("getbyte3", Byte.valueOf((byte) 0));
    verify(mockConfiguration, times(1)).getDouble("getdouble1");
    verify(mockConfiguration, times(1)).getDouble("getdouble2", 0.2);
    verify(mockConfiguration, times(1)).getDouble("getdouble3", Double.valueOf(0.2));
    verify(mockConfiguration, times(1)).getFloat("getfloat1");
    verify(mockConfiguration, times(1)).getFloat("getfloat2", 0f);
    verify(mockConfiguration, times(1)).getFloat("getfloat3", Float.valueOf(0f));
    verify(mockConfiguration, times(1)).getInt("getint1");
    verify(mockConfiguration, times(1)).getInt("getint2", 0);
    verify(mockConfiguration, times(1)).getInteger("getint3", Integer.valueOf(0));
    verify(mockConfiguration, times(1)).getLong("getlong1");
    verify(mockConfiguration, times(1)).getLong("getlong2", 0L);
    verify(mockConfiguration, times(1)).getLong("getlong3", Long.valueOf(0L));
    verify(mockConfiguration, times(1)).getShort("getshort1");
    verify(mockConfiguration, times(1)).getShort("getshort2", (short) 0);
    verify(mockConfiguration, times(1)).getShort("getshort3", Short.valueOf((short) 0));
    verify(mockConfiguration, times(1)).getBigDecimal("getbigd1");
    verify(mockConfiguration, times(1)).getBigDecimal("getbigd2", BigDecimal.valueOf(0.4));
    verify(mockConfiguration, times(1)).getBigInteger("getbigi1");
    verify(mockConfiguration, times(1)).getBigInteger("getbigi2", BigInteger.valueOf(2L));
    verify(mockConfiguration, times(1)).getString("getstring1");
    verify(mockConfiguration, times(1)).getString("getstring2", "def");
    verify(mockConfiguration, times(1)).getStringArray("stringarray");
    verify(mockConfiguration, times(1)).getList("getlist1");
    verify(mockConfiguration, times(1)).getList("getlist2", Arrays.asList("a", "b"));
}

From source file:org.neo4j.server.configuration.validation.WebadminConfigurationRule.java

private String validateConfigurationContainsKey(Configuration configuration, String key)
        throws RuleFailedException {
    if (!configuration.containsKey(key)) {
        throw new RuleFailedException(
                "Webadmin configuration not found. Check that the neo4j-server.properties file contains the [%s] property.",
                key);//from   ww w  .ja  v  a2s. c  o  m
    }

    return (String) configuration.getProperty(key);
}

From source file:org.restcomm.connect.commons.configuration.sets.impl.MgAsrConfigurationSet.java

public MgAsrConfigurationSet(ConfigurationSource source, Configuration config) {
    super(source);
    drivers = Collections.unmodifiableList(config.getList("runtime-settings.mg-asr-drivers.driver"));
    defaultDriver = config.getString("runtime-settings.mg-asr-drivers[@default]");
    languages = Collections.unmodifiableList(config.getList("runtime-settings.asr-languages.language"));
    defaultLanguage = config.getString("runtime-settings.asr-languages[@default]");
    asrMRT = config.containsKey("runtime-settings.asr-mrt-timeout")
            ? config.getInt("runtime-settings.asr-mrt-timeout")
            : 60;/*w  ww  . j  av  a 2s  . c om*/
    defaultGatheringTimeout = config.containsKey("runtime-settings.default-gathering-timeout")
            ? config.getInt("runtime-settings.default-gathering-timeout")
            : 5;
}

From source file:org.seedstack.hub.infra.vcs.ProxySelectorService.java

private void initializeProxiesFromConfiguration() {
    Configuration proxyConfig = application.getConfiguration().subset(PROXY);

    if (!proxyConfig.isEmpty()) {
        if (!proxyConfig.containsKey(TYPE)) {
            throw new ConfigurationException("Missing \"type\"  in the proxy configuration.");
        }/*from   w  w w . jav a 2s. c  o m*/
        String type = proxyConfig.getString(TYPE);

        if (!proxyConfig.containsKey(HOST)) {
            throw new ConfigurationException("Missing \"url\" in the proxy configuration.");
        }
        String url = proxyConfig.getString(HOST);

        if (!proxyConfig.containsKey(PORT)) {
            throw new ConfigurationException("Missing \"port\"  in the proxy configuration.");
        }
        int port = proxyConfig.getInt(PORT);

        String[] exclusionsConfig = proxyConfig.getStringArray(EXCLUSIONS);
        if (exclusionsConfig != null) {
            exclusions = Arrays.stream(exclusionsConfig).map(this::makePattern).collect(toList());
        }
        proxy = Optional.of(new Proxy(Proxy.Type.valueOf(type), new InetSocketAddress(url, port)));
    } else {
        proxy = Optional.empty();
        exclusions = new ArrayList<>();
    }
}