1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.krad.config; |
17 | |
|
18 | |
import org.kuali.rice.core.api.config.ConfigurationException; |
19 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
20 | |
import org.springframework.beans.factory.FactoryBean; |
21 | |
import org.springframework.beans.factory.InitializingBean; |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
public class GlobalResourceLoaderServiceFactoryBean implements FactoryBean<Object>, InitializingBean { |
30 | |
|
31 | |
private String serviceName; |
32 | |
private boolean singleton; |
33 | |
private boolean mustExist; |
34 | |
|
35 | |
|
36 | 0 | private boolean isFetchingService = false; |
37 | |
|
38 | 0 | public GlobalResourceLoaderServiceFactoryBean() { |
39 | 0 | this.mustExist = true; |
40 | 0 | } |
41 | |
|
42 | |
public Object getObject() throws Exception { |
43 | 0 | if (isFetchingService) return null; |
44 | 0 | isFetchingService = true; |
45 | |
try { |
46 | 0 | Object service = GlobalResourceLoader.getService(this.getServiceName()); |
47 | 0 | if (mustExist && service == null) { |
48 | 0 | throw new IllegalStateException("Service must exist and no service could be located with name: " + this.getServiceName()); |
49 | |
} |
50 | 0 | return service; |
51 | |
} finally { |
52 | 0 | isFetchingService = false; |
53 | |
} |
54 | |
} |
55 | |
|
56 | |
public Class<?> getObjectType() { |
57 | 0 | return Object.class; |
58 | |
} |
59 | |
|
60 | |
public boolean isSingleton() { |
61 | 0 | return singleton; |
62 | |
} |
63 | |
|
64 | |
public String getServiceName() { |
65 | 0 | return serviceName; |
66 | |
} |
67 | |
|
68 | |
public void setServiceName(String serviceName) { |
69 | 0 | this.serviceName = serviceName; |
70 | 0 | } |
71 | |
|
72 | |
public void setSingleton(boolean singleton) { |
73 | 0 | this.singleton = singleton; |
74 | 0 | } |
75 | |
|
76 | |
public boolean isMustExist() { |
77 | 0 | return mustExist; |
78 | |
} |
79 | |
|
80 | |
public void setMustExist(boolean mustExist) { |
81 | 0 | this.mustExist = mustExist; |
82 | 0 | } |
83 | |
|
84 | |
|
85 | |
public void afterPropertiesSet() throws Exception { |
86 | 0 | if (this.getServiceName() == null) { |
87 | 0 | throw new ConfigurationException("No serviceName given."); |
88 | |
} |
89 | 0 | } |
90 | |
|
91 | |
} |