1 | |
package org.kuali.rice.ksb.api.bus.support; |
2 | |
|
3 | |
import org.kuali.rice.core.api.CoreConstants; |
4 | |
import org.kuali.rice.core.api.mo.AbstractDataTransferObject; |
5 | |
import org.kuali.rice.core.api.security.credentials.CredentialsType; |
6 | |
import org.kuali.rice.core.api.util.jaxb.EnumStringAdapter; |
7 | |
import org.kuali.rice.core.api.util.jaxb.QNameAsStringAdapter; |
8 | |
import org.kuali.rice.ksb.api.bus.ServiceConfiguration; |
9 | |
import org.kuali.rice.ksb.api.bus.ServiceDefinition; |
10 | |
import org.w3c.dom.Element; |
11 | |
|
12 | |
import javax.xml.bind.annotation.XmlAccessType; |
13 | |
import javax.xml.bind.annotation.XmlAccessorType; |
14 | |
import javax.xml.bind.annotation.XmlAnyElement; |
15 | |
import javax.xml.bind.annotation.XmlElement; |
16 | |
import javax.xml.bind.annotation.XmlType; |
17 | |
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; |
18 | |
import javax.xml.namespace.QName; |
19 | |
import java.io.Serializable; |
20 | |
import java.net.URL; |
21 | |
import java.util.Collection; |
22 | |
|
23 | |
@XmlAccessorType(XmlAccessType.NONE) |
24 | |
@XmlType(name = AbstractServiceConfiguration.Constants.TYPE_NAME, propOrder = { |
25 | |
AbstractServiceConfiguration.Elements.SERVICE_NAME, |
26 | |
AbstractServiceConfiguration.Elements.ENDPOINT_URL, |
27 | |
AbstractServiceConfiguration.Elements.APPLICATION_ID, |
28 | |
AbstractServiceConfiguration.Elements.INSTANCE_ID, |
29 | |
AbstractServiceConfiguration.Elements.SERVICE_VERSION, |
30 | |
AbstractServiceConfiguration.Elements.TYPE, |
31 | |
AbstractServiceConfiguration.Elements.QUEUE, |
32 | |
AbstractServiceConfiguration.Elements.PRIORITY, |
33 | |
AbstractServiceConfiguration.Elements.RETRY_ATTEMPTS, |
34 | |
AbstractServiceConfiguration.Elements.MILLIS_TO_LIVE, |
35 | |
AbstractServiceConfiguration.Elements.MESSAGE_EXCEPTION_HANDLER, |
36 | |
AbstractServiceConfiguration.Elements.BUS_SECURITY, |
37 | |
AbstractServiceConfiguration.Elements.CREDENTIALS_TYPE, |
38 | |
AbstractServiceConfiguration.Elements.CACHE_MANAGER, |
39 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
40 | |
}) |
41 | |
public abstract class AbstractServiceConfiguration extends AbstractDataTransferObject implements ServiceConfiguration { |
42 | |
|
43 | |
private static final long serialVersionUID = 2681595879406587302L; |
44 | |
|
45 | |
@XmlJavaTypeAdapter(QNameAsStringAdapter.class) |
46 | |
@XmlElement(name = Elements.SERVICE_NAME, required = true) |
47 | |
private final QName serviceName; |
48 | |
|
49 | |
@XmlElement(name = Elements.ENDPOINT_URL, required = true) |
50 | |
private final URL endpointUrl; |
51 | |
|
52 | |
@XmlElement(name = Elements.INSTANCE_ID, required = true) |
53 | |
private final String instanceId; |
54 | |
|
55 | |
@XmlElement(name = Elements.APPLICATION_ID, required = true) |
56 | |
private final String applicationId; |
57 | |
|
58 | |
@XmlElement(name = Elements.SERVICE_VERSION, required = true) |
59 | |
private final String serviceVersion; |
60 | |
|
61 | |
@XmlElement(name = Elements.TYPE, required = true) |
62 | |
private final String type; |
63 | |
|
64 | |
@XmlElement(name = Elements.QUEUE, required = false) |
65 | |
private final boolean queue; |
66 | |
|
67 | |
@XmlElement(name = Elements.PRIORITY, required = false) |
68 | |
private final Integer priority; |
69 | |
|
70 | |
@XmlElement(name = Elements.RETRY_ATTEMPTS, required = false) |
71 | |
private final Integer retryAttempts; |
72 | |
|
73 | |
@XmlElement(name = Elements.MILLIS_TO_LIVE, required = false) |
74 | |
private final Long millisToLive; |
75 | |
|
76 | |
@XmlElement(name = Elements.MESSAGE_EXCEPTION_HANDLER, required = false) |
77 | |
private final String messageExceptionHandler; |
78 | |
|
79 | |
@XmlElement(name = Elements.BUS_SECURITY, required = false) |
80 | |
private final Boolean busSecurity; |
81 | |
|
82 | |
@XmlJavaTypeAdapter(CredentialsTypeAdapter.class) |
83 | |
@XmlElement(name = Elements.CREDENTIALS_TYPE, required = false) |
84 | |
private final String credentialsType; |
85 | |
|
86 | |
@XmlElement(name = Elements.CACHE_MANAGER, required = false) |
87 | |
private final String cacheManager; |
88 | |
|
89 | 27 | @SuppressWarnings("unused") |
90 | |
@XmlAnyElement |
91 | |
private final Collection<Element> _futureElements = null; |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | 19 | protected AbstractServiceConfiguration() { |
97 | 19 | this.serviceName = null; |
98 | 19 | this.endpointUrl = null; |
99 | 19 | this.instanceId = null; |
100 | 19 | this.applicationId = null; |
101 | 19 | this.serviceVersion = null; |
102 | 19 | this.type = null; |
103 | 19 | this.queue = false; |
104 | 19 | this.priority = null; |
105 | 19 | this.retryAttempts = null; |
106 | 19 | this.millisToLive = null; |
107 | 19 | this.messageExceptionHandler = null; |
108 | 19 | this.busSecurity = null; |
109 | 19 | this.credentialsType = null; |
110 | 19 | this.cacheManager = null; |
111 | 19 | } |
112 | |
|
113 | 8 | protected AbstractServiceConfiguration(Builder<?> builder) { |
114 | 8 | this.serviceName = builder.getServiceName(); |
115 | 8 | this.endpointUrl = builder.getEndpointUrl(); |
116 | 8 | this.instanceId = builder.getInstanceId(); |
117 | 8 | this.applicationId = builder.getApplicationId(); |
118 | 8 | this.serviceVersion = builder.getServiceVersion(); |
119 | 8 | this.type = builder.getType(); |
120 | 8 | this.queue = builder.isQueue(); |
121 | 8 | this.priority = builder.getPriority(); |
122 | 8 | this.retryAttempts = builder.getRetryAttempts(); |
123 | 8 | this.millisToLive = builder.getMillisToLive(); |
124 | 8 | this.messageExceptionHandler = builder.getMessageExceptionHandler(); |
125 | 8 | this.busSecurity = builder.getBusSecurity(); |
126 | 8 | CredentialsType cred = builder.getCredentialsType(); |
127 | 8 | this.credentialsType = cred == null ? null : cred.name(); |
128 | 8 | this.cacheManager = builder.getCacheManager(); |
129 | 8 | } |
130 | |
|
131 | |
public QName getServiceName() { |
132 | 3 | return serviceName; |
133 | |
} |
134 | |
|
135 | |
public URL getEndpointUrl() { |
136 | 3 | return endpointUrl; |
137 | |
} |
138 | |
|
139 | |
public String getInstanceId() { |
140 | 1 | return instanceId; |
141 | |
} |
142 | |
|
143 | |
public String getApplicationId() { |
144 | 3 | return applicationId; |
145 | |
} |
146 | |
|
147 | |
public String getServiceVersion() { |
148 | 3 | return serviceVersion; |
149 | |
} |
150 | |
|
151 | |
public String getType() { |
152 | 0 | return type; |
153 | |
} |
154 | |
|
155 | |
public boolean isQueue() { |
156 | 0 | return queue; |
157 | |
} |
158 | |
|
159 | |
public Integer getPriority() { |
160 | 0 | return priority; |
161 | |
} |
162 | |
|
163 | |
public Integer getRetryAttempts() { |
164 | 0 | return retryAttempts; |
165 | |
} |
166 | |
|
167 | |
public Long getMillisToLive() { |
168 | 0 | return millisToLive; |
169 | |
} |
170 | |
|
171 | |
public String getMessageExceptionHandler() { |
172 | 0 | return messageExceptionHandler; |
173 | |
} |
174 | |
|
175 | |
public Boolean getBusSecurity() { |
176 | 0 | return busSecurity; |
177 | |
} |
178 | |
|
179 | |
public CredentialsType getCredentialsType() { |
180 | 0 | if (credentialsType == null) { |
181 | 0 | return null; |
182 | |
} |
183 | 0 | return CredentialsType.valueOf(credentialsType); |
184 | |
} |
185 | |
|
186 | |
public String getCacheManager() { |
187 | 0 | return cacheManager; |
188 | |
} |
189 | |
|
190 | 8 | protected static abstract class Builder<T> implements Serializable { |
191 | |
|
192 | |
private static final long serialVersionUID = -3002495884401672488L; |
193 | |
|
194 | |
private QName serviceName; |
195 | |
private URL endpointUrl; |
196 | |
private String instanceId; |
197 | |
private String applicationId; |
198 | |
private String serviceVersion; |
199 | |
private String type; |
200 | |
private boolean queue; |
201 | |
private Integer priority; |
202 | |
private Integer retryAttempts; |
203 | |
private Long millisToLive; |
204 | |
private String messageExceptionHandler; |
205 | |
private Boolean busSecurity; |
206 | |
private CredentialsType credentialsType; |
207 | |
private String cacheManager; |
208 | |
|
209 | |
public abstract T build(); |
210 | |
|
211 | |
protected void copyServiceDefinitionProperties(ServiceDefinition serviceDefinition) { |
212 | 8 | setServiceName(serviceDefinition.getServiceName()); |
213 | 8 | setEndpointUrl(serviceDefinition.getEndpointUrl()); |
214 | 8 | setApplicationId(serviceDefinition.getApplicationId()); |
215 | 8 | setInstanceId(serviceDefinition.getInstanceId()); |
216 | 8 | setServiceVersion(serviceDefinition.getServiceVersion()); |
217 | 8 | setType(serviceDefinition.getType()); |
218 | 8 | setQueue(serviceDefinition.isQueue()); |
219 | 8 | setPriority(serviceDefinition.getPriority()); |
220 | 8 | setRetryAttempts(serviceDefinition.getRetryAttempts()); |
221 | 8 | setMillisToLive(serviceDefinition.getMillisToLive()); |
222 | 8 | setMessageExceptionHandler(serviceDefinition.getMessageExceptionHandler()); |
223 | 8 | setBusSecurity(serviceDefinition.getBusSecurity()); |
224 | 8 | setCredentialsType(serviceDefinition.getCredentialsType()); |
225 | 8 | setCacheManager(serviceDefinition.getCacheManager()); |
226 | 8 | } |
227 | |
|
228 | |
public QName getServiceName() { |
229 | 8 | return serviceName; |
230 | |
} |
231 | |
public void setServiceName(QName serviceName) { |
232 | 8 | this.serviceName = serviceName; |
233 | 8 | } |
234 | |
public URL getEndpointUrl() { |
235 | 8 | return endpointUrl; |
236 | |
} |
237 | |
public void setEndpointUrl(URL endpointUrl) { |
238 | 8 | this.endpointUrl = endpointUrl; |
239 | 8 | } |
240 | |
public String getInstanceId() { |
241 | 8 | return instanceId; |
242 | |
} |
243 | |
public void setInstanceId(String instanceId) { |
244 | 8 | this.instanceId = instanceId; |
245 | 8 | } |
246 | |
public String getApplicationId() { |
247 | 8 | return applicationId; |
248 | |
} |
249 | |
public void setApplicationId(String applicationId) { |
250 | 8 | this.applicationId = applicationId; |
251 | 8 | } |
252 | |
public String getServiceVersion() { |
253 | 8 | return serviceVersion; |
254 | |
} |
255 | |
public void setServiceVersion(String serviceVersion) { |
256 | 8 | this.serviceVersion = serviceVersion; |
257 | 8 | } |
258 | |
public String getType() { |
259 | 8 | return type; |
260 | |
} |
261 | |
public void setType(String type) { |
262 | 8 | this.type = type; |
263 | 8 | } |
264 | |
public boolean isQueue() { |
265 | 8 | return queue; |
266 | |
} |
267 | |
public void setQueue(boolean queue) { |
268 | 8 | this.queue = queue; |
269 | 8 | } |
270 | |
public Integer getPriority() { |
271 | 8 | return priority; |
272 | |
} |
273 | |
public void setPriority(Integer priority) { |
274 | 8 | this.priority = priority; |
275 | 8 | } |
276 | |
public Integer getRetryAttempts() { |
277 | 8 | return retryAttempts; |
278 | |
} |
279 | |
public void setRetryAttempts(Integer retryAttempts) { |
280 | 8 | this.retryAttempts = retryAttempts; |
281 | 8 | } |
282 | |
public Long getMillisToLive() { |
283 | 8 | return millisToLive; |
284 | |
} |
285 | |
public void setMillisToLive(Long millisToLive) { |
286 | 8 | this.millisToLive = millisToLive; |
287 | 8 | } |
288 | |
public String getMessageExceptionHandler() { |
289 | 8 | return messageExceptionHandler; |
290 | |
} |
291 | |
public void setMessageExceptionHandler(String messageExceptionHandler) { |
292 | 8 | this.messageExceptionHandler = messageExceptionHandler; |
293 | 8 | } |
294 | |
public Boolean getBusSecurity() { |
295 | 8 | return busSecurity; |
296 | |
} |
297 | |
public void setBusSecurity(Boolean busSecurity) { |
298 | 8 | this.busSecurity = busSecurity; |
299 | 8 | } |
300 | |
public CredentialsType getCredentialsType() { |
301 | 8 | return credentialsType; |
302 | |
} |
303 | |
public void setCredentialsType(CredentialsType credentialsType) { |
304 | 8 | this.credentialsType = credentialsType; |
305 | 8 | } |
306 | |
|
307 | |
public String getCacheManager() { |
308 | 8 | return cacheManager; |
309 | |
} |
310 | |
|
311 | |
public void setCacheManager(String cacheManager) { |
312 | 8 | this.cacheManager = cacheManager; |
313 | 8 | } |
314 | |
} |
315 | |
|
316 | |
|
317 | |
|
318 | |
|
319 | 0 | protected static class Constants { |
320 | |
protected final static String TYPE_NAME = "ServiceConfigurationType"; |
321 | |
} |
322 | |
|
323 | |
|
324 | |
|
325 | |
|
326 | |
|
327 | 0 | protected static class Elements { |
328 | |
protected final static String SERVICE_NAME = "serviceName"; |
329 | |
protected final static String ENDPOINT_URL = "endpointUrl"; |
330 | |
protected final static String INSTANCE_ID = "instanceId"; |
331 | |
protected final static String APPLICATION_ID = "applicationId"; |
332 | |
protected final static String SERVICE_VERSION = "serviceVersion"; |
333 | |
protected final static String TYPE = "type"; |
334 | |
protected final static String QUEUE = "queue"; |
335 | |
protected final static String PRIORITY = "priority"; |
336 | |
protected final static String RETRY_ATTEMPTS = "retryAttempts"; |
337 | |
protected final static String MILLIS_TO_LIVE = "millisToLive"; |
338 | |
protected final static String MESSAGE_EXCEPTION_HANDLER = "messageExceptionHandler"; |
339 | |
protected final static String BUS_SECURITY = "busSecurity"; |
340 | |
protected final static String CREDENTIALS_TYPE = "credentialsType"; |
341 | |
protected final static String CACHE_MANAGER = "cacheManager"; |
342 | |
} |
343 | |
|
344 | 3 | static final class CredentialsTypeAdapter extends EnumStringAdapter<CredentialsType> { |
345 | |
|
346 | |
protected Class<CredentialsType> getEnumClass() { |
347 | 4 | return CredentialsType.class; |
348 | |
} |
349 | |
|
350 | |
} |
351 | |
|
352 | |
} |