1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.config.spring.parsers.generic; |
12 | |
|
13 | |
import org.mule.config.spring.parsers.assembly.BeanAssembler; |
14 | |
|
15 | |
import org.springframework.beans.factory.support.AbstractBeanDefinition; |
16 | |
import org.springframework.beans.factory.xml.ParserContext; |
17 | |
import org.w3c.dom.Element; |
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
public class NamedDefinitionParser extends ParentDefinitionParser |
24 | |
{ |
25 | |
|
26 | |
private String name; |
27 | 0 | private boolean isDynamic = false; |
28 | |
|
29 | |
public NamedDefinitionParser() |
30 | 0 | { |
31 | 0 | isDynamic = true; |
32 | 0 | } |
33 | |
|
34 | |
public NamedDefinitionParser(String name) |
35 | 0 | { |
36 | 0 | addIgnored(ATTRIBUTE_NAME); |
37 | 0 | this.name = name; |
38 | 0 | } |
39 | |
|
40 | |
public String getName() |
41 | |
{ |
42 | 0 | return name; |
43 | |
} |
44 | |
|
45 | |
public void setName(String name) |
46 | |
{ |
47 | 0 | this.name = name; |
48 | 0 | } |
49 | |
|
50 | |
protected String getParentBeanName(Element element) |
51 | |
{ |
52 | 0 | return name; |
53 | |
} |
54 | |
|
55 | |
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) |
56 | |
{ |
57 | 0 | if (isDynamic) |
58 | |
{ |
59 | 0 | if (element.hasAttribute(ATTRIBUTE_NAME)) |
60 | |
{ |
61 | 0 | setName(element.getAttribute(ATTRIBUTE_NAME)); |
62 | 0 | element.removeAttribute(ATTRIBUTE_NAME); |
63 | |
} |
64 | |
else |
65 | |
{ |
66 | 0 | throw new IllegalStateException("Missing name attribute for " + element.getLocalName()); |
67 | |
} |
68 | |
} |
69 | 0 | return super.parseInternal(element, parserContext); |
70 | |
} |
71 | |
|
72 | |
protected void postProcess(ParserContext context, BeanAssembler assembler, Element element) |
73 | |
{ |
74 | 0 | super.postProcess(context, assembler, element); |
75 | |
|
76 | 0 | AutoIdUtils.ensureUniqueId(element, "named"); |
77 | 0 | } |
78 | |
} |