Class DefaultDataProviderFactory

java.lang.Object
org.fastnate.data.AbstractDataProviderFactory
org.fastnate.data.DefaultDataProviderFactory
All Implemented Interfaces:
DataProviderFactory

public class DefaultDataProviderFactory extends AbstractDataProviderFactory
Finds and builds all implementations of DataProvider from the class path. Each found non abstract class extending DataProvider is instantiated:
  1. First a constructor with parameters of an allowed type is searched.
  2. Then all fields and setters marked with @Resource are initiated.
  3. At the end all methods marked with @PostConstruct are invoked.
  4. If nothing fails, the new provider is registered.
Allowed types for constructor parameters and resources: The factory will search for the available data providers in the packages defined in the property EntityImporter.PACKAGES_KEY. In addition one can define one or more data providers in the file /META-INF/services/org.fastnate.data.DataProvider.
Author:
Tobias Liefke
  • Constructor Details

    • DefaultDataProviderFactory

      public DefaultDataProviderFactory()
  • Method Details

    • addProvider

      protected <C extends DataProvider> C addProvider(EntityImporter importer, Class<C> providerClass)
      Tries to instantiate the provider from the given class.
      Parameters:
      importer - the current importer that will be used with that provider
      providerClass - the class of the provider to instantiate
      Returns:
      the created provider or null if the given class has no appropriate constructor
    • addProvider

      protected <C extends DataProvider> C addProvider(EntityImporter importer, Constructor<C> constructor)
      Tries to create a provider using the given constructor and adds it to list of providers in the EntityImporter.
      Parameters:
      importer - the current instance of the importer for adding the new provider
      constructor - the constructor of the new provider
      Returns:
      the created provider or null if the given constructor is not appropriate
    • createDataProviders

      public void createDataProviders(EntityImporter importer)
      Description copied from interface: DataProviderFactory
      Discovers, builds and registers all DataProviders that are available for the current environment. Ensures that the order of the providers is set in accordance with their dependencies.
      Parameters:
      importer - the current importer that needs the providers, new providers are added with EntityImporter.addDataProvider(DataProvider) or EntityImporter.addDataProvider(DataProvider, int)