com.github.dynamicextensionsalfresco.osgi.spring.ConfigurationValuesFactoryBean Maven / Gradle / Ivy
Show all versions of alfresco-integration Show documentation
package com.github.dynamicextensionsalfresco.osgi.spring;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import com.github.dynamicextensionsalfresco.osgi.ConfigurationValues;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.util.Assert;
/**
* {@link FactoryBean} that combines all the items from multiple Sets into a single Set.
*
* This implementation preserves the original item order.
*
* @author Laurens Fridael
*
* @param
*/
public class ConfigurationValuesFactoryBean implements FactoryBean> {
/* Configuration */
private List> sets;
private ConfigurationValues instance;
/* Main operations */
@Override
public boolean isSingleton() {
return true;
}
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public Class getObjectType() {
return ConfigurationValues.class;
}
@Override
public ConfigurationValues getObject() throws Exception {
if (instance == null) {
instance = createContainerConfiguration();
}
return instance;
}
/* Utility operations */
protected ConfigurationValues createContainerConfiguration() {
final Set items = new LinkedHashSet(getTotalSize());
for (final Set set : getSets()) {
items.addAll(set);
}
return new ConfigurationValues(items);
}
protected int getTotalSize() {
int totalSize = 0;
for (final Set set : getSets()) {
totalSize += set.size();
}
return totalSize;
}
/* Configuration */
public void setSets(final List> sets) {
Assert.notNull(sets);
this.sets = sets;
}
protected List> getSets() {
return sets;
}
}