View Javadoc
1   /**
2    * Copyright 2005-2014 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.ksb.api.KsbApiServiceLocator;
19  import org.kuali.rice.ksb.api.bus.ServiceBus;
20  import org.kuali.rice.ksb.api.bus.ServiceDefinition;
21  import org.springframework.beans.factory.InitializingBean;
22  
23  /**
24   * Used from Spring to register service definitions from an already configured and started KSB.
25   * 
26   * @author Kuali Rice Team (rice.collab@kuali.org)
27   */
28  public class ServiceBusExporter implements InitializingBean {
29  	
30  	private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ServiceBusExporter.class);
31  	
32  	private ServiceDefinition serviceDefinition;
33  	private boolean forceSync = false;
34  	private ServiceBus serviceBus;
35  
36  	public void afterPropertiesSet() {
37  		if (getServiceDefinition() == null) {
38  			throw new IllegalStateException("serviceDefinition must be set");
39  		}
40  		getServiceDefinition().validate();
41  		if ( LOG.isInfoEnabled() ) {
42  			LOG.info("Attempting to export service with service name '" + getServiceDefinition().getServiceName());
43  		}
44  		if (getServiceBus() == null) {
45  			setServiceBus(autoLocateServiceBus());
46  		}
47  		if (getServiceBus() == null) {
48  			throw new IllegalStateException("serviceBus could not be located and was not set, must not be null");
49  		}
50  		getServiceBus().publishService(getServiceDefinition(), forceSync);
51  	}
52  	
53  	protected ServiceBus autoLocateServiceBus() {
54  		return KsbApiServiceLocator.getServiceBus();
55  	}
56  
57  	public ServiceDefinition getServiceDefinition() {
58  		return this.serviceDefinition;
59  	}
60  
61  	public void setServiceDefinition(ServiceDefinition serviceDefinition) {
62  		this.serviceDefinition = serviceDefinition;
63  	}
64  	
65  	public boolean isForceSync() {
66  		return this.forceSync;
67  	}
68  
69  	public void setForceRefresh(boolean forceSync) {
70  		this.forceSync = forceSync;
71  	}
72  
73  	public ServiceBus getServiceBus() {
74  		return this.serviceBus;
75  	}
76  
77  	public void setServiceBus(ServiceBus serviceBus) {
78  		this.serviceBus = serviceBus;
79  	}
80  
81  }