|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.basedb.util.extensions.Registry
public class Registry
A registry for keeping track of extensions points and
installed extensions. Extension points and extensions can, for example,
be created programmatically using the 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.
ExtensionsDirectory
Nested Class Summary | |
---|---|
(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. |
Field Summary | |
---|---|
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
|
private static Comparator<ExtensionPoint<?>> |
EXTENSIONPOINT_COMPARATOR
|
private Map<String,Registry.RegisteredExtensionPoint<?>> |
extensionPoints
|
private Map<String,Registry.RegisteredExtension<?>> |
extensions
|
private static Logger |
log
|
Constructor Summary | |
---|---|
Registry()
Create a new empty registry. |
Method Summary | ||
---|---|---|
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. |
|
Iterator<ExtensionPoint<?>> |
getExtensionPoints()
Get an iterator returning all registered extension points. |
|
Iterator<Extension<?>> |
getExtensions()
Get an iterator returning all registered extensions. |
|
Iterator<Extension<?>> |
getExtensions(String id)
Get an iterator returning 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. |
|
|
registerExtension(Extension<A> extension)
Register an extension. |
|
|
registerExtensionPoint(ExtensionPoint<A> extensionPoint)
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final Logger log
private static final Comparator<ExtensionPoint<?>> EXTENSIONPOINT_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...)
Constructor Detail |
---|
public Registry()
Method Detail |
---|
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 attribute
public 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)
.
EventType.AFTER_REGISTRATION
EventType.BEFORE_UPDATE
EventType.AFTER_UPDATE
EventType.BEFORE_UNREGISTRATION
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
public <A extends Action> void registerExtensionPoint(ExtensionPoint<A> extensionPoint)
extensionPoint
- The extension point to register
InvalidUseOfNullException
- If the extension point is null, or if the ID
or actionClass is null
ClassCastException
- If the action class doesn't implement the
Action
interfacepublic void unregisterExtensionPoint(String id)
id
- The ID of the extension point to unregister
InvalidUseOfNullException
- If the ID is nullpublic ExtensionPoint<?> getExtensionPoint(String id)
id
- The ID of the extension point
Registry.RegisteredExtensionPoint
object or null if that
extension point doesn't existspublic Iterator<ExtensionPoint<?>> getExtensionPoints()
public boolean extensionIsRegistered(String id)
id
- The ID of the extension
public Throwable getLastExtensionPointError(String id)
id
- The id of the extension point
public <A extends Action> void registerExtension(Extension<A> extension)
extension
- The extension to register
InvalidUseOfNullException
- 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 unregister
InvalidUseOfNullException
- If the ID is nullpublic Extension<?> getExtension(String id)
id
- The ID of the extension point
Extension
object or null if that
extension doesn't existspublic Throwable getLastExtensionError(String id)
id
- The id of the extension
public Iterator<Extension<?>> getExtensions()
public Iterator<Extension<?>> getExtensions(String id)
id
- The ID of the extension point
public 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 Registry.RegisteredExtensionPoint.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.
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |