|
6 | 6 | import org.w3c.dom.NodeList; |
7 | 7 | import us.codecraft.tinyioc.AbstractBeanDefinitionReader; |
8 | 8 | import us.codecraft.tinyioc.BeanDefinition; |
| 9 | +import us.codecraft.tinyioc.BeanReference; |
9 | 10 | import us.codecraft.tinyioc.PropertyValue; |
10 | 11 | import us.codecraft.tinyioc.io.ResourceLoader; |
11 | 12 |
|
@@ -57,22 +58,32 @@ protected void parseBeanDefinitions(Element root) { |
57 | 58 | protected void processBeanDefinition(Element ele) { |
58 | 59 | String name = ele.getAttribute("name"); |
59 | 60 | String className = ele.getAttribute("class"); |
60 | | - BeanDefinition beanDefinition = new BeanDefinition(); |
61 | | - processProperty(ele,beanDefinition); |
62 | | - beanDefinition.setBeanClassName(className); |
| 61 | + BeanDefinition beanDefinition = new BeanDefinition(); |
| 62 | + processProperty(ele, beanDefinition); |
| 63 | + beanDefinition.setBeanClassName(className); |
63 | 64 | getRegistry().put(name, beanDefinition); |
64 | 65 | } |
65 | 66 |
|
66 | | - private void processProperty(Element ele,BeanDefinition beanDefinition) { |
67 | | - NodeList propertyNode = ele.getElementsByTagName("property"); |
68 | | - for (int i = 0; i < propertyNode.getLength(); i++) { |
69 | | - Node node = propertyNode.item(i); |
70 | | - if (node instanceof Element) { |
71 | | - Element propertyEle = (Element) node; |
72 | | - String name = propertyEle.getAttribute("name"); |
73 | | - String value = propertyEle.getAttribute("value"); |
74 | | - beanDefinition.getPropertyValues().addPropertyValue(new PropertyValue(name,value)); |
75 | | - } |
76 | | - } |
77 | | - } |
| 67 | + private void processProperty(Element ele, BeanDefinition beanDefinition) { |
| 68 | + NodeList propertyNode = ele.getElementsByTagName("property"); |
| 69 | + for (int i = 0; i < propertyNode.getLength(); i++) { |
| 70 | + Node node = propertyNode.item(i); |
| 71 | + if (node instanceof Element) { |
| 72 | + Element propertyEle = (Element) node; |
| 73 | + String name = propertyEle.getAttribute("name"); |
| 74 | + String value = propertyEle.getAttribute("value"); |
| 75 | + if (value != null && value.length() > 0) { |
| 76 | + beanDefinition.getPropertyValues().addPropertyValue(new PropertyValue(name, value)); |
| 77 | + } else { |
| 78 | + String ref = propertyEle.getAttribute("ref"); |
| 79 | + if (ref == null || ref.length() == 0) { |
| 80 | + throw new IllegalArgumentException("Configuration problem: <property> element for property '" |
| 81 | + + name + "' must specify a ref or value"); |
| 82 | + } |
| 83 | + BeanReference beanReference = new BeanReference(ref); |
| 84 | + beanDefinition.getPropertyValues().addPropertyValue(new PropertyValue(name, beanReference)); |
| 85 | + } |
| 86 | + } |
| 87 | + } |
| 88 | + } |
78 | 89 | } |
0 commit comments