1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.config.spring.parsers.collection; |
12 | |
|
13 | |
import org.mule.config.spring.parsers.AbstractChildDefinitionParser; |
14 | |
import org.mule.config.spring.util.SpringXMLUtils; |
15 | |
import org.mule.util.StringUtils; |
16 | |
|
17 | |
import org.springframework.beans.factory.support.BeanDefinitionBuilder; |
18 | |
import org.springframework.beans.factory.xml.ParserContext; |
19 | |
import org.w3c.dom.Attr; |
20 | |
import org.w3c.dom.Element; |
21 | |
|
22 | |
public class AttributeListEntryDefinitionParser |
23 | |
extends AbstractChildDefinitionParser implements DynamicAttributeDefinitionParser |
24 | |
{ |
25 | |
|
26 | |
private String setterMethod; |
27 | |
private String attributeName; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
public AttributeListEntryDefinitionParser(String setterMethod) |
33 | |
{ |
34 | 0 | this(setterMethod, null); |
35 | 0 | } |
36 | |
|
37 | |
public AttributeListEntryDefinitionParser(String setterMethod, String attributeName) |
38 | 0 | { |
39 | 0 | this.setterMethod = setterMethod; |
40 | 0 | setAttributeName(attributeName); |
41 | 0 | } |
42 | |
|
43 | |
public String getPropertyName(Element element) |
44 | |
{ |
45 | 0 | return setterMethod; |
46 | |
} |
47 | |
|
48 | |
protected Class getBeanClass(Element element) |
49 | |
{ |
50 | 0 | return ChildListEntryDefinitionParser.ListEntry.class; |
51 | |
} |
52 | |
|
53 | |
public void setAttributeName(String attributeName) |
54 | |
{ |
55 | 0 | this.attributeName = attributeName; |
56 | 0 | } |
57 | |
|
58 | |
protected void parseChild(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) |
59 | |
{ |
60 | 0 | Attr attribute = element.getAttributeNode(attributeName); |
61 | 0 | if (null == attribute || StringUtils.isEmpty(attribute.getNodeValue())) |
62 | |
{ |
63 | 0 | throw new IllegalStateException( |
64 | |
"No value for " + attributeName + " in " + SpringXMLUtils.elementToString(element)); |
65 | |
} |
66 | 0 | String value = attribute.getNodeValue(); |
67 | 0 | builder.getRawBeanDefinition().setSource(new ChildListEntryDefinitionParser.ListEntry(value)); |
68 | 0 | this.postProcess(parserContext, getBeanAssembler(element, builder), element); |
69 | 0 | } |
70 | |
|
71 | |
} |