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.Map;
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   * Copy all of the mappings from <code>source</code> to <code>target</code>
26   */
27  public class AddToMapFactoryBean<K, V> implements FactoryBean<Map<K, V>>, InitializingBean {
28  
29  	Map<K, V> source;
30  	Map<K, V> target;
31  
32  	@Override
33  	public void afterPropertiesSet() throws Exception {
34  		Assert.notNull(source, "source is null");
35  		Assert.notNull(target, "target is null");
36  		target.putAll(source);
37  	}
38  
39  	@Override
40  	public Map<K, V> getObject() throws Exception {
41  		return target;
42  	}
43  
44  	@Override
45  	public Class<?> getObjectType() {
46  		return Map.class;
47  	}
48  
49  	@Override
50  	public boolean isSingleton() {
51  		return false;
52  	}
53  
54  	public Map<K, V> getSource() {
55  		return source;
56  	}
57  
58  	public void setSource(Map<K, V> source) {
59  		this.source = source;
60  	}
61  
62  	public Map<K, V> getTarget() {
63  		return target;
64  	}
65  
66  	public void setTarget(Map<K, V> target) {
67  		this.target = target;
68  	}
69  
70  }