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