1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.common.test.resourceloader;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.CoreApiServiceLocator;
20 import org.kuali.rice.core.api.config.property.ConfigurationService;
21 import org.kuali.rice.core.api.resourceloader.ServiceLocator;
22 import org.kuali.rice.kim.api.identity.IdentityService;
23 import org.kuali.rice.kim.api.role.RoleService;
24 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
25 import org.kuali.rice.krad.service.impl.KualiModuleServiceImpl;
26 import org.kuali.student.kim.permission.mock.IdentityServiceMockImpl;
27 import org.kuali.student.kim.permission.mock.RoleServiceMockImpl;
28 import org.springframework.context.ApplicationContext;
29
30 import javax.xml.namespace.QName;
31 import java.util.Map;
32
33
34
35
36
37
38
39 public class SimpleSpringResourceLoader implements ServiceLocator {
40
41 private static final ConfigurationService configurationService = new ConfigurationService() {
42 @Override public String getPropertyValueAsString(String key) { return "{0} message"; }
43 @Override public boolean getPropertyValueAsBoolean(String key) { return false; }
44 @Override public Map<String, String> getAllProperties() { return null; }
45 };
46
47 private static final KualiModuleServiceImpl kualiModuleService = new KualiModuleServiceImpl();
48 private static final IdentityService identityService = new IdentityServiceMockImpl();
49 private static final RoleService roleService = new RoleServiceMockImpl();
50
51 private ApplicationContext applicationContext;
52
53 public SimpleSpringResourceLoader(ApplicationContext applicationContext) {
54 this.applicationContext = applicationContext;
55
56 kualiModuleService.setApplicationContext(applicationContext);
57 }
58
59 public Object getService(QName qname) {
60 if (qname == null || StringUtils.isEmpty(qname.toString())) {
61 throw new IllegalArgumentException("The service name must be non-null.");
62 }
63
64 String qualifiedServiceName = qname.toString();
65
66 if (CoreApiServiceLocator.KUALI_CONFIGURATION_SERVICE.equals(qualifiedServiceName)) {
67 return configurationService;
68 } else if (KRADServiceLocatorWeb.KUALI_MODULE_SERVICE.equals(qualifiedServiceName)) {
69 return kualiModuleService;
70 } else if ("{http://rice.kuali.org/kim/v2_0}identityService".equals(qualifiedServiceName)) {
71 return identityService;
72 } else if ("{http://rice.kuali.org/kim/v2_0}roleService".equals(qualifiedServiceName)) {
73 return roleService;
74 } else {
75
76 String localBeanName = qname.getLocalPart();
77 return applicationContext.getBean(localBeanName);
78 }
79 }
80
81
82
83 @Override
84 public String getContents(String indent, boolean servicePerLine) {
85 return null;
86 }
87
88 @Override
89 public void start() throws Exception {
90 }
91
92 @Override
93 public void stop() throws Exception {
94 }
95
96 @Override
97 public boolean isStarted() {
98 return false;
99 }
100 }