001/** 002 * Copyright 2005-2016 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 */ 016package org.kuali.rice.ksb.api.bus.support; 017 018import org.kuali.rice.ksb.api.KsbApiServiceLocator; 019import org.kuali.rice.ksb.api.bus.ServiceBus; 020import org.kuali.rice.ksb.api.bus.ServiceDefinition; 021import org.springframework.beans.factory.InitializingBean; 022 023/** 024 * Used from Spring to register service definitions from an already configured and started KSB. 025 * 026 * @author Kuali Rice Team (rice.collab@kuali.org) 027 */ 028public class ServiceBusExporter implements InitializingBean { 029 030 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ServiceBusExporter.class); 031 032 private ServiceDefinition serviceDefinition; 033 private boolean forceSync = false; 034 private ServiceBus serviceBus; 035 036 public void afterPropertiesSet() { 037 if (getServiceDefinition() == null) { 038 throw new IllegalStateException("serviceDefinition must be set"); 039 } 040 getServiceDefinition().validate(); 041 if ( LOG.isInfoEnabled() ) { 042 LOG.info("Attempting to export service with service name '" + getServiceDefinition().getServiceName()); 043 } 044 if (getServiceBus() == null) { 045 setServiceBus(autoLocateServiceBus()); 046 } 047 if (getServiceBus() == null) { 048 throw new IllegalStateException("serviceBus could not be located and was not set, must not be null"); 049 } 050 getServiceBus().publishService(getServiceDefinition(), forceSync); 051 } 052 053 protected ServiceBus autoLocateServiceBus() { 054 return KsbApiServiceLocator.getServiceBus(); 055 } 056 057 public ServiceDefinition getServiceDefinition() { 058 return this.serviceDefinition; 059 } 060 061 public void setServiceDefinition(ServiceDefinition serviceDefinition) { 062 this.serviceDefinition = serviceDefinition; 063 } 064 065 public boolean isForceSync() { 066 return this.forceSync; 067 } 068 069 public void setForceRefresh(boolean forceSync) { 070 this.forceSync = forceSync; 071 } 072 073 public ServiceBus getServiceBus() { 074 return this.serviceBus; 075 } 076 077 public void setServiceBus(ServiceBus serviceBus) { 078 this.serviceBus = serviceBus; 079 } 080 081}