1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.config.spring.parsers.specific.endpoint.support; |
12 | |
|
13 | |
import org.mule.api.config.MuleProperties; |
14 | |
import org.mule.config.spring.parsers.AbstractMuleBeanDefinitionParser; |
15 | |
import org.mule.config.spring.parsers.MuleChildDefinitionParser; |
16 | |
import org.mule.config.spring.parsers.MuleDefinitionParser; |
17 | |
import org.mule.config.spring.parsers.delegate.AbstractSingleParentFamilyDefinitionParser; |
18 | |
import org.mule.config.spring.parsers.generic.AttributePropertiesDefinitionParser; |
19 | |
import org.mule.config.spring.parsers.processors.BlockAttribute; |
20 | |
import org.mule.config.spring.parsers.processors.CheckExclusiveAttributes; |
21 | |
import org.mule.config.spring.parsers.processors.CheckRequiredAttributes; |
22 | |
import org.mule.endpoint.AbstractEndpointBuilder; |
23 | |
import org.mule.endpoint.URIBuilder; |
24 | |
|
25 | |
import org.apache.commons.logging.Log; |
26 | |
import org.apache.commons.logging.LogFactory; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
public class AddressedEndpointDefinitionParser extends AbstractSingleParentFamilyDefinitionParser |
38 | |
{ |
39 | |
|
40 | 0 | protected Log logger = LogFactory.getLog(getClass()); |
41 | |
public static final boolean META = ChildAddressDefinitionParser.META; |
42 | |
public static final boolean PROTOCOL = ChildAddressDefinitionParser.PROTOCOL; |
43 | |
public static final String PROPERTIES = "properties"; |
44 | 0 | public static final String[] RESTRICTED_ENDPOINT_ATTRIBUTES = |
45 | |
new String[]{MuleProperties.EXCHANGE_PATTERN, |
46 | |
AbstractEndpointBuilder.PROPERTY_RESPONSE_TIMEOUT, "encoding", |
47 | |
"connector", "createConnector", "transformer", "responseTransformer", "disableTransportTransformer", "mimeType"}; |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
public AddressedEndpointDefinitionParser(String protocol, MuleDefinitionParser endpointParser) |
57 | |
{ |
58 | 0 | this(protocol, PROTOCOL, endpointParser); |
59 | 0 | } |
60 | |
|
61 | |
public AddressedEndpointDefinitionParser(String metaOrProtocol, boolean isMeta, MuleDefinitionParser endpointParser) |
62 | |
{ |
63 | 0 | this(metaOrProtocol, isMeta, endpointParser, new String[]{}, new String[]{}); |
64 | 0 | } |
65 | |
|
66 | |
public AddressedEndpointDefinitionParser(String metaOrProtocol, boolean isMeta, |
67 | |
MuleDefinitionParser endpointParser, |
68 | |
String[] requiredAddressAttributes, |
69 | |
String[] requiredProperties) |
70 | |
{ |
71 | 0 | this(metaOrProtocol, isMeta, endpointParser, |
72 | |
RESTRICTED_ENDPOINT_ATTRIBUTES, URIBuilder.ALL_ATTRIBUTES, |
73 | |
new String[][]{requiredAddressAttributes}, new String[][]{requiredProperties}); |
74 | 0 | } |
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
public AddressedEndpointDefinitionParser(String metaOrProtocol, boolean isMeta, |
89 | |
MuleDefinitionParser endpointParser, |
90 | |
String[] endpointAttributes, |
91 | |
String[] addressAttributes, |
92 | |
String[][] requiredAddressAttributes, |
93 | |
String[][] requiredProperties) |
94 | 0 | { |
95 | |
|
96 | 0 | enableAttributes(endpointParser, endpointAttributes); |
97 | 0 | enableAttribute(endpointParser, AbstractMuleBeanDefinitionParser.ATTRIBUTE_NAME); |
98 | 0 | addDelegate(endpointParser); |
99 | |
|
100 | |
|
101 | |
|
102 | 0 | MuleChildDefinitionParser addressParser = |
103 | |
new AddressParser(metaOrProtocol, isMeta, addressAttributes, requiredAddressAttributes); |
104 | |
|
105 | |
|
106 | 0 | addHandledException(BlockAttribute.BlockAttributeException.class); |
107 | 0 | addChildDelegate(addressParser); |
108 | |
|
109 | 0 | MuleChildDefinitionParser propertiesParser = |
110 | |
new PropertiesParser(PROPERTIES, endpointAttributes, requiredAddressAttributes, requiredProperties); |
111 | 0 | addChildDelegate(propertiesParser); |
112 | 0 | } |
113 | |
|
114 | |
private static class AddressParser extends ChildAddressDefinitionParser |
115 | |
{ |
116 | |
|
117 | |
public AddressParser(String metaOrProtocol, boolean isMeta, |
118 | |
String[] addressAttributes, String[][] requiredAddressAttributes) |
119 | |
{ |
120 | 0 | super(metaOrProtocol, isMeta); |
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | 0 | registerPreProcessor(new BlockAttribute(AbstractMuleBeanDefinitionParser.ATTRIBUTE_REF)); |
128 | |
|
129 | |
|
130 | 0 | enableAttributes(this, addressAttributes); |
131 | |
|
132 | |
|
133 | |
|
134 | 0 | String[][] addressAttributeSets = |
135 | |
new String[(null != requiredAddressAttributes ? requiredAddressAttributes.length : 0) + 2][]; |
136 | 0 | addressAttributeSets[0] = new String[]{URIBuilder.ADDRESS}; |
137 | 0 | addressAttributeSets[1] = new String[]{AbstractMuleBeanDefinitionParser.ATTRIBUTE_REF}; |
138 | 0 | if (null != requiredAddressAttributes) |
139 | |
{ |
140 | 0 | enableAttributes(this, requiredAddressAttributes); |
141 | 0 | System.arraycopy(requiredAddressAttributes, 0, addressAttributeSets, 2, requiredAddressAttributes.length); |
142 | |
} |
143 | 0 | registerPreProcessor(new CheckRequiredAttributes(addressAttributeSets)); |
144 | |
|
145 | 0 | registerPreProcessor(new CheckExclusiveAttributes(addressAttributeSets)); |
146 | 0 | } |
147 | |
|
148 | |
} |
149 | |
|
150 | |
private static class PropertiesParser extends AttributePropertiesDefinitionParser |
151 | |
{ |
152 | |
|
153 | |
public PropertiesParser(String setter, |
154 | |
String[] endpointAttributes, String[][] requiredAddressAttributes, String[][] requiredProperties) |
155 | |
{ |
156 | 0 | super(setter); |
157 | |
|
158 | |
|
159 | |
|
160 | 0 | disableAttributes(this, endpointAttributes); |
161 | 0 | disableAttributes(this, URIBuilder.ALL_ATTRIBUTES); |
162 | 0 | disableAttributes(this, requiredAddressAttributes); |
163 | 0 | disableAttribute(this, AbstractMuleBeanDefinitionParser.ATTRIBUTE_NAME); |
164 | 0 | disableAttribute(this, AbstractMuleBeanDefinitionParser.ATTRIBUTE_REF); |
165 | 0 | if (null != requiredProperties && requiredProperties.length > 0 && |
166 | |
null != requiredProperties[0] && requiredProperties[0].length > 0) |
167 | |
{ |
168 | |
|
169 | |
|
170 | 0 | String[][] requiredPropertiesSets = new String[requiredProperties.length + 1][]; |
171 | 0 | requiredPropertiesSets[0] = new String[]{AbstractMuleBeanDefinitionParser.ATTRIBUTE_REF}; |
172 | 0 | System.arraycopy(requiredProperties, 0, requiredPropertiesSets, 1, requiredProperties.length); |
173 | 0 | registerPreProcessor(new CheckRequiredAttributes(requiredPropertiesSets)); |
174 | |
} |
175 | 0 | } |
176 | |
|
177 | |
} |
178 | |
|
179 | |
} |