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.service;
17  
18  import javax.xml.namespace.QName;
19  
20  import org.apache.log4j.Logger;
21  import org.kuali.rice.core.api.config.module.RunMode;
22  import org.kuali.rice.core.api.config.property.ConfigContext;
23  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
24  import org.kuali.rice.kim.api.KimConstants;
25  import org.kuali.rice.kim.impl.group.GroupInternalService;
26  
27  /**
28   * Service locator for KIM.
29   *
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   *
32   */
33  public final class KIMServiceLocatorInternal {
34  
35  	private static final Logger LOG = Logger.getLogger(KIMServiceLocatorInternal.class);
36  
37  	public static final String KIM_RUN_MODE_PROPERTY = "kim.mode";
38  
39      public static final String KIM_UI_DOCUMENT_SERVICE = "kimUiDocumentService";
40  	public static final String GROUP_INTERNAL_SERVICE = "groupInternalService";
41  
42      public static Object getService(String serviceName) {
43  		return getBean(serviceName);
44  	}
45  
46  	public static Object getBean(String serviceName) {
47  		if ( LOG.isDebugEnabled() ) {
48  			LOG.debug("Fetching service " + serviceName);
49  		}
50          QName name = new QName(serviceName);
51          RunMode kimRunMode = RunMode.valueOf(ConfigContext.getCurrentContextConfig().getProperty(KIM_RUN_MODE_PROPERTY));
52          if (kimRunMode == RunMode.REMOTE || kimRunMode == RunMode.THIN) {
53              name = new QName(KimConstants.KIM_MODULE_NAMESPACE, serviceName);
54          }
55          return GlobalResourceLoader.getResourceLoader().getService(name);
56  	}
57  
58      public static UiDocumentService getUiDocumentService() {
59      	return (UiDocumentService)getService(KIM_UI_DOCUMENT_SERVICE);
60      }
61  
62      public static GroupInternalService getGroupInternalService() {
63          return (GroupInternalService)getService(GROUP_INTERNAL_SERVICE);
64      }
65  }