Class StreamFactoryRegistry

java.lang.Object
opennlp.tools.cmdline.StreamFactoryRegistry

public final class StreamFactoryRegistry extends Object
  • Field Details

  • Constructor Details

    • StreamFactoryRegistry

      private StreamFactoryRegistry()
  • Method Details

    • registerFactory

      public static <T,P> boolean registerFactory(Class<T> sampleClass, String formatName, ObjectStreamFactory<T,P> factory)
      Registers factory which reads format named formatName and instantiates streams producing objects of sampleClass class.
      Parameters:
      sampleClass - class of the objects, produced by the streams instantiated by the factory
      formatName - name of the format
      factory - instance of the factory
      Returns:
      true if the factory was successfully registered
    • unregisterFactory

      public static <T> void unregisterFactory(Class<T> sampleClass, String formatName)
      Unregisters a factory which reads format named formatName and instantiates streams producing objects of sampleClass class.
      Parameters:
      sampleClass - class of the objects, produced by the streams instantiated by the factory
      formatName - name of the format
    • getFactories

      public static <T,P> Map<String, ObjectStreamFactory<T,P>> getFactories(Class<T> sampleClass)
      Returns all factories which produce objects of sampleClass class.
      Parameters:
      sampleClass - class of the objects, produced by the streams instantiated by the factory
      Returns:
      formats mapped to factories
    • getFactory

      public static <T,P> ObjectStreamFactory<T,P> getFactory(Class<T> sampleClass, String formatName)
      Returns a factory which reads format named formatName and instantiates streams producing objects of sampleClass class.

      If no factory is registered for formatName, an attempt is made to interpret formatName as the fully qualified class name of an ObjectStreamFactory implementation and load it via the ExtensionLoader. Such a class must reside in an allowed package, see ExtensionLoader.registerAllowedPackage(String).

      Parameters:
      sampleClass - class of the objects, produced by the streams instantiated by the factory
      formatName - name of the format, if null, assumes OpenNLP format
      Returns:
      factory instance, or null if no factory could be found or loaded