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.Collection;
019 import java.util.List;
020
021 import org.kuali.common.util.Assert;
022 import org.springframework.beans.factory.FactoryBean;
023 import org.springframework.beans.factory.InitializingBean;
024
025 /**
026 * Append all of the elements from <code>source</code> to the end of <code>target</code>
027 */
028 public class AddAllListFactoryBean<T> implements FactoryBean<List<T>>, InitializingBean {
029
030 List<T> source;
031 List<T> target;
032
033 @Override
034 public void afterPropertiesSet() throws Exception {
035 Assert.notNull(source, "source is null");
036 Assert.notNull(target, "target is null");
037 target.addAll(source);
038 }
039
040 @Override
041 public List<T> getObject() throws Exception {
042 return target;
043 }
044
045 @Override
046 public Class<?> getObjectType() {
047 return null;
048 }
049
050 @Override
051 public boolean isSingleton() {
052 return false;
053 }
054
055 public Collection<T> getSource() {
056 return source;
057 }
058
059 public void setSource(List<T> source) {
060 this.source = source;
061 }
062
063 public Collection<T> getTarget() {
064 return target;
065 }
066
067 public void setTarget(List<T> target) {
068 this.target = target;
069 }
070
071 }