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