List of usage examples for org.apache.commons.configuration.beanutils XMLBeanDeclaration getNode
public ConfigurationNode getNode()
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();//from w w w . j a va 2s. c o m 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; } 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();//from ww w . j a va 2s .c o m 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.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();//from w w w .ja v a 2 s . c o m 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; } 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();//from w ww . j a v a 2s. c o m 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; } 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; }