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

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

Introduction

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

Prototype

BaseConfiguration

Source Link

Usage

From source file:org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraphTest.java

@Test
public void shouldPersistToGryo() {
    final String graphLocation = TestHelper.makeTestDataDirectory(TinkerGraphTest.class)
            + "shouldPersistToGryo.kryo";
    final File f = new File(graphLocation);
    if (f.exists() && f.isFile())
        f.delete();/*from  w  w w  . ja v a2 s.c  o m*/

    final Configuration conf = new BaseConfiguration();
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_FORMAT, "gryo");
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, graphLocation);
    final TinkerGraph graph = TinkerGraph.open(conf);
    TinkerFactory.generateModern(graph);
    graph.close();

    final TinkerGraph reloadedGraph = TinkerGraph.open(conf);
    IoTest.assertModernGraph(reloadedGraph, true, false);
    reloadedGraph.close();
}

From source file:org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraphTest.java

@Test
public void shouldPersistToAnyGraphFormat() {
    final String graphLocation = TestHelper.makeTestDataDirectory(TinkerGraphTest.class)
            + "shouldPersistToAnyGraphFormat.dat";
    final File f = new File(graphLocation);
    if (f.exists() && f.isFile())
        f.delete();/*from   w ww  .  jav  a 2  s .  c om*/

    final Configuration conf = new BaseConfiguration();
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_FORMAT, TestIoBuilder.class.getName());
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, graphLocation);
    final TinkerGraph graph = TinkerGraph.open(conf);
    TinkerFactory.generateModern(graph);

    //Test write graph
    graph.close();
    assertEquals(TestIoBuilder.calledRegistry, 1);
    assertEquals(TestIoBuilder.calledGraph, 1);
    assertEquals(TestIoBuilder.calledCreate, 1);

    try (BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(f))) {
        os.write("dummy string".getBytes());
    } catch (Exception e) {
        e.printStackTrace();
    }

    //Test read graph
    final TinkerGraph readGraph = TinkerGraph.open(conf);
    assertEquals(TestIoBuilder.calledRegistry, 1);
    assertEquals(TestIoBuilder.calledGraph, 1);
    assertEquals(TestIoBuilder.calledCreate, 1);
}

From source file:org.apache.tinkerpop.gremlin.util.SystemUtil.java

/**
 * Generate a {@link Configuration} from the {@link System#getProperties}.
 * Only those properties with specified prefix key are aggregated.
 * If the prefix and a . should be removed, then trim prefix.
 *
 * @param prefix     the prefix of the keys to include in the configuration
 * @param trimPrefix whether to trim the prefix + . from the key
 * @return a configuration generated from the System properties
 *//*from   ww w  .  ja va  2s. c  o  m*/
public static Configuration getSystemPropertiesConfiguration(final String prefix, final boolean trimPrefix) {
    final BaseConfiguration apacheConfiguration = new BaseConfiguration();
    apacheConfiguration.setDelimiterParsingDisabled(true);
    for (final Map.Entry<Object, Object> entry : System.getProperties().entrySet()) {
        final String key = entry.getKey().toString();
        final Object value = entry.getValue();
        if (key.startsWith(prefix + "."))
            apacheConfiguration.setProperty(trimPrefix ? key.substring(prefix.length() + 1) : key, value);
    }
    return apacheConfiguration;
}

From source file:org.finra.herd.dao.ReloadablePropertySourceTest.java

/**
 * Asserts that when a property is requested from the configruation, and it fires an error event (ex. Database is not available), the previously stored
 * values are not cleared./*  w w w  . j a v  a2  s. c o  m*/
 */
@Test
public void testAssertGetPropertyErrorReturnPreviousValue() throws Exception {
    // Get a reloadable property source that loads properties from the configuration every time a property is read.
    BaseConfiguration configuration = new BaseConfiguration() {
        @Override
        public Object getProperty(String key) {
            fireError(EVENT_READ_PROPERTY, key, null, new IllegalStateException("test exception"));
            return null;
        }
    };
    configuration.addProperty(TEST_KEY, TEST_VALUE_1);
    ReloadablePropertySource reloadablePropertySource = getNewReloadablePropertiesSource(0L, configuration);
    verifyPropertySourceValue(reloadablePropertySource, TEST_VALUE_1);
}

From source file:org.gss_project.gss.server.configuration.GSSConfigurationFactory.java

/**
 * @return the configuration object//from   w  ww. j  a v  a2 s. co  m
 */
public synchronized static DataConfiguration getConfiguration() {
    try {
        if (configuration == null) {
            PropertiesConfiguration gssConfig = (PropertiesConfiguration) getClass(
                    PropertiesConfiguration.class.getCanonicalName()).newInstance();
            gssConfig.setBasePath("");
            gssConfig.setFileName(configFilename);
            gssConfig.setEncoding("ISO-8859-7");
            // Set automatic reloading.
            gssConfig.setReloadingStrategy(new VfsFileChangedReloadingStrategy());
            gssConfig.load();
            // Decorator.
            configuration = new DataConfiguration(gssConfig);
        }
        return configuration;
    } catch (ClassNotFoundException e) {
        // Use empty configuration, so we get no NPE but default values
        configuration = new DataConfiguration(new BaseConfiguration());
        logger.error("Error in ExternalAPI initialization! GSS is running with default values!", e);
        return configuration;
    } catch (InstantiationException e) {
        // Use empty configuration, so we get no NPE but default values
        configuration = new DataConfiguration(new BaseConfiguration());
        logger.error("Error in ExternalAPI initialization! GSS is running with default values!", e);
        return configuration;
    } catch (IllegalAccessException e) {
        // Use empty configuration, so we get no NPE but default values
        configuration = new DataConfiguration(new BaseConfiguration());
        logger.error("Error in ExternalAPI initialization! GSS is running with default values!", e);
        return configuration;
    } catch (ConfigurationException e) {
        // Use empty configuration, so we get no NPE but default values
        configuration = new DataConfiguration(new BaseConfiguration());
        logger.error("Error in ExternalAPI initialization! GSS is running with default values!", e);
        return configuration;
    }
}

From source file:org.janusgraph.core.JanusGraphFactory.java

private static ReadConfiguration getLocalConfiguration(String shortcutOrFile) {
    File file = new File(shortcutOrFile);
    if (file.exists())
        return getLocalConfiguration(file);
    else {/*from  w w w  .j  a  v a2  s  . c o m*/
        int pos = shortcutOrFile.indexOf(':');
        if (pos < 0)
            pos = shortcutOrFile.length();
        String backend = shortcutOrFile.substring(0, pos);
        Preconditions.checkArgument(
                StandardStoreManager.getAllManagerClasses().containsKey(backend.toLowerCase()),
                "Backend shorthand unknown: %s", backend);
        String secondArg = null;
        if (pos + 1 < shortcutOrFile.length())
            secondArg = shortcutOrFile.substring(pos + 1).trim();
        BaseConfiguration config = new BaseConfiguration();
        ModifiableConfiguration writeConfig = new ModifiableConfiguration(ROOT_NS,
                new CommonsConfiguration(config), BasicConfiguration.Restriction.NONE);
        writeConfig.set(STORAGE_BACKEND, backend);
        ConfigOption option = Backend.getOptionForShorthand(backend);
        if (option == null) {
            Preconditions.checkArgument(secondArg == null);
        } else if (option == STORAGE_DIRECTORY || option == STORAGE_CONF_FILE) {
            Preconditions.checkArgument(StringUtils.isNotBlank(secondArg),
                    "Need to provide additional argument to initialize storage backend");
            writeConfig.set(option, getAbsolutePath(secondArg));
        } else if (option == STORAGE_HOSTS) {
            Preconditions.checkArgument(StringUtils.isNotBlank(secondArg),
                    "Need to provide additional argument to initialize storage backend");
            writeConfig.set(option, new String[] { secondArg });
        } else
            throw new IllegalArgumentException("Invalid configuration option for backend " + option);
        return new CommonsConfiguration(config);
    }
}

From source file:org.janusgraph.diskstorage.common.LocalStoreManagerTest.java

public LocalStoreManager getStoreManager(Map<ConfigOption, String> map) throws BackendException {
    final ModifiableConfiguration mc = new ModifiableConfiguration(ROOT_NS,
            new CommonsConfiguration(new BaseConfiguration()), NONE);
    map.forEach(mc::set);/*from w  w  w .j  a  va  2s  .  c  o  m*/
    return new LocalStoreManagerSampleImplementation(mc);
}

From source file:org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration.java

public CommonsConfiguration() {
    this(new BaseConfiguration());
}

From source file:org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration.java

@Override
public WriteConfiguration copy() {
    BaseConfiguration copy = new BaseConfiguration();
    copy.copy(config);/*from   w ww .  j a va  2  s  .  co  m*/
    return new CommonsConfiguration(copy);
}

From source file:org.janusgraph.diskstorage.configuration.CommonConfigTest.java

@Override
public WriteConfiguration getConfig() {
    return new CommonsConfiguration(new BaseConfiguration());
}