List of usage examples for org.apache.commons.configuration SubnodeConfiguration getRootNode
public ConfigurationNode getRootNode()
From source file:com.oltpbenchmark.multitenancy.MuTeBench.java
private static List<String> get_weights(String plugin, SubnodeConfiguration work) { List<String> weight_strings = new LinkedList<String>(); @SuppressWarnings("unchecked") List<SubnodeConfiguration> weights = work.configurationsAt("weights"); boolean weights_started = false; for (SubnodeConfiguration weight : weights) { // stop if second attributed node encountered if (weights_started && weight.getRootNode().getAttributeCount() > 0) { break; }/*from w w w . j a va2 s .com*/ // start adding node values, if node with attribute equal to current // plugin encountered if (weight.getRootNode().getAttributeCount() > 0 && weight.getRootNode().getAttribute(0).getValue().equals(plugin)) { weights_started = true; } if (weights_started) { weight_strings.add(weight.getString("")); } } return weight_strings; }
From source file:com.oltpbenchmark.DBWorkload.java
private static List<String> get_weights(String plugin, SubnodeConfiguration work) { List<String> weight_strings = new LinkedList<String>(); @SuppressWarnings("unchecked") List<SubnodeConfiguration> weights = work.configurationsAt("weights"); boolean weights_started = false; for (SubnodeConfiguration weight : weights) { // stop if second attributed node encountered if (weights_started && weight.getRootNode().getAttributeCount() > 0) { break; }// www. jav a2s . com //start adding node values, if node with attribute equal to current plugin encountered if (weight.getRootNode().getAttributeCount() > 0 && weight.getRootNode().getAttribute(0).getValue().equals(plugin)) { weights_started = true; } if (weights_started) { weight_strings.add(weight.getString("")); } } return weight_strings; }
From source file:au.org.intersect.dms.instrument.harvester.Fv1000OifHarvester.java
@Override String process(InputStream input) throws IOException { Fv1000OifParser parser = new Fv1000OifParser(Mode.INCLUSION, INCLUSIONS_FIELDS, TYPES, TEMPLATE, FV1000_DATE_TIME_FORMATTER); parser.setEncoding("UTF-16"); parser.setSectionChecker(new SectionChecker() { @Override/* w ww .j ava 2 s .co m*/ public boolean includeSection(SubnodeConfiguration section) { return !("Laser Enable".equals(section.getRootNode().getChild(0).getName()) && "0".equals(section.getRootNode().getChild(0).getValue())); } }); return parser.parse(input); }
From source file:au.org.intersect.dms.instrument.harvester.WindowsIniLogParser.java
private String parseLogIniFile(HierarchicalINIConfiguration iniConf) { StringTemplate template = ST_HARVESTERS.getInstanceOf(templateFilePath); Map<String, Map<String, Object>> values = new HashMap<String, Map<String, Object>>(); for (String sectionName : (Set<String>) iniConf.getSections()) { Map<String, Object> sectionMap = new HashMap<String, Object>(); SubnodeConfiguration section = iniConf.getSection(sectionName); if (sectionChecker == null || sectionChecker.includeSection(section)) { for (Iterator it = section.getRootNode().getChildren().iterator(); it.hasNext();) { ConfigurationNode node = (ConfigurationNode) it.next(); sectionMap = parseFields(sectionName, sectionMap, node); }/*w ww . j av a2 s. c o m*/ if (!sectionMap.isEmpty()) { values.put(AbstractHarvester.toXML(sectionName), sectionMap); } } } template.setAttribute("sections", values); return template.toString(); }
From source file:core.commonapp.server.data.RequiredDataReader.java
/** * Initialize data reader//w w w . ja va 2 s . co m * * if there are relationships that need to be defined. In the xml define the * forgein relation first. Then reference the relation as the value of the * columns with ${RelationType.KeyValue}. The relation type is the class * name with no package. i.e. 'forgeinKey=${GeoType._STATE}' */ public void read(String filename) { try { log.debug("Reading data file {0}.", filename); XMLConfiguration reader = new XMLConfiguration(getClass().getResource(filename)); List<SubnodeConfiguration> records = reader.configurationsAt("record"); for (SubnodeConfiguration record : records) { String beanName = record.getString("[@bean]"); Object object = context.getBean(beanName); ConfigurationNode node = record.getRootNode(); List<ConfigurationNode> attributes = node.getAttributes(); // attempt to load from db, if found then use it to update // instead of a new object to insert Object dbObject = null; String key = record.getString("[@key]"); if (object instanceof Keyable && key != null) { Keyable keyable = (Keyable) object; // FIXME: Find existing record // KeyedCache cache = context.getBean(KeyedCache.class); // // // KeyedCacheStore<?> store = cache.getCacheStore(object.getClass()); // // // // // Object dao = context.getBean("defaultDao"); // dbObject = ((DefaultDao) dao).getEntityManager().createQuery(" from " + object.getClass() + " where key = " + key); if (dbObject != null) { log.debug("Found keyed object in database (dbObject={0}).", dbObject); // set the object to the one in the db so we can update the // fields with data from xml object = dbObject; } } for (ConfigurationNode attribute : attributes) { String name = attribute.getName(); String value = (String) attribute.getValue(); if (value.startsWith("$")) { // remove the wrapping ${...} // TODO: reg expr error check format value = value.substring(2); value = value.substring(0, value.length() - 1); log.debug("Static data reference found (refId={0})", value); // set method String methodName = "set" + name.substring(0, 1).toUpperCase() + name.substring(1); Method method = getMethod(object, methodName); method.invoke(object, referenceMap.get(value)); } else if ("%CURRENT_TIMESTAMP".equals(value)) { String methodName = "set" + name.substring(0, 1).toUpperCase() + name.substring(1); Method method = getMethod(object, methodName); method.invoke(object, new Date()); } else if ("refId".equals(name)) { referenceMap.put(value, object); log.debug("Adding declared reference object by id (refId={0},object={1}).", value, object); } else if (!"bean".equals(name)) { String methodName = "set" + name.substring(0, 1).toUpperCase() + name.substring(1); Method method = getMethod(object, methodName); method.invoke(object, value); } } // if the object is keyable then infer the reference if (object instanceof Keyable) { Keyable keyable = (Keyable) object; String refId = keyable.getClass().getSimpleName().replace("HibernateImpl", "") + "." + keyable.getKey(); referenceMap.put(refId, object); log.debug("Inferred reference for object (refId={0},object={1}).", refId, object); } // add object to list for saving dataObjects.add(object); } } catch (ConfigurationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } }
From source file:velo.resource.resourceDescriptor.ResourceDescriptor.java
public Map<String, String> getAllTags(String key) { try {/* w ww. j av a2s.c o m*/ Map<String, String> map = new HashMap<String, String>(); SubnodeConfiguration specificNodes = getConfig().configurationAt(key); Iterator nodes = specificNodes.getRootNode().getChildren().listIterator(); while (nodes.hasNext()) { XMLConfiguration.Node currNode = (XMLConfiguration.Node) nodes.next(); if (currNode.getChildren().size() < 1) { map.put(currNode.getName(), currNode.getValue().toString()); } } return map; } catch (ConfigurationException e) { log.error("Could not get key: " + getTag(key)); return null; } }