Class ModelLocations<M extends IModel>

  • Type Parameters:
    M - the specific model type

    public class ModelLocations<M extends IModel>
    extends java.lang.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
    • Constructor Detail

      • ModelLocations

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

      • clear

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

        public void addExcludedLocation​(java.io.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​(java.io.File location)
        Removes an excluded model location.
        Parameters:
        location - the location to be discarded
      • getLocationFor

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

        private ModelLocations.Location getLocationFor​(java.io.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​(java.io.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 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
      • addLocationToFront

        public ModelLocations.Location addLocationToFront​(java.io.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​(java.io.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
      • isLocationKnown

        public boolean isLocationKnown​(java.io.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​(java.io.File location,
                                 java.util.Set<java.io.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:
        java.lang.IndexOutOfBoundsException - if index < 0 || index >=getLocationCount()
      • scan

        void scan​(java.io.File location,
                  ModelInfoHolder<M> holder,
                  IModelLoader<M> loader,
                  ObservableTask task,
                  java.util.Set<java.io.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​(java.io.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