org.springframework.beans.factory.config
public class: ListFactoryBean [javadoc |
source]
java.lang.Object
org.springframework.beans.factory.config.AbstractFactoryBean
org.springframework.beans.factory.config.ListFactoryBean
All Implemented Interfaces:
BeanClassLoaderAware, DisposableBean, BeanFactoryAware, InitializingBean, FactoryBean
Simple factory for shared List instances. Allows for central setup
of Lists via the "list" element in XML bean definitions.
| Methods from org.springframework.beans.factory.config.AbstractFactoryBean: |
|---|
|
afterPropertiesSet, createInstance, destroy, destroyInstance, getBeanFactory, getBeanTypeConverter, getEarlySingletonInterfaces, getObject, getObjectType, isSingleton, setBeanClassLoader, setBeanFactory, setSingleton |
| Method from org.springframework.beans.factory.config.ListFactoryBean Detail: |
protected Object createInstance() {
if (this.sourceList == null) {
throw new IllegalArgumentException("'sourceList' is required");
}
List result = null;
if (this.targetListClass != null) {
result = (List) BeanUtils.instantiateClass(this.targetListClass);
}
else {
result = new ArrayList(this.sourceList.size());
}
Class valueType = null;
if (this.targetListClass != null && JdkVersion.isAtLeastJava15()) {
valueType = GenericCollectionTypeResolver.getCollectionType(this.targetListClass);
}
if (valueType != null) {
TypeConverter converter = getBeanTypeConverter();
for (Iterator it = this.sourceList.iterator(); it.hasNext();) {
result.add(converter.convertIfNecessary(it.next(), valueType));
}
}
else {
result.addAll(this.sourceList);
}
return result;
}
|
public Class getObjectType() {
return List.class;
}
|
public void setSourceList(List sourceList) {
this.sourceList = sourceList;
}
Set the source List, typically populated via XML "list" elements. |
public void setTargetListClass(Class targetListClass) {
if (targetListClass == null) {
throw new IllegalArgumentException("'targetListClass' must not be null");
}
if (!List.class.isAssignableFrom(targetListClass)) {
throw new IllegalArgumentException("'targetListClass' must implement [java.util.List]");
}
this.targetListClass = targetListClass;
}
|