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