3.0.4: 2012-03-05

net.sf.basedb.util.extensions.manager.processor
Class RegisterExtensionsProcessor

java.lang.Object
  extended by 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: 2011-08-11 12:45:58 +0200 (Thu, 11 Aug 2011) $

Nested Class Summary
(package private) static class RegisterExtensionsProcessor.FileData
          Keep track of the extension points and extensions found in a file.
 
Field Summary
private  List<RegisterExtensionsProcessor.FileData> allData
           
private  boolean delayRegistration
           
private  boolean forceUpdate
           
private  XmlLoader loader
           
private static Logger log
           
private  int numError
           
private  int numFiles
           
private  int numRegistered
           
private  int numUnregistered
           
private  ProcessResults results
           
 
Constructor Summary
RegisterExtensionsProcessor(XmlLoader loader, ProcessResults results)
          Create a new processor.
 
Method Summary
 void begin(ExtensionsManager manager, int numFiles)
          Called by the extensions manager before the processing starts.
 void done(ExtensionsManager manager)
          Called by the extensions manager after a successful completion of the processing.
 void done(ExtensionsManager manager, Throwable t)
          Called by the extensions manager if an exception was thrown by the processor.
 void finalizeRegistration(ExtensionsManager manager, boolean unregisterMissing)
           
 int getNumError()
          Get the number of files that was had an error.
 int getNumFiles()
          Get the number of files that was successfully processed.
 int getNumRegistered()
          Get the number of extensions + extension points that was registered.
 int getNumUnregistered()
          Get the number of extensions + extension points that was unregistered.
 ProcessResults getProcessResults()
           
 XmlLoader getXmlLoader()
          Get the loader the processor is using for parsing xml files with extension definitions.
 boolean isRegistrationDelayed()
          Is the actual registration delayed or not?
 void processFile(ExtensionsManager manager, ExtensionsFile.WriteableExtensionsFile wFile)
          Called by the extensions manager for each extensions file that it manages.
private  int registerExtensionPoints(RegisterExtensionsProcessor.FileData data, Registry registry, boolean forceUpdate)
           
private  int registerExtensions(RegisterExtensionsProcessor.FileData data, Registry registry, boolean forceUpdate)
           
private  void registerFactory(RegisterExtensionsProcessor.FileData data, Object factory)
          Register factory parameters for the given factory instance.
 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.
 void setForceUpdate(boolean forceUpdate)
          Set a flag to indicate if already registered extensions should be re-registered or not.
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.
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.
private  void unregisterFactory(RegisterExtensionsProcessor.FileData data, Object factory)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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

private List<RegisterExtensionsProcessor.FileData> allData

numFiles

private int numFiles

numError

private int numError

numRegistered

private int numRegistered

numUnregistered

private int numUnregistered
Constructor Detail

RegisterExtensionsProcessor

public RegisterExtensionsProcessor(XmlLoader loader,
                                   ProcessResults results)
Create a new processor.

Parameters:
loader - The XML loader to use when parsing the metadata
Method Detail

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)

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,
                               Registry registry,
                               boolean forceUpdate)

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)

3.0.4: 2012-03-05