View Javadoc

1   /*
2    * Copyright 2005-2008 The Kuali Foundation
3    * 
4    * 
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    * 
9    * http://www.opensource.org/licenses/ecl2.php
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.kuali.rice.ksb.messaging;
18  
19  import org.kuali.rice.ksb.service.KSBServiceLocator;
20  import org.springframework.beans.factory.InitializingBean;
21  import org.springframework.context.ApplicationContext;
22  import org.springframework.context.ApplicationContextAware;
23  
24  /**
25   * Used from Spring to register service definitions from an already configured and started KSB.
26   * 
27   * @author Kuali Rice Team (rice.collab@kuali.org)
28   */
29  public class KSBExporter implements InitializingBean, ApplicationContextAware {
30  	
31  	private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(KSBExporter.class);
32  	
33  	private ServiceDefinition serviceDefinition;
34  	private boolean forceRefresh = false;
35  	protected RemotedServiceRegistry remotedServiceRegistry;
36  	protected ApplicationContext applicationContext;
37  
38  	public void afterPropertiesSet() throws Exception {
39  		this.getServiceDefinition().validate();
40  		if ( LOG.isInfoEnabled() ) {
41  			LOG.info("Attempting to expose service with localServiceName '" + this.getServiceDefinition().getLocalServiceName() + "' and QName '" + this.getServiceDefinition().getServiceName() + "'");
42  		}
43  		if(getRemotedServiceRegistry()!=null) {
44  			getRemotedServiceRegistry().registerService(this.getServiceDefinition(), this.isForceRefresh());
45  		} else if ( KSBServiceLocator.getServiceDeployer() != null ) {
46  			KSBServiceLocator.getServiceDeployer().registerService(this.getServiceDefinition(), this.isForceRefresh());
47  		} else {
48  			((RemotedServiceRegistry)applicationContext.getBean( KSBServiceLocator.REMOTED_SERVICE_REGISTRY )).registerService(this.getServiceDefinition(), this.isForceRefresh());
49  		}
50  	}
51  
52  	public ServiceDefinition getServiceDefinition() {
53  		return serviceDefinition;
54  	}
55  
56  	public void setServiceDefinition(ServiceDefinition serviceDefinition) {
57  		this.serviceDefinition = serviceDefinition;
58  	}
59  
60  	public boolean isForceRefresh() {
61  		return forceRefresh;
62  	}
63  
64  	public void setForceRefresh(boolean forceRefresh) {
65  		this.forceRefresh = forceRefresh;
66  	}
67  
68  	/**
69  	 * @return the remotedServiceRegistry
70  	 */
71  	public RemotedServiceRegistry getRemotedServiceRegistry() {
72  		return this.remotedServiceRegistry;
73  	}
74  
75  	/**
76  	 * @param remotedServiceRegistry the remotedServiceRegistry to set
77  	 */
78  	public void setRemotedServiceRegistry(
79  			RemotedServiceRegistry remotedServiceRegistry) {
80  		this.remotedServiceRegistry = remotedServiceRegistry;
81  	}
82  
83  	public void setApplicationContext(ApplicationContext applicationContext) {
84  		this.applicationContext = applicationContext;
85  	}
86  
87  }