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

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

Introduction

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

Prototype

Iterator getKeys();

Source Link

Document

Get the list of the keys contained in the configuration.

Usage

From source file:maltcms.ui.fileHandles.properties.tools.SceneParser.java

/**
 * Supports both absolute and relative paths and also arbitrary combinations
 * of the two. In case of relative paths, the location of the file
 * containing the pipeline configuration is used as basedir to resolve the
 * relative path.//from   w w  w  .j a va  2  s  .  com
 *
 * Example for relative path:
 * <pre>pipelines.properties = fragmentCommands/myClassName.properties</pre>
 * Example for absolute path:
 * <pre>pipelines.properties = /home/juser/myFunkyDir/myClassName.properties</pre>
 *
 * <pre>pipeline.properties</pre> accepts multiple entries, separated by a
 * ',' (comma) character. Example:
 * <pre>pipeline.properties = fragmentCommands/myClassName.properties,/home/juser/myFunkyDir/myClassName.properties</pre>
 *
 * @param filename the filename of the base configuration, which contains
 * the pipeline= and pipeline.properties keys.
 * @param cfg the configuration object resembling the content of filename.
 * @param scene the graph scene into which to load the configuration.
 */
public static void parseIntoScene(String filename, Configuration cfg, PipelineGraphScene scene) {
    Logger.getLogger(SceneParser.class.getName())
            .info("###################################################################");
    Logger.getLogger(SceneParser.class.getName()).info("Creating graph scene from file");
    File f = new File(filename);
    //Get pipeline from configuration
    cfg.addProperty("config.basedir", f.getParentFile().getAbsoluteFile().toURI().getPath());
    String pipelineXml = cfg.getString("pipeline.xml");

    FileSystemXmlApplicationContext fsxmac = new FileSystemXmlApplicationContext(new String[] { pipelineXml },
            true);
    ICommandSequence commandSequence = fsxmac.getBean("commandPipeline",
            cross.datastructures.pipeline.CommandPipeline.class);
    //        String[] pipes = pipeline.toArray(new String[]{});
    Logger.getLogger(SceneParser.class.getName()).log(Level.INFO, "Pipeline elements: {0}",
            commandSequence.getCommands());
    PipelineGeneralConfigWidget pgcw = (PipelineGeneralConfigWidget) scene.createGeneralWidget();
    pgcw.setProperties(cfg);
    String lastNode = null;
    String edge;
    int edgeCounter = 0;
    int nodeCounter = 0;
    Configuration pipeHash = new PropertiesConfiguration();
    for (IFragmentCommand command : commandSequence.getCommands()) {
        Collection<String> configKeys = cross.annotations.AnnotationInspector
                .getRequiredConfigKeys(command.getClass());
        //        for (String pipe : pipes) {
        String nodeId = command.getClass().getCanonicalName() + "" + nodeCounter;
        PipelineElementWidget node = (PipelineElementWidget) scene.addNode(nodeId);
        //            node.setPropertyFile();

        //            System.out.println("Parsing pipeline element " + pipeCfg.getAbsolutePath());
        node.setBean(command);
        node.setLabel(command.getClass().getSimpleName());
        node.setCurrentClassProperties();
        Configuration prop = node.getProperties();
        //            pipeHash = PropertyLoader.getHash(pipeCfg.getAbsolutePath());
        //            node.setPropertyFile(pipeCfg.getAbsolutePath());
        Iterator iter = pipeHash.getKeys();
        while (iter.hasNext()) {
            String key = (String) iter.next();
            prop.setProperty(key, pipeHash.getProperty(key));
        }
        node.setProperties(prop);

        if (lastNode != null) {
            edge = "Ledge" + edgeCounter++;
            scene.addEdge(edge);
            Logger.getLogger(SceneParser.class.getName()).log(Level.INFO,
                    "Adding edge between lastNode {0} and {1}", new Object[] { lastNode, nodeId });
            scene.setEdgeSource(edge, lastNode);
            scene.setEdgeTarget(edge, nodeId);
            scene.validate();
        }
        //                x += dx;
        //                y += dy;
        scene.validate();
        lastNode = nodeId;
        nodeCounter++;
    }

    scene.validate();
    SceneLayouter.layoutVertical(scene);
}

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

/**
 * Create an instance by copying the properties from an existing Configuration.
 * Future changes to the Configuration passed in will not be reflected in this
 * object.//from  www.  j  a va2 s. co m
 * 
 * @param config Configuration to be copied
 */
public ConcurrentMapConfiguration(Configuration config) {
    this();
    for (Iterator i = config.getKeys(); i.hasNext();) {
        String name = (String) i.next();
        Object value = config.getProperty(name);
        map.put(name, value);
    }
}

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

@Test
public void test010SimpleConfigTest() {
    LOGGER.info("---------------- test010SimpleConfigTest -----------------");

    System.clearProperty("midpoint.home");
    LOGGER.info("midpoint.home => " + System.getProperty("midpoint.home"));

    assertNull(System.getProperty("midpoint.home"), "midpoint.home");

    StartupConfiguration sc = new StartupConfiguration();
    assertNotNull(sc);//from  www .  jav  a  2  s . c o m
    sc.init();
    Configuration c = sc.getConfiguration("midpoint.repository");
    assertEquals(c.getString("repositoryServiceFactoryClass"),
            "com.evolveum.midpoint.repo.sql.SqlRepositoryFactory");
    LOGGER.info(sc.toString());

    @SuppressWarnings("unchecked")
    Iterator<String> i = c.getKeys();

    while (i.hasNext()) {
        String key = i.next();
        LOGGER.info("  " + key + " = " + c.getString(key));
    }

    assertEquals(c.getBoolean("asServer"), true);
    assertEquals(c.getString("baseDir"), System.getProperty("midpoint.home"));

}

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

/**
 * Copy properties of a configuration into this configuration. This method simply
 * iterates the keys of the configuration to be copied and call {@link #setProperty(String, Object)}
 * for non-null key/value./*from   w w w . j ava  2 s.  c om*/
 */
@Override
public void copy(Configuration c) {
    if (c != null) {
        for (Iterator it = c.getKeys(); it.hasNext();) {
            String key = (String) it.next();
            Object value = c.getProperty(key);
            if (key != null && value != null) {
                setProperty(key, value);
            }
        }
    }
}

From source file:net.sf.mpaxs.spi.computeHost.Settings.java

/**
 *
 * @param config/*from   www .  j  a v a2s .c  om*/
 */
public Settings(Configuration config) {
    this();
    //overwrite defaults
    Iterator iter = config.getKeys();
    while (iter.hasNext()) {
        String key = (String) iter.next();
        this.config.setProperty(key, config.getProperty(key));
    }
}

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

@Test(enabled = false)
public void t01simpleConfigTest() {
    LOGGER.info("---------------- simpleConfigTest -----------------");

    System.clearProperty("midpoint.home");
    LOGGER.info("midpoint.home => " + System.getProperty("midpoint.home"));

    assertNull(System.getProperty("midpoint.home"), "midpoint.home");

    StartupConfiguration sc = new StartupConfiguration();
    assertNotNull(sc);/*w  w  w  . ja va2 s.  c  o m*/
    sc.init();
    Configuration c = sc.getConfiguration("midpoint.repository");
    assertEquals(c.getString("repositoryServiceFactoryClass"),
            "com.evolveum.midpoint.repo.xml.XmlRepositoryServiceFactory");
    LOGGER.info(sc.toString());

    @SuppressWarnings("unchecked")
    Iterator<String> i = c.getKeys();

    while (i.hasNext()) {
        String key = i.next();
        LOGGER.info("  " + key + " = " + c.getString(key));
    }

    assertEquals(c.getInt("port"), 1984);
    assertEquals(c.getString("serverPath"), "");

}

From source file:com.virtualparadigm.packman.processor.JPackageManagerOld.java

private static VelocityContext createVelocityContext(Configuration configuration) {

    ToolManager velocityToolManager = new ToolManager();
    velocityToolManager.configure("velocity-tools.xml");
    VelocityContext velocityContext = new VelocityContext(velocityToolManager.createContext());

    //       VelocityContext velocityContext = new VelocityContext();
    if (configuration != null) {
        String key = null;/*from w w w.j  a  v  a2s.c o  m*/
        for (Iterator<String> it = configuration.getKeys(); it.hasNext();) {
            key = it.next();
            velocityContext.put(key, configuration.getString(key));
        }
    }
    return velocityContext;
}

From source file:com.steelbridgelabs.oss.neo4j.Neo4JTestGraphProvider.java

@Override
public Map<String, Object> getBaseConfiguration(String graphName, Class<?> test, String testMethodName,
        LoadGraphWith.GraphData graphData) {
    // build configuration
    Configuration configuration = Neo4JGraphConfigurationBuilder.connect("localhost", "neo4j", "123")
            .withName(graphName).withElementIdProvider(ElementIdProvider.class).build();
    // create property map from configuration
    Map<String, Object> map = StreamSupport
            .stream(Spliterators.spliteratorUnknownSize(configuration.getKeys(),
                    Spliterator.NONNULL | Spliterator.IMMUTABLE), false)
            .collect(Collectors.toMap(key -> key, configuration::getProperty));
    // append class name
    map.put(Graph.GRAPH, Neo4JGraph.class.getName());
    // return configuration map
    return map;/*ww w.j  av  a  2 s.  c o  m*/
}

From source file:com.nesscomputing.migratory.mojo.database.AbstractDatabaseMojo.java

protected List<String> getAvailableDatabases() {
    final List<String> databaseList = Lists.newArrayList();

    final Configuration dbConfig = config.subset(getPropertyName("db"));

    for (Iterator<?> it = dbConfig.getKeys(); it.hasNext();) {
        final String key = (String) it.next();
        if (key.contains(".")) {
            continue;
        }//from ww w.j a va 2s.c  om
        databaseList.add(key);
    }
    return databaseList;
}

From source file:com.ripariandata.timberwolf.conf4j.ConfigFileParserTest.java

License:asdf

private Configuration mockConfiguration(final Object... settings) {
    if ((settings.length % 2) != 0) {
        return null;
    }//from   ww w  .j  av a 2 s  .  c o m

    Configuration config = mock(Configuration.class);

    Vector<String> keys = new Vector<String>();
    for (int i = 0; i < settings.length; i += 2) {
        String key = settings[i].toString();
        keys.add(key);
        when(config.getProperty(key)).thenReturn(settings[i + 1]);
    }
    when(config.getKeys()).thenReturn(keys.iterator());

    return config;
}