001 /**
002 * Copyright 2010-2012 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.common.util.spring;
017
018 import java.util.Properties;
019
020 import org.kuali.common.util.PropertyUtils;
021 import org.kuali.common.util.property.DefaultPropertyLoadContext;
022 import org.kuali.common.util.service.DefaultPropertyService;
023 import org.kuali.common.util.service.PropertyService;
024 import org.springframework.beans.factory.FactoryBean;
025
026 public class PropertyFactoryBean extends DefaultPropertyLoadContext implements FactoryBean<Properties> {
027
028 protected static Properties instance;
029 boolean singleton = false;
030 PropertyService service = new DefaultPropertyService();
031 boolean show;
032
033 @Override
034 public Properties getObject() throws Exception {
035 if (isSingleton()) {
036 return getInstance();
037 } else {
038 Properties properties = service.load(this);
039 if (show) {
040 PropertyUtils.info(properties);
041 }
042 return properties;
043 }
044 }
045
046 protected synchronized Properties getInstance() {
047 if (instance == null) {
048 instance = service.load(this);
049 }
050 if (show) {
051 PropertyUtils.info(instance);
052 }
053 return instance;
054 }
055
056 @Override
057 public Class<Properties> getObjectType() {
058 return Properties.class;
059 }
060
061 @Override
062 public boolean isSingleton() {
063 return this.singleton;
064 }
065
066 public void setSingleton(boolean singleton) {
067 this.singleton = singleton;
068 }
069
070 public PropertyService getService() {
071 return service;
072 }
073
074 public void setService(PropertyService service) {
075 this.service = service;
076 }
077
078 public boolean isShow() {
079 return show;
080 }
081
082 public void setShow(boolean show) {
083 this.show = show;
084 }
085 }