View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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.BASIC_AUTHENTICATION,
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.BASIC_AUTHENTICATION, required = false)
102 	private final Boolean basicAuthentication;
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.basicAuthentication = false;
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.basicAuthentication = builder.isBasicAuthentication();
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 	@Override
202 	public Boolean isBasicAuthentication() {
203 		return basicAuthentication;
204 	}
205 
206 	protected static abstract class Builder<T> implements Serializable {
207 		
208 		private static final long serialVersionUID = -3002495884401672488L;
209 
210 		private QName serviceName;
211 		private URL endpointUrl;
212         private String instanceId;
213 		private String applicationId;
214 		private String serviceVersion;
215 		private String type;
216 		private boolean queue;
217 		private Integer priority;
218 		private Integer retryAttempts;
219 		private Long millisToLive;
220 		private String messageExceptionHandler;
221 		private Boolean busSecurity;
222 		private CredentialsType credentialsType;
223 		private Boolean basicAuthentication = false;
224 
225 		public abstract T build();
226 		
227 		protected void copyServiceDefinitionProperties(ServiceDefinition serviceDefinition) {
228 			setServiceName(serviceDefinition.getServiceName());
229 			setEndpointUrl(serviceDefinition.getEndpointUrl());
230 			setApplicationId(serviceDefinition.getApplicationId());
231             setInstanceId(serviceDefinition.getInstanceId());
232 			setServiceVersion(serviceDefinition.getServiceVersion());
233 			setType(serviceDefinition.getType());
234 			setQueue(serviceDefinition.isQueue());
235 			setPriority(serviceDefinition.getPriority());
236 			setRetryAttempts(serviceDefinition.getRetryAttempts());
237 			setMillisToLive(serviceDefinition.getMillisToLive());
238 			setMessageExceptionHandler(serviceDefinition.getMessageExceptionHandler());
239 			setBusSecurity(serviceDefinition.getBusSecurity());
240 			setCredentialsType(serviceDefinition.getCredentialsType());
241 			setBasicAuthentication(serviceDefinition.isBasicAuthentication());
242 		}
243 		
244 		public QName getServiceName() {
245 			return serviceName;
246 		}
247 		public void setServiceName(QName serviceName) {
248 			this.serviceName = serviceName;
249 		}
250 		public URL getEndpointUrl() {
251 			return endpointUrl;
252 		}
253 		public void setEndpointUrl(URL endpointUrl) {
254 			this.endpointUrl = endpointUrl;
255 		}
256         public String getInstanceId() {
257            return instanceId;
258         }
259         public void setInstanceId(String instanceId) {
260             this.instanceId = instanceId;
261         }
262 		public String getApplicationId() {
263 			return applicationId;
264 		}
265 		public void setApplicationId(String applicationId) {
266 			this.applicationId = applicationId;
267 		}
268 		public String getServiceVersion() {
269 			return serviceVersion;
270 		}
271 		public void setServiceVersion(String serviceVersion) {
272 			this.serviceVersion = serviceVersion;
273 		}
274 		public String getType() {
275 			return type;
276 		}
277 		public void setType(String type) {
278 			this.type = type;
279 		}
280 		public boolean isQueue() {
281 			return queue;
282 		}
283 		public void setQueue(boolean queue) {
284 			this.queue = queue;
285 		}
286 		public Integer getPriority() {
287 			return priority;
288 		}
289 		public void setPriority(Integer priority) {
290 			this.priority = priority;
291 		}
292 		public Integer getRetryAttempts() {
293 			return retryAttempts;
294 		}
295 		public void setRetryAttempts(Integer retryAttempts) {
296 			this.retryAttempts = retryAttempts;
297 		}
298 		public Long getMillisToLive() {
299 			return millisToLive;
300 		}
301 		public void setMillisToLive(Long millisToLive) {
302 			this.millisToLive = millisToLive;
303 		}
304 		public String getMessageExceptionHandler() {
305 			return messageExceptionHandler;
306 		}
307 		public void setMessageExceptionHandler(String messageExceptionHandler) {
308 			this.messageExceptionHandler = messageExceptionHandler;
309 		}
310 		public Boolean getBusSecurity() {
311 			return busSecurity;
312 		}
313 		public void setBusSecurity(Boolean busSecurity) {
314 			this.busSecurity = busSecurity;
315 		}
316 		public CredentialsType getCredentialsType() {
317 			return credentialsType;
318 		}
319 		public void setCredentialsType(CredentialsType credentialsType) {
320 			this.credentialsType = credentialsType;
321 		}
322 		public Boolean isBasicAuthentication() {
323 			return basicAuthentication;
324 		}
325 		public void setBasicAuthentication(Boolean basicAuthentication) {
326 			this.basicAuthentication = basicAuthentication;
327 		}
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 BASIC_AUTHENTICATION = "basicAuthentication";
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 }