View Javadoc
1   /**
2    * Copyright 2005-2015 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.data.DataIntegrityService;
25  import org.kuali.rice.kim.impl.group.GroupInternalService;
26  import org.kuali.rice.kim.impl.responsibility.ResponsibilityInternalService;
27  import org.kuali.rice.kim.impl.role.RoleDao;
28  import org.kuali.rice.kim.impl.role.RoleInternalService;
29  import org.springframework.cache.CacheManager;
30  
31  import javax.sql.DataSource;
32  import javax.xml.namespace.QName;
33  
34  public class KimImplServiceLocator {
35      private static final Logger LOG = Logger.getLogger(KimImplServiceLocator.class);
36  
37      public static final String KIM_RUN_MODE_PROPERTY = "kim.mode";
38      public static final String RESPONSIBILITY_INTERNAL_SERVICE = "responsibilityInternalService";
39      public static final String GROUP_INTERNAL_SERVICE = "groupInternalService";
40      public static final String ROLE_INTERNAL_SERVICE = "kimRoleInternalService";
41      public static final String LOCAL_CACHE_MANAGER = "kimLocalCacheManager";
42      public static final String DEFAULT_ROLE_TYPE_SERVICE = "kimRoleTypeService";
43      public static final String DATA_INTEGRITY_SERVICE = "kimDataIntegrityService";
44  
45      public static final String KIM_ROLE_DAO = "kimRoleDao";
46      public static final String KIM_DATA_SOURCE = "kimDataSource";
47  
48      public static Object getService(String serviceName) {
49          return getBean(serviceName);
50      }
51  
52      public static Object getBean(String serviceName) {
53          if (LOG.isDebugEnabled()) {
54              LOG.debug("Fetching service " + serviceName);
55          }
56          QName name = new QName(serviceName);
57          RunMode kimRunMode = RunMode.valueOf(ConfigContext.getCurrentContextConfig().getProperty(KIM_RUN_MODE_PROPERTY));
58          if (kimRunMode == RunMode.REMOTE || kimRunMode == RunMode.THIN) {
59              name = new QName(KimConstants.KIM_MODULE_NAMESPACE, serviceName);
60          }
61          return GlobalResourceLoader.getResourceLoader().getService(name);
62      }
63  
64      public static ResponsibilityInternalService getResponsibilityInternalService() {
65          return (ResponsibilityInternalService) getService(RESPONSIBILITY_INTERNAL_SERVICE);
66      }
67  
68      public static GroupInternalService getGroupInternalService() {
69          return (GroupInternalService) getService(GROUP_INTERNAL_SERVICE);
70      }
71  
72      public static RoleInternalService getRoleInternalService() {
73          return (RoleInternalService) getService(ROLE_INTERNAL_SERVICE);
74      }
75  
76      public static CacheManager getLocalCacheManager() {
77          return (CacheManager) getService(LOCAL_CACHE_MANAGER);
78      }
79  
80      public static RoleTypeService getDefaultRoleTypeService() {
81          return (RoleTypeService) getService(DEFAULT_ROLE_TYPE_SERVICE);
82      }
83  
84      public static DataIntegrityService getDataIntegrityService() {
85          return (DataIntegrityService) getService(DATA_INTEGRITY_SERVICE);
86      }
87  
88      public static RoleDao getRoleDao() {
89          return (RoleDao) getService(KIM_ROLE_DAO);
90      }
91  
92      public static DataSource getDataSource() {
93          return (DataSource)getService(KIM_DATA_SOURCE);
94      }
95  }