Class RegisterExtensionsProcessor

java.lang.Object
net.sf.basedb.util.extensions.manager.processor.RegisterExtensionsProcessor
All Implemented Interfaces:
ExtensionsFileProcessor
Direct Known Subclasses:
WebClientRegisterExtensionsProcessor

public class RegisterExtensionsProcessor extends Object implements ExtensionsFileProcessor
Extension file processor implementation that will load the extension definitions from each file and register them with the registry that is managed by the manager. This processor is a two-step processer. The first step will load extension definitions from the files. The second step will register the loaded extension with the managers registry.

The first step is executed via the manager: ExtensionsManager.processFiles(ExtensionsFileProcessor). The second step is either automatically executed when all files have been processed or executed by by calling finalizeRegistration(ExtensionsManager, boolean).

Note! It is recommended that this processor is paired with a ValidAndNewOrModifiedFilter since it is usually no point in trying to register invalid extensions.

Since:
3.0
Author:
Nicklas
Last modified
$Date: 2015-04-20 11:08:18 +0200 (må, 20 apr 2015) $
  • Field Details

    • log

      private static final Logger log
    • loader

      private final XmlLoader loader
    • results

      private final ProcessResults results
    • delayRegistration

      private boolean delayRegistration
    • forceUpdate

      private boolean forceUpdate
    • allData

    • numFiles

      private int numFiles
    • numError

      private int numError
    • numRegistered

      private int numRegistered
    • numUnregistered

      private int numUnregistered
  • Constructor Details

    • RegisterExtensionsProcessor

      public RegisterExtensionsProcessor(XmlLoader loader, ProcessResults results)
      Create a new processor.
      Parameters:
      loader - The XML loader to use when parsing the metadata
  • Method Details

    • begin

      public void begin(ExtensionsManager manager, int numFiles)
      Description copied from interface: ExtensionsFileProcessor
      Called by the extensions manager before the processing starts.
      Specified by:
      begin in interface ExtensionsFileProcessor
      Parameters:
      manager - The manager that is executing the action
      numFiles - The number of extension files that is going to be processed this time
    • processFile

      public void processFile(ExtensionsManager manager, ExtensionsFile.WriteableExtensionsFile wFile)
      Description copied from interface: ExtensionsFileProcessor
      Called by the extensions manager for each extensions file that it manages. The order of the files is generally not predicatable and may change from one invokation to the next.

      If the processor throws an exception the manager will abort processing and call ExtensionsFileProcessor.done(ExtensionsManager, Throwable). Error that are related to a specific file should be catched by the processor and registered by calling .......

      If all files was processed without exceptions the manager will call ExtensionsFileProcessor.done(ExtensionsManager).

      Note that the file is read-only to begin with. If the processor wants to call any write-operation the file must be opened by calling ExtensionsFile.WriteableExtensionsFile.open(). It is recommended that the processor calls ExtensionsFile.WriteableExtensionsFile.close() once it is done writing.

      Specified by:
      processFile in interface ExtensionsFileProcessor
      Parameters:
      manager - The manager that is executing the action
      wFile - The file to be processed
    • done

      public void done(ExtensionsManager manager)
      Description copied from interface: ExtensionsFileProcessor
      Called by the extensions manager after a successful completion of the processing.
      Specified by:
      done in interface ExtensionsFileProcessor
      Parameters:
      manager - The manager that is executing the action
    • done

      public void done(ExtensionsManager manager, Throwable t)
      Description copied from interface: ExtensionsFileProcessor
      Called by the extensions manager if an exception was thrown by the processor.
      Specified by:
      done in interface ExtensionsFileProcessor
      Parameters:
      manager - The manager that is executing the action
      t - The exception
    • setDelayRegistration

      public void setDelayRegistration(boolean delayRegistration)
      Set a flag to indicate if the actual registration of the found extensions and extension points should be delayed or not. The default is to not delay registration, which means that it happend when the done(ExtensionsManager) method is called by the manager. If this flag is set the finalizeRegistration(ExtensionsManager, boolean) method must be explicitely called.
    • isRegistrationDelayed

      public boolean isRegistrationDelayed()
      Is the actual registration delayed or not?
    • setForceUpdate

      public void setForceUpdate(boolean forceUpdate)
      Set a flag to indicate if already registered extensions should be re-registered or not.
      Parameters:
      forceUpdate - TRUE to always re-register extensions, FALSE to only register new or updated extensions
    • getXmlLoader

      public XmlLoader getXmlLoader()
      Get the loader the processor is using for parsing xml files with extension definitions.
    • getProcessResults

      public ProcessResults getProcessResults()
    • finalizeRegistration

      public void finalizeRegistration(ExtensionsManager manager, boolean unregisterMissing)
    • getNumFiles

      public int getNumFiles()
      Get the number of files that was successfully processed.
    • getNumError

      public int getNumError()
      Get the number of files that was had an error.
    • getNumRegistered

      public int getNumRegistered()
      Get the number of extensions + extension points that was registered.
    • getNumUnregistered

      public int getNumUnregistered()
      Get the number of extensions + extension points that was unregistered.
    • registerExtensionPoints

      private int registerExtensionPoints(RegisterExtensionsProcessor.FileData data, Registry registry, boolean forceUpdate) throws IOException
      Throws:
      IOException
    • unregisterExtensionPoint

      private boolean unregisterExtensionPoint(RegisterExtensionsProcessor.FileData data, ExtensionPoint<?> ep, Registry registry)
      Unregister the given extension point if it is not included in the new file data information. In all cases, factory metadata must be removed, since we leak memory otherwise (new factory instances are always created when scanning a modified file).
      Returns:
      TRUE if the extension point is not going to be registered again
    • registerExtensions

      private int registerExtensions(RegisterExtensionsProcessor.FileData data, ExtensionsManager manager, boolean forceUpdateOrModified) throws IOException
      Throws:
      IOException
    • unregisterExtension

      private boolean unregisterExtension(RegisterExtensionsProcessor.FileData data, Extension<?> ext, Registry registry)
      Unregister the given extension if it is not included in the new file data information. In all cases, factory metadata must be removed, since we leak memory otherwise (new factory instances are always created when scanning a modified file).
      Returns:
      TRUE if the extension point is not going to be registered again
    • registerFactory

      private void registerFactory(RegisterExtensionsProcessor.FileData data, Object factory)
      Register factory parameters for the given factory instance. The parameters are retreived from the XmlLoader.getFactoryParameters(Object) method.
      Parameters:
      data - The extension file the factory was defined in
      factory - The factory instance (if null, no registration is done)
    • unregisterFactory

      private void unregisterFactory(RegisterExtensionsProcessor.FileData data, Object factory)