public class Registry extends Object
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.Modifier and Type | Class and Description |
---|---|
(package private) static class |
Registry.AttributeKey
Identifies attribute.
|
(package private) static class |
Registry.RegisteredAbout |
(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.
|
Modifier and Type | Field and Description |
---|---|
private Map<Registry.AttributeKey,Object> |
attributes |
private static ExtensionsFilter |
DEFAULT_FILTER
Default filter implementation for
useExtensions(ClientContext, ExtensionsFilter, String...) |
private ErrorHandlerFactory<Action> |
defaultErrorHandlerFactory |
private Map<EventHandler,EventFilter> |
eventHandlers |
static Comparator<Extension<?>> |
EXTENSION_COMPARATOR
Comparator that sort extensions according to their names.
|
static Comparator<Extension<?>> |
EXTENSION_ID_COMPARATOR
Comparator that sort extensions according to their ids.
|
static Comparator<ExtensionPoint<?>> |
EXTENSIONPOINT_COMPARATOR
Comparator that sort extension points according to their names.
|
static Comparator<ExtensionPoint<?>> |
EXTENSIONPOINT_ID_COMPARATOR
Comparator that sort extensions according to their ids.
|
private Map<String,Registry.RegisteredExtensionPoint<?>> |
extensionPoints |
private Map<String,Registry.RegisteredExtension<?>> |
extensions |
private static org.slf4j.Logger |
log |
Constructor and Description |
---|
Registry()
Create a new empty registry.
|
Modifier and Type | Method and Description |
---|---|
boolean |
extensionIsRegistered(String id)
Checks if an extension is registered or not.
|
boolean |
extensionPointIsRegistered(String id)
Checks if an extension point is registered or not.
|
Object |
getAttribute(String id,
String name)
Get the value of a extra attribute for a registered extension
or extension point.
|
ErrorHandlerFactory<Action> |
getDefaultErrorHandlerFactory()
Get the default error handler factory.
|
Extension<?> |
getExtension(String id)
Get the extension with a given ID.
|
ExtensionPoint<?> |
getExtensionPoint(String id)
Get the extension point with a given ID.
|
List<ExtensionPoint<?>> |
getExtensionPoints()
Get a list with all registered extension points.
|
List<Extension<?>> |
getExtensions()
Get a list with all registered extensions.
|
List<Extension<?>> |
getExtensions(String id)
Get a list with all registered extensions
for a given extension point.
|
Throwable |
getLastExtensionError(String id)
Get information about the last error that happened
when rendering an extension.
|
Throwable |
getLastExtensionPointError(String id)
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)
Register an event handler for responding to events happening to
extension points and extensions in the registry.
|
<A extends Action> |
registerExtension(Extension<A> extension)
Deprecated.
In 3.2, use
registerExtension(Extension, ClassLoader) instead |
<A extends Action> |
registerExtension(Extension<A> extension,
ClassLoader classLoader)
Register an extension.
|
<A extends Action> |
registerExtensionPoint(ExtensionPoint<A> extensionPoint)
Deprecated.
In 3.2, use
registerExtensionPoint(ExtensionPoint, ClassLoader) instead |
<A extends Action> |
registerExtensionPoint(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 |
unregisterExtension(String id)
Unregister an extension.
|
void |
unregisterExtensionPoint(String id)
Unregister an extension point.
|
ExtensionsInvoker<?> |
useExtensions(ClientContext clientContext,
ExtensionsFilter filter,
String... extensionPointIds)
Use extensions from one or more extension points.
|
private static final org.slf4j.Logger log
public static final Comparator<ExtensionPoint<?>> EXTENSIONPOINT_COMPARATOR
public static final Comparator<Extension<?>> EXTENSION_COMPARATOR
public static final Comparator<ExtensionPoint<?>> EXTENSIONPOINT_ID_COMPARATOR
public static final Comparator<Extension<?>> EXTENSION_ID_COMPARATOR
private final Map<String,Registry.RegisteredExtensionPoint<?>> extensionPoints
private final Map<String,Registry.RegisteredExtension<?>> extensions
private Map<Registry.AttributeKey,Object> attributes
private Map<EventHandler,EventFilter> eventHandlers
private ErrorHandlerFactory<Action> defaultErrorHandlerFactory
private static final ExtensionsFilter DEFAULT_FILTER
useExtensions(ClientContext, ExtensionsFilter, String...)
public void setDefaultErrorHandlerFactory(ErrorHandlerFactory<Action> defaultErrorHandlerFactory)
defaultErrorHandlerFactory
- Null is not allowedpublic ErrorHandlerFactory<Action> getDefaultErrorHandlerFactory()
public Object getAttribute(String id, String name)
id
- The ID of a registered extension or extension pointname
- The name of the attributepublic void setAttribute(String id, String name, Object value)
id
- The ID of a registered extension or extension pointname
- The name of the attributevalue
- The attribute value. A null value removes the attribute.public void registerEventHandler(EventHandler eventHandler, EventFilter filter)
handleEvent(EventType, ExtensionPoint, Extension)
.
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 eventspublic void unregisterEventHandler(EventHandler eventHandler)
eventHandler
- The event handlerpublic void handleEvent(EventType eventType, ExtensionPoint<?> extensionPoint, Extension<?> extension)
eventType
- The event typeextensionPoint
- The extension point the event is aboutextension
- The extension the event is about, or nullpublic boolean extensionPointIsRegistered(String id)
id
- The ID of the extension point@Deprecated public <A extends Action> void registerExtensionPoint(ExtensionPoint<A> extensionPoint)
registerExtensionPoint(ExtensionPoint, ClassLoader)
insteadpublic <A extends Action> void registerExtensionPoint(ExtensionPoint<A> extensionPoint, ClassLoader classLoader)
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 usedInvalidUseOfNullException
- If the extension point is null, or if the ID
or actionClass is nullClassCastException
- If the action class doesn't implement the
Action
interfacepublic void unregisterExtensionPoint(String id)
id
- The ID of the extension point to unregisterInvalidUseOfNullException
- If the ID is nullpublic ExtensionPoint<?> getExtensionPoint(String id)
id
- The ID of the extension pointExtensionPoint
object or null if that
extension point doesn't existspublic List<ExtensionPoint<?>> getExtensionPoints()
public boolean extensionIsRegistered(String id)
id
- The ID of the extensionpublic Throwable getLastExtensionPointError(String id)
id
- The id of the extension point@Deprecated public <A extends Action> void registerExtension(Extension<A> extension)
registerExtension(Extension, ClassLoader)
insteadpublic <A extends Action> void registerExtension(Extension<A> extension, ClassLoader classLoader)
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 usedInvalidUseOfNullException
- If the extension is null, or if
the ID or action factory is nullpublic void unregisterExtension(String id)
id
- The ID of the extension to unregisterInvalidUseOfNullException
- If the ID is nullpublic Extension<?> getExtension(String id)
id
- The ID of the extension pointExtension
object or null if that
extension doesn't existspublic Throwable getLastExtensionError(String id)
id
- The id of the extensionpublic List<Extension<?>> getExtensions()
public List<Extension<?>> getExtensions(String id)
id
- The ID of the extension pointpublic ExtensionsInvoker<?> useExtensions(ClientContext clientContext, ExtensionsFilter filter, String... extensionPointIds)
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.
See ExtensionPoint.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.
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 their Extension.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.