1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.core.resourceloader;
17
18 import javax.xml.namespace.QName;
19
20 import org.kuali.rice.core.config.Config;
21 import org.kuali.rice.core.config.ConfigContext;
22 import org.kuali.rice.core.config.ConfigurationException;
23
24
25
26
27
28
29
30
31
32 public class RiceResourceLoaderFactory {
33
34 private static final String RICE_ROOT_RESOURCE_LOADER_NAME = "RICE_ROOT_RESOURCE_LOADER";
35 private static final String RICE_SPRING_RESOURCE_LOADER_NAME = "RICE_SPRING_RESOURCE_LOADER_NAME";
36
37 private static void initialize() {
38 Config config = ConfigContext.getCurrentContextConfig();
39 if (config.getServiceNamespace() == null) {
40 throw new ConfigurationException("No service namespace available at this time");
41 }
42 if (getRootResourceLoaderName() == null) {
43 setRootResourceLoaderName(new QName(ConfigContext.getCurrentContextConfig().getServiceNamespace(), RICE_ROOT_RESOURCE_LOADER_NAME));
44 }
45 if (getSpringResourceLoaderName() == null) {
46 setSpringResourceLoaderName(new QName(ConfigContext.getCurrentContextConfig().getServiceNamespace(), RICE_SPRING_RESOURCE_LOADER_NAME));
47 }
48 }
49
50 public static ResourceLoader createRootRiceResourceLoader(String springFileLocations) {
51 initialize();
52 ResourceLoader rootResourceLoader =
53 new BaseResourceLoader((QName)ConfigContext.getCurrentContextConfig().getObject(RICE_ROOT_RESOURCE_LOADER_NAME),
54 new SimpleServiceLocator());
55 ResourceLoader springResourceLoader =
56 new SpringResourceLoader((QName)ConfigContext.getCurrentContextConfig().getObject(RICE_SPRING_RESOURCE_LOADER_NAME),
57 springFileLocations.split(SpringLoader.SPRING_SEPARATOR_CHARACTER));
58 rootResourceLoader.addResourceLoaderFirst(springResourceLoader);
59 return rootResourceLoader;
60 }
61
62 public static BaseResourceLoader getRootResourceLoader() {
63 return (BaseResourceLoader)GlobalResourceLoader.getResourceLoader(getRootResourceLoaderName());
64 }
65
66 public static SpringResourceLoader getSpringResourceLoader() {
67 return (SpringResourceLoader)GlobalResourceLoader.getResourceLoader(getSpringResourceLoaderName());
68 }
69
70 public static QName getRootResourceLoaderName() {
71 return (QName)ConfigContext.getCurrentContextConfig().getObject(RICE_ROOT_RESOURCE_LOADER_NAME);
72 }
73
74 public static void setRootResourceLoaderName(QName name) {
75 ConfigContext.getCurrentContextConfig().putObject(RICE_ROOT_RESOURCE_LOADER_NAME, name);
76 }
77
78 public static QName getSpringResourceLoaderName() {
79 return (QName)ConfigContext.getCurrentContextConfig().getObject(RICE_SPRING_RESOURCE_LOADER_NAME);
80 }
81
82 public static void setSpringResourceLoaderName(QName ksbRsourceLoaderName) {
83 ConfigContext.getCurrentContextConfig().putObject(RICE_SPRING_RESOURCE_LOADER_NAME, ksbRsourceLoaderName);
84 }
85
86 }