Class ExtensionsManager

java.lang.Object
net.sf.basedb.util.extensions.manager.ExtensionsManager

public class ExtensionsManager
extends Object
An extensions manager is responsible for handling a group of extensions in the form of files stored in the file system. The manager will keep track of added, updated and removed files.
Since:
3.0
Author:
Nicklas
Last modified
$Date: 2016-11-17 13:36:34 +0100 (to, 17 nov 2016) $
  • Field Details

    • log

      private static final org.slf4j.Logger log
    • registry

      private final Registry registry
    • settings

      private final Settings settings
    • ignore

      private final Set<File> ignore
    • directories

      private final Set<File> directories
    • xtFiles

      private final Map<URI,​ExtensionsFile> xtFiles
    • installedObjects

      private final Map<ObjectKey<?>,​ExtensionsFile> installedObjects
    • lastResults

      private ProcessResults lastResults
    • numNew

      private int numNew
    • numModified

      private int numModified
    • numUnmodified

      private int numUnmodified
    • numDeleted

      private int numDeleted
    • numIgnored

      private int numIgnored
  • Constructor Details

    • ExtensionsManager

      public ExtensionsManager​(Registry registry, File settingsFile)
      Create a new extensions manager and use the given registry to store extensions.
      Parameters:
      registry - The registry to use
      settingsFile - The file were settings are stored
  • Method Details

    • getRegistry

      public Registry getRegistry()
      Get the registry in which all extensions that are managed by this manager are stored.
    • getSettings

      public Settings getSettings()
      Get the settings for the extension manager.
    • setLastProcessResults

      public void setLastProcessResults​(ProcessResults results)
      Save the last process results so that they can be used later on.
      Since:
      3.3
    • getLastProcessResults

      public ProcessResults getLastProcessResults()
      Get the results of the last processing.
      Since:
      3.3
    • addIgnore

      public void addIgnore​(File file)
      Add a file to the ignore list. Files in this list will never be checked for extensions again. This is only neccessary for XML/JAR files that doesn't contain extensions.
      Parameters:
      file - The file to add
      See Also:
      removeIgnore(File)
    • removeIgnore

      public void removeIgnore​(File file)
      Remove a file from the ignore list.
      Parameters:
      file - The file to remove
      See Also:
      addIgnore(File)
    • getIgnoredFiles

      public List<File> getIgnoredFiles​(boolean onlyInManagedDirectory)
      Get all ignored files.
      Parameters:
      onlyInManagedDirectory - TRUE to only look for files that are located in a managed directory
      Since:
      3.10
    • addDirectory

      public int addDirectory​(File dir)
      Add a directory to this manager. The directory will be monitored for extension files in the future. Files in the directory that are installed as per the settings Settings.isInstalledFile(File) are loaded into manager.

      This method call is ignored if the path is not pointing to an existing directory.

      Parameters:
      dir - An existing directory
      Returns:
      The number of files in the directory that was installed
    • addFile

      public ExtensionsFile addFile​(File file)
      Add a file to the manager that is supposed to contain extensions. The file either be an XML file containing definitions, or a JAR file with the definitions in the META-INF/extensions.xml path.
      Parameters:
      file - An extensions file (null is not allowed)
      Returns:
      The extension file object representing the added file
    • removeFile

      ExtensionsFile removeFile​(File file)
      Remove a file from the extensions manager. This method will remove some information about the file from the manager itself, but it will not touch registered extensions, plug-ins, extracted resources, etc. The file itself is not deleted from the disk.

      Note that if the file remains in a managed directory it will reappear in the manager if scanForChanges() is called.

      Parameters:
      file - The file to remove (if null this method is ignored)
    • addURI

      public ExtensionsFile addURI​(URI uri)
      Add an URI that points to an XML file containing definitions. This method is mostly useful for system-defined extensions that are defined in a XML file inside a JAR file.

      This method can't be used for JAR files and if used for XML files it doesn't detect changes that are made after installation.

      Parameters:
      uri - An URI pointing to an extensions file (null is not allowed)
      Returns:
      The extension file object representing the added uri
    • addExtensionsFile

      private void addExtensionsFile​(ExtensionsFile xtFile)
    • scanForChanges

      public int scanForChanges()
      Scan the managed directories for new, updated and deleted files. This method is used for gathering statistics only. To do something with the files the processFiles(ExtensionsFileProcessor) method must be called.

      Note! The new or modified status of files are NOT reset as a result of calling this method. The status can only be changed as a result of some processing.

      Returns:
      The number of new + modified + deleted files that was found
    • getNumNew

      public int getNumNew()
      Get the number of new files that was found in the last call to scanForChanges().
    • getNumModified

      public int getNumModified()
      Get the number of modified files that was found in the last call to scanForChanges().
    • getNumUnmodified

      public int getNumUnmodified()
      Get the number of unmodified files that was found in the last call to scanForChanges().
    • getNumDeleted

      public int getNumDeleted()
      Get the number of deleted files that was found in the last call to scanForChanges().
    • getNumIgnored

      public int getNumIgnored()
      Get the number of ignored files that was found in the last call to scanForChanges().
      Since:
      3.10
    • scanForNewFiles

      private int scanForNewFiles​(File dir)
      Scan the given directory and add files that are new.
      Parameters:
      dir - The directory to scan
      Returns:
      The number of new files in the given directory
    • scanForInstalledFiles

      private int scanForInstalledFiles​(File dir, Settings settings)
      Scan the given directory and add files that are installed according to the settings.
      Parameters:
      dir - The directory to scan
      Returns:
      The number of installed files in the given directory
    • getFiles

      public List<ExtensionsFile> getFiles()
      Get a list of all extension files managed by this manager.
      Returns:
      A list
    • getFileByURI

      public ExtensionsFile getFileByURI​(String uri)
      Get the extension file that is located at the given URI. This method can be used for all files even those that have been added with addFile(File) or addDirectory(File).
      Parameters:
      uri - An URI that is pointing to an extensions file
      Returns:
      An extensions file object, or null if no file is found
    • getFileByObjectKey

      public ExtensionsFile getFileByObjectKey​(ObjectKey<?> key)
      Find out which file the object with the given key was defined. See implementations of ObjectKey for various types of objects to look for.
      Parameters:
      key - The object key
      Returns:
      Information about the file the object is defined in, or null if no object is found for the given key
    • registerObject

      void registerObject​(ObjectKey<?> key, ExtensionsFile xtFile)
      Register an object as defined by the given extensions file.
      Parameters:
      key - The object key
      xtFile - The extensions file the object is defined in
    • unregisterObject

      void unregisterObject​(ObjectKey<?> key, ExtensionsFile xtFile)
      Unregister an object. The given extensions file must match be equal to the one that registered the object, otherwise the unregistration is ignored.
      Parameters:
      key - The object key
      xtFile - The extensions file the object is defined in
    • unregisterAllObjects

      void unregisterAllObjects​(ExtensionsFile xtFile)
      Unregister all objects know in the file.
    • processFiles

      public void processFiles​(ExtensionsFileProcessor processor)
      Process all know file with the given processer.
      Parameters:
      processor - A processor implementation, null is not allowed
    • processFiles

      public void processFiles​(ExtensionsFileProcessor processor, Filter<ExtensionsFile> filter)
      Process all known extension files with the given processor.
      Parameters:
      processor - A processor implementation, null is not allowed
      filter - An optional filter implementation that can be used to limit which files are sent to the processor