List of usage examples for org.apache.commons.configuration HierarchicalConfiguration subset
public Configuration subset(String prefix)
Configuration
object containing all keys that start with the specified prefix. From source file:org.ambraproject.queue.MessageServiceImpl.java
public void sendSyndicationMessage(String target, String articleId, String archive) throws ApplicationException { List<HierarchicalConfiguration> syndications = ((HierarchicalConfiguration) ambraConfiguration) .configurationsAt("ambra.services.syndications.syndication"); String queue = null;/*from w w w . ja v a 2 s. c om*/ String additionalBodyContent = null; if (syndications != null) { for (HierarchicalConfiguration syndication : syndications) { if (target.equals(syndication.getString("[@target]"))) { queue = syndication.getString("queue", null); HierarchicalConfiguration message = (HierarchicalConfiguration) syndication.subset("message"); additionalBodyContent = createAdditionalBodyFromConfiguration(message); } } } if (queue == null) { throw new ApplicationException(target + " queue not configured"); } sender.sendMessage(queue, createBody(articleId, archive, additionalBodyContent)); }
From source file:pl.psnc.synat.wrdz.mdz.config.MdzConfiguration.java
/** * Reads the configuration form the {@value #CONFIG_FILE} file. *///from w w w . ja v a 2s. c om @PostConstruct protected void init() { try { XMLConfiguration config = new XMLConfiguration(CONFIG_FILE); checkFormats = config.getBoolean(FORMAT_ENABLED, true); checkIntegrity = config.getBoolean(INTEGRITY_ENABLED, true); analyzeMasterObjectFileFormats = config.getBoolean(FORMAT_ANALYZE_MASTER, true); analyzeOptimizedObjectFileFormats = config.getBoolean(FORMAT_ANALYZE_OPTIMIZED, false); analyzeConvertedObjectFileFormats = config.getBoolean(FORMAT_ANALYZE_CONVERTED, false); formatWorkerAlwaysActive = config.getBoolean(FORMAT_WORKER_ALWAYS_ACTIVE, false); formatWorkerActivationSchedule = readSchedule(config.subset(FORMAT_WORKER_ACTIVATION_SCHEDULE)); formatWorkerDeactivationSchedule = readSchedule(config.subset(FORMAT_WORKER_DEACTIVATION_SCHEDULE)); formatWorkInitializerSchedule = readSchedule(config.subset(FORMAT_INITIALIZER_SCHEDULE)); formatVerifierThreshold = config.getInt(FORMAT_VERIFIER_THRESHOLD); integrityWorkerActivationSchedule = readSchedule(config.subset(INTEGRITY_WORKER_ACTIVATION_SCHEDULE)); integrityWorkerDeactivationSchedule = readSchedule( config.subset(INTEGRITY_WORKER_DEACTIVATION_SCHEDULE)); zmdObjectUrl = config.getString(INTEGRITY_ZMD_OBJECT_URL); plugins = new ArrayList<PluginInfo>(); @SuppressWarnings("unchecked") List<HierarchicalConfiguration> pluginConfigs = config.configurationsAt(PLUGINS); for (HierarchicalConfiguration pluginConfig : pluginConfigs) { String name = pluginConfig.getString(PLUGIN_NAME); String clazz = pluginConfig.getString(PLUGIN_CLASS); VerificationPlugin plugin; try { plugin = (VerificationPlugin) Class.forName(clazz).newInstance(); } catch (ClassNotFoundException e) { logger.warn("Could not load the plugin class", e); continue; } catch (InstantiationException e) { logger.warn("Could not load the plugin class", e); continue; } catch (IllegalAccessException e) { logger.warn("Could not load the plugin class", e); continue; } catch (ClassCastException e) { logger.warn("Could not load the plugin class", e); continue; } ScheduleExpression activationSchedule = readSchedule( pluginConfig.subset(PLUGIN_ACTIVATION_SCHEDULE)); ScheduleExpression deactivationSchedule = readSchedule( pluginConfig.subset(PLUGIN_DEACTIVATION_SCHEDULE)); plugins.add(new PluginInfo(name, plugin, activationSchedule, deactivationSchedule)); } plugins = Collections.unmodifiableList(plugins); } catch (ConfigurationException e) { throw new WrdzConfigurationError("Error while loading the MDZ configuration.", e); } }
From source file:playground.michalm.jtrrouter.JTRRouter.java
protected void readConfigs(String dir, String flowsFile, String turnsFile) { // process flows.xml ////w w w. j a v a 2s. co m // <flows startTime="0" stopTime="3600"> // .... // .... // </flows> try { HierarchicalConfiguration flowCfg = new XMLConfiguration(dir + "\\" + flowsFile); genStartTime = flowCfg.getInt("[@startTime]"); genStopTime = flowCfg.getInt("[@stopTime]"); genPeriod = genStopTime - genStartTime; flowFactor = flowCfg.getDouble("[@flowFactor]"); int count = flowCfg.getMaxIndex("flow") + 1; for (int i = 0; i < count; i++) { initFlow((HierarchicalConfiguration) flowCfg.subset("flow(" + i + ')')); } // process turns.xml HierarchicalConfiguration nodeCfg = new XMLConfiguration(dir + "\\" + turnsFile); count = nodeCfg.getMaxIndex("turn") + 1; for (int i = 0; i < count; i++) { initTurn((HierarchicalConfiguration) nodeCfg.subset("turn(" + i + ')')); } } catch (ConfigurationException e) { throw new RuntimeException(e); } }
From source file:playground.michalm.jtrrouter.JTRRouter.java
protected void initTurn(HierarchicalConfiguration nodeCfg) { int id = nodeCfg.getInt("[@id]"); int prev = nodeCfg.getInt("[@prev]"); int length = nodeCfg.getMaxIndex("next") + 1; int[] nodes = new int[length]; double[] probs = new double[length]; for (int i = 0; i < length; i++) { Configuration nextCfg = nodeCfg.subset("next(" + i + ')'); nodes[i] = nextCfg.getInt("[@node]"); probs[i] = nextCfg.getDouble("[@probability]"); }/*from ww w .j av a2 s . com*/ turns[prev][id] = new Turn(id, prev, nodes, probs); }
From source file:playground.michalm.jtrrouter.transims.TransimsJTRRouter.java
protected void initFlow(HierarchicalConfiguration flowCfg) { int node = flowCfg.getInt("[@node]"); int next = flowCfg.getInt("[@next]"); int in = flowCfg.getInt("[@inParking]", -1); int out = flowCfg.getInt("[@outParking]", -1); int length = flowCfg.getMaxIndex("vehicle") + 1; int[] types = new int[length]; int[] subTypes = new int[length]; int[] nos = new int[length]; for (int i = 0; i < length; i++) { Configuration vehCfg = flowCfg.subset("vehicle(" + i + ')'); types[i] = vehCfg.getInt("[@type]"); subTypes[i] = vehCfg.getInt("[@subtype]"); nos[i] = vehCfg.getInt("[@no]"); }//w w w. ja v a 2 s. co m flows[node] = new TransimsFlow(node, in, out, next, types, subTypes, nos); }