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.kim.impl.services; 017 018 import org.apache.log4j.Logger; 019 import org.kuali.rice.core.api.config.module.RunMode; 020 import org.kuali.rice.core.api.config.property.ConfigContext; 021 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; 022 import org.kuali.rice.kim.api.KimConstants; 023 import org.kuali.rice.kim.impl.group.GroupInternalService; 024 import org.kuali.rice.kim.impl.responsibility.ResponsibilityInternalService; 025 import org.kuali.rice.kim.impl.role.RoleDao; 026 import org.kuali.rice.kim.impl.role.RoleInternalService; 027 import org.springframework.cache.CacheManager; 028 029 import javax.xml.namespace.QName; 030 031 public class KimImplServiceLocator { 032 private static final Logger LOG = Logger.getLogger(KimImplServiceLocator.class); 033 034 public static final String KIM_RUN_MODE_PROPERTY = "kim.mode"; 035 public static final String RESPONSIBILITY_INTERNAL_SERVICE = "responsibilityInternalService"; 036 public static final String GROUP_INTERNAL_SERVICE = "groupInternalService"; 037 public static final String ROLE_INTERNAL_SERVICE = "kimRoleInternalService"; 038 public static final String LOCAL_CACHE_MANAGER = "kimLocalCacheManager"; 039 040 public static final String KIM_ROLE_DAO = "kimRoleDao"; 041 042 public static Object getService(String serviceName) { 043 return getBean(serviceName); 044 } 045 046 public static Object getBean(String serviceName) { 047 if (LOG.isDebugEnabled()) { 048 LOG.debug("Fetching service " + serviceName); 049 } 050 QName name = new QName(serviceName); 051 RunMode kimRunMode = RunMode.valueOf(ConfigContext.getCurrentContextConfig().getProperty(KIM_RUN_MODE_PROPERTY)); 052 if (kimRunMode == RunMode.REMOTE || kimRunMode == RunMode.THIN) { 053 name = new QName(KimConstants.KIM_MODULE_NAMESPACE, serviceName); 054 } 055 return GlobalResourceLoader.getResourceLoader().getService(name); 056 } 057 058 public static ResponsibilityInternalService getResponsibilityInternalService() { 059 return (ResponsibilityInternalService) getService(RESPONSIBILITY_INTERNAL_SERVICE); 060 } 061 062 public static GroupInternalService getGroupInternalService() { 063 return (GroupInternalService) getService(GROUP_INTERNAL_SERVICE); 064 } 065 066 public static RoleInternalService getRoleInternalService() { 067 return (RoleInternalService) getService(ROLE_INTERNAL_SERVICE); 068 } 069 070 public static CacheManager getLocalCacheManager() { 071 return (CacheManager) getService(LOCAL_CACHE_MANAGER); 072 } 073 074 public static RoleDao getRoleDao() { 075 return (RoleDao) getService(KIM_ROLE_DAO); 076 } 077 }