001 /** 002 * Copyright 2005-2012 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 CoreConstants.CommonElements.FUTURE_ELEMENTS 054 }) 055 public abstract class AbstractServiceConfiguration extends AbstractDataTransferObject implements ServiceConfiguration { 056 057 private static final long serialVersionUID = 2681595879406587302L; 058 059 @XmlJavaTypeAdapter(QNameAsStringAdapter.class) 060 @XmlElement(name = Elements.SERVICE_NAME, required = true) 061 private final QName serviceName; 062 063 @XmlElement(name = Elements.ENDPOINT_URL, required = true) 064 private final URL endpointUrl; 065 066 @XmlElement(name = Elements.INSTANCE_ID, required = true) 067 private final String instanceId; 068 069 @XmlElement(name = Elements.APPLICATION_ID, required = true) 070 private final String applicationId; 071 072 @XmlElement(name = Elements.SERVICE_VERSION, required = true) 073 private final String serviceVersion; 074 075 @XmlElement(name = Elements.TYPE, required = true) 076 private final String type; 077 078 @XmlElement(name = Elements.QUEUE, required = false) 079 private final boolean queue; 080 081 @XmlElement(name = Elements.PRIORITY, required = false) 082 private final Integer priority; 083 084 @XmlElement(name = Elements.RETRY_ATTEMPTS, required = false) 085 private final Integer retryAttempts; 086 087 @XmlElement(name = Elements.MILLIS_TO_LIVE, required = false) 088 private final Long millisToLive; 089 090 @XmlElement(name = Elements.MESSAGE_EXCEPTION_HANDLER, required = false) 091 private final String messageExceptionHandler; 092 093 @XmlElement(name = Elements.BUS_SECURITY, required = false) 094 private final Boolean busSecurity; 095 096 @XmlJavaTypeAdapter(CredentialsTypeAdapter.class) 097 @XmlElement(name = Elements.CREDENTIALS_TYPE, required = false) 098 private final String credentialsType; 099 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 }