List of usage examples for org.apache.commons.configuration Configuration subset
Configuration subset(String prefix);
From source file:es.udc.gii.common.eaf.factory.XMLSimpleFactory.java
@Override public OperatorChain<ReplaceOperator> createReplaceChain() { Configuration conf = EAFConfiguration.getInstance().subset("OperatorChains.ReplaceChain"); OperatorChain<ReplaceOperator> oChain = null; List ops = conf.getList("Operator.Class"); if (ops.size() > 0) { oChain = new OperatorChain<ReplaceOperator>(); for (int i = 0; i < ops.size(); i++) { try { ReplaceOperator op = (ReplaceOperator) Class.forName((String) ops.get(i)).newInstance(); op.configure(conf.subset("Operator(" + i + ")")); oChain.addOperators(op); } catch (Exception ex) { throw new ConfigurationException("Wrong replace operator configuration for " + (String) ops.get(i) + " ?" + " \n Thrown exception: \n" + ex); }/*from ww w .j a v a 2 s . com*/ } } return oChain; }
From source file:es.udc.gii.common.eaf.factory.XMLSimpleFactory.java
@Override public OperatorChain<EvaluationOperator> createEvaluationChain() { Configuration conf = EAFConfiguration.getInstance().subset("OperatorChains.EvaluationChain"); OperatorChain<EvaluationOperator> oChain = null; List ops = conf.getList("Operator.Class"); if (ops.size() > 0) { oChain = new OperatorChain<EvaluationOperator>(); for (int i = 0; i < ops.size(); i++) { try { EvaluationOperator op = (EvaluationOperator) Class.forName((String) ops.get(i)).newInstance(); op.configure(conf.subset("Operator(" + i + ")")); oChain.addOperators(op); } catch (Exception ex) { throw new ConfigurationException("Wrong evaluation operator configuration for " + (String) ops.get(i) + " ?" + " \n Thrown exception: \n" + ex); }//from w w w . ja v a 2 s.c o m } } return oChain; }
From source file:net.sf.jclal.activelearning.scenario.AbstractScenario.java
/** * Configuration of Oracle./*from w w w. java 2 s . c om*/ * * @param configuration The configuration object to use */ public void setOracleConfiguration(Configuration configuration) { String oracleError = "oracle type= "; try { // oracle classname String oracleClassname = configuration.getString("oracle[@type]"); oracleError += oracleClassname; // oracle class Class<? extends IOracle> oracleClass = (Class<? extends IOracle>) Class.forName(oracleClassname); // oracle instance IOracle oracle = oracleClass.newInstance(); // Configure query strategy (if necessary) if (oracle instanceof IConfigure) { ((IConfigure) oracle).configure(configuration.subset("oracle")); } // Add this oracle to the scenario setOracle(oracle); } catch (ClassNotFoundException e) { throw new ConfigurationRuntimeException("\nIllegal oracle classname: " + oracleError, e); } catch (InstantiationException e) { throw new ConfigurationRuntimeException("\nIllegal oracle classname: " + oracleError, e); } catch (IllegalAccessException e) { throw new ConfigurationRuntimeException("\nIllegal oracle classname: " + oracleError, e); } }
From source file:es.udc.gii.common.eaf.factory.XMLSimpleFactory.java
@Override public OperatorChain<ReproductionOperator> createReproductionChain() { Configuration conf = EAFConfiguration.getInstance().subset("OperatorChains.ReproductionChain"); OperatorChain<ReproductionOperator> oChain = null; List ops = conf.getList("Operator.Class"); if (ops.size() > 0) { oChain = new OperatorChain<ReproductionOperator>(); for (int i = 0; i < ops.size(); i++) { try { ReproductionOperator op = (ReproductionOperator) Class.forName((String) ops.get(i)) .newInstance();/* w w w . j a va2 s .c o m*/ op.configure(conf.subset("Operator(" + i + ")")); oChain.addOperators(op); } catch (Exception ex) { throw new ConfigurationException("Wrong reproduction operator configuration for " + (String) ops.get(i) + " ?" + " \n Thrown exception: \n" + ex); } } } return oChain; }
From source file:net.sf.jclal.activelearning.scenario.AbstractScenario.java
/** * Configuration of Batch Mode/*from ww w .j a v a 2 s . c o m*/ * * @param configuration The configuration object to use */ public void setBatchModeConfiguration(Configuration configuration) { String batchError = "batch-mode type= "; try { // Set batch String batchModeClassName = configuration.getString("batch-mode[@type]", ""); batchError += batchModeClassName; // batch-mode class Class<? extends IBatchMode> batchModeClass = (Class<? extends IBatchMode>) Class .forName(batchModeClassName); IBatchMode batchModeT = batchModeClass.newInstance(); // Configure query strategy (if necessary) if (batchModeT instanceof IConfigure) { ((IConfigure) batchModeT).configure(configuration.subset("batch-mode")); } setBatchMode(batchModeT); } catch (ClassNotFoundException e) { throw new ConfigurationRuntimeException("\nIllegal batch-mode classname: " + batchError, e); } catch (InstantiationException e) { throw new ConfigurationRuntimeException("\nIllegal batch-mode classname: " + batchError, e); } catch (IllegalAccessException e) { throw new ConfigurationRuntimeException("\nIllegal batch-mode classname: " + batchError, e); } }
From source file:com.boozallen.cognition.ingest.storm.bolt.geo.LocationResolverBolt.java
@Override public void configure(Configuration conf) throws ConfigurationException { _luceneIndexDir = conf.getString(LUCENE_INDEX_DIR); _localIndexDir = conf.getString(LOCAL_INDEX_DIR); _textFields = conf.getList(TEXT_FIELDS); _pipClavinLocationPrefix = conf.getString(PIP_CLAVIN_LOCATION_PREFIX, "pip.clavinLocation_"); _fieldName = conf.getString(FIELD_NAME, FIELD_NAME); _name = conf.getString(NAME, NAME);// w w w. j a v a 2 s . c o m _admin1Code = conf.getString(ADMIN1CODE, ADMIN1CODE); _admin2Code = conf.getString(ADMIN2CODE, ADMIN2CODE); _countryCode = conf.getString(COUNTRYCODE, COUNTRYCODE); _latitude = conf.getString(LATITUDE, LATITUDE); _longitude = conf.getString(LONGITUDE, LONGITUDE); _confidence = conf.getString(CONFIDENCE, CONFIDENCE); Configuration hadoopConfigSubset = conf.subset(HADOOP_CONFIG); for (Iterator<String> itr = hadoopConfigSubset.getKeys(); itr.hasNext();) { String key = itr.next(); String value = hadoopConfigSubset.getString(key); hadoopConfig.put(key, value); } }
From source file:ezbake.services.graph.TitanGraphStore.java
/** * Creates a new graph instance for the specified graph name. This method is used by LoadingCache. */// www . ja va 2s .c om private SecureTitanGraph<AccumuloSecurityToken> newInstanceGraph(String graphName) { String graphName1 = graphName; if (StringUtils.isEmpty(graphName1)) { graphName1 = EzGraphServiceConstants.GLOBAL_GRAPH; } // first we clone the current configuration, this gives us a deep copy final Configuration conf = (Configuration) config.clone(); // now we override the graph name from the original config with the new // specified one final Configuration storageConf = conf.subset(GraphDatabaseConfiguration.STORAGE_NAMESPACE); storageConf.setProperty(AccumuloStoreManager.TABLE_NAME_KEY, graphName1); // finally, create new graph instance and return it final SecureTitanGraph<AccumuloSecurityToken> stg = new SecureTitanGraph<>( new SecureGraphDatabaseConfiguration(conf)); return stg; }
From source file:es.udc.gii.common.eaf.algorithm.mga.AbstractMGAAlgorithm.java
/** * Configures the algorithm./*from w w w.jav a 2 s . c o m*/ */ @Override public void configure(Configuration conf) { try { super.configure(conf); if (conf.containsKey("Elitism")) { this.setElitism(conf.getInt("Elitism")); } else { this.setElitism(1); (new ConfWarning("AbstractMGAAlgorithm.Elitism", 1)).warn(); } if (conf.containsKey("NominalConvergence.Class")) { this.setNominalConvergence( (StopTest) Class.forName(conf.getString("NominalConvergence.Class")).newInstance()); } else { (new ConfWarning("AbstractMGAAlgorithm.NominalConvergence", "MicroGenerationsConvergence")).warn(); this.setNominalConvergence(new MicroGenerationsConvergence(3)); } this.getNominalConvergence().configure(conf.subset("NominalConvergence")); } catch (Exception ex) { throw new ConfigurationException(this.getClass(), ex); } }
From source file:net.sf.jclal.activelearning.scenario.AbstractScenario.java
/** * Configuration of Query Strategy.// w w w . j av a2 s .c o 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.github.anba.test262.environment.Environments.java
/** * Creates a new Rhino environment/* ww w . j ava 2 s . c o m*/ */ public static <T extends GlobalObject> EnvironmentProvider<T> rhino(final Configuration configuration) { final int version = configuration.getInt("rhino.version", Context.VERSION_DEFAULT); final String compiler = configuration.getString("rhino.compiler.default"); List<?> enabledFeatures = configuration.getList("rhino.features.enabled", emptyList()); List<?> disabledFeatures = configuration.getList("rhino.features.disabled", emptyList()); final Set<Integer> enabled = intoCollection(filterMap(enabledFeatures, notEmptyString, toInteger), new HashSet<Integer>()); final Set<Integer> disabled = intoCollection(filterMap(disabledFeatures, notEmptyString, toInteger), new HashSet<Integer>()); /** * Initializes the global {@link ContextFactory} according to the * supplied configuration * * @see ContextFactory#initGlobal(ContextFactory) */ final ContextFactory factory = new ContextFactory() { @Override protected boolean hasFeature(Context cx, int featureIndex) { if (enabled.contains(featureIndex)) { return true; } else if (disabled.contains(featureIndex)) { return false; } return super.hasFeature(cx, featureIndex); } @Override protected Context makeContext() { Context context = super.makeContext(); context.setLanguageVersion(version); return context; } }; EnvironmentProvider<RhinoGlobalObject> provider = new EnvironmentProvider<RhinoGlobalObject>() { @Override public RhinoEnv<RhinoGlobalObject> environment(final String testsuite, final String sourceName, final Test262Info info) { Configuration c = configuration.subset(testsuite); final boolean strictSupported = c.getBoolean("strict", false); final String encoding = c.getString("encoding", "UTF-8"); final String libpath = c.getString("lib_path"); final Context cx = factory.enterContext(); final AtomicReference<RhinoGlobalObject> $global = new AtomicReference<>(); final RhinoEnv<RhinoGlobalObject> environment = new RhinoEnv<RhinoGlobalObject>() { @Override public RhinoGlobalObject global() { return $global.get(); } @Override protected String getEvaluator() { return compiler; } @Override protected String getCharsetName() { return encoding; } @Override public void exit() { Context.exit(); } }; @SuppressWarnings({ "serial" }) final RhinoGlobalObject global = new RhinoGlobalObject() { { cx.initStandardObjects(this, false); } @Override protected boolean isStrictSupported() { return strictSupported; } @Override protected String getDescription() { return info.getDescription(); } @Override protected void failure(String message) { failWith(message, sourceName); } @Override protected void include(Path path) throws IOException { // resolve the input file against the library path Path file = Paths.get(libpath).resolve(path); InputStream source = Files.newInputStream(file); environment.eval(file.getFileName().toString(), source); } }; $global.set(global); return environment; } }; @SuppressWarnings("unchecked") EnvironmentProvider<T> p = (EnvironmentProvider<T>) provider; return p; }