001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.messaging;
018:
019: import java.io.Serializable;
020: import java.net.URL;
021: import java.net.URLEncoder;
022:
023: import javax.xml.namespace.QName;
024:
025: import org.apache.log4j.Logger;
026: import org.kuali.rice.config.ConfigurationException;
027: import org.kuali.rice.core.Core;
028: import org.kuali.rice.security.credentials.CredentialsSource;
029: import org.kuali.rice.security.credentials.CredentialsSource.CredentialsType;
030: import org.springframework.util.Assert;
031:
032: import edu.iu.uis.eden.messaging.exceptionhandling.DefaultMessageExceptionHandler;
033:
034: /**
035: * The definition of a service on the service bus.
036: *
037: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
038: */
039: public abstract class ServiceDefinition implements Serializable {
040:
041: private static final Logger LOG = Logger
042: .getLogger(ServiceDefinition.class);
043:
044: private static final long serialVersionUID = 43631161206712702L;
045:
046: private Object service;
047: private String localServiceName;
048: private String serviceNameSpaceURI;
049: private transient QName serviceName;
050: private Boolean queue = Boolean.TRUE;
051: private Integer priority;
052: private Integer retryAttempts;
053: private Long millisToLive;
054: private String messageExceptionHandler;
055: private URL serviceEndPoint;
056: private Boolean busSecurity = Boolean.TRUE;
057: private CredentialsType credentialsType;
058: private String messageEntity;
059:
060: public ServiceDefinition() {
061: // nothing to do
062: }
063:
064: public ServiceDefinition(final Boolean busSecurity) {
065: Assert.notNull(busSecurity, "busSecurity cannot be null");
066: this .busSecurity = busSecurity;
067: }
068:
069: public Object getService() {
070: return this .service;
071: }
072:
073: public void setService(Object service) {
074: this .service = service;
075: }
076:
077: public String getLocalServiceName() {
078: return this .localServiceName;
079: }
080:
081: public void setLocalServiceName(String serviceName) {
082: this .localServiceName = serviceName;
083: }
084:
085: public String getMessageExceptionHandler() {
086: return this .messageExceptionHandler;
087: }
088:
089: public void setMessageExceptionHandler(
090: String messageExceptionHandler) {
091: this .messageExceptionHandler = messageExceptionHandler;
092: }
093:
094: public Integer getPriority() {
095: return this .priority;
096: }
097:
098: public void setPriority(Integer priority) {
099: this .priority = priority;
100: }
101:
102: public Boolean getQueue() {
103: return this .queue;
104: }
105:
106: public void setQueue(Boolean queue) {
107: this .queue = queue;
108: }
109:
110: public Integer getRetryAttempts() {
111: return this .retryAttempts;
112: }
113:
114: public void setRetryAttempts(Integer retryAttempts) {
115: this .retryAttempts = retryAttempts;
116: }
117:
118: public QName getServiceName() {
119: if (this .serviceName == null) {
120: if (this .localServiceName == null) {
121: int i = 0;
122: }
123: if (this .serviceNameSpaceURI == null) {
124: this .serviceName = new QName(this .messageEntity,
125: this .localServiceName);
126: } else {
127: this .serviceName = new QName(this .serviceNameSpaceURI,
128: this .localServiceName);
129: }
130:
131: }
132: return this .serviceName;
133: }
134:
135: public void setServiceName(QName serviceName) {
136: this .serviceName = serviceName;
137: }
138:
139: public URL getServiceEndPoint() {
140: return this .serviceEndPoint;
141: }
142:
143: public void setServiceEndPoint(URL serviceEndPoint) {
144: this .serviceEndPoint = serviceEndPoint;
145: }
146:
147: public void setCredentialsType(
148: CredentialsSource.CredentialsType credentialsType) {
149: this .credentialsType = credentialsType;
150: }
151:
152: public CredentialsSource.CredentialsType getCredentialsType() {
153: return this .credentialsType;
154: }
155:
156: public void validate() {
157:
158: if (this .serviceName == null && this .localServiceName == null) {
159: throw new ConfigurationException(
160: "Must give a serviceName or localServiceName");
161: }
162:
163: String messageEntity = Core.getCurrentContextConfig()
164: .getMessageEntity();
165: if (messageEntity == null) {
166: throw new ConfigurationException(
167: "Must have a messageEntity");
168: }
169: this .messageEntity = messageEntity;
170:
171: // if (this.serviceName == null) {
172: // if (this.serviceNameSpaceURI == null) {
173: // this.serviceName = new QName(messageEntity, this.localServiceName);
174: // } else {
175: // this.serviceName = new QName(this.serviceNameSpaceURI, this.localServiceName);
176: // }
177: //
178: // }
179: if (this .serviceName != null && this .localServiceName == null) {
180: this .localServiceName = this .getServiceName()
181: .getLocalPart();
182: }
183:
184: LOG.debug("Validating service " + this .serviceName);
185:
186: String endPointURL = Core.getCurrentContextConfig()
187: .getEndPointUrl();
188: if (this .serviceEndPoint == null && endPointURL == null) {
189: throw new ConfigurationException(
190: "Must provide a serviceEndPoint or serviceServletURL");
191: } else if (this .serviceEndPoint == null) {
192: if (!endPointURL.endsWith("/")) {
193: endPointURL += "/";
194: }
195: try {
196: this .serviceEndPoint = new URL(endPointURL
197: + URLEncoder.encode(this .getServiceName()
198: .toString(), "UTF-8"));
199: } catch (Exception e) {
200: throw new ConfigurationException(
201: "Service Endpoint URL creation failed.", e);
202: }
203:
204: }
205:
206: if (this .service == null) {
207: throw new ConfigurationException("Must provide a service");
208: }
209:
210: if (this .priority == null) {
211: setPriority(5);
212: }
213:
214: if (this .retryAttempts == null) {
215: setRetryAttempts(0);
216: }
217:
218: if (this .millisToLive == null) {
219: setMillisToLive(new Long(-1));
220: }
221:
222: if (getMessageExceptionHandler() == null) {
223: setMessageExceptionHandler(DefaultMessageExceptionHandler.class
224: .getName());
225: }
226: }
227:
228: public String getServiceNameSpaceURI() {
229: return this .serviceNameSpaceURI;
230: }
231:
232: public void setServiceNameSpaceURI(String serviceNameSpaceURI) {
233: this .serviceNameSpaceURI = serviceNameSpaceURI;
234: }
235:
236: public Long getMillisToLive() {
237: return this .millisToLive;
238: }
239:
240: public void setMillisToLive(Long millisToLive) {
241: this .millisToLive = millisToLive;
242: }
243:
244: public Boolean getBusSecurity() {
245: return this .busSecurity;
246: }
247:
248: public void setBusSecurity(Boolean busSecurity) {
249: this .busSecurity = busSecurity;
250: }
251:
252: public boolean isSame(ServiceDefinition serviceDefinition) {
253: return this.getBusSecurity().equals(
254: serviceDefinition.getBusSecurity())
255: && this.getMessageExceptionHandler().equals(
256: serviceDefinition.getMessageExceptionHandler())
257: && this.getMillisToLive().equals(
258: serviceDefinition.getMillisToLive())
259: && this.getPriority().equals(
260: serviceDefinition.getPriority())
261: && this.getQueue().equals(serviceDefinition.getQueue())
262: && this.getRetryAttempts().equals(
263: serviceDefinition.getRetryAttempts())
264: && this.getServiceEndPoint().equals(
265: serviceDefinition.getServiceEndPoint())
266: && this.getServiceName().equals(
267: serviceDefinition.getServiceName())
268: && this.getCredentialsType() == serviceDefinition
269: .getCredentialsType();
270: }
271: }
|