1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.mule.config.endpoint; |
11 | |
|
12 | |
import org.mule.MessageExchangePattern; |
13 | |
import org.mule.api.annotations.meta.ChannelType; |
14 | |
import org.mule.api.transport.Connector; |
15 | |
import org.mule.util.StringUtils; |
16 | |
|
17 | |
import java.lang.annotation.Annotation; |
18 | |
import java.lang.reflect.Method; |
19 | |
import java.util.HashMap; |
20 | |
import java.util.Map; |
21 | |
import java.util.Properties; |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
public class AnnotatedEndpointData |
28 | |
{ |
29 | |
private String encoding; |
30 | 0 | private Map properties = new HashMap(); |
31 | |
private String connectorName; |
32 | |
private String transformers; |
33 | |
private String address; |
34 | |
private String name; |
35 | |
private String filter; |
36 | |
private String correlationExpression; |
37 | |
private Connector connector; |
38 | |
private MessageExchangePattern mep; |
39 | |
private ChannelType type; |
40 | |
private Annotation annotation; |
41 | |
|
42 | |
public AnnotatedEndpointData(MessageExchangePattern mep, ChannelType type, Annotation annotation) |
43 | 0 | { |
44 | 0 | this.mep = mep; |
45 | 0 | this.annotation = annotation; |
46 | 0 | this.type = type; |
47 | 0 | } |
48 | |
|
49 | |
protected String emptyToNull(String value) |
50 | |
{ |
51 | 0 | return (StringUtils.EMPTY.equals(value) ? null : value); |
52 | |
} |
53 | |
|
54 | |
|
55 | |
public String getConnectorName() |
56 | |
{ |
57 | 0 | return connectorName; |
58 | |
} |
59 | |
|
60 | |
public String getEncoding() |
61 | |
{ |
62 | 0 | return encoding; |
63 | |
} |
64 | |
|
65 | |
public String getAddress() |
66 | |
{ |
67 | 0 | return address; |
68 | |
} |
69 | |
|
70 | |
public Map getProperties() |
71 | |
{ |
72 | 0 | return properties; |
73 | |
} |
74 | |
|
75 | |
public ChannelType getType() |
76 | |
{ |
77 | 0 | return type; |
78 | |
} |
79 | |
|
80 | |
public String getFilter() |
81 | |
{ |
82 | 0 | return filter; |
83 | |
} |
84 | |
|
85 | |
public String getCorrelationExpression() |
86 | |
{ |
87 | 0 | return correlationExpression; |
88 | |
} |
89 | |
|
90 | |
public Connector getConnector() |
91 | |
{ |
92 | 0 | return connector; |
93 | |
} |
94 | |
|
95 | |
public void setConnector(Connector connector) |
96 | |
{ |
97 | 0 | this.connector = connector; |
98 | 0 | } |
99 | |
|
100 | |
public String getTransformers() |
101 | |
{ |
102 | 0 | return transformers; |
103 | |
} |
104 | |
|
105 | |
public String getName() |
106 | |
{ |
107 | 0 | return name; |
108 | |
} |
109 | |
|
110 | |
public void setName(String name) |
111 | |
{ |
112 | 0 | this.name = emptyToNull(name); |
113 | 0 | } |
114 | |
|
115 | |
public void setEncoding(String encoding) |
116 | |
{ |
117 | 0 | this.encoding = emptyToNull(encoding); |
118 | 0 | } |
119 | |
|
120 | |
public Annotation getAnnotation() |
121 | |
{ |
122 | 0 | return annotation; |
123 | |
} |
124 | |
|
125 | |
public void setProperties(Map properties) |
126 | |
{ |
127 | 0 | if (properties == null) |
128 | |
{ |
129 | 0 | return; |
130 | |
} |
131 | |
|
132 | 0 | this.properties = properties; |
133 | |
|
134 | 0 | if (properties != null) |
135 | |
{ |
136 | 0 | if (properties.containsKey("connectorName")) |
137 | |
{ |
138 | 0 | setConnectorName((String) properties.remove("connectorName")); |
139 | |
} |
140 | |
} |
141 | 0 | } |
142 | |
|
143 | |
public void setConnectorName(String connectorName) |
144 | |
{ |
145 | 0 | this.connectorName = emptyToNull(connectorName); |
146 | 0 | } |
147 | |
|
148 | |
public void setTransformers(String transformers) |
149 | |
{ |
150 | 0 | this.transformers = emptyToNull(transformers); |
151 | 0 | } |
152 | |
|
153 | |
public void setAddress(String address) |
154 | |
{ |
155 | 0 | this.address = emptyToNull(address); |
156 | 0 | } |
157 | |
|
158 | |
public void setFilter(String filter) |
159 | |
{ |
160 | 0 | this.filter = emptyToNull(filter); |
161 | 0 | } |
162 | |
|
163 | |
public void setCorrelationExpression(String correlationExpression) |
164 | |
{ |
165 | 0 | this.correlationExpression = emptyToNull(correlationExpression); |
166 | 0 | } |
167 | |
|
168 | |
public MessageExchangePattern getMep() |
169 | |
{ |
170 | 0 | return mep; |
171 | |
} |
172 | |
|
173 | |
|
174 | |
|
175 | |
public void setMEPUsingMethod(Method method) |
176 | |
{ |
177 | 0 | if (method.getReturnType().equals(Void.TYPE)) |
178 | |
{ |
179 | 0 | mep = MessageExchangePattern.ONE_WAY; |
180 | |
} |
181 | |
else |
182 | |
{ |
183 | 0 | mep = MessageExchangePattern.REQUEST_RESPONSE; |
184 | |
} |
185 | |
|
186 | 0 | } |
187 | |
|
188 | |
public static Map convert(String[] properties) |
189 | |
{ |
190 | 0 | if (properties.length > 0) |
191 | |
{ |
192 | 0 | Properties props = new Properties(); |
193 | 0 | for (int i = 0; i < properties.length; i++) |
194 | |
{ |
195 | 0 | String property = properties[i]; |
196 | 0 | if (property.length() == 0) |
197 | |
{ |
198 | 0 | continue; |
199 | |
} |
200 | 0 | int x = property.indexOf("="); |
201 | 0 | if (x < 1) |
202 | |
{ |
203 | 0 | throw new IllegalArgumentException("Property string is malformed: " + property); |
204 | |
} |
205 | 0 | String value = property.substring(x + 1); |
206 | 0 | property = property.substring(0, x); |
207 | 0 | props.setProperty(property, value); |
208 | |
|
209 | |
} |
210 | 0 | return props; |
211 | |
} |
212 | 0 | return null; |
213 | |
} |
214 | |
} |