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

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

There is a newer version: 8.4.5
Show newest version
package org.molgenis.data;

import static java.util.Objects.requireNonNull;

import java.util.Map;
import org.springframework.context.ApplicationContext;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * Discovers and registers entity factories with the entity factory registry.
 *
 * @see EntityFactory
 * @see EntityFactoryRegistry
 */
@Component
public class EntityFactoryRegistrar {
  private final EntityFactoryRegistry entityFactoryRegistry;

  public EntityFactoryRegistrar(EntityFactoryRegistry entityFactoryRegistry) {
    this.entityFactoryRegistry = requireNonNull(entityFactoryRegistry);
  }

  public void register(ContextRefreshedEvent event) {
    ApplicationContext ctx = event.getApplicationContext();
    Map entityFactoryMap = ctx.getBeansOfType(EntityFactory.class);
    entityFactoryMap.values().forEach(this::registerStaticEntityFactory);
  }

  private void registerStaticEntityFactory(EntityFactory untypedEntityFactory) {
    entityFactoryRegistry.registerStaticEntityFactory(
        (EntityFactory) untypedEntityFactory);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy