1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.mule.config.spring.handlers; |
11 | |
|
12 | |
import org.mule.config.spring.factories.InboundEndpointFactoryBean; |
13 | |
import org.mule.config.spring.factories.OutboundEndpointFactoryBean; |
14 | |
import org.mule.config.spring.parsers.MuleDefinitionParser; |
15 | |
import org.mule.config.spring.parsers.MuleDefinitionParserConfiguration; |
16 | |
import org.mule.config.spring.parsers.PostProcessor; |
17 | |
import org.mule.config.spring.parsers.PreProcessor; |
18 | |
import org.mule.config.spring.parsers.assembly.configuration.ValueMap; |
19 | |
import org.mule.config.spring.parsers.generic.MuleOrphanDefinitionParser; |
20 | |
import org.mule.config.spring.parsers.specific.endpoint.TransportEndpointDefinitionParser; |
21 | |
import org.mule.config.spring.parsers.specific.endpoint.TransportGlobalEndpointDefinitionParser; |
22 | |
import org.mule.config.spring.parsers.specific.endpoint.support.AddressedEndpointDefinitionParser; |
23 | |
import org.mule.endpoint.EndpointURIEndpointBuilder; |
24 | |
|
25 | |
import java.util.HashSet; |
26 | |
import java.util.Iterator; |
27 | |
import java.util.Map; |
28 | |
import java.util.Set; |
29 | |
|
30 | |
import org.springframework.beans.factory.config.BeanDefinition; |
31 | |
import org.springframework.beans.factory.xml.BeanDefinitionParser; |
32 | |
import org.springframework.beans.factory.xml.NamespaceHandlerSupport; |
33 | |
import org.springframework.beans.factory.xml.ParserContext; |
34 | |
import org.w3c.dom.Element; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | 0 | public abstract class AbstractMuleNamespaceHandler extends NamespaceHandlerSupport |
41 | |
{ |
42 | |
|
43 | |
public static final String GLOBAL_ENDPOINT = "endpoint"; |
44 | |
public static final String INBOUND_ENDPOINT = "inbound-endpoint"; |
45 | |
public static final String OUTBOUND_ENDPOINT = "outbound-endpoint"; |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
protected final void registerIgnoredElement(String name) |
51 | |
{ |
52 | 0 | registerBeanDefinitionParser(name, new IgnoredDefinitionParser()); |
53 | 0 | } |
54 | |
|
55 | |
protected MuleDefinitionParserConfiguration registerConnectorDefinitionParser(Class connectorClass) |
56 | |
{ |
57 | 0 | return registerConnectorDefinitionParser( new MuleOrphanDefinitionParser(connectorClass, true)); |
58 | |
} |
59 | |
|
60 | |
protected MuleDefinitionParserConfiguration registerConnectorDefinitionParser(MuleDefinitionParser parser) |
61 | |
{ |
62 | 0 | registerBeanDefinitionParser("connector", parser); |
63 | 0 | return parser; |
64 | |
} |
65 | |
|
66 | |
protected MuleDefinitionParserConfiguration registerMuleBeanDefinitionParser(String name, MuleDefinitionParser parser) |
67 | |
{ |
68 | 0 | registerBeanDefinitionParser(name, parser); |
69 | 0 | return parser; |
70 | |
} |
71 | |
|
72 | |
protected MuleDefinitionParserConfiguration registerStandardTransportEndpoints(String protocol, String[] requiredAttributes) |
73 | |
{ |
74 | 0 | return new RegisteredMdps(protocol, AddressedEndpointDefinitionParser.PROTOCOL, requiredAttributes); |
75 | |
} |
76 | |
|
77 | |
protected MuleDefinitionParserConfiguration registerMetaTransportEndpoints(String protocol) |
78 | |
{ |
79 | 0 | return new RegisteredMdps(protocol, AddressedEndpointDefinitionParser.META, new String[]{}); |
80 | |
} |
81 | |
|
82 | 0 | private class IgnoredDefinitionParser implements BeanDefinitionParser |
83 | |
{ |
84 | |
public BeanDefinition parse(Element element, ParserContext parserContext) |
85 | |
{ |
86 | 0 | return null; |
87 | |
} |
88 | |
} |
89 | |
|
90 | |
protected Class getInboundEndpointFactoryBeanClass() |
91 | |
{ |
92 | 0 | return InboundEndpointFactoryBean.class; |
93 | |
} |
94 | |
|
95 | |
protected Class getOutboundEndpointFactoryBeanClass() |
96 | |
{ |
97 | 0 | return OutboundEndpointFactoryBean.class; |
98 | |
} |
99 | |
|
100 | |
protected Class getGlobalEndpointBuilderBeanClass() |
101 | |
{ |
102 | 0 | return EndpointURIEndpointBuilder.class; |
103 | |
} |
104 | |
|
105 | |
|
106 | 0 | private class RegisteredMdps implements MuleDefinitionParserConfiguration |
107 | |
{ |
108 | |
|
109 | 0 | private Set bdps = new HashSet(); |
110 | |
|
111 | |
private RegisteredMdps(String protocol, boolean isMeta, String[] requiredAttributes) |
112 | 0 | { |
113 | 0 | registerBeanDefinitionParser("endpoint", add(new TransportGlobalEndpointDefinitionParser(protocol, isMeta, AbstractMuleNamespaceHandler.this.getGlobalEndpointBuilderBeanClass(), requiredAttributes, new String[]{}))); |
114 | 0 | registerBeanDefinitionParser("inbound-endpoint", add(new TransportEndpointDefinitionParser(protocol, isMeta, AbstractMuleNamespaceHandler.this.getInboundEndpointFactoryBeanClass(), requiredAttributes, new String[]{}))); |
115 | 0 | registerBeanDefinitionParser("outbound-endpoint", add(new TransportEndpointDefinitionParser(protocol, isMeta, AbstractMuleNamespaceHandler.this.getOutboundEndpointFactoryBeanClass(), requiredAttributes, new String[]{}))); |
116 | 0 | } |
117 | |
|
118 | |
private MuleDefinitionParser add(MuleDefinitionParser bdp) |
119 | |
{ |
120 | 0 | bdps.add(bdp); |
121 | 0 | return bdp; |
122 | |
} |
123 | |
|
124 | |
public MuleDefinitionParserConfiguration registerPreProcessor(PreProcessor preProcessor) |
125 | |
{ |
126 | 0 | for (Iterator bdp = bdps.iterator(); bdp.hasNext();) |
127 | |
{ |
128 | 0 | ((MuleDefinitionParserConfiguration) bdp.next()).registerPreProcessor(preProcessor); |
129 | |
} |
130 | 0 | return this; |
131 | |
} |
132 | |
|
133 | |
public MuleDefinitionParserConfiguration registerPostProcessor(PostProcessor postProcessor) |
134 | |
{ |
135 | 0 | for (Iterator bdp = bdps.iterator(); bdp.hasNext();) |
136 | |
{ |
137 | 0 | ((MuleDefinitionParserConfiguration) bdp.next()).registerPostProcessor(postProcessor); |
138 | |
} |
139 | 0 | return this; |
140 | |
} |
141 | |
|
142 | |
public MuleDefinitionParserConfiguration addReference(String propertyName) |
143 | |
{ |
144 | 0 | for (Iterator bdp = bdps.iterator(); bdp.hasNext();) |
145 | |
{ |
146 | 0 | ((MuleDefinitionParserConfiguration) bdp.next()).addReference(propertyName); |
147 | |
} |
148 | 0 | return this; |
149 | |
} |
150 | |
|
151 | |
public MuleDefinitionParserConfiguration addMapping(String propertyName, Map mappings) |
152 | |
{ |
153 | 0 | for (Iterator bdp = bdps.iterator(); bdp.hasNext();) |
154 | |
{ |
155 | 0 | ((MuleDefinitionParserConfiguration) bdp.next()).addMapping(propertyName, mappings); |
156 | |
} |
157 | 0 | return this; |
158 | |
} |
159 | |
|
160 | |
public MuleDefinitionParserConfiguration addMapping(String propertyName, String mappings) |
161 | |
{ |
162 | 0 | for (Iterator bdp = bdps.iterator(); bdp.hasNext();) |
163 | |
{ |
164 | 0 | ((MuleDefinitionParserConfiguration) bdp.next()).addMapping(propertyName, mappings); |
165 | |
} |
166 | 0 | return this; |
167 | |
} |
168 | |
|
169 | |
public MuleDefinitionParserConfiguration addMapping(String propertyName, ValueMap mappings) |
170 | |
{ |
171 | 0 | for (Iterator bdp = bdps.iterator(); bdp.hasNext();) |
172 | |
{ |
173 | 0 | ((MuleDefinitionParserConfiguration) bdp.next()).addMapping(propertyName, mappings); |
174 | |
} |
175 | 0 | return this; |
176 | |
} |
177 | |
|
178 | |
public MuleDefinitionParserConfiguration addAlias(String alias, String propertyName) |
179 | |
{ |
180 | 0 | for (Iterator bdp = bdps.iterator(); bdp.hasNext();) |
181 | |
{ |
182 | 0 | ((MuleDefinitionParserConfiguration) bdp.next()).addAlias(alias, propertyName); |
183 | |
} |
184 | 0 | return this; |
185 | |
} |
186 | |
|
187 | |
public MuleDefinitionParserConfiguration addCollection(String propertyName) |
188 | |
{ |
189 | 0 | for (Iterator bdp = bdps.iterator(); bdp.hasNext();) |
190 | |
{ |
191 | 0 | ((MuleDefinitionParserConfiguration) bdp.next()).addCollection(propertyName); |
192 | |
} |
193 | 0 | return this; |
194 | |
} |
195 | |
|
196 | |
public MuleDefinitionParserConfiguration addIgnored(String propertyName) |
197 | |
{ |
198 | 0 | for (Iterator bdp = bdps.iterator(); bdp.hasNext();) |
199 | |
{ |
200 | 0 | ((MuleDefinitionParserConfiguration) bdp.next()).addIgnored(propertyName); |
201 | |
} |
202 | 0 | return this; |
203 | |
} |
204 | |
|
205 | |
public MuleDefinitionParserConfiguration removeIgnored(String propertyName) |
206 | |
{ |
207 | 0 | for (Iterator bdp = bdps.iterator(); bdp.hasNext();) |
208 | |
{ |
209 | 0 | ((MuleDefinitionParserConfiguration) bdp.next()).removeIgnored(propertyName); |
210 | |
} |
211 | 0 | return this; |
212 | |
} |
213 | |
|
214 | |
public MuleDefinitionParserConfiguration setIgnoredDefault(boolean ignoreAll) |
215 | |
{ |
216 | 0 | for (Iterator bdp = bdps.iterator(); bdp.hasNext();) |
217 | |
{ |
218 | 0 | ((MuleDefinitionParserConfiguration) bdp.next()).setIgnoredDefault(ignoreAll); |
219 | |
} |
220 | 0 | return this; |
221 | |
} |
222 | |
|
223 | |
public MuleDefinitionParserConfiguration addBeanFlag(String flag) |
224 | |
{ |
225 | 0 | for (Iterator bdp = bdps.iterator(); bdp.hasNext();) |
226 | |
{ |
227 | 0 | ((MuleDefinitionParserConfiguration) bdp.next()).addBeanFlag(flag); |
228 | |
} |
229 | 0 | return this; |
230 | |
} |
231 | |
|
232 | |
} |
233 | |
|
234 | |
} |