List of usage examples for org.apache.commons.configuration.tree ConfigurationNode getChildren
List getChildren();
From source file:jp.primecloud.auto.ui.mock.XmlDataLoader.java
public static <T> List<T> getData(String filename, Class<T> clazz) { try {//w w w . ja va 2 s . c o m XMLConfiguration config = new XMLConfiguration(filename); ConfigurationNode o = config.getRootNode(); List<T> result = new ArrayList<T>(); List<?> list = o.getChildren(); for (Object row : list) { Map<String, Object> map = new HashMap<String, Object>(); for (Object field : ((Node) row).getChildren()) { Object name = ((Node) ((Node) field).getAttributes().get(0)).getValue(); Object value = ((Node) field).getValue(); map.put(toCamelCase((String) name), value); } T c = clazz.newInstance(); BeanUtils.populate(c, map); result.add(c); } return result; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.aol.advertising.qiao.util.XmlConfigUtil.java
public static void walkTree(ConfigurationNode node) { if (node != null) { logger.info("node name=" + node.getName() + ", #childrens=" + node.getChildrenCount()); List<ConfigurationNode> childrens = node.getChildren(); for (ConfigurationNode sub : childrens) walkTree(sub);/*from www. ja v a2 s .co m*/ } }
From source file:com.cedarsoft.configuration.xml.XmlConfigurationManagerTest.java
@Test public void testGetConfiguration() throws Exception { assertNotNull(manager.getConfiguration()); ConfigurationNode rootNode = manager.getConfiguration().getRootNode(); assertEquals(0, rootNode.getChildren().size()); assertNotNull(manager.getModuleConfiguration(Integer.class)); assertEquals(1, rootNode.getChildren().size()); HierarchicalConfiguration stringConfig = manager.getModuleConfiguration(String.class); stringConfig.setProperty("daProp", 7); assertEquals(7, manager.getModuleConfiguration(String.class).getProperty("daProp")); }
From source file:com.wrmsr.neurosis.util.Configs.java
protected static Object unpackNode(ConfigurationNode node) { List<ConfigurationNode> children = node.getChildren(); if (!children.isEmpty()) { Map<String, List<ConfigurationNode>> namedChildren = newHashMap(); for (ConfigurationNode child : children) { if (namedChildren.containsKey(child.getName())) { namedChildren.get(child.getName()).add(child); } else { namedChildren.put(child.getName(), Lists.newArrayList(child)); }//w ww . j a v a 2 s . com } Map ret = newHashMap(); for (Map.Entry<String, List<ConfigurationNode>> e : namedChildren.entrySet()) { List<ConfigurationNode> l = e.getValue(); checkState(!l.isEmpty()); boolean hasListAtt = l.stream().flatMap(n -> n.getAttributes(IS_LIST_ATTR).stream()) .map(o -> toBool(o)).findFirst().isPresent(); Object no; if (l.size() > 1 || hasListAtt) { no = l.stream().map(n -> unpackNode(n)).filter(o -> o != null) .collect(ImmutableCollectors.toImmutableList()); } else { no = unpackNode(l.get(0)); } ret.put(e.getKey(), no); } if (ret.size() == 1 && ret.containsKey("")) { return ret.get(""); } else { return ret; } } return node.getValue(); }
From source file:com.gamma.dam.conf.db.DBConfig.java
/** * Parses the.//from ww w. j a v a 2 s. co m * * @param node the node */ public void parse(ConfigurationNode node) { if (node.getChildrenCount() > 0) { for (ConfigurationNode n : node.getChildren()) { String name = n.getName(); String val = (String) n.getValue(); switch (name) { case "host": setHost(val); break; case "port": setPort(val); break; case "database": setDatabase(val); break; case "username": setUsername(val); break; case "password": setPassword(val); break; case "driver": setDriver(val); break; case "idleMaxAgeInMinutes": setIdleMaxAgeInMinutes(val); break; case "idleConnectionTestPeriodInMinutes": setIdleConnectionTestPeriodInMinutes(val); break; case "maxConnectionsPerPartition": setMaxConnectionsPerPartition(val); break; case "minConnectionsPerPartition": setMinConnectionsPerPartition(val); break; case "partitionCount": setPartitionCount(val); break; case "acquireIncrement": setAcquireIncrement(val); break; case "statementsCacheSize": setStatementsCacheSize(val); break; default: break; } } } }
From source file:com.github.mbredel.commons.configuration.YAMLConfiguration.java
/** * Constructs a YAML map, i.e. String -> Object from a given * configuration node.//from w ww . j ava 2 s .c o m * * @param node The configuration node to create a map from. * @return A Map that contains the configuration node information. */ public Map<String, Object> constructMap(ConfigurationNode node) { Map<String, Object> map = new HashMap<>(node.getChildrenCount()); for (ConfigurationNode cNode : node.getChildren()) { if (cNode.getChildren().isEmpty()) { map.put(cNode.getName(), cNode.getValue()); } else { map.put(cNode.getName(), constructMap(cNode)); } } return map; }
From source file:io.datalayer.conf.XmlConfigurationTest.java
/** * Tests the copy constructor./* w w w . ja va 2 s .c o m*/ */ @Test public void testInitCopy() throws ConfigurationException { XMLConfiguration copy = new XMLConfiguration(conf); assertEquals("value", copy.getProperty("element")); assertNull("Document was copied, too", copy.getDocument()); ConfigurationNode root = copy.getRootNode(); for (ConfigurationNode node : root.getChildren()) { assertNull("Reference was not cleared", node.getReference()); } removeTestFile(); copy.setFile(testSaveConf); copy.save(); copy.clear(); checkSavedConfig(copy); }
From source file:nz.co.senanque.madura.configuration.ListBeanFactory.java
public synchronized Object createBean(Class beanClass, BeanDeclaration decl, Object param) throws Exception { XMLBeanDeclaration xmlDecl = (XMLBeanDeclaration) decl; ConfigurationNode n = xmlDecl.getNode(); String nodeName = n.getName(); n = n.getParentNode();//from www . ja v a 2s . c om while (n != null) { if (n.getName() != null) nodeName = n.getName() + "/" + nodeName; n = n.getParentNode(); } Object bean = beans.get(nodeName); if (bean != null) { // Yes, there is already an instance return bean; } final List<String> list = new ArrayList<String>(); n = xmlDecl.getNode(); List<ConfigurationNode> children = n.getChildren(); for (ConfigurationNode node : children) { list.add(node.getValue().toString()); } // Store it in map bean = list; beans.put(nodeName, bean); return bean; }
From source file:nz.co.senanque.madura.configuration.XMLBeanFactory.java
private Element makeElement(ConfigurationNode node) { Element element = new Element(node.getName()); Object value = node.getValue(); if (value != null) element.setText(value.toString()); List<ConfigurationNode> attributes = node.getAttributes(); for (ConfigurationNode attribute : attributes) { element.setAttribute(new Attribute(attribute.getName(), attribute.getValue().toString())); }/*from ww w.j a v a2 s . com*/ List<ConfigurationNode> children = node.getChildren(); for (ConfigurationNode child : children) { element.addContent(makeElement(child)); } return element; }
From source file:org.apache.tinkerpop.gremlin.util.config.YamlConfiguration.java
protected Object saveHierarchy(final ConfigurationNode parentNode) { if (parentNode.getChildrenCount() == 0) return parentNode.getValue(); if (parentNode.getChildrenCount("item") == parentNode.getChildrenCount()) { return parentNode.getChildren().stream().map(this::saveHierarchy).collect(Collectors.toList()); } else {//www. ja v a 2s .c om final Map<String, Object> map = new LinkedHashMap<>(); for (ConfigurationNode childNode : parentNode.getChildren()) { String nodeName = childNode.getName(); if (this.xmlCompatibility && childNode.getAttributes("name").size() > 0) nodeName = String.valueOf(childNode.getAttributes("name").get(0).getValue()); map.put(nodeName, saveHierarchy(childNode)); } return map; } }