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