View Javadoc

1   /**
2    * Copyright 2010-2012 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.common.util.spring;
17  
18  import java.util.Properties;
19  
20  import org.kuali.common.util.property.DefaultPropertyLoadContext;
21  import org.kuali.common.util.service.DefaultPropertyService;
22  import org.kuali.common.util.service.PropertyService;
23  import org.springframework.beans.factory.FactoryBean;
24  
25  public class PropertyFactoryBean extends DefaultPropertyLoadContext implements FactoryBean<Properties> {
26  
27  	protected static Properties properties;
28  	boolean singleton = true;
29  	PropertyService service = new DefaultPropertyService();
30  
31  	@Override
32  	public Properties getObject() throws Exception {
33  		if (isSingleton()) {
34  			return getInstance();
35  		} else {
36  			return service.load(this);
37  		}
38  	}
39  
40  	protected synchronized Properties getInstance() {
41  		if (properties == null) {
42  			properties = service.load(this);
43  		}
44  		return properties;
45  	}
46  
47  	@Override
48  	public Class<Properties> getObjectType() {
49  		return Properties.class;
50  	}
51  
52  	@Override
53  	public boolean isSingleton() {
54  		return this.singleton;
55  	}
56  
57  	public void setSingleton(boolean singleton) {
58  		this.singleton = singleton;
59  	}
60  
61  	public PropertyService getService() {
62  		return service;
63  	}
64  
65  	public void setService(PropertyService service) {
66  		this.service = service;
67  	}
68  }