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.Assert;
21  import org.springframework.beans.factory.FactoryBean;
22  import org.springframework.beans.factory.InitializingBean;
23  
24  /**
25   * Call <code>setProperty(key,value)</code> on <code>properties</code>
26   */
27  public class SetPropertyFactoryBean implements FactoryBean<Properties>, InitializingBean {
28  
29  	Properties properties;
30  	String key;
31  	String value;
32  
33  	@Override
34  	public void afterPropertiesSet() throws Exception {
35  		Assert.notNull(properties, "properties is null");
36  		Assert.notNull(key, "key is null");
37  		Assert.notNull(value, "value is null");
38  		properties.setProperty(key, value);
39  	}
40  
41  	@Override
42  	public Properties getObject() throws Exception {
43  		return properties;
44  	}
45  
46  	@Override
47  	public Class<Properties> getObjectType() {
48  		return Properties.class;
49  	}
50  
51  	@Override
52  	public boolean isSingleton() {
53  		return false;
54  	}
55  
56  	public Properties getProperties() {
57  		return properties;
58  	}
59  
60  	public void setProperties(Properties properties) {
61  		this.properties = properties;
62  	}
63  
64  	public String getKey() {
65  		return key;
66  	}
67  
68  	public void setKey(String key) {
69  		this.key = key;
70  	}
71  
72  	public String getValue() {
73  		return value;
74  	}
75  
76  	public void setValue(String value) {
77  		this.value = value;
78  	}
79  
80  }