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