001/**
002 * Copyright 2005-2017 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.service;
017
018import org.apache.cxf.Bus;
019import org.apache.cxf.interceptor.Interceptor;
020import org.apache.cxf.message.Message;
021import org.kuali.rice.core.api.exception.RiceRemoteServiceConnectionException;
022import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
023import org.kuali.rice.ksb.messaging.bam.service.BAMService;
024import org.kuali.rice.ksb.messaging.exceptionhandling.ExceptionRoutingService;
025import org.kuali.rice.ksb.messaging.service.MessageQueueService;
026import org.kuali.rice.ksb.messaging.serviceexporters.ServiceExportManager;
027import org.kuali.rice.ksb.messaging.threadpool.KSBScheduledPool;
028import org.kuali.rice.ksb.messaging.threadpool.KSBThreadPool;
029import org.kuali.rice.ksb.security.admin.service.JavaSecurityManagementService;
030import org.kuali.rice.ksb.security.service.DigitalSignatureService;
031import org.kuali.rice.ksb.util.KSBConstants;
032import org.quartz.Scheduler;
033import org.springframework.transaction.PlatformTransactionManager;
034import org.springframework.transaction.support.TransactionTemplate;
035
036import javax.persistence.EntityManagerFactory;
037import javax.sql.DataSource;
038import java.util.List;
039
040
041public class KSBServiceLocator {
042    public static Object getService(String name) {
043        return GlobalResourceLoader.getService(name);
044    }
045
046    public static EntityManagerFactory getMessageEntityManagerFactory() {
047        return (EntityManagerFactory) getService(KSBConstants.ServiceNames.MESSAGE_ENTITY_MANAGER_FACTORY);
048    }
049    
050    public static EntityManagerFactory getRegistryEntityManagerFactory() {
051        return (EntityManagerFactory) getService(KSBConstants.ServiceNames.REGISTRY_ENTITY_MANAGER_FACTORY);
052    }
053    
054    public static TransactionTemplate getTransactionTemplate() {
055        return (TransactionTemplate) getService(KSBConstants.ServiceNames.TRANSACTION_TEMPLATE);
056    }
057
058    public static PlatformTransactionManager getPlatformTransactionManager() {
059        return (PlatformTransactionManager) getService(KSBConstants.ServiceNames.TRANSACTION_MANAGER);
060    }
061
062    public static BAMService getBAMService() {
063        return (BAMService) getService(KSBConstants.ServiceNames.BAM_SERVICE);
064    }
065
066    public static MessageQueueService getMessageQueueService() {
067        return (MessageQueueService) getService(KSBConstants.ServiceNames.MESSAGE_QUEUE_SERVICE);
068    }
069
070    public static ExceptionRoutingService getExceptionRoutingService() {
071        return (ExceptionRoutingService) getService(KSBConstants.ServiceNames.EXCEPTION_MESSAGING_SERVICE);
072    }
073    
074    public static ServiceExportManager getServiceExportManager() {
075        return (ServiceExportManager) getService(KSBConstants.ServiceNames.SERVICE_EXPORT_MANAGER);
076    }
077
078    public static DigitalSignatureService getDigitalSignatureService() {
079        return (DigitalSignatureService) getService(KSBConstants.ServiceNames.DIGITAL_SIGNATURE_SERVICE);
080    }
081
082    public static JavaSecurityManagementService getJavaSecurityManagementService() {
083        return (JavaSecurityManagementService) getService(KSBConstants.ServiceNames.JAVA_SECURITY_MANAGEMENT_SERVICE);
084    }
085
086    public static KSBThreadPool getThreadPool() {
087        return (KSBThreadPool) getService(KSBConstants.ServiceNames.THREAD_POOL_SERVICE);
088    }
089
090    public static KSBScheduledPool getScheduledPool() {
091        return (KSBScheduledPool) getService(KSBConstants.ServiceNames.SCHEDULED_THREAD_POOL_SERVICE);
092    }
093
094    public static Bus getCXFBus(){
095        return (Bus) getService(KSBConstants.ServiceNames.CXF_BUS);
096    }
097
098    public static List<Interceptor<? extends Message>> getInInterceptors() {
099        try {
100                return (List<Interceptor<? extends Message>>) getService(KSBConstants.ServiceNames.BUS_IN_INTERCEPTORS);
101        }
102        catch(RiceRemoteServiceConnectionException ex) {
103                // swallow this exception, means no bus wide interceptors defined
104                return null;
105        }
106    }
107    
108    public static List<Interceptor<? extends Message>> getOutInterceptors() {
109        try {
110                return (List<Interceptor<? extends Message>>) getService(KSBConstants.ServiceNames.BUS_OUT_INTERCEPTORS);
111        }
112        catch(RiceRemoteServiceConnectionException ex) {
113                // swallow this exception, means no bus wide interceptors defined
114                return null;
115        }
116    }
117
118    public static DataSource getMessageDataSource() {
119        return (DataSource) getService(KSBConstants.ServiceNames.MESSAGE_DATASOURCE);
120    }
121
122    public static DataSource getMessageNonTransactionalDataSource() {
123        return (DataSource) getService(KSBConstants.ServiceNames.MESSAGE_NON_TRANSACTIONAL_DATASOURCE);
124    }
125
126    public static DataSource getRegistryDataSource() {
127        return (DataSource) getService(KSBConstants.ServiceNames.REGISTRY_DATASOURCE);
128    }
129
130    public static Scheduler getScheduler() {
131        return (Scheduler) getService(KSBConstants.ServiceNames.SCHEDULER);
132    }
133
134    public static BasicAuthenticationService getBasicAuthenticationService() {
135        return (BasicAuthenticationService) getService(KSBConstants.ServiceNames.BASIC_AUTHENTICATION_SERVICE);
136    }
137
138}