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