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 {
53 normalConfig = new ComponentDefinitionParser(clazz);
54 shortcutConfig = new ShortcutComponentDefinitionParser(clazz);
55 addDelegate(normalConfig);
56 addDelegate(shortcutConfig);
57 registerPreProcessor(new CheckExclusiveClassAttributeObjectFactory());
58 }
59
60 protected MuleDefinitionParser getDelegate(Element element, ParserContext parserContext)
61 {
62 if (StringUtils.isEmpty(element.getAttribute(AbstractMuleBeanDefinitionParser.ATTRIBUTE_CLASS)))
63 {
64 return normalConfig;
65 }
66 else
67 {
68 return shortcutConfig;
69 }
70 }
71
72
73
74
75
76
77
78
79
80 class CheckExclusiveClassAttributeObjectFactory implements PreProcessor
81 {
82
83 private static final String BINDING_CHILD_ELEMENT = "binding";
84 private static final String POOLING_PROFILE_CHILD_ELEMENT = "pooling-profile";
85 private static final String LIFECYCLE_ADAPTER_FACTORT_CHILD_ELEMENT = "lifecycle-adapter-factory";
86 private static final String ENTRY_POINT_RESOLVER_CHILD_ELEMENT = "entry-point-resolver";
87 private static final String ENTRY_POINT_RESOLVER_SET_CHILD_ELEMENT = "entry-point-resolver-set";
88
89 public void preProcess(PropertyConfiguration config, Element element)
90 {
91 NamedNodeMap attributes = element.getAttributes();
92 for (int i = 0; i < attributes.getLength(); i++)
93 {
94 String alias = SpringXMLUtils.attributeName((Attr) attributes.item(i));
95 if (alias.equals(AbstractMuleBeanDefinitionParser.ATTRIBUTE_CLASS))
96 {
97 for (int j = 0; j < element.getChildNodes().getLength(); j++)
98 {
99 Node child = element.getChildNodes().item(j);
100 if (child instanceof Element
101 && !(child.getLocalName().equals(BINDING_CHILD_ELEMENT)
102 || child.getLocalName().equals(POOLING_PROFILE_CHILD_ELEMENT)
103 || child.getLocalName().equals(ENTRY_POINT_RESOLVER_CHILD_ELEMENT)
104 || child.getLocalName().equals(ENTRY_POINT_RESOLVER_SET_CHILD_ELEMENT) || child.getLocalName()
105 .endsWith(LIFECYCLE_ADAPTER_FACTORT_CHILD_ELEMENT)))
106 {
107 StringBuffer message = new StringBuffer("The child element '");
108 message.append(child.getLocalName());
109 message.append("' cannot appear with the 'class' attribute");
110 message.append(" in element ");
111 message.append(SpringXMLUtils.elementToString(element));
112 message.append(".");
113 throw new CheckExclusiveClassAttributeObjectFactoryException(message.toString());
114 }
115 }
116
117 }
118 }
119 }
120 }
121
122 class CheckExclusiveClassAttributeObjectFactoryException extends IllegalStateException
123 {
124 private static final long serialVersionUID = 4625276914151932111L;
125
126 private CheckExclusiveClassAttributeObjectFactoryException(String message)
127 {
128 super(message);
129 }
130 }
131
132 }