View Javadoc

1   /**
2    * Copyright 2010-2013 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.Collection;
19  import java.util.List;
20  
21  import org.kuali.common.util.Assert;
22  import org.springframework.beans.factory.FactoryBean;
23  import org.springframework.beans.factory.InitializingBean;
24  
25  /**
26   * Append all of the elements from <code>source</code> to the end of <code>target</code>
27   */
28  public class AddToListFactoryBean<T> implements FactoryBean<List<T>>, InitializingBean {
29  
30  	List<T> source;
31  	List<T> target;
32  
33  	@Override
34  	public void afterPropertiesSet() throws Exception {
35  		Assert.notNull(source, "source is null");
36  		Assert.notNull(target, "target is null");
37  		target.addAll(source);
38  	}
39  
40  	@Override
41  	public List<T> getObject() throws Exception {
42  		return target;
43  	}
44  
45  	@Override
46  	public Class<?> getObjectType() {
47  		return List.class;
48  	}
49  
50  	@Override
51  	public boolean isSingleton() {
52  		return false;
53  	}
54  
55  	public Collection<T> getSource() {
56  		return source;
57  	}
58  
59  	public void setSource(List<T> source) {
60  		this.source = source;
61  	}
62  
63  	public Collection<T> getTarget() {
64  		return target;
65  	}
66  
67  	public void setTarget(List<T> target) {
68  		this.target = target;
69  	}
70  
71  }