001 /**
002 * Copyright 2005-2011 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.ksb.api.bus.support;
017
018 import org.kuali.rice.core.api.CoreConstants;
019 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
020 import org.kuali.rice.core.api.security.credentials.CredentialsType;
021 import org.kuali.rice.core.api.util.jaxb.EnumStringAdapter;
022 import org.kuali.rice.core.api.util.jaxb.QNameAsStringAdapter;
023 import org.kuali.rice.ksb.api.bus.ServiceConfiguration;
024 import org.kuali.rice.ksb.api.bus.ServiceDefinition;
025 import org.w3c.dom.Element;
026
027 import javax.xml.bind.annotation.XmlAccessType;
028 import javax.xml.bind.annotation.XmlAccessorType;
029 import javax.xml.bind.annotation.XmlAnyElement;
030 import javax.xml.bind.annotation.XmlElement;
031 import javax.xml.bind.annotation.XmlType;
032 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
033 import javax.xml.namespace.QName;
034 import java.io.Serializable;
035 import java.net.URL;
036 import java.util.Collection;
037
038 @XmlAccessorType(XmlAccessType.NONE)
039 @XmlType(name = AbstractServiceConfiguration.Constants.TYPE_NAME, propOrder = {
040 AbstractServiceConfiguration.Elements.SERVICE_NAME,
041 AbstractServiceConfiguration.Elements.ENDPOINT_URL,
042 AbstractServiceConfiguration.Elements.APPLICATION_ID,
043 AbstractServiceConfiguration.Elements.INSTANCE_ID,
044 AbstractServiceConfiguration.Elements.SERVICE_VERSION,
045 AbstractServiceConfiguration.Elements.TYPE,
046 AbstractServiceConfiguration.Elements.QUEUE,
047 AbstractServiceConfiguration.Elements.PRIORITY,
048 AbstractServiceConfiguration.Elements.RETRY_ATTEMPTS,
049 AbstractServiceConfiguration.Elements.MILLIS_TO_LIVE,
050 AbstractServiceConfiguration.Elements.MESSAGE_EXCEPTION_HANDLER,
051 AbstractServiceConfiguration.Elements.BUS_SECURITY,
052 AbstractServiceConfiguration.Elements.CREDENTIALS_TYPE,
053 AbstractServiceConfiguration.Elements.CACHE_MANAGER,
054 CoreConstants.CommonElements.FUTURE_ELEMENTS
055 })
056 public abstract class AbstractServiceConfiguration extends AbstractDataTransferObject implements ServiceConfiguration {
057
058 private static final long serialVersionUID = 2681595879406587302L;
059
060 @XmlJavaTypeAdapter(QNameAsStringAdapter.class)
061 @XmlElement(name = Elements.SERVICE_NAME, required = true)
062 private final QName serviceName;
063
064 @XmlElement(name = Elements.ENDPOINT_URL, required = true)
065 private final URL endpointUrl;
066
067 @XmlElement(name = Elements.INSTANCE_ID, required = true)
068 private final String instanceId;
069
070 @XmlElement(name = Elements.APPLICATION_ID, required = true)
071 private final String applicationId;
072
073 @XmlElement(name = Elements.SERVICE_VERSION, required = true)
074 private final String serviceVersion;
075
076 @XmlElement(name = Elements.TYPE, required = true)
077 private final String type;
078
079 @XmlElement(name = Elements.QUEUE, required = false)
080 private final boolean queue;
081
082 @XmlElement(name = Elements.PRIORITY, required = false)
083 private final Integer priority;
084
085 @XmlElement(name = Elements.RETRY_ATTEMPTS, required = false)
086 private final Integer retryAttempts;
087
088 @XmlElement(name = Elements.MILLIS_TO_LIVE, required = false)
089 private final Long millisToLive;
090
091 @XmlElement(name = Elements.MESSAGE_EXCEPTION_HANDLER, required = false)
092 private final String messageExceptionHandler;
093
094 @XmlElement(name = Elements.BUS_SECURITY, required = false)
095 private final Boolean busSecurity;
096
097 @XmlJavaTypeAdapter(CredentialsTypeAdapter.class)
098 @XmlElement(name = Elements.CREDENTIALS_TYPE, required = false)
099 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 * Constructor intended for use only by JAXB.
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 * Defines some internal constants used on this class.
333 */
334 protected static class Constants {
335 protected final static String TYPE_NAME = "ServiceConfigurationType";
336 }
337
338 /**
339 * A private class which exposes constants which define the XML element names to use
340 * when this object is marshalled to XML.
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 }