List of usage examples for org.apache.commons.configuration HierarchicalConfiguration getString
public String getString(String key)
From source file:jsprit.core.algorithm.io.InsertionFactory.java
@SuppressWarnings("deprecation") public static InsertionStrategy createInsertion(VehicleRoutingProblem vrp, HierarchicalConfiguration config, VehicleFleetManager vehicleFleetManager, StateManager stateManager, List<PrioritizedVRAListener> algorithmListeners, ExecutorService executorService, int nuOfThreads, ConstraintManager constraintManager, boolean addDefaultCostCalculators) { if (config.containsKey("[@name]")) { String insertionName = config.getString("[@name]"); if (!insertionName.equals("bestInsertion") && !insertionName.equals("regretInsertion")) { throw new IllegalStateException( insertionName + " is not supported. use either \"bestInsertion\" or \"regretInsertion\""); }//from w w w .j ava 2 s. c om InsertionBuilder iBuilder = new InsertionBuilder(vrp, vehicleFleetManager, stateManager, constraintManager); if (executorService != null) { iBuilder.setConcurrentMode(executorService, nuOfThreads); } if (config.containsKey("level")) { String level = config.getString("level"); if (level.equals("local")) { iBuilder.setLocalLevel(addDefaultCostCalculators); } else if (level.equals("route")) { int forwardLooking = 0; int memory = 1; String forward = config.getString("level[@forwardLooking]"); String mem = config.getString("level[@memory]"); if (forward != null) forwardLooking = Integer.parseInt(forward); else log.warn( "parameter route[@forwardLooking] is missing. by default it is 0 which equals to local level"); if (mem != null) memory = Integer.parseInt(mem); else log.warn("parameter route[@memory] is missing. by default it is 1"); iBuilder.setRouteLevel(forwardLooking, memory, addDefaultCostCalculators); } else throw new IllegalStateException( "level " + level + " is not known. currently it only knows \"local\" or \"route\""); } else iBuilder.setLocalLevel(addDefaultCostCalculators); if (config.containsKey("considerFixedCosts") || config.containsKey("considerFixedCost")) { if (addDefaultCostCalculators) { String val = config.getString("considerFixedCosts"); if (val == null) val = config.getString("considerFixedCost"); if (val.equals("true")) { double fixedCostWeight = 0.5; String weight = config.getString("considerFixedCosts[@weight]"); if (weight == null) weight = config.getString("considerFixedCost[@weight]"); if (weight != null) fixedCostWeight = Double.parseDouble(weight); else throw new IllegalStateException( "fixedCostsParameter 'weight' must be set, e.g. <considerFixedCosts weight=1.0>true</considerFixedCosts>.\n" + "this has to be changed in algorithm-config-xml-file."); iBuilder.considerFixedCosts(fixedCostWeight); } else if (val.equals("false")) { } else throw new IllegalStateException( "considerFixedCosts must either be true or false, i.e. <considerFixedCosts weight=1.0>true</considerFixedCosts> or \n<considerFixedCosts weight=1.0>false</considerFixedCosts>. " + "if latter, you can also omit the tag. this has to be changed in algorithm-config-xml-file"); } } String timeSliceString = config.getString("experimental[@timeSlice]"); String neighbors = config.getString("experimental[@neighboringSlices]"); if (timeSliceString != null && neighbors != null) { iBuilder.experimentalTimeScheduler(Double.parseDouble(timeSliceString), Integer.parseInt(neighbors)); } String allowVehicleSwitch = config.getString("allowVehicleSwitch"); if (allowVehicleSwitch != null) { iBuilder.setAllowVehicleSwitch(Boolean.parseBoolean(allowVehicleSwitch)); } if (insertionName.equals("regretInsertion")) { iBuilder.setInsertionStrategy(InsertionBuilder.Strategy.REGRET); String fastRegret = config.getString("fastRegret"); if (fastRegret != null) { iBuilder.setFastRegret(Boolean.parseBoolean(fastRegret)); } } return iBuilder.build(); } else throw new IllegalStateException("cannot create insertionStrategy, since it has no name."); }
From source file:com.graphhopper.jsprit.core.algorithm.io.InsertionFactory.java
@SuppressWarnings("deprecation") public static InsertionStrategy createInsertion(VehicleRoutingProblem vrp, HierarchicalConfiguration config, VehicleFleetManager vehicleFleetManager, StateManager stateManager, List<VehicleRoutingAlgorithmListeners.PrioritizedVRAListener> algorithmListeners, ExecutorService executorService, int nuOfThreads, ConstraintManager constraintManager, boolean addDefaultCostCalculators) { if (config.containsKey("[@name]")) { String insertionName = config.getString("[@name]"); if (!insertionName.equals("bestInsertion") && !insertionName.equals("regretInsertion")) { throw new IllegalStateException( insertionName + " is not supported. use either \"bestInsertion\" or \"regretInsertion\""); }/* www .java 2 s.c o m*/ InsertionBuilder iBuilder = new InsertionBuilder(vrp, vehicleFleetManager, stateManager, constraintManager); if (executorService != null) { iBuilder.setConcurrentMode(executorService, nuOfThreads); } if (config.containsKey("level")) { String level = config.getString("level"); if (level.equals("local")) { iBuilder.setLocalLevel(addDefaultCostCalculators); } else if (level.equals("route")) { int forwardLooking = 0; int memory = 1; String forward = config.getString("level[@forwardLooking]"); String mem = config.getString("level[@memory]"); if (forward != null) forwardLooking = Integer.parseInt(forward); else log.warn( "parameter route[@forwardLooking] is missing. by default it is 0 which equals to local level"); if (mem != null) memory = Integer.parseInt(mem); else log.warn("parameter route[@memory] is missing. by default it is 1"); iBuilder.setRouteLevel(forwardLooking, memory, addDefaultCostCalculators); } else throw new IllegalStateException( "level " + level + " is not known. currently it only knows \"local\" or \"route\""); } else iBuilder.setLocalLevel(addDefaultCostCalculators); if (config.containsKey("considerFixedCosts") || config.containsKey("considerFixedCost")) { if (addDefaultCostCalculators) { String val = config.getString("considerFixedCosts"); if (val == null) val = config.getString("considerFixedCost"); if (val.equals("true")) { double fixedCostWeight = 0.5; String weight = config.getString("considerFixedCosts[@weight]"); if (weight == null) weight = config.getString("considerFixedCost[@weight]"); if (weight != null) fixedCostWeight = Double.parseDouble(weight); else throw new IllegalStateException( "fixedCostsParameter 'weight' must be set, e.g. <considerFixedCosts weight=1.0>true</considerFixedCosts>.\n" + "this has to be changed in algorithm-config-xml-file."); iBuilder.considerFixedCosts(fixedCostWeight); } else if (val.equals("false")) { } else throw new IllegalStateException( "considerFixedCosts must either be true or false, i.e. <considerFixedCosts weight=1.0>true</considerFixedCosts> or \n<considerFixedCosts weight=1.0>false</considerFixedCosts>. " + "if latter, you can also omit the tag. this has to be changed in algorithm-config-xml-file"); } } String allowVehicleSwitch = config.getString("allowVehicleSwitch"); if (allowVehicleSwitch != null) { iBuilder.setAllowVehicleSwitch(Boolean.parseBoolean(allowVehicleSwitch)); } if (insertionName.equals("regretInsertion")) { iBuilder.setInsertionStrategy(InsertionBuilder.Strategy.REGRET); String fastRegret = config.getString("fastRegret"); if (fastRegret != null) { iBuilder.setFastRegret(Boolean.parseBoolean(fastRegret)); } } return iBuilder.build(); } else throw new IllegalStateException("cannot create insertionStrategy, since it has no name."); }
From source file:elaborate.editor.config.Configuration.java
private static void processConfiguration(HierarchicalConfiguration h_config) { renditions = Maps.newTreeMap();//from w ww . j a va2 s . c om HierarchicalConfiguration config = configurationAt(h_config, "renditions"); if (config != null) { extractRenditions(config); } messages = Maps.newTreeMap(); config = configurationAt(h_config, "messages"); if (config != null) { int n = config.getMaxIndex("group"); for (int i = 0; i <= n; i++) { String groupId = config.getString("group(" + i + ")[@id]"); if (groupId != null) { HierarchicalConfiguration group = config.configurationAt("group(" + i + ")"); extractMessages(groupId, group); } } } }
From source file:com.easyvalidation.xml.processor.XMLProcessor.java
/** * Parse the XML & return list of rules. * //w w w .ja v a 2s. c om * @param fileNames * @return * @throws ValidationException */ public static Map<String, List<Rule>> parseXML(String[] fileNames) throws ValidationException { Map<String, List<Rule>> validationMap = new HashMap<String, List<Rule>>(); com.easyvalidation.xml.config.EasyValidationXmlConfiguration configuration = new com.easyvalidation.xml.config.EasyValidationXmlConfiguration(); //System.out.println("Have we came here?"); configuration.setAutoSave(false); //System.out.println("Have we came here?"); configuration.clear(); //System.out.println("Have we came here?"); configuration.setValidating(true); try { for (String fileName : fileNames) { //System.out.println("Have we came here4?"); configuration.load(fileName); //System.out.println("Have we came here5?"); } //System.out.println("Have we came here?"); boolean isMessageFromKeyAllowed = false; Map<String, PropertiesConfiguration> propertiesMap = new HashMap<String, PropertiesConfiguration>(); int propertiesSize = configuration.getMaxIndex(Nodes.PROPERTIES); for (int propertiesIndex = 0; propertiesIndex <= propertiesSize; propertiesIndex++) { String locale = configuration.getString(RuleElementPathUtil.getPropsFileLocale(propertiesIndex)); PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); propertiesConfiguration.setAutoSave(false); propertiesConfiguration.clear(); HierarchicalConfiguration subConfig = configuration .configurationAt(RuleElementPathUtil.getPropertiesPath(propertiesIndex)); //System.out.println("Have we came here6?"); int propFileSize = subConfig.getMaxIndex(Nodes.FILE); for (int propFileIndex = 0; propFileIndex <= propFileSize; propFileIndex++) { String propFileName = subConfig.getString(RuleElementPathUtil.getPropsFilePath(propFileIndex)); if (!Utils.isEmpty(propFileName)) { propertiesConfiguration.load(propFileName); } } propertiesMap.put(locale, propertiesConfiguration); } //System.out.println("Have we came here7?"); if (!propertiesMap.isEmpty()) { isMessageFromKeyAllowed = true; } int validationSize = configuration.getMaxIndex(Nodes.VALIDATION); for (int validationIndex = 0; validationIndex <= validationSize; validationIndex++) { String name = configuration.getString(RuleElementPathUtil.getValidationName(validationIndex)); HierarchicalConfiguration subConfig = configuration .configurationAt(RuleElementPathUtil.getValidation(validationIndex)); int ruleSize = subConfig.getMaxIndex(Nodes.RULE); List<Rule> ruleList = new ArrayList<Rule>(); for (int ruleIndex = 0; ruleIndex <= ruleSize; ruleIndex++) { String ruleType = subConfig.getString(RuleElementPathUtil.getRuleType(ruleIndex)); String property = subConfig.getString(RuleElementPathUtil.getRuleFieldName(ruleIndex)); String message = subConfig.getString(RuleElementPathUtil.getRuleMessage(ruleIndex)); String min = subConfig.getString(RuleElementPathUtil.getRuleMin(ruleIndex)); String max = subConfig.getString(RuleElementPathUtil.getRuleMax(ruleIndex)); String dateFormat = subConfig.getString(RuleElementPathUtil.getRuleDateFormat(ruleIndex)); String key = subConfig.getString(RuleElementPathUtil.getMessageKey(ruleIndex)); String useAttributePlaceHolder = subConfig .getString(RuleElementPathUtil.getMessageUseAttributePlaceHolder(ruleIndex)); String regEx = subConfig.getString(RuleElementPathUtil.getRuleRegEx(ruleIndex)); String expression = subConfig.getString(RuleElementPathUtil.getRuleExpression(ruleIndex)); Rule rule = new Rule(ruleType); rule.setProperty(property); rule.setMessage(message); rule.setMin(min); rule.setMax(max); rule.setDateFormat(dateFormat); rule.setKey(key); rule.setUseAttributePlaceHolder(Boolean.valueOf(useAttributePlaceHolder)); rule.setRegEx(Boolean.valueOf(regEx)); rule.setExpression(expression); if (isMessageFromKeyAllowed) { rule.setPropertiesMap(propertiesMap); } rule.populateRule(); ruleList.add(rule); } validationMap.put(name, ruleList); } } catch (Exception ex) { throw new ValidationException(ex); } return validationMap; }
From source file:com.servioticy.queueclient.QueueClient.java
private static QueueClient createInstance(String configPath) throws QueueClientException { QueueClient instance;/* ww w. j a v a 2 s. com*/ File f = new File(configPath); if (!f.exists()) { if (Thread.currentThread().getContextClassLoader().getResource(configPath) == null) { return createInstance(configPath, "kestrel", "localhost:22133", "services"); } } String type; HierarchicalConfiguration config; try { config = new XMLConfiguration(configPath); config.setExpressionEngine(new XPathExpressionEngine()); if (!config.containsKey("defaultQueue/queueType")) { String errMsg = "No default queue. Fix your configuration file."; logger.error(errMsg); throw new QueueClientException(errMsg); } type = config.getString("defaultQueue/queueType"); instance = createInstance(configPath, type, config.getString("defaultQueue/baseAddress", "localhost:22133"), config.getString("defaultQueue/relativeAddress", "services")); } catch (ConfigurationException e) { String errMsg = "'" + configPath + "' configuration file is malformed (" + e.getMessage() + ")."; logger.error(errMsg); throw new QueueClientException(errMsg); } return instance; }
From source file:com.graphhopper.jsprit.core.problem.io.VrpXMLReader.java
private static Coordinate getCoord(HierarchicalConfiguration serviceConfig, String prefix) { Coordinate pickupCoord = null;/* w ww . ja va 2 s. c o m*/ if (serviceConfig.getString(prefix + "coord[@x]") != null && serviceConfig.getString(prefix + "coord[@y]") != null) { double x = Double.parseDouble(serviceConfig.getString(prefix + "coord[@x]")); double y = Double.parseDouble(serviceConfig.getString(prefix + "coord[@y]")); pickupCoord = Coordinate.newInstance(x, y); } return pickupCoord; }
From source file:com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms.java
private static InsertionStrategy createInitialSolution(XMLConfiguration config, final VehicleRoutingProblem vrp, VehicleFleetManager vehicleFleetManager, final StateManager routeStates, Set<PrioritizedVRAListener> algorithmListeners, TypedMap definedClasses, ExecutorService executorService, int nuOfThreads, final SolutionCostCalculator solutionCostCalculator, ConstraintManager constraintManager, boolean addDefaultCostCalculators) { List<HierarchicalConfiguration> modConfigs = config.configurationsAt("construction.insertion"); if (modConfigs == null) return null; if (modConfigs.isEmpty()) return null; if (modConfigs.size() != 1) throw new IllegalStateException("#construction.modules != 1. 1 expected"); HierarchicalConfiguration modConfig = modConfigs.get(0); String insertionName = modConfig.getString("[@name]"); if (insertionName == null) throw new IllegalStateException("insertion[@name] is missing."); String insertionId = modConfig.getString("[@id]"); if (insertionId == null) insertionId = "noId"; ModKey modKey = makeKey(insertionName, insertionId); InsertionStrategyKey insertionStrategyKey = new InsertionStrategyKey(modKey); InsertionStrategy insertionStrategy = definedClasses.get(insertionStrategyKey); if (insertionStrategy == null) { List<PrioritizedVRAListener> prioListeners = new ArrayList<PrioritizedVRAListener>(); insertionStrategy = createInsertionStrategy(modConfig, vrp, vehicleFleetManager, routeStates, prioListeners, executorService, nuOfThreads, constraintManager, addDefaultCostCalculators); algorithmListeners.addAll(prioListeners); definedClasses.put(insertionStrategyKey, insertionStrategy); }//ww w. j a v a 2 s. c om return insertionStrategy; }
From source file:com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms.java
private static String getName(HierarchicalConfiguration strategyConfig) { if (strategyConfig.containsKey("[@name]")) { return strategyConfig.getString("[@name]"); }//from w w w . j a va 2s. c om return ""; }
From source file:com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms.java
private static PrematureAlgorithmTermination getTerminationCriterion(HierarchicalConfiguration config, Set<PrioritizedVRAListener> algorithmListeners) { String basedOn = config.getString("[@basedOn]"); if (basedOn == null) { log.debug("set default prematureBreak, i.e. no premature break at all."); return null; }// w ww .ja va 2 s .c o m if (basedOn.equals("iterations")) { log.debug("set prematureBreak based on iterations"); String iter = config.getString("iterations"); if (iter == null) throw new IllegalStateException("iterations is missing"); int iterations = Integer.valueOf(iter); return new IterationWithoutImprovementTermination(iterations); } if (basedOn.equals("time")) { log.debug("set prematureBreak based on time"); String timeString = config.getString("time"); if (timeString == null) throw new IllegalStateException("time is missing"); long time = Long.parseLong(timeString); TimeTermination timeBreaker = new TimeTermination(time); algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, timeBreaker)); return timeBreaker; } if (basedOn.equals("variationCoefficient")) { log.debug("set prematureBreak based on variation coefficient"); String thresholdString = config.getString("threshold"); String iterationsString = config.getString("iterations"); if (thresholdString == null) throw new IllegalStateException("threshold is missing"); if (iterationsString == null) throw new IllegalStateException("iterations is missing"); double threshold = Double.valueOf(thresholdString); int iterations = Integer.valueOf(iterationsString); VariationCoefficientTermination variationCoefficientBreaker = new VariationCoefficientTermination( iterations, threshold); algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, variationCoefficientBreaker)); return variationCoefficientBreaker; } throw new IllegalStateException("prematureBreak basedOn " + basedOn + " is not defined"); }
From source file:com.vangent.hieos.empi.config.AccountNumberTreatmentConfig.java
/** * * @param hc/* ww w . j ava 2 s . com*/ * @param empiConfig * @throws EMPIException */ public void load(HierarchicalConfiguration hc, EMPIConfig empiConfig) throws EMPIException { defaultUniversalId = hc.getString(DEFAULT_UNIVERSAL_ID); }