1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.core.impl.resourceloader; |
18 | |
|
19 | |
import java.util.ArrayList; |
20 | |
import java.util.Collection; |
21 | |
import java.util.List; |
22 | |
|
23 | |
import javax.servlet.ServletContext; |
24 | |
import javax.xml.namespace.QName; |
25 | |
|
26 | |
import org.kuali.rice.core.api.config.CoreConfigHelper; |
27 | |
import org.kuali.rice.core.api.config.property.ConfigContext; |
28 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
29 | |
import org.kuali.rice.core.api.resourceloader.ResourceLoader; |
30 | |
import org.kuali.rice.core.framework.resourceloader.BaseResourceLoader; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | 0 | public class RiceResourceLoaderFactory { |
41 | |
|
42 | |
private static final String RICE_ROOT_RESOURCE_LOADER_NAME = "RICE_ROOT_RESOURCE_LOADER"; |
43 | |
private static final String RICE_SPRING_RESOURCE_LOADER_NAME = "RICE_SPRING_RESOURCE_LOADER_NAME"; |
44 | |
|
45 | |
public static ResourceLoader createRootRiceResourceLoader(ServletContext context, List<String> springFileLocations, String prefix) { |
46 | |
|
47 | |
|
48 | 0 | if ("KSB".equals(prefix.toUpperCase())) { |
49 | 0 | prefix = "K~S~B"; |
50 | |
} |
51 | |
|
52 | 0 | String applicationId = CoreConfigHelper.getApplicationId(); |
53 | 0 | final QName root = new QName(applicationId, prefix.toUpperCase() + "_" + RICE_ROOT_RESOURCE_LOADER_NAME); |
54 | |
|
55 | 0 | if (getRootResourceLoaderNames() == null || !getRootResourceLoaderNames().contains(root)) { |
56 | 0 | addRootResourceLoaderName(root); |
57 | |
} |
58 | |
|
59 | 0 | final QName spring = new QName(applicationId, prefix.toUpperCase() + "_" + RICE_SPRING_RESOURCE_LOADER_NAME); |
60 | 0 | if (getSpringResourceLoaderNames() == null || !getSpringResourceLoaderNames().contains(root)) { |
61 | 0 | addSpringResourceLoaderName(spring); |
62 | |
} |
63 | |
|
64 | 0 | final ResourceLoader rootResourceLoader = new BaseResourceLoader(root, new SimpleServiceLocator()); |
65 | |
|
66 | 0 | final ResourceLoader springResourceLoader = new SpringResourceLoader(spring, springFileLocations, context); |
67 | 0 | rootResourceLoader.addResourceLoaderFirst(springResourceLoader); |
68 | |
|
69 | 0 | return rootResourceLoader; |
70 | |
} |
71 | |
|
72 | |
public static Collection<BaseResourceLoader> getRootResourceLoaders() { |
73 | 0 | final Collection<QName> names = getRootResourceLoaderNames(); |
74 | 0 | final Collection<BaseResourceLoader> loaders = new ArrayList<BaseResourceLoader>(); |
75 | 0 | for (QName name : names) { |
76 | 0 | loaders.add((BaseResourceLoader) GlobalResourceLoader.getResourceLoader(name)); |
77 | |
} |
78 | 0 | return loaders; |
79 | |
} |
80 | |
|
81 | |
public static Collection<SpringResourceLoader> getSpringResourceLoaders() { |
82 | 0 | final Collection<QName> names = getSpringResourceLoaderNames(); |
83 | 0 | final Collection<SpringResourceLoader> loaders = new ArrayList<SpringResourceLoader>(); |
84 | 0 | for (QName name : names) { |
85 | 0 | loaders.add((SpringResourceLoader) GlobalResourceLoader.getResourceLoader(name)); |
86 | |
} |
87 | 0 | return loaders; |
88 | |
} |
89 | |
|
90 | |
@SuppressWarnings("unchecked") |
91 | |
private static Collection<QName> getRootResourceLoaderNames() { |
92 | 0 | return (Collection<QName>) ConfigContext.getCurrentContextConfig().getObject(RICE_ROOT_RESOURCE_LOADER_NAME); |
93 | |
} |
94 | |
|
95 | |
private static void addRootResourceLoaderName(QName name) { |
96 | |
@SuppressWarnings("unchecked") |
97 | 0 | Collection<QName> names = (Collection<QName>) ConfigContext.getCurrentContextConfig().getObject(RICE_ROOT_RESOURCE_LOADER_NAME); |
98 | 0 | if (names == null) { |
99 | 0 | names = new ArrayList<QName>(); |
100 | |
} |
101 | 0 | names.add(name); |
102 | |
|
103 | 0 | ConfigContext.getCurrentContextConfig().putObject(RICE_ROOT_RESOURCE_LOADER_NAME, names); |
104 | 0 | } |
105 | |
|
106 | |
@SuppressWarnings("unchecked") |
107 | |
private static Collection<QName> getSpringResourceLoaderNames() { |
108 | 0 | return (Collection<QName>) ConfigContext.getCurrentContextConfig().getObject(RICE_SPRING_RESOURCE_LOADER_NAME); |
109 | |
} |
110 | |
|
111 | |
private static void addSpringResourceLoaderName(QName name) { |
112 | |
@SuppressWarnings("unchecked") |
113 | 0 | Collection<QName> names = (Collection<QName>) ConfigContext.getCurrentContextConfig().getObject(RICE_SPRING_RESOURCE_LOADER_NAME); |
114 | 0 | if (names == null) { |
115 | 0 | names = new ArrayList<QName>(); |
116 | |
} |
117 | 0 | names.add(name); |
118 | |
|
119 | 0 | ConfigContext.getCurrentContextConfig().putObject(RICE_SPRING_RESOURCE_LOADER_NAME, names); |
120 | 0 | } |
121 | |
|
122 | |
} |