List of usage examples for org.apache.commons.configuration Configuration getProperty
Object getProperty(String key);
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 ava2 s .co m * * 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:net.sf.mpaxs.spi.computeHost.Settings.java
/** * * @param config/*from www.ja v a2s . com*/ */ 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.github.pith.typedconfig.TypedConfigPlugin.java
private Map<Class<Object>, Object> initConfigClasses(Collection<Class<?>> configClasses, Configuration configuration) { Map<Class<Object>, Object> configClassesMap = new HashMap<Class<Object>, Object>(); for (Class<?> configClass : configClasses) { try {/*from w w w .ja va2 s .co m*/ Object configObject = configClass.newInstance(); for (Method method : configClass.getDeclaredMethods()) { if (method.getName().startsWith("get")) { Object property = configuration.getProperty(configClass.getSimpleName().toLowerCase() + method.getName().substring(3).toLowerCase()); if (property != null) { try { Method setter = configClass.getDeclaredMethod("set" + method.getName().substring(3), method.getReturnType()); setter.setAccessible(true); setter.invoke(configObject, property); } catch (NoSuchMethodException e) { throw new IllegalStateException("The TypedConfigPlugin can't initialize " + method.getName() + " because there is no associated setter."); } catch (InvocationTargetException e) { if (e.getCause() != null) { throw new IllegalStateException("Failed to initialize " + method.getName(), e.getCause()); } } } } } //noinspection unchecked configClassesMap.put((Class<Object>) configClass, configObject); } catch (InstantiationException e) { throw new IllegalStateException("Failed to instantiate " + configClass, e.getCause()); } catch (IllegalAccessException e) { throw new IllegalStateException("Failed to access the constructor of " + configClass, e.getCause()); } } return configClassesMap; }
From source file:at.salzburgresearch.kmt.zkconfig.ZookeeperConfigurationTest.java
@Test public void testInt() throws Exception { Configuration config = new ZookeeperConfiguration(zkConnection, 5000, "/test"); final String key = UUID.randomUUID().toString(); final Random random = new Random(); final int val1 = random.nextInt(); final Integer val2 = random.nextInt(); assertThat(config.getProperty(key), nullValue()); config.setProperty(key, val1); assertEquals(val1, config.getInt(key)); assertEquals(new Integer(val1), config.getInteger(key, val2)); config.setProperty(key, val2); assertEquals(val2.intValue(), config.getInt(key)); assertEquals(val2, config.getInteger(key, val1)); }
From source file:at.salzburgresearch.kmt.zkconfig.ZookeeperConfigurationTest.java
@Test public void testLong() throws Exception { Configuration config = new ZookeeperConfiguration(zkConnection, 5000, "/test"); final String key = UUID.randomUUID().toString(); final Random random = new Random(); final long val1 = random.nextLong(); final Long val2 = random.nextLong(); assertThat(config.getProperty(key), nullValue()); config.setProperty(key, val1); assertEquals(val1, config.getLong(key)); assertEquals(Long.valueOf(val1), config.getLong(key, val2)); config.setProperty(key, val2); assertEquals(val2.longValue(), config.getLong(key)); assertEquals(val2, config.getLong(key, Long.valueOf(val1))); }
From source file:at.salzburgresearch.kmt.zkconfig.ZookeeperConfigurationTest.java
@Test public void testFloat() throws Exception { Configuration config = new ZookeeperConfiguration(zkConnection, 5000, "/test"); final String key = UUID.randomUUID().toString(); final Random random = new Random(); final float val1 = random.nextFloat(); final Float val2 = random.nextFloat(); assertThat(config.getProperty(key), nullValue()); config.setProperty(key, val1); assertEquals(val1, config.getFloat(key), 10e-6); assertEquals(new Float(val1), config.getFloat(key, val2)); config.setProperty(key, val2); assertEquals(val2, config.getFloat(key), 10e-6); assertEquals(val2, config.getFloat(key, Float.valueOf(val1))); }
From source file:at.salzburgresearch.kmt.zkconfig.ZookeeperConfigurationTest.java
@Test public void testDouble() throws Exception { Configuration config = new ZookeeperConfiguration(zkConnection, 5000, "/test"); final String key = UUID.randomUUID().toString(); final Random random = new Random(); final double val1 = random.nextDouble(); final Double val2 = random.nextDouble(); assertThat(config.getProperty(key), nullValue()); config.setProperty(key, val1); assertEquals(val1, config.getDouble(key), 10e-6); assertEquals(Double.valueOf(val1), config.getDouble(key, val2)); config.setProperty(key, val2); assertEquals(val2, config.getDouble(key), 10e-6); assertEquals(val2, config.getDouble(key, Double.valueOf(val1))); }
From source file:com.netflix.client.config.DefaultClientConfigImpl.java
/** * This is to workaround the issue that {@link AbstractConfiguration} by default * automatically convert comma delimited string to array *//*from ww w . java 2 s.c om*/ protected static String getStringValue(Configuration config, String key) { try { String values[] = config.getStringArray(key); if (values == null) { return null; } if (values.length == 0) { return config.getString(key); } else if (values.length == 1) { return values[0]; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < values.length; i++) { sb.append(values[i]); if (i != values.length - 1) { sb.append(","); } } return sb.toString(); } catch (Exception e) { Object v = config.getProperty(key); if (v != null) { return String.valueOf(v); } else { return null; } } }
From source file:at.salzburgresearch.kmt.zkconfig.ZookeeperConfigurationTest.java
@Test public void testList() throws Exception { Configuration config = new ZookeeperConfiguration(zkConnection, 5000, "/test"); final String key = UUID.randomUUID().toString(); final String val = "An extended List, with several, commas, that should stay within, the, same value,"; final List<?> list = Lists.transform(Arrays.asList(val.split(",")), new Function<String, String>() { @Override// w ww. j a v a 2 s.co m public String apply(String input) { return input.trim(); } }); assertThat(config.getProperty(key), nullValue()); config.setProperty(key, list); assertThat(config.getList(key), IsIterableContainingInOrder.contains(list.toArray())); assertThat(config.getString(key), is(val.split(",")[0].trim())); config.setProperty(key, val.split(",")); assertThat(config.getString(key), is(val.split(",")[0])); assertThat(config.getList(key), CoreMatchers.<Object>hasItems(val.split(","))); assertThat(config.getStringArray(key), arrayContaining(val.split(","))); assertThat(config.getStringArray(key), arrayWithSize(val.split(",").length)); }
From source file:com.linkedin.pinot.broker.broker.helix.HelixBrokerStarter.java
private BrokerServerBuilder startBroker(Configuration config) throws Exception { if (config == null) { config = DefaultHelixBrokerConfig.getDefaultBrokerConf(); }/*from w w w . j av a 2s . co m*/ final BrokerServerBuilder brokerServerBuilder = new BrokerServerBuilder(config, _helixExternalViewBasedRouting, _helixExternalViewBasedRouting.getTimeBoundaryService(), _liveInstancesListener); brokerServerBuilder.buildNetwork(); brokerServerBuilder.buildHTTP(); _helixExternalViewBasedRouting.setBrokerMetrics(brokerServerBuilder.getBrokerMetrics()); brokerServerBuilder.start(); LOGGER.info("Pinot broker ready and listening on port {} for API requests", config.getProperty("pinot.broker.client.queryPort")); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { brokerServerBuilder.stop(); } catch (final Exception e) { LOGGER.error("Caught exception while running shutdown hook", e); } } }); return brokerServerBuilder; }