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