1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ksb.messaging.resourceloader;
17
18 import org.kuali.rice.core.api.config.CoreConfigHelper;
19 import org.kuali.rice.core.api.config.property.ConfigContext;
20 import org.kuali.rice.core.api.resourceloader.ResourceLoader;
21 import org.kuali.rice.core.framework.resourceloader.BaseResourceLoader;
22 import org.kuali.rice.ksb.api.KsbApiServiceLocator;
23 import org.kuali.rice.ksb.api.bus.ServiceBus;
24
25 import javax.xml.namespace.QName;
26
27
28
29
30
31
32
33
34
35
36
37
38
39 public class KSBResourceLoaderFactory {
40
41 private static final String KSB_ROOT_RESOURCE_LOACER_NAME = "KSB_ROOT_RESOURCE_LOADER";
42 private static final String KSB_REMOTE_RESOURCE_LOADER_LOCAL_NAME = "KSB_REMOTE_RESOURCE_LOADER";
43
44 private static void initialize() {
45 String applicationId = CoreConfigHelper.getApplicationId();
46 if (getRootResourceLoaderName() == null) {
47 setRootResourceLoaderName(new QName(applicationId, KSB_ROOT_RESOURCE_LOACER_NAME));
48 }
49 if (getRemoteResourceLoaderName() == null) {
50 setRemoteResourceLoaderName(new QName(applicationId, KSB_REMOTE_RESOURCE_LOADER_LOCAL_NAME));
51 }
52 }
53
54 public static ResourceLoader createRootKSBRemoteResourceLoader() {
55 initialize();
56 ResourceLoader rootResourceLoader = new BaseResourceLoader(getRootResourceLoaderName());
57 ServiceBus serviceBus = KsbApiServiceLocator.getServiceBus();
58 if (serviceBus == null) {
59 throw new IllegalStateException("Failed to locate the ServiceBus");
60 }
61 rootResourceLoader.addResourceLoader(new ServiceBusResourceLoader(getRemoteResourceLoaderName(), serviceBus));
62 return rootResourceLoader;
63 }
64
65 public static QName getRootResourceLoaderName() {
66 return (QName)ConfigContext.getCurrentContextConfig().getObject(KSB_ROOT_RESOURCE_LOACER_NAME);
67 }
68
69 public static void setRootResourceLoaderName(QName name) {
70 ConfigContext.getCurrentContextConfig().putObject(KSB_ROOT_RESOURCE_LOACER_NAME, name);
71 }
72
73 public static QName getRemoteResourceLoaderName() {
74 return (QName)ConfigContext.getCurrentContextConfig().getObject(KSB_REMOTE_RESOURCE_LOADER_LOCAL_NAME);
75 }
76
77 public static void setRemoteResourceLoaderName(QName remoteResourceLoaderName) {
78 ConfigContext.getCurrentContextConfig().putObject(KSB_REMOTE_RESOURCE_LOADER_LOCAL_NAME, remoteResourceLoaderName);
79 }
80
81 }