1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.config.spring.parsers.specific; |
12 | |
|
13 | |
import org.mule.config.spring.parsers.AbstractMuleBeanDefinitionParser; |
14 | |
import org.mule.config.spring.parsers.MuleDefinitionParser; |
15 | |
import org.mule.config.spring.parsers.PreProcessor; |
16 | |
import org.mule.config.spring.parsers.assembly.configuration.PropertyConfiguration; |
17 | |
import org.mule.config.spring.parsers.delegate.AbstractParallelDelegatingDefinitionParser; |
18 | |
import org.mule.config.spring.util.SpringXMLUtils; |
19 | |
import org.mule.util.StringUtils; |
20 | |
|
21 | |
import org.springframework.beans.factory.xml.ParserContext; |
22 | |
import org.w3c.dom.Attr; |
23 | |
import org.w3c.dom.Element; |
24 | |
import org.w3c.dom.NamedNodeMap; |
25 | |
import org.w3c.dom.Node; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
public class ComponentDelegatingDefinitionParser extends AbstractParallelDelegatingDefinitionParser |
46 | |
{ |
47 | |
|
48 | |
private MuleDefinitionParser normalConfig; |
49 | |
private MuleDefinitionParser shortcutConfig; |
50 | |
|
51 | |
public ComponentDelegatingDefinitionParser(Class clazz) |
52 | 0 | { |
53 | 0 | normalConfig = new ComponentDefinitionParser(clazz); |
54 | 0 | shortcutConfig = new ShortcutComponentDefinitionParser(clazz); |
55 | 0 | addDelegate(normalConfig); |
56 | 0 | addDelegate(shortcutConfig); |
57 | 0 | registerPreProcessor(new CheckExclusiveClassAttributeObjectFactory()); |
58 | 0 | } |
59 | |
|
60 | |
@Override |
61 | |
protected MuleDefinitionParser getDelegate(Element element, ParserContext parserContext) |
62 | |
{ |
63 | 0 | if (StringUtils.isEmpty(element.getAttribute(AbstractMuleBeanDefinitionParser.ATTRIBUTE_CLASS))) |
64 | |
{ |
65 | 0 | return normalConfig; |
66 | |
} |
67 | |
else |
68 | |
{ |
69 | 0 | return shortcutConfig; |
70 | |
} |
71 | |
} |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | 0 | class CheckExclusiveClassAttributeObjectFactory implements PreProcessor |
85 | |
{ |
86 | |
|
87 | |
private static final String OBJECT_FACTORY_ELEMENT_CONVENTION_SUFFIX = "object"; |
88 | |
|
89 | |
public void preProcess(PropertyConfiguration config, Element element) |
90 | |
{ |
91 | 0 | NamedNodeMap attributes = element.getAttributes(); |
92 | 0 | for (int i = 0; i < attributes.getLength(); i++) |
93 | |
{ |
94 | 0 | String alias = SpringXMLUtils.attributeName((Attr) attributes.item(i)); |
95 | 0 | if (alias.equals(AbstractMuleBeanDefinitionParser.ATTRIBUTE_CLASS)) |
96 | |
{ |
97 | 0 | for (int j = 0; j < element.getChildNodes().getLength(); j++) |
98 | |
{ |
99 | 0 | Node child = element.getChildNodes().item(j); |
100 | 0 | if (child instanceof Element |
101 | |
&& child.getLocalName().endsWith(OBJECT_FACTORY_ELEMENT_CONVENTION_SUFFIX)) |
102 | |
{ |
103 | 0 | StringBuffer message = new StringBuffer("The child element '"); |
104 | 0 | message.append(child.getLocalName()); |
105 | 0 | message.append("' cannot appear with the 'class' attribute"); |
106 | 0 | message.append(" in element "); |
107 | 0 | message.append(SpringXMLUtils.elementToString(element)); |
108 | 0 | message.append("."); |
109 | 0 | throw new CheckExclusiveClassAttributeObjectFactoryException(message.toString()); |
110 | |
} |
111 | |
} |
112 | |
} |
113 | |
} |
114 | 0 | } |
115 | |
} |
116 | |
|
117 | |
class CheckExclusiveClassAttributeObjectFactoryException extends IllegalStateException |
118 | |
{ |
119 | |
private static final long serialVersionUID = 4625276914151932111L; |
120 | |
|
121 | |
CheckExclusiveClassAttributeObjectFactoryException(String message) |
122 | 0 | { |
123 | 0 | super(message); |
124 | 0 | } |
125 | |
} |
126 | |
|
127 | |
} |