Class ExtensionsManager
java.lang.Object
net.sf.basedb.util.extensions.manager.ExtensionsManager
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) $
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Compare URI:s so that 'jar:' scheme always are listed first. -
Field Summary
Modifier and TypeFieldDescriptionprivate final Map<ObjectKey<?>,
ExtensionsFile> private ProcessResults
private static final Logger
private int
private int
private int
private int
private int
private final Registry
private final Settings
private final Map<URI,
ExtensionsFile> -
Constructor Summary
ConstructorDescriptionExtensionsManager
(Registry registry, File settingsFile) Create a new extensions manager and use the given registry to store extensions. -
Method Summary
Modifier and TypeMethodDescriptionint
addDirectory
(File dir) Add a directory to this manager.private void
addExtensionsFile
(ExtensionsFile xtFile) Add a file to the manager that is supposed to contain extensions.void
Add a file to the ignore list.Add an URI that points to an XML file containing definitions.getFileByObjectKey
(ObjectKey<?> key) Find out which file the object with the given key was defined.getFileByURI
(String uri) Get the extension file that is located at the given URI.getFiles()
Get a list of all extension files managed by this manager.getIgnoredFiles
(boolean onlyInManagedDirectory) Get all ignored files.Get the results of the last processing.int
Get the number of deleted files that was found in the last call toscanForChanges()
.int
Get the number of ignored files that was found in the last call toscanForChanges()
.int
Get the number of modified files that was found in the last call toscanForChanges()
.int
Get the number of new files that was found in the last call toscanForChanges()
.int
Get the number of unmodified files that was found in the last call toscanForChanges()
.Get the registry in which all extensions that are managed by this manager are stored.Get the settings for the extension manager.void
processFiles
(ExtensionsFileProcessor processor) Process all know file with the given processer.void
processFiles
(ExtensionsFileProcessor processor, Filter<ExtensionsFile> filter) Process all known extension files with the given processor.(package private) void
registerObject
(ObjectKey<?> key, ExtensionsFile xtFile) Register an object as defined by the given extensions file.(package private) ExtensionsFile
removeFile
(File file) Remove a file from the extensions manager.void
removeIgnore
(File file) Remove a file from the ignore list.int
Scan the managed directories for new, updated and deleted files.private int
scanForInstalledFiles
(File dir, Settings settings) Scan the given directory and add files that are installed according to the settings.private int
scanForNewFiles
(File dir) Scan the given directory and add files that are new.void
setLastProcessResults
(ProcessResults results) Save the last process results so that they can be used later on.(package private) void
unregisterAllObjects
(ExtensionsFile xtFile) Unregister all objects know in the file.(package private) void
unregisterObject
(ObjectKey<?> key, ExtensionsFile xtFile) Unregister an object.
-
Field Details
-
log
-
registry
-
settings
-
ignore
-
directories
-
xtFiles
-
installedObjects
-
lastResults
-
numNew
private int numNew -
numModified
private int numModified -
numUnmodified
private int numUnmodified -
numDeleted
private int numDeleted -
numIgnored
private int numIgnored
-
-
Constructor Details
-
ExtensionsManager
Create a new extensions manager and use the given registry to store extensions.- Parameters:
registry
- The registry to usesettingsFile
- The file were settings are stored
-
-
Method Details
-
getRegistry
Get the registry in which all extensions that are managed by this manager are stored. -
getSettings
Get the settings for the extension manager. -
setLastProcessResults
Save the last process results so that they can be used later on.- Since:
- 3.3
-
getLastProcessResults
Get the results of the last processing.- Since:
- 3.3
-
addIgnore
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
Remove a file from the ignore list.- Parameters:
file
- The file to remove- See Also:
-
getIgnoredFiles
Get all ignored files.- Parameters:
onlyInManagedDirectory
- TRUE to only look for files that are located in a managed directory- Since:
- 3.10
-
addDirectory
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 settingsSettings.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
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
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
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
-
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 theprocessFiles(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 toscanForChanges()
. -
getNumModified
public int getNumModified()Get the number of modified files that was found in the last call toscanForChanges()
. -
getNumUnmodified
public int getNumUnmodified()Get the number of unmodified files that was found in the last call toscanForChanges()
. -
getNumDeleted
public int getNumDeleted()Get the number of deleted files that was found in the last call toscanForChanges()
. -
getNumIgnored
public int getNumIgnored()Get the number of ignored files that was found in the last call toscanForChanges()
.- Since:
- 3.10
-
scanForNewFiles
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
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
Get a list of all extension files managed by this manager.- Returns:
- A list
-
getFileByURI
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 withaddFile(File)
oraddDirectory(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
Find out which file the object with the given key was defined. See implementations ofObjectKey
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
Register an object as defined by the given extensions file.- Parameters:
key
- The object keyxtFile
- The extensions file the object is defined in
-
unregisterObject
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 keyxtFile
- The extensions file the object is defined in
-
unregisterAllObjects
Unregister all objects know in the file. -
processFiles
Process all know file with the given processer.- Parameters:
processor
- A processor implementation, null is not allowed
-
processFiles
Process all known extension files with the given processor.- Parameters:
processor
- A processor implementation, null is not allowedfilter
- An optional filter implementation that can be used to limit which files are sent to the processor
-