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