Module ch.turic
Package ch.turic

Interface ServiceLoaded

All Known Subinterfaces:
TuriClass, TuriFunction, TuriMacro

public interface ServiceLoaded
This helper interface can load classes that implement a specific interface using the service loader. If the service loader does not see the classes (the program sees that zero service instances were loaded), then as a fallback it tries to load the META-INF/services/className files and the classes listed in those.

This is a very general interface, it was copied here from the project Jamal.

  • Method Details

    • getInstances

      static <T> List<T> getInstances(Class<T> service)
      Load the classes that implement the interface service and are provided by the modules or are available.
      Type Parameters:
      T - the interface
      Parameters:
      service - the interface for which the implementing class instances are needed
      Returns:
      the list of instances
    • getInstances

      static <T> List<T> getInstances(Class<T> service, ClassLoader cl)
    • loadViaMetaInf

      static <T> void loadViaMetaInf(Class<T> klass, List<T> list, ClassLoader cl)
      Load the classes using the names listed in the META-INF/services/class name resources found by the classloader.

      The implementation mimics the behaviour of the class loader using the provider() public static method if it exists in the implementation.

      Class types and assignability is not checked by the method. If there is any discrepancy a class cast exception will occur.

      Type Parameters:
      T - the klass types
      Parameters:
      klass - the interface for which the classes are to be loaded
      list - the list to fill the instances to
    • loadResources

      static List<URL> loadResources(String name, ClassLoader classLoader) throws IOException
      Get the url list of the resources for the given name.
      Parameters:
      name - the name of the resource
      classLoader - the class loader to use or null to use the system class loader
      Returns:
      the list of the urls
      Throws:
      IOException - if the resources cannot be loaded