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