001 /* 002 * Copyright 2005-2008 The Kuali Foundation 003 * 004 * 005 * Licensed under the Educational Community License, Version 2.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/ecl2.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 org.kuali.rice.ksb.messaging; 018 019 import org.kuali.rice.ksb.service.KSBServiceLocator; 020 import org.springframework.beans.factory.InitializingBean; 021 import org.springframework.context.ApplicationContext; 022 import org.springframework.context.ApplicationContextAware; 023 024 /** 025 * Used from Spring to register service definitions from an already configured and started KSB. 026 * 027 * @author Kuali Rice Team (rice.collab@kuali.org) 028 */ 029 public class KSBExporter implements InitializingBean, ApplicationContextAware { 030 031 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(KSBExporter.class); 032 033 private ServiceDefinition serviceDefinition; 034 private boolean forceRefresh = false; 035 protected RemotedServiceRegistry remotedServiceRegistry; 036 protected ApplicationContext applicationContext; 037 038 public void afterPropertiesSet() throws Exception { 039 this.getServiceDefinition().validate(); 040 if ( LOG.isInfoEnabled() ) { 041 LOG.info("Attempting to expose service with localServiceName '" + this.getServiceDefinition().getLocalServiceName() + "' and QName '" + this.getServiceDefinition().getServiceName() + "'"); 042 } 043 if(getRemotedServiceRegistry()!=null) { 044 getRemotedServiceRegistry().registerService(this.getServiceDefinition(), this.isForceRefresh()); 045 } else if ( KSBServiceLocator.getServiceDeployer() != null ) { 046 KSBServiceLocator.getServiceDeployer().registerService(this.getServiceDefinition(), this.isForceRefresh()); 047 } else { 048 ((RemotedServiceRegistry)applicationContext.getBean( KSBServiceLocator.REMOTED_SERVICE_REGISTRY )).registerService(this.getServiceDefinition(), this.isForceRefresh()); 049 } 050 } 051 052 public ServiceDefinition getServiceDefinition() { 053 return serviceDefinition; 054 } 055 056 public void setServiceDefinition(ServiceDefinition serviceDefinition) { 057 this.serviceDefinition = serviceDefinition; 058 } 059 060 public boolean isForceRefresh() { 061 return forceRefresh; 062 } 063 064 public void setForceRefresh(boolean forceRefresh) { 065 this.forceRefresh = forceRefresh; 066 } 067 068 /** 069 * @return the remotedServiceRegistry 070 */ 071 public RemotedServiceRegistry getRemotedServiceRegistry() { 072 return this.remotedServiceRegistry; 073 } 074 075 /** 076 * @param remotedServiceRegistry the remotedServiceRegistry to set 077 */ 078 public void setRemotedServiceRegistry( 079 RemotedServiceRegistry remotedServiceRegistry) { 080 this.remotedServiceRegistry = remotedServiceRegistry; 081 } 082 083 public void setApplicationContext(ApplicationContext applicationContext) { 084 this.applicationContext = applicationContext; 085 } 086 087 }