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