View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kim.impl.services;
17  
18  import org.apache.log4j.Logger;
19  import org.kuali.rice.core.api.config.module.RunMode;
20  import org.kuali.rice.core.api.config.property.ConfigContext;
21  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
22  import org.kuali.rice.kim.api.KimConstants;
23  import org.kuali.rice.kim.framework.role.RoleTypeService;
24  import org.kuali.rice.kim.impl.group.GroupInternalService;
25  import org.kuali.rice.kim.impl.responsibility.ResponsibilityInternalService;
26  import org.kuali.rice.kim.impl.role.RoleDao;
27  import org.kuali.rice.kim.impl.role.RoleInternalService;
28  import org.springframework.cache.CacheManager;
29  
30  import javax.sql.DataSource;
31  import javax.xml.namespace.QName;
32  
33  public class KimImplServiceLocator {
34      private static final Logger LOG = Logger.getLogger(KimImplServiceLocator.class);
35  
36      public static final String KIM_RUN_MODE_PROPERTY = "kim.mode";
37      public static final String RESPONSIBILITY_INTERNAL_SERVICE = "responsibilityInternalService";
38      public static final String GROUP_INTERNAL_SERVICE = "groupInternalService";
39      public static final String ROLE_INTERNAL_SERVICE = "kimRoleInternalService";
40      public static final String LOCAL_CACHE_MANAGER = "kimLocalCacheManager";
41      public static final String DEFAULT_ROLE_TYPE_SERVICE = "kimRoleTypeService";
42  
43      public static final String KIM_ROLE_DAO = "kimRoleDao";
44      public static final String KIM_DATA_SOURCE = "kimDataSource";
45  
46      public static Object getService(String serviceName) {
47          return getBean(serviceName);
48      }
49  
50      public static Object getBean(String serviceName) {
51          if (LOG.isDebugEnabled()) {
52              LOG.debug("Fetching service " + serviceName);
53          }
54          QName name = new QName(serviceName);
55          RunMode kimRunMode = RunMode.valueOf(ConfigContext.getCurrentContextConfig().getProperty(KIM_RUN_MODE_PROPERTY));
56          if (kimRunMode == RunMode.REMOTE || kimRunMode == RunMode.THIN) {
57              name = new QName(KimConstants.KIM_MODULE_NAMESPACE, serviceName);
58          }
59          return GlobalResourceLoader.getResourceLoader().getService(name);
60      }
61  
62      public static ResponsibilityInternalService getResponsibilityInternalService() {
63          return (ResponsibilityInternalService) getService(RESPONSIBILITY_INTERNAL_SERVICE);
64      }
65  
66      public static GroupInternalService getGroupInternalService() {
67          return (GroupInternalService) getService(GROUP_INTERNAL_SERVICE);
68      }
69  
70      public static RoleInternalService getRoleInternalService() {
71          return (RoleInternalService) getService(ROLE_INTERNAL_SERVICE);
72      }
73  
74      public static CacheManager getLocalCacheManager() {
75          return (CacheManager) getService(LOCAL_CACHE_MANAGER);
76      }
77  
78      public static RoleTypeService getDefaultRoleTypeService() {
79          return (RoleTypeService) getService(DEFAULT_ROLE_TYPE_SERVICE);
80      }
81  
82      public static RoleDao getRoleDao() {
83          return (RoleDao) getService(KIM_ROLE_DAO);
84      }
85  
86      public static DataSource getDataSource() {
87          return (DataSource)getService(KIM_DATA_SOURCE);
88      }
89  }