org.molgenis.data.EntityFactoryRegistry Maven / Gradle / Ivy
package org.molgenis.data;
import com.google.common.collect.Maps;
import java.util.Map;
import org.molgenis.data.meta.model.EntityType;
import org.springframework.stereotype.Component;
/**
* Registry containing all static entity factories.
*
* @see EntityFactory
* @see org.molgenis.data.support.StaticEntity
*/
@Component
public class EntityFactoryRegistry {
private final Map> staticEntityFactoryMap;
public EntityFactoryRegistry() {
this.staticEntityFactoryMap = Maps.newHashMap();
}
/**
* Registers a static entity factory
*
* @param staticEntityFactory static entity factory
* @param static entity type (e.g. Tag, Language, Package)
*/
void registerStaticEntityFactory(EntityFactory staticEntityFactory) {
String entityTypeId = staticEntityFactory.getEntityTypeId();
staticEntityFactoryMap.put(entityTypeId, staticEntityFactory);
}
/**
* Returns a entity factory for the given entity meta data.
*
* @param entityType entity meta data
* @return static entity factory or null if no factory exists for the given meta data.
*/
EntityFactory extends Entity, ?> getEntityFactory(EntityType entityType) {
return staticEntityFactoryMap.get(entityType.getId());
}
}