1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.impl.util;
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.krms.impl.provider.repository.RepositoryToEngineTranslator;
23
24 import javax.xml.namespace.QName;
25
26
27
28
29
30
31 public class KRMSServiceLocatorInternal {
32
33 public static final String REPOSITORY_TO_ENGINE_TRANSLATOR = "repositoryToEngineTranslator";
34
35 public static final String KRMS_RUN_MODE_PROPERTY = "krms.mode";
36 public static final String KRMS_MODULE_NAMESPACE = "KRMS";
37
38 private static final Logger LOG = Logger.getLogger(KRMSServiceLocatorInternal.class);
39
40
41 @SuppressWarnings("unchecked")
42 public static <A> A getService(String serviceName) {
43 return (A)getBean(serviceName, false);
44 }
45
46 public static <A> A getBean(String serviceName, boolean forceLocal) {
47 if ( LOG.isDebugEnabled() ) {
48 LOG.debug("Fetching service " + serviceName);
49 }
50 QName name = new QName(serviceName);
51 RunMode krmsRunMode = RunMode.valueOf(ConfigContext.getCurrentContextConfig().getProperty(KRMS_RUN_MODE_PROPERTY));
52 if (!forceLocal) {
53 if (krmsRunMode == RunMode.REMOTE || krmsRunMode == RunMode.THIN) {
54 name = new QName(KRMS_MODULE_NAMESPACE, serviceName);
55 }
56 }
57 return GlobalResourceLoader.getResourceLoader().getService(name);
58 }
59
60
61
62
63
64 public static RepositoryToEngineTranslator getRepositoryToEngineTranslator() {
65 return getBean(REPOSITORY_TO_ENGINE_TRANSLATOR, true);
66 }
67
68 }