List of usage examples for org.apache.commons.configuration Configuration getString
String getString(String key);
From source file:keel.Algorithms.Neural_Networks.NNEP_Regr.problem.regression.RegressionProblemEvaluator.java
/** * <p>//w w w . j a va 2 s . c om * Configuration parameters for NeuralNetEvaluator are: * </p> * <ul> * <li> * <code>Problem evaluator configuration</code></p> * @see net.sf.jclec.problem.ProblemEvaluator * </li> * <li> * <code>error-function: complex</code></p> * Error function used for evaluating individuals. * </li> * </ul> * @param settings Settings to Configure */ @SuppressWarnings("unchecked") public void configure(Configuration settings) { // ProblemEvaluator configuration super.configure(settings); // Individual error function try { // Error function classname String errorFunctionClassname = settings.getString("error-function"); // Error function class Class<IErrorFunction<double[]>> errorFunctionClass = (Class<IErrorFunction<double[]>>) Class .forName(errorFunctionClassname); // Error function instance IErrorFunction<double[]> errorFunction = errorFunctionClass.newInstance(); // Set error function setErrorFunction(errorFunction); } catch (ClassNotFoundException e) { throw new ConfigurationRuntimeException("Illegal error function classname"); } catch (InstantiationException e) { throw new ConfigurationRuntimeException("Problems creating an instance of error function", e); } catch (IllegalAccessException e) { throw new ConfigurationRuntimeException("Problems creating an instance of error function", e); } }
From source file:com.appeligo.captions.CaptionListener.java
private CaptionStore getCaptionStore() throws MalformedURLException { if (captionStore == null) { Configuration config = ConfigUtils.getSystemConfig(); HessianProxyFactory factory = new HessianProxyFactory(); String url = config.getString("captionsEndpoint"); if (log.isInfoEnabled()) { log.info("CaptionStore endpoint is " + url); }/*from w w w. j av a2s . com*/ captionStore = (CaptionStore) factory.create(CaptionStore.class, url); } return captionStore; }
From source file:com.appeligo.alerts.KeywordAlertThread.java
public KeywordAlertThread(Configuration config) throws IOException { super("KeywordAlertThread"); isActive = true;/*from ww w . j a v a 2 s.c o m*/ alertManager = AlertManager.getInstance(); liveIndexDir = config.getString("luceneLiveIndex"); liveLineup = config.getString("liveLineup"); maxConsecutiveExceptions = config.getInt("maxConsecutiveExceptions", 10); shortestTimeBetweenQueriesMs = config.getLong("shortestTimeBetweenQueriesMs", DEFAULT_SHORTEST_TIME_BETWEEN_QUERIES_MS); keywordAlertProximity = config.getInt("keywordAlertProximity", 10); if (!IndexReader.indexExists(liveIndexDir)) { log.error("Lucene Live Index is missing or invalid at " + liveIndexDir + ". Trying anyway in case this gets resolved."); } parser = new QueryParser("text", new PorterStemAnalyzer(LuceneIndexer.STOP_WORDS)); parser.setDefaultOperator(Operator.AND); helper = new KeywordAlertChecker(config); }
From source file:com.yahoo.bard.webservice.config.ConfigurationGraph.java
/** * Take a configuration and if it is a valid module, load it into the moduleConfigurations map and load it's * dependency moduleDependencies.//from ww w.j a v a 2 s . com * * @param configuration A configuration which may be a module * @param configName The resource name for that configuration * @param nameValidator A function which throws exceptions on module names which are not valid. */ @SuppressWarnings("unchecked") private void addVertex(Configuration configuration, String configName, Consumer<String> nameValidator) { if (!configuration.containsKey(MODULE_NAME_KEY)) { // This may be the result of another library using one of our configuration names LOG.warn(MODULE_NAME_MISSING.logFormat(configName)); return; } String moduleName = configuration.getString(MODULE_NAME_KEY); nameValidator.accept(moduleName); LOG.debug(MODULE_FOUND_MESSAGE.logFormat(moduleName, configName)); if (moduleConfigurations.containsKey(moduleName)) { LOG.error(MODULE_NAME_DUPLICATION.format(configName, moduleName)); throw new SystemConfigException(MODULE_NAME_DUPLICATION.format(configName, moduleName)); } moduleConfigurations.put(moduleName, configuration); List<String> dependencies = new ArrayList<>( configuration.getList(DEPENDENT_MODULE_KEY, Collections.<String>emptyList())); // later dependencies have higher precedence. Store moduleDependencies in precedence order descending Collections.reverse(dependencies); moduleDependencies.put(moduleName, dependencies); }
From source file:com.norconex.importer.parser.GenericDocumentParserFactory.java
@Override public void loadFromXML(Reader in) throws IOException { try {// ww w . j a v a 2 s. c o m XMLConfiguration xml = ConfigurationUtil.newXMLConfiguration(in); setIgnoredContentTypesRegex(xml.getString("ignoredContentTypes", getIgnoredContentTypesRegex())); setSplitEmbedded(xml.getBoolean("[@splitEmbedded]", isSplitEmbedded())); Configuration ocrXml = xml.subset("ocr"); OCRConfig ocrConfig = null; if (!ocrXml.isEmpty()) { ocrConfig = new OCRConfig(); ocrConfig.setPath(ocrXml.getString("[@path]")); ocrConfig.setLanguages(ocrXml.getString("languages")); ocrConfig.setContentTypes(ocrXml.getString("contentTypes")); } setOCRConfig(ocrConfig); } catch (ConfigurationException e) { throw new IOException("Cannot load XML.", e); } }
From source file:com.netflix.config.ConcurrentMapConfigurationTest.java
@Test public void testSubset() { Map<String, String> properties = new HashMap<String, String>(); properties.put("a", "x.y.a"); properties.put("b", "x.y.b"); properties.put("c", "x.y.c"); ConcurrentMapConfiguration config = new ConcurrentMapConfiguration(); for (String prop : properties.values()) { config.addProperty(prop, prop);//ww w . ja va 2 s. c o m } Configuration subconfig = config.subset("x.y"); Set<String> subsetKeys = new HashSet<String>(); for (Iterator<String> i = subconfig.getKeys(); i.hasNext();) { String key = i.next(); subsetKeys.add(key); assertEquals(properties.get(key), subconfig.getString(key)); } assertEquals(properties.keySet(), subsetKeys); }
From source file:com.nokia.ant.taskdefs.AntConfigurationTask.java
private void importFile(final File file) { try {/*from w ww .j a v a 2 s .com*/ String filename = file.getName(); Configuration config = null; if (filename.endsWith(".txt")) { config = new PropertiesConfiguration(file); } else if (filename.endsWith(".xml")) { config = new XMLConfiguration(file); } Iterator keysIter = config.getKeys(); while (keysIter.hasNext()) { String key = (String) keysIter.next(); getProject().setProperty(key, config.getString(key)); } } catch (ConfigurationException e) { throw new BuildException("Not able to import the ANT file " + e.getMessage()); } }
From source file:net.sf.jclal.activelearning.scenario.AbstractScenario.java
/** * Configuration of Query Strategy./*from w w w . j a v a2 s. co m*/ * * @param configuration The configuration object to use */ public void setQueryStrategyConfiguration(Configuration configuration) { String queryError = "query-strategy type= "; try { // query strategy // query strategy classname String queryStrategyClassname = configuration.getString("query-strategy[@type]"); queryError += queryStrategyClassname; // query strategy class Class<? extends IQueryStrategy> queryStrategyClass = (Class<? extends IQueryStrategy>) Class .forName(queryStrategyClassname); // query strategy instance IQueryStrategy queryStrategyTemp = queryStrategyClass.newInstance(); // Configure query strategy (if necessary) if (queryStrategyTemp instanceof IConfigure) { ((IConfigure) queryStrategyTemp).configure(configuration.subset("query-strategy")); } // Add this query strategy to the scenario setQueryStrategy(queryStrategyTemp); } catch (ClassNotFoundException e) { throw new ConfigurationRuntimeException("\nIllegal query strategy classname: " + queryError, e); } catch (InstantiationException e) { throw new ConfigurationRuntimeException("\nIllegal query strategy classname: " + queryError, e); } catch (IllegalAccessException e) { throw new ConfigurationRuntimeException("\nIllegal query strategy classname: " + queryError, e); } }
From source file:com.kixeye.chassis.bootstrap.configuration.zookeeper.CuratorFrameworkBuilder.java
private CuratorFramework buildCuratorWithExhibitor(Configuration configuration) { LOGGER.debug("configuring zookeeper connection through Exhibitor..."); ExhibitorEnsembleProvider ensembleProvider = new KixeyeExhibitorEnsembleProvider(exhibitors, new KixeyeExhibitorRestClient(configuration.getBoolean(EXHIBITOR_USE_HTTPS.getPropertyName())), configuration.getString(EXHIBITOR_URI_PATH.getPropertyName()), configuration.getInt(EXHIBITOR_POLL_INTERVAL.getPropertyName()), new ExponentialBackoffRetry(configuration.getInt(EXHIBITOR_INITIAL_SLEEP_MILLIS.getPropertyName()), configuration.getInt(EXHIBITOR_MAX_RETRIES.getPropertyName()), configuration.getInt(EXHIBITOR_RETRIES_MAX_MILLIS.getPropertyName()))); //without this (undocumented) step, curator will attempt (and fail) to connect to a local instance of zookeeper (default behavior if no zookeeper connection string is provided) for //several seconds until the EnsembleProvider polls to get the SERVER list from Exhibitor. Polling before staring curator //ensures that the SERVER list from Exhibitor is already downloaded before curator attempts to connect to zookeeper. try {//w ww .ja va2s . c om ensembleProvider.pollForInitialEnsemble(); } catch (Exception e) { try { Closeables.close(ensembleProvider, true); } catch (IOException e1) { } throw new BootstrapException("Failed to initialize Exhibitor with host(s) " + exhibitors.getHostnames(), e); } CuratorFramework curator = CuratorFrameworkFactory.builder().ensembleProvider(ensembleProvider) .retryPolicy(buildZookeeperRetryPolicy(configuration)).build(); curator.getConnectionStateListenable().addListener(new ConnectionStateListener() { public void stateChanged(CuratorFramework client, ConnectionState newState) { LOGGER.debug("Connection state to ZooKeeper changed: " + newState); } }); return curator; }
From source file:com.kixeye.chassis.bootstrap.ConfigurationBuilderTest.java
@Test public void buildConfigurationInAws() { String az = "testaz"; String instanceId = RandomStringUtils.randomAlphabetic(10); String region = Regions.DEFAULT_REGION.getName(); ServerInstanceContext serverInstanceContext = EasyMock.createMock(ServerInstanceContext.class); EasyMock.expect(serverInstanceContext.getAvailabilityZone()).andReturn(az); EasyMock.expect(serverInstanceContext.getInstanceId()).andReturn(instanceId); EasyMock.expect(serverInstanceContext.getRegion()).andReturn(region); EasyMock.expect(serverInstanceContext.getPrivateIp()).andReturn("127.0.0.1"); EasyMock.expect(serverInstanceContext.getPublicIp()).andReturn(null); EasyMock.replay(serverInstanceContext); Configuration configuration = configurationBuilder.withServerInstanceContext(serverInstanceContext).build(); Assert.assertEquals(az,//www.j a v a2 s . c o m configuration.getString(BootstrapConfigKeys.AWS_INSTANCE_AVAILABILITY_ZONE.getPropertyName())); Assert.assertEquals(instanceId, configuration.getString(BootstrapConfigKeys.AWS_INSTANCE_ID.getPropertyName())); Assert.assertEquals(region, configuration.getString(BootstrapConfigKeys.AWS_INSTANCE_REGION.getPropertyName())); Assert.assertEquals("127.0.0.1", configuration.getString(BootstrapConfigKeys.AWS_INSTANCE_PRIVATE_IP.getPropertyName())); Assert.assertEquals(null, configuration.getString(BootstrapConfigKeys.AWS_INSTANCE_PUBLIC_IP.getPropertyName())); EasyMock.verify(serverInstanceContext); }