All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.molgenis.data.EntityFactoryRegistry Maven / Gradle / Ivy

There is a newer version: 8.4.5
Show newest version
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 getEntityFactory(EntityType entityType) {
    return staticEntityFactoryMap.get(entityType.getId());
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy