View Javadoc

1   /*
2    * Copyright 2007-2009 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kns.config;
17  
18  import org.kuali.rice.core.config.ConfigurationException;
19  import org.kuali.rice.core.resourceloader.GlobalResourceLoader;
20  import org.springframework.beans.factory.FactoryBean;
21  import org.springframework.beans.factory.InitializingBean;
22  
23  /**
24   * Exports services in the {@link GlobalResourceLoader} as beans available to Spring.
25   * 
26   * @author Kuali Rice Team (rice.collab@kuali.org)
27   *
28   */
29  public class GlobalResourceLoaderServiceFactoryBean implements FactoryBean, InitializingBean {
30  
31  	private String serviceName;
32  	private boolean singleton;
33  	
34  	public Object getObject() throws Exception {
35  		return GlobalResourceLoader.getService(this.getServiceName());
36  	}
37  
38  	public Class getObjectType() {
39  		return Object.class;
40  	}
41  
42  	public boolean isSingleton() {
43  		return singleton;
44  	}
45  
46  	public String getServiceName() {
47  		return serviceName;
48  	}
49  
50  	public void setServiceName(String serviceName) {
51  		this.serviceName = serviceName;
52  	}
53  
54  	public void setSingleton(boolean singleton) {
55  		this.singleton = singleton;
56  	}
57  
58  	public void afterPropertiesSet() throws Exception {
59  		if (this.getServiceName() == null) {
60  			throw new ConfigurationException("No serviceName given.");
61  		}
62  	}
63  
64  }