Class OptionalDependency

java.lang.Object
org.apache.sis.internal.system.SystemListener
org.apache.sis.internal.system.OptionalDependency
All Implemented Interfaces:
EventListener
Direct Known Subclasses:
MetadataServices, ReferencingServices

public abstract class OptionalDependency extends SystemListener
Base class of internal hooks for accessing optional dependencies. This is used for example for allowing the "sis-metadata" module to access some services of the "sis-referencing" module if the latter is present on the classpath.
Since:
0.6
Version:
0.6
  • Field Details

    • dependency

      private final String dependency
      The name of the optional module on which we depend.
  • Constructor Details

    • OptionalDependency

      protected OptionalDependency(String module, String dependency)
      Creates a new optional dependency.
      Parameters:
      module - a constant from the Modules class which identify the module that need the optional dependency.
      dependency - the Maven artifact name (not a name from the Modules class) of the optional module on which the module depend.
  • Method Details

    • classpathChanged

      protected void classpathChanged()
      Invoked when the classpath is likely to have changed. Subclasses must override like below:
      Specified by:
      classpathChanged in class SystemListener
    • getInstance

      protected static <T extends OptionalDependency> T getInstance(Class<T> type, String module, String dependency, String implementation)
      Returns the optional dependency, or null if not found. This is a helper method for implementation of getInstance() static method in subclasses.
      Type Parameters:
      T - compile-time type of the type argument.
      Parameters:
      type - the subclass type.
      module - same argument value than the one given to the constructor.
      dependency - same argument value than the one given to the constructor.
      implementation - the fully-qualified name of the class to instantiate by reflection.
      Returns:
      an instance of the implementation class, or null if not found.
    • moduleNotFound

      protected final UnsupportedOperationException moduleNotFound()
      Returns the exception to throw when a method requiring the optional dependency is invoked but that module is not on the classpath.
      Returns:
      the exception to throw.