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