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.
A generic class for discovering all subtypes of a given root element within a
set of packages.
- Author:
- Luca Frosini (ISTI - CNR)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanWhether the discovery process has been completed.protected final List<DiscoveredElementAction<Element>>The list of actions to be executed on each discovered element.The list of discovered element classes.static org.slf4j.LoggerThe logger for this class.The set of packages to be scanned.The root class of the element hierarchy to discover.A set of classes where the discovery process should stop. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAdds a class to the list of discovered elements and notifies any registered actions.voidaddDiscoveredElementActions(DiscoveredElementAction<Element> discoveredElementAction) Adds aDiscoveredElementActionto be executed on each discovered element.voidAdds a package to be scanned during discovery.voidaddPackages(Collection<Package> packages) Adds a collection of packages to be scanned.voidaddStopClass(Class<? extends E> stopClass) Adds a class to the set of stop classes for the discovery process.protected voidanalizeElement(Class<E> clz) Recursively analyzes a class to find subtypes of the root element.voiddiscover()Starts the discovery process, scanning all registered packages.voidexecuteDiscoveredElementActions(DiscoveredElementAction<Element> discoveredElementAction) Executes a givenDiscoveredElementActionon all already discovered elements.Returns the list of discovered element classes.
-
Field Details
-
logger
public static org.slf4j.Logger loggerThe logger for this class. -
root
The root class of the element hierarchy to discover. -
packages
The set of packages to be scanned. -
discoveredElements
The list of discovered element classes. -
discoveredElementActions
The list of actions to be executed on each discovered 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 discoveredWhether the discovery process has been completed.
-
-
Constructor Details
-
Discovery
Constructs a newDiscoveryinstance 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
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
Returns the list of discovered element classes.- Returns:
- A list of discovered classes.
-
addDiscoveredElementActions
public void addDiscoveredElementActions(DiscoveredElementAction<Element> discoveredElementAction) throws Exception Adds aDiscoveredElementActionto 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 givenDiscoveredElementActionon all already discovered elements.- Parameters:
discoveredElementAction- The action to execute.- Throws:
Exception- if an error occurs during execution.
-
addPackage
Adds a package to be scanned during discovery.- Parameters:
p- The package to add.
-
addPackages
Adds a collection of packages to be scanned.- Parameters:
packages- The collection of packages.
-
add
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 aDiscoveredElementAction.
-
analizeElement
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
Starts the discovery process, scanning all registered packages.- Throws:
Exception- if an error occurs during discovery.
-