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.PropertyUtils;
21  import org.kuali.common.util.property.DefaultPropertyLoadContext;
22  import org.kuali.common.util.service.DefaultPropertyService;
23  import org.kuali.common.util.service.PropertyService;
24  import org.springframework.beans.factory.FactoryBean;
25  
26  public class PropertyFactoryBean extends DefaultPropertyLoadContext implements FactoryBean<Properties> {
27  
28  	protected static Properties instance;
29  	boolean singleton = false;
30  	PropertyService service = new DefaultPropertyService();
31  	boolean show;
32  
33  	@Override
34  	public Properties getObject() throws Exception {
35  		if (isSingleton()) {
36  			return getInstance();
37  		} else {
38  			Properties properties = service.load(this);
39  			if (show) {
40  				PropertyUtils.info(properties);
41  			}
42  			return properties;
43  		}
44  	}
45  
46  	protected synchronized Properties getInstance() {
47  		if (instance == null) {
48  			instance = service.load(this);
49  		}
50  		if (show) {
51  			PropertyUtils.info(instance);
52  		}
53  		return instance;
54  	}
55  
56  	@Override
57  	public Class<Properties> getObjectType() {
58  		return Properties.class;
59  	}
60  
61  	@Override
62  	public boolean isSingleton() {
63  		return this.singleton;
64  	}
65  
66  	public void setSingleton(boolean singleton) {
67  		this.singleton = singleton;
68  	}
69  
70  	public PropertyService getService() {
71  		return service;
72  	}
73  
74  	public void setService(PropertyService service) {
75  		this.service = service;
76  	}
77  
78  	public boolean isShow() {
79  		return show;
80  	}
81  
82  	public void setShow(boolean show) {
83  		this.show = show;
84  	}
85  }