Class Registry
ExtensionPointBean
and ExtensionBean
implementations, or loaded from
an XML extension definition file with the XmlLoader
class. Applications may provide other means of creating and
registering extensions and extensions points.- Version:
- 2.7
- Author:
- nicklas
- Last modified
- $Date:2008-03-20 12:15:25 +0100 (Thu, 20 Mar 2008) $
-
Nested Class Summary
Modifier and TypeClassDescription(package private) static class
Identifies attribute.(package private) static class
(package private) static class
(package private) static class
Registry.RegisteredExtension<A extends Action>
Internal representation of an extension.(package private) static class
Registry.RegisteredExtensionPoint<A extends Action>
Internal representation of an extension point. -
Field Summary
Modifier and TypeFieldDescriptionprivate Map<Registry.AttributeKey,
Object> private static final ExtensionsFilter
Default filter implementation foruseExtensions(ClientContext, ExtensionsFilter, String...)
private ErrorHandlerFactory<Action>
static final Comparator<Extension<?>>
Comparator that sort extensions according to their names.static final Comparator<Extension<?>>
Comparator that sort extensions according to their ids.static final Comparator<ExtensionPoint<?>>
Comparator that sort extension points according to their names.static final Comparator<ExtensionPoint<?>>
Comparator that sort extensions according to their ids.private final Map<String,
Registry.RegisteredExtensionPoint<?>> private final Map<String,
Registry.RegisteredExtension<?>> private static final Logger
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks if an extension is registered or not.boolean
Checks if an extension point is registered or not.getAttribute
(String id, String name) Get the value of a extra attribute for a registered extension or extension point.Get the default error handler factory.Extension<?>
getExtension
(String id) Get the extension with a given ID.Get the extension point with a given ID.List<ExtensionPoint<?>>
Get a list with all registered extension points.Get a list with all registered extensions.getExtensions
(String id) Get a list with all registered extensions for a given extension point.Get information about the last error that happened when rendering an extension.Get information about the last error that happened when rendering an extension point.void
handleEvent
(EventType eventType, ExtensionPoint<?> extensionPoint, Extension<?> extension) Send an event to all event handlers.void
registerEventHandler
(EventHandler eventHandler, EventFilter filter, ClassLoader classLoader) Register an event handler for responding to events happening to extension points and extensions in the registry.<A extends Action>
voidregisterExtension
(Extension<A> extension, ClassLoader classLoader) Register an extension.<A extends Action>
voidregisterExtensionPoint
(ExtensionPoint<A> extensionPoint, ClassLoader classLoader) Register an extension point.void
setAttribute
(String id, String name, Object value) Set an extra attribute on a registered extension or extension point.void
setDefaultErrorHandlerFactory
(ErrorHandlerFactory<Action> defaultErrorHandlerFactory) Set the default error handler factory.void
unregisterEventHandler
(EventHandler eventHandler) Unregisters an event handler.void
unregisterEventHandlers
(ClassLoader classLoader) Unregister all event handlers that was loaded by the given class loader.void
Unregister an extension.void
Unregister an extension point.<A extends Action>
ExtensionsInvoker<A>useExtensions
(ClientContext clientContext, ExtensionsFilter filter, String... extensionPointIds) Use extensions from one or more extension points.
-
Field Details
-
log
-
EXTENSIONPOINT_COMPARATOR
Comparator that sort extension points according to their names. If two names are equal, the sort is also done on the id.- Since:
- 3.0
-
EXTENSION_COMPARATOR
Comparator that sort extensions according to their names. If two names are equal, the sort is also done on the id.- Since:
- 3.0
-
EXTENSIONPOINT_ID_COMPARATOR
Comparator that sort extensions according to their ids.- Since:
- 3.4
-
EXTENSION_ID_COMPARATOR
Comparator that sort extensions according to their ids.- Since:
- 3.4
-
extensionPoints
-
extensions
-
attributes
-
eventHandlers
-
defaultErrorHandlerFactory
-
DEFAULT_FILTER
Default filter implementation foruseExtensions(ClientContext, ExtensionsFilter, String...)
-
-
Constructor Details
-
Registry
public Registry()Create a new empty registry.
-
-
Method Details
-
setDefaultErrorHandlerFactory
Set the default error handler factory.- Parameters:
defaultErrorHandlerFactory
- Null is not allowed- Since:
- 2.17
-
getDefaultErrorHandlerFactory
Get the default error handler factory.- Since:
- 2.17
-
getAttribute
Get the value of a extra attribute for a registered extension or extension point.- Parameters:
id
- The ID of a registered extension or extension pointname
- The name of the attribute- Returns:
- The attribute value or null if no value has been set
-
setAttribute
Set an extra attribute on a registered extension or extension point.- Parameters:
id
- The ID of a registered extension or extension pointname
- The name of the attributevalue
- The attribute value. A null value removes the attribute.
-
registerEventHandler
public void registerEventHandler(EventHandler eventHandler, EventFilter filter, ClassLoader classLoader) Register an event handler for responding to events happening to extension points and extensions in the registry. The registry itself sends the events listed below. Other events may be sent externally by callinghandleEvent(EventType, ExtensionPoint, Extension)
.- Parameters:
eventHandler
- The handler that should be calledfilter
- A filter that determines which events that should be sent to the handler, or null to send all eventsclassLoader
- The class loader that "owns" the event handler. The class loader is requried to be able to automatically unregister event handlers when an extension is uninstalled or updated. If null, automatic unloading is disabled (beware of memory leaks!).- Since:
- 3.10
-
unregisterEventHandler
Unregisters an event handler.- Parameters:
eventHandler
- The event handler- Since:
- 2.8
-
unregisterEventHandlers
Unregister all event handlers that was loaded by the given class loader. This method should be called when an extension file is being uninstalled or updated since the old registered event handlers can then no longer be used and it is really complicated for an extension that register event handler to detect a re-installation property. It is better to try to handle this at the core level.- Parameters:
classLoader
- The class loader that is responsible for the extension file that is about to be uninstalled or updated- Since:
- 3.10
-
handleEvent
public void handleEvent(EventType eventType, ExtensionPoint<?> extensionPoint, Extension<?> extension) Send an event to all event handlers.- Parameters:
eventType
- The event typeextensionPoint
- The extension point the event is aboutextension
- The extension the event is about, or null- Since:
- 2.8
-
extensionPointIsRegistered
Checks if an extension point is registered or not.- Parameters:
id
- The ID of the extension point- Returns:
- TRUE if an extension point with the given ID is registered, FALSE otherwise
-
registerExtensionPoint
public <A extends Action> void registerExtensionPoint(ExtensionPoint<A> extensionPoint, ClassLoader classLoader) Register an extension point. If the extension point already exists, the description and renderer factory is updated. The action class can't be changed for a registered extension point. The registry keeps it's own internal representation of the extension point. Changes to the object passed as a parameter to this method will not be reflected in the registry.- Parameters:
extensionPoint
- The extension point to registerclassLoader
- The class loader that is responsible for loading classes for the extension point, or null if the default class loader should be used- Throws:
InvalidUseOfNullException
- If the extension point is null, or if the ID or actionClass is nullClassCastException
- If the action class doesn't implement theAction
interface- Since:
- 3.2
-
unregisterExtensionPoint
Unregister an extension point. If the extension point doesn't exists, nothing is done. This method will also unregister all extensions that extends the given extension point.- Parameters:
id
- The ID of the extension point to unregister- Throws:
InvalidUseOfNullException
- If the ID is null
-
getExtensionPoint
Get the extension point with a given ID.- Parameters:
id
- The ID of the extension point- Returns:
- An
ExtensionPoint
object or null if that extension point doesn't exists
-
getExtensionPoints
Get a list with all registered extension points. The returned list is a copy of the registered extension points at the time of this call and will not reflect changes made to the registry after this call has returned.- Returns:
- A list
- Since:
- 3.0 (Returned an Iterator in BASE 2.x)
-
extensionIsRegistered
Checks if an extension is registered or not.- Parameters:
id
- The ID of the extension- Returns:
- TRUE if an extension with the given ID is registered, FALSE otherwise
-
getLastExtensionPointError
Get information about the last error that happened when rendering an extension point.- Parameters:
id
- The id of the extension point- Returns:
- The error, or null if no error information is available
- Since:
- 2.9
-
registerExtension
Register an extension. If the extension is already registered, the description, position, action factory and renderer factory is updated. The registry keeps it's own internal representation of the extension. Changes made to the object passed as a parameter to this method will not be reflected in the registry.- Parameters:
extension
- The extension to registerclassLoader
- The class loader that is responsible for loading classes for the extension, or null if the default class loader should be used- Throws:
InvalidUseOfNullException
- If the extension is null, or if the ID or action factory is null- Since:
- 3.2
-
unregisterExtension
Unregister an extension. If the extension point doesn't exists, nothing is done.- Parameters:
id
- The ID of the extension to unregister- Throws:
InvalidUseOfNullException
- If the ID is null
-
getExtension
Get the extension with a given ID.- Parameters:
id
- The ID of the extension point- Returns:
- An
Extension
object or null if that extension doesn't exists
-
getLastExtensionError
Get information about the last error that happened when rendering an extension.- Parameters:
id
- The id of the extension- Returns:
- The error, or null if no error information is available
- Since:
- 2.9
-
getExtensions
Get a list with all registered extensions. The returned list is a copy of the registered extensions at the time of this call and will not reflect changes made to the registry after this call has returned.- Returns:
- A list
- Since:
- 3.0 (Returned an Iterator in BASE 2.x)
-
getExtensions
Get a list with all registered extensions for a given extension point. If the extension point is not found an empty list is returned. The returned list is a copy of the registered extension points at the time of this call and will not reflect changes made to the registry after this call has returned.- Parameters:
id
- The ID of the extension point- Returns:
- A list
- Since:
- 3.0 (Returned an Iterator in BASE 2.x)
-
useExtensions
public <A extends Action> ExtensionsInvoker<A> useExtensions(ClientContext clientContext, ExtensionsFilter filter, String... extensionPointIds) Use extensions from one or more extension points. This method will return an invoker object that allows the use and rendering of extensions for one or more extension points. The context object should have been initialised with information about the currently logged in user and, depending on the application, some information about what it about to happen. For example, that we are going to display a list of samples.Each extension that has been registered with the extension points will get a chance to check the context object and to further initialise it with extension-dependent information. This is a task for the
ActionFactory.prepareContext(InvokationContext)
method. If this method returns false the extension will not be included in the invoker. Extensions may for example use this to check if the logged in user has enough permissions to be able to use the extension.If the extension points and/or extensions also provide renderer factories, the
RendererFactory.prepareContext(InvokationContext)
is called. For renderer factories that are attached to extension points the method is only called if at least one enabled extension exists. If the method is called, it is only called once with a null argument for the extension. Renderer factories that are attached to extensions are called once for each enabled extension, but only if the extension point allows renderer overriding. SeeExtensionPoint.allowRendererOverride()
.The returned invoker will not reflect changes made to the registry by the same or other threads after this call has returned. Each use/invokation of an extension point should call this method to get a new invoker object.
- Parameters:
clientContext
- Information about the current contextfilter
- A filter object that can be used to filter out disabled extensions and sort the extensions in a particular order. If this value is null, no extensions are filtered out and they are sorted according to theirExtension.getIndex()
valueextensionPointIds
- An array of extension point ID:s to get extension for. In most cases the extension points should require the same action class but this is not required if the extension point renderer can handle more than one action type. Extension points that are not found are ignored.
-