Class ModelLocations<M extends IModel>

java.lang.Object
net.ssehub.easy.basics.modelManagement.ModelLocations<M>
Type Parameters:
M - the specific model type

public class ModelLocations<M extends IModel> extends Object
Manages the model locations. Locations are stored in terms of a list, which also defines the model resolution sequence. This class is not intended to be instantiated directly rather than being created from ModelManagement. Please not that each individual location is considered recursively, i.e., nested folders will be considered automatically and do not need to be added separately.
Author:
Holger Eichelberger
  • Field Details

  • Constructor Details

    • ModelLocations

      ModelLocations(IModelManagementRepository<M> repository)
      Prevents this class from being instantiated from outside this package.
      Parameters:
      repository - the model management repository for callbacks
  • Method Details

    • clear

      void clear()
      Removes all known model locations.
    • addExcludedLocation

      public void addExcludedLocation(File location)
      Adds an excluded model location. The location disables all contained locations and will be considered with the next update of the file information (already known models will not be discarded).
      Parameters:
      location - the location to be excluded
    • removeExcludedLocation

      public void removeExcludedLocation(File location)
      Removes an excluded model location.
      Parameters:
      location - the location to be discarded
    • getLocationFor

      public ModelLocations.Location getLocationFor(URI uri)
      Returns the location for uri.
      Parameters:
      uri - the URI to search for
      Returns:
      the related location
    • getLocationFor

      private ModelLocations.Location getLocationFor(File file) throws ModelManagementException
      Returns the location for file.
      Parameters:
      file - the file to return the location for
      Returns:
      the location (or null if the related location is currently not known)
      Throws:
      ModelManagementException - in case that file cannot be accessed / resolved
      See Also:
    • getLocationFor

      private ModelLocations.Location getLocationFor(File file, boolean create) throws ModelManagementException
      Returns the location for file.
      Parameters:
      file - the file to return the location for
      create - true if a location shall be created for file if no location is known, false if no new location shall be created
      Returns:
      the location related to file, may be null depending on create
      Throws:
      ModelManagementException - in case that file cannot be accessed / resolved
    • addLocation

      public ModelLocations.Location addLocation(File file, ProgressObserver observer) throws ModelManagementException
      Adds a file location to the end of the list of locations, i.e., a location from where models can be loaded. Please note that file is considered recursively, i.e., nested folders will be considered automatically and do not need to be added separately.
      Parameters:
      file - the file location (null is ignored)
      observer - an optional progress observer (use ProgressObserver.NO_OBSERVER but not null in case that no observation is intended)
      Returns:
      the actual location object corresponding to file
      Throws:
      ModelManagementException - in case that the available information may be come inconsistent due to the new location or that file cannot be accessed / resolved
    • addLocationToFront

      public ModelLocations.Location addLocationToFront(File file, ProgressObserver observer) throws ModelManagementException
      Adds a file location, i.e., a location from where models can be loaded. Please not that file is considered recursively, i.e., nested folders will be considered automatically and do not need to be added separately.
      Parameters:
      file - the file location (null is ignored)
      observer - an optional progress observer (use ProgressObserver.NO_OBSERVER but not null in case that no observation is intended)
      Returns:
      the actual location object corresponding to file
      Throws:
      ModelManagementException - in case that the available information may be come inconsistent due to the new location or that file cannot be accessed / resolved
    • addLocation

      private ModelLocations.Location addLocation(File file, boolean front, ProgressObserver observer) throws ModelManagementException
      Adds a file location, i.e., a location from where models can be loaded. Please not that file is considered recursively, i.e., nested folders will be considered automatically and do not need to be added separately.
      Parameters:
      file - the file location (null is ignored)
      front - add to the front or the end of the list of locations
      observer - an optional progress observer (use ProgressObserver.NO_OBSERVER but not null in case that no observation is intended)
      Returns:
      the actual location object corresponding to file
      Throws:
      ModelManagementException - in case that the available information may be come inconsistent due to the new location or that file cannot be accessed / resolved
    • removeLocation

      public void removeLocation(ModelLocations.Location location, ProgressObserver observer) throws ModelManagementException
      Removes a location, i.e. a location from where models can be loaded.
      Parameters:
      location - the location (null is ignored)
      observer - an optional progress observer (use ProgressObserver.NO_OBSERVER but not null in case that no observation is intended)
      Throws:
      ModelManagementException - in case that file cannot be accessed
    • removeLocation

      public void removeLocation(File file, ProgressObserver observer) throws ModelManagementException
      Removes a file location, i.e. a location from where models can be loaded.
      Parameters:
      file - the file location (null is ignored)
      observer - an optional progress observer (use ProgressObserver.NO_OBSERVER but not null in case that no observation is intended)
      Throws:
      ModelManagementException - in case that file cannot be accessed
    • updateLocation

      public void updateLocation(File file, ProgressObserver observer) throws ModelManagementException
      Updates a file location, i.e., a location from where models can be loaded. The location must be registered beforehand using addLocation(File, ProgressObserver).
      Parameters:
      file - the file location (null is ignored)
      observer - an optional progress observer (use ProgressObserver.NO_OBSERVER but not null in case that no observation is intended)
      Throws:
      ModelManagementException - in case that the available information may be come inconsistent due to the new location or file cannot be accessed
    • isLocationKnown

      public boolean isLocationKnown(File file)
      Returns whether the specified location is already known.
      Parameters:
      file - the location to search for
      Returns:
      true if it is known, false else
    • count

      private static int count(File location, Set<File> excludedLocations)
      Returns the number of files in the given location.
      Parameters:
      location - the location to scan
      excludedLocations - explicitly excluded locations (may be null if no locations shall be excluded)
      Returns:
      the number of files
    • countFilesInLocations

      int countFilesInLocations()
      Returns the number of files in all locations.
      Returns:
      the number of files in all locations
    • getLocationCount

      public int getLocationCount()
      Returns the number of locations configured.
      Returns:
      the number of locations
    • getLocation

      public ModelLocations.Location getLocation(int index)
      Returns the specified location.
      Parameters:
      index - the index pointing to the desired location
      Returns:
      the specified location
      Throws:
      IndexOutOfBoundsException - if index < 0 || index >=getLocationCount()
    • scan

      void scan(File location, ModelInfoHolder<M> holder, IModelLoader<M> loader, ObservableTask task, Set<File> done)
      Scans the given location for model information objects.
      Parameters:
      location - the location to scan
      holder - the combined information and result collection instance
      loader - the specific loader to consider (may be null)
      task - the task to be informed
      done - records visited directories in order to avoid unintended looping
    • removeLocationFor

      void removeLocationFor(File file) throws ModelManagementException
      Removes the location for file from the set of model locations of this instance as well as from all dependent locations.
      Parameters:
      file - the file pointing to the location
      Throws:
      ModelManagementException - in case that file cannot be resolved
    • removeLocation

      void removeLocation(ModelLocations.Location location)
      Removes the given location from the set of model locations of this instance as well as from all dependent locations.
      Parameters:
      location - the location to be removed
    • updateModelInformation

      public void updateModelInformation() throws ModelManagementException
      Updates all model information for all locations.
      Throws:
      ModelManagementException - in case that updating fails for some reason
    • getDefaultLibraryLocations

      public List<ModelLocations.Location> getDefaultLibraryLocations()
      Returns the known default library locations.
      Returns:
      the locations