List of usage examples for org.apache.commons.configuration.tree ConfigurationNode getParentNode
ConfigurationNode getParentNode();
From source file:nz.co.senanque.madura.configuration.ConstructorBeanFactory.java
public synchronized Object createBean(Class beanClass, BeanDeclaration decl, Object param) throws Exception { Map m = decl.getBeanProperties(); XMLBeanDeclaration xmlDecl = (XMLBeanDeclaration) decl; ConfigurationNode n = xmlDecl.getNode(); String nodeName = n.getName(); n = n.getParentNode(); while (n != null) { if (n.getName() != null) nodeName = n.getName() + "/" + nodeName; n = n.getParentNode();//from ww w. j av a 2 s. co m } Object bean = beans.get(nodeName); if (bean != null) { // Yes, there is already an instance return bean; } else { // No, create it now (done by the super class) List<Class> constructorClasses = new ArrayList<Class>(); List<Object> constructorArguments = new ArrayList<Object>(); Object o = m.get("constructor-arg"); if (o != null) { constructorClasses.add(o.getClass()); constructorArguments.add(o); } o = m.get("constructor-arg0"); if (o != null) { constructorClasses.add(o.getClass()); constructorArguments.add(o); } for (int i = 1; i < 10; i++) { o = m.get("constructor-arg" + i); if (o == null) break; constructorClasses.add(o.getClass()); constructorArguments.add(o); } Constructor constructor = beanClass .getDeclaredConstructor(constructorClasses.toArray(new Class[constructorClasses.size()])); bean = constructor.newInstance(constructorArguments.toArray(new Object[constructorArguments.size()])); // Store it in map beans.put(nodeName, bean); return bean; } }
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(); while (n != null) { if (n.getName() != null) nodeName = n.getName() + "/" + nodeName; n = n.getParentNode();/*from ww w . ja v a 2s . c o m*/ } 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.SetterBeanFactory.java
public synchronized Object createBean(Class beanClass, BeanDeclaration decl, Object param) throws Exception { Map<String, String> m = decl.getBeanProperties(); XMLBeanDeclaration xmlDecl = (XMLBeanDeclaration) decl; ConfigurationNode n = xmlDecl.getNode(); String nodeName = n.getName(); n = n.getParentNode(); while (n != null) { if (n.getName() != null) nodeName = n.getName() + "/" + nodeName; n = n.getParentNode();/*from w w w. j a v a 2 s .co m*/ } Object bean = beans.get(nodeName); if (bean != null) { // Yes, there is already an instance return bean; } else { // create the bean and use the rest of the attributes as properties bean = beanClass.newInstance(); for (Map.Entry entry : m.entrySet()) { String key = (String) entry.getKey(); if (key.equals("config-class")) continue; org.apache.commons.beanutils.BeanUtils.setProperty(bean, key, entry.getValue()); } // Store it in map beans.put(nodeName, bean); return bean; } }
From source file:nz.co.senanque.madura.configuration.XMLBeanFactory.java
public synchronized Object createBean(Class beanClass, BeanDeclaration decl, Object param) throws Exception { Map m = decl.getBeanProperties(); XMLBeanDeclaration xmlDecl = (XMLBeanDeclaration) decl; ConfigurationNode n = xmlDecl.getNode(); String nodeName = n.getName(); n = n.getParentNode(); while (n != null) { if (n.getName() != null) nodeName = n.getName() + "/" + nodeName; n = n.getParentNode();//w w w. j a v a 2 s . c o m } Object bean = beans.get(nodeName); if (bean != null) { // Yes, there is already an instance return bean; } String fileLocation = (String) m.get("fileLocation"); Document doc = null; SAXBuilder sax = new SAXBuilder(); if (fileLocation == null) { // build the doc from the children ConfigurationNode node = xmlDecl.getNode(); doc = new Document(); doc.addContent(makeElement(node)); } else { InputStream in = new FileInputStream(fileLocation); doc = sax.build(in); } bean = doc; // Store it in map beans.put(nodeName, bean); return bean; }
From source file:org.ssh.test.conf.IConfiguration.java
/** * Determines the configuration that owns the specified node. * /*w w w. j a v a2s .co m*/ * @param node * the node * @return the owning configuration */ private Configuration findSourceConfiguration(ConfigurationNode node) { synchronized (getReloadLock()) { ConfigurationNode root = null; ConfigurationNode current = node; // find the root node in this hierarchy while (current != null) { root = current; current = current.getParentNode(); } // Check with the root nodes of the child configurations for (ConfigData cd : configurations) { if (root == cd.getRootNode()) { return cd.getConfiguration(); } } } return this; }
From source file:org.zaproxy.admin.VerifyCoreZapVersionsEntries.java
private static String getHierarchicalName(ConfigurationNode node) { if (node.getParentNode() == null) { return node.getName(); }/*from w ww . jav a2 s . c o m*/ return getHierarchicalName(node.getParentNode()) + "." + node.getName(); }