View Javadoc

1   /**
2    * Copyright 2005-2012 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          CoreConstants.CommonElements.FUTURE_ELEMENTS
54  })
55  public abstract class AbstractServiceConfiguration extends AbstractDataTransferObject implements ServiceConfiguration {
56  
57  	private static final long serialVersionUID = 2681595879406587302L;
58  
59  	@XmlJavaTypeAdapter(QNameAsStringAdapter.class)
60  	@XmlElement(name = Elements.SERVICE_NAME, required = true)
61  	private final QName serviceName;
62  	
63  	@XmlElement(name = Elements.ENDPOINT_URL, required = true)
64  	private final URL endpointUrl;
65  
66      @XmlElement(name = Elements.INSTANCE_ID, required = true)
67  	private final String instanceId;
68  
69  	@XmlElement(name = Elements.APPLICATION_ID, required = true)
70  	private final String applicationId;
71  	
72  	@XmlElement(name = Elements.SERVICE_VERSION, required = true)
73  	private final String serviceVersion;
74  	
75  	@XmlElement(name = Elements.TYPE, required = true)
76  	private final String type;
77  	
78  	@XmlElement(name = Elements.QUEUE, required = false)
79  	private final boolean queue;
80  	
81  	@XmlElement(name = Elements.PRIORITY, required = false)
82  	private final Integer priority;
83  	
84  	@XmlElement(name = Elements.RETRY_ATTEMPTS, required = false)
85  	private final Integer retryAttempts;
86  	
87  	@XmlElement(name = Elements.MILLIS_TO_LIVE, required = false)
88  	private final Long millisToLive;
89  	
90  	@XmlElement(name = Elements.MESSAGE_EXCEPTION_HANDLER, required = false)
91  	private final String messageExceptionHandler;
92  	
93  	@XmlElement(name = Elements.BUS_SECURITY, required = false)
94  	private final Boolean busSecurity;
95  	
96  	@XmlJavaTypeAdapter(CredentialsTypeAdapter.class)
97  	@XmlElement(name = Elements.CREDENTIALS_TYPE, required = false)
98  	private final String credentialsType;
99  
100 	@SuppressWarnings("unused")
101     @XmlAnyElement
102     private final Collection<Element> _futureElements = null;
103 
104 	/**
105      * Constructor intended for use only by JAXB.
106      */
107 	protected AbstractServiceConfiguration() {
108 		this.serviceName = null;
109 		this.endpointUrl = null;
110         this.instanceId = null;
111 		this.applicationId = null;
112 		this.serviceVersion = null;
113 		this.type = null;
114 		this.queue = false;
115 		this.priority = null;
116 		this.retryAttempts = null;
117 		this.millisToLive = null;
118 		this.messageExceptionHandler = null;
119 		this.busSecurity = null;
120 		this.credentialsType = null;
121 	}
122 	
123 	protected AbstractServiceConfiguration(Builder<?> builder) {
124 		this.serviceName = builder.getServiceName();
125 		this.endpointUrl = builder.getEndpointUrl();
126         this.instanceId = builder.getInstanceId();
127 		this.applicationId = builder.getApplicationId();
128 		this.serviceVersion = builder.getServiceVersion();
129 		this.type = builder.getType();
130 		this.queue = builder.isQueue();
131 		this.priority = builder.getPriority();
132 		this.retryAttempts = builder.getRetryAttempts();
133 		this.millisToLive = builder.getMillisToLive();
134 		this.messageExceptionHandler = builder.getMessageExceptionHandler();
135 		this.busSecurity = builder.getBusSecurity();
136 		CredentialsType cred = builder.getCredentialsType();
137 		this.credentialsType = cred == null ? null : cred.name();
138 	}
139 	
140 	public QName getServiceName() {
141 		return serviceName;
142 	}
143 
144 	public URL getEndpointUrl() {
145 		return endpointUrl;
146 	}
147 
148     public String getInstanceId() {
149         return instanceId;
150     }
151 
152 	public String getApplicationId() {
153 		return applicationId;
154 	}
155 	
156 	public String getServiceVersion() {
157 		return serviceVersion;
158 	}
159 	
160 	public String getType() {
161 		return type;
162 	}
163 
164 	public boolean isQueue() {
165 		return queue;
166 	}
167 
168 	public Integer getPriority() {
169 		return priority;
170 	}
171 
172 	public Integer getRetryAttempts() {
173 		return retryAttempts;
174 	}
175 
176 	public Long getMillisToLive() {
177 		return millisToLive;
178 	}
179 
180 	public String getMessageExceptionHandler() {
181 		return messageExceptionHandler;
182 	}
183 
184 	public Boolean getBusSecurity() {
185 		return busSecurity;
186 	}
187 
188 	public CredentialsType getCredentialsType() {
189 		if (credentialsType == null) {
190 			return null;
191 		}
192 		return CredentialsType.valueOf(credentialsType);
193 	}
194 
195 	protected static abstract class Builder<T> implements Serializable {
196 		
197 		private static final long serialVersionUID = -3002495884401672488L;
198 
199 		private QName serviceName;
200 		private URL endpointUrl;
201         private String instanceId;
202 		private String applicationId;
203 		private String serviceVersion;
204 		private String type;
205 		private boolean queue;
206 		private Integer priority;
207 		private Integer retryAttempts;
208 		private Long millisToLive;
209 		private String messageExceptionHandler;
210 		private Boolean busSecurity;
211 		private CredentialsType credentialsType;
212 
213 		public abstract T build();
214 		
215 		protected void copyServiceDefinitionProperties(ServiceDefinition serviceDefinition) {
216 			setServiceName(serviceDefinition.getServiceName());
217 			setEndpointUrl(serviceDefinition.getEndpointUrl());
218 			setApplicationId(serviceDefinition.getApplicationId());
219             setInstanceId(serviceDefinition.getInstanceId());
220 			setServiceVersion(serviceDefinition.getServiceVersion());
221 			setType(serviceDefinition.getType());
222 			setQueue(serviceDefinition.isQueue());
223 			setPriority(serviceDefinition.getPriority());
224 			setRetryAttempts(serviceDefinition.getRetryAttempts());
225 			setMillisToLive(serviceDefinition.getMillisToLive());
226 			setMessageExceptionHandler(serviceDefinition.getMessageExceptionHandler());
227 			setBusSecurity(serviceDefinition.getBusSecurity());
228 			setCredentialsType(serviceDefinition.getCredentialsType());
229 		}
230 		
231 		public QName getServiceName() {
232 			return serviceName;
233 		}
234 		public void setServiceName(QName serviceName) {
235 			this.serviceName = serviceName;
236 		}
237 		public URL getEndpointUrl() {
238 			return endpointUrl;
239 		}
240 		public void setEndpointUrl(URL endpointUrl) {
241 			this.endpointUrl = endpointUrl;
242 		}
243         public String getInstanceId() {
244            return instanceId;
245         }
246         public void setInstanceId(String instanceId) {
247             this.instanceId = instanceId;
248         }
249 		public String getApplicationId() {
250 			return applicationId;
251 		}
252 		public void setApplicationId(String applicationId) {
253 			this.applicationId = applicationId;
254 		}
255 		public String getServiceVersion() {
256 			return serviceVersion;
257 		}
258 		public void setServiceVersion(String serviceVersion) {
259 			this.serviceVersion = serviceVersion;
260 		}
261 		public String getType() {
262 			return type;
263 		}
264 		public void setType(String type) {
265 			this.type = type;
266 		}
267 		public boolean isQueue() {
268 			return queue;
269 		}
270 		public void setQueue(boolean queue) {
271 			this.queue = queue;
272 		}
273 		public Integer getPriority() {
274 			return priority;
275 		}
276 		public void setPriority(Integer priority) {
277 			this.priority = priority;
278 		}
279 		public Integer getRetryAttempts() {
280 			return retryAttempts;
281 		}
282 		public void setRetryAttempts(Integer retryAttempts) {
283 			this.retryAttempts = retryAttempts;
284 		}
285 		public Long getMillisToLive() {
286 			return millisToLive;
287 		}
288 		public void setMillisToLive(Long millisToLive) {
289 			this.millisToLive = millisToLive;
290 		}
291 		public String getMessageExceptionHandler() {
292 			return messageExceptionHandler;
293 		}
294 		public void setMessageExceptionHandler(String messageExceptionHandler) {
295 			this.messageExceptionHandler = messageExceptionHandler;
296 		}
297 		public Boolean getBusSecurity() {
298 			return busSecurity;
299 		}
300 		public void setBusSecurity(Boolean busSecurity) {
301 			this.busSecurity = busSecurity;
302 		}
303 		public CredentialsType getCredentialsType() {
304 			return credentialsType;
305 		}
306 		public void setCredentialsType(CredentialsType credentialsType) {
307 			this.credentialsType = credentialsType;
308 		}
309 
310 	}
311 	
312     /**
313      * Defines some internal constants used on this class.
314      */
315     protected static class Constants {
316         protected final static String TYPE_NAME = "ServiceConfigurationType";
317     }
318 
319     /**
320      * A private class which exposes constants which define the XML element names to use
321      * when this object is marshalled to XML.
322      */
323     protected static class Elements {
324     	protected final static String SERVICE_NAME = "serviceName";
325     	protected final static String ENDPOINT_URL = "endpointUrl";
326         protected final static String INSTANCE_ID = "instanceId";
327     	protected final static String APPLICATION_ID = "applicationId";
328     	protected final static String SERVICE_VERSION = "serviceVersion";
329     	protected final static String TYPE = "type";
330     	protected final static String QUEUE = "queue";
331     	protected final static String PRIORITY = "priority";
332     	protected final static String RETRY_ATTEMPTS = "retryAttempts";
333     	protected final static String MILLIS_TO_LIVE = "millisToLive";
334     	protected final static String MESSAGE_EXCEPTION_HANDLER = "messageExceptionHandler";
335     	protected final static String BUS_SECURITY = "busSecurity";
336     	protected final static String CREDENTIALS_TYPE = "credentialsType";
337     }
338     
339     static final class CredentialsTypeAdapter extends EnumStringAdapter<CredentialsType> {
340 		
341 		protected Class<CredentialsType> getEnumClass() {
342 			return CredentialsType.class;
343 		}
344 		
345 	}
346 	
347 }