Class Discovery<E extends Element>

java.lang.Object
org.gcube.informationsystem.discovery.Discovery<E>
Type Parameters:
E - The root element type for the discovery process.

public class Discovery<E extends Element> extends Object
A generic class for discovering all subtypes of a given root element within a set of packages.
Author:
Luca Frosini (ISTI - CNR)
  • Field Details

    • logger

      public static org.slf4j.Logger logger
      The logger for this class.
    • root

      protected final Class<E extends Element> root
      The root class of the element hierarchy to discover.
    • packages

      protected final Set<Package> packages
      The set of packages to be scanned.
    • discoveredElements

      protected final List<Class<E extends Element>> discoveredElements
      The list of discovered element classes.
    • discoveredElementActions

      protected final List<DiscoveredElementAction<Element>> discoveredElementActions
      The list of actions to be executed on each discovered element.
    • stopClasses

      protected Set<Class<? extends E extends Element>> stopClasses
      A set of classes where the discovery process should stop. It is mainly used to avoid analyzing Model Classes (Resource, Facet, IsRelatedTo, ConsistsOf, Property) when discoverying lower level classes. As an example when when root is EntityElement the discovery must stop to Resource and Facet classes which hierarchy is not interesting for that level and will be discovered by using Resource and Facet as root classes respectively.
    • discovered

      protected boolean discovered
      Whether the discovery process has been completed.
  • Constructor Details

    • Discovery

      public Discovery(Class<E> root) throws Exception
      Constructs a new Discovery instance for the given root type.
      Parameters:
      root - The root class of the element hierarchy to discover.
      Throws:
      Exception - if an error occurs during initialization.
  • Method Details

    • addStopClass

      public void addStopClass(Class<? extends E> stopClass)
      Adds a class to the set of stop classes for the discovery process. The stop classes are not analyzed or added to the discovered elements.
      Parameters:
      stopClass - The class to add as a stop class.
    • getDiscoveredElements

      public List<Class<E>> getDiscoveredElements()
      Returns the list of discovered element classes.
      Returns:
      A list of discovered classes.
    • addDiscoveredElementActions

      public void addDiscoveredElementActions(DiscoveredElementAction<Element> discoveredElementAction) throws Exception
      Adds a DiscoveredElementAction to be executed on each discovered element.
      Parameters:
      discoveredElementAction - The action to add.
      Throws:
      Exception - if an error occurs while analyzing existing elements.
    • executeDiscoveredElementActions

      public void executeDiscoveredElementActions(DiscoveredElementAction<Element> discoveredElementAction) throws Exception
      Executes a given DiscoveredElementAction on all already discovered elements.
      Parameters:
      discoveredElementAction - The action to execute.
      Throws:
      Exception - if an error occurs during execution.
    • addPackage

      public void addPackage(Package p)
      Adds a package to be scanned during discovery.
      Parameters:
      p - The package to add.
    • addPackages

      public void addPackages(Collection<Package> packages)
      Adds a collection of packages to be scanned.
      Parameters:
      packages - The collection of packages.
    • add

      protected void add(Class<E> clz) throws Exception
      Adds a class to the list of discovered elements and notifies any registered actions.
      Parameters:
      clz - The class to add.
      Throws:
      Exception - if an error occurs in a DiscoveredElementAction.
    • analizeElement

      protected void analizeElement(Class<E> clz) throws Exception
      Recursively analyzes a class to find subtypes of the root element.
      Parameters:
      clz - The class to analyze.
      Throws:
      Exception - if an error occurs during analysis.
    • discover

      public void discover() throws Exception
      Starts the discovery process, scanning all registered packages.
      Throws:
      Exception - if an error occurs during discovery.