Package de.xima.fc.gui.common.plugingui
Class GuiBeanCache<Key,Bean,Plugin extends IFCPlugin,PluginBean extends IPluginGenericCustomGUIBean>
- java.lang.Object
-
- de.xima.fc.gui.common.plugingui.GuiBeanCache<Key,Bean,Plugin,PluginBean>
-
- Type Parameters:
Key- The key used to identify which bean to retrieve, e.g. a workflow node handler's type.Bean- The interface type of the beans that all beans must implement.Plugin- The interface type of the plugin that provides the beans, must implementIFCPlugin.PluginBean- The interface type of the plugin bean that all beans from plugins must implement, must implementIPluginGenericCustomGUIBean; and must be a subtype ofGuiBeanCache.
- All Implemented Interfaces:
Serializable
public final class GuiBeanCache<Key,Bean,Plugin extends IFCPlugin,PluginBean extends IPluginGenericCustomGUIBean> extends Object implements Serializable
Helper for custom UIs with beans that come from either a plugin class or from a built-in class. For each plugin bean, keeps track of the correspondingPluginBeanHelper. Creates the bean helper when needed and closes all helpers whendestroy()is called. If a plugin is updated while the UI is active, destroy the old bean helper and create a new one.This class is intended to be used as part of another scoped bean, and the lifecycle of this cache should be tied to the lifecycle of that bean. Create a new cache during the
PostConstructphase of that bean, and calldestroy()during thePreDestroyphase.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGuiBeanCache.Builder<Key,Bean,Plugin extends IFCPlugin>A builder for creating instances ofGuiBeanCache.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <Key,Bean,Plugin extends IFCPlugin>
GuiBeanCache.Builder<Key,Bean,Plugin>builder(Class<? extends Bean> beanClass, IClientScopeProvider clientScopeProvider, IBeanProvidingPluginLocator<Key,Plugin> pluginLocator)Creates a new builder for a GUI bean cache instance.voiddestroy()Destroys all bean entries in the cache.BeanretrieveBean(Key key)Gets the bean for the given key.<B extends Bean>
BretrieveBean(Key key, Class<B> beanClass)Gets the bean for the given key, if it's a subtype of the given class.
-
-
-
Method Detail
-
destroy
public void destroy()
Destroys all bean entries in the cache. This should be once the beans are not needed anymore. Usually called during thePreDestroyphase of the bean that uses this cache.
-
retrieveBean
public Bean retrieveBean(Key key) throws Exception
Gets the bean for the given key. If a bean instance exists already, returns that instance. If no instance exists, creates a new beans. If the bean is stale (e.g. when the plugin that provides the bean has been updated), destroys the old bean and creates a new one.- Parameters:
key- The key used to identify the bean, e.g. a workflow node handler's type.- Returns:
- The bean instance of the given class, or null if no bean of that class exists for the given key.
- Throws:
Exception- If an error occurs while creating the bean or retrieving it from the plugin.
-
retrieveBean
public <B extends Bean> B retrieveBean(Key key, Class<B> beanClass) throws Exception
Gets the bean for the given key, if it's a subtype of the given class. If a bean instance exists already, returns that instance. If no instance exists, creates a new beans. If the bean is stale (e.g. when the plugin that provides the bean has been updated), destroys the old bean and creates a new one.- Type Parameters:
B- The interface type of the beans that all beans must implement, must be a subtype ofGuiBeanCache.- Parameters:
key- The key used to identify the bean, e.g. a workflow node handler's type.beanClass- The class of the bean to retrieve. Must be a subtype ofGuiBeanCache.- Returns:
- The bean instance of the given class, or null if no bean of that class exists for the given key.
- Throws:
Exception- If an error occurs while creating the bean or retrieving it from the plugin.
-
builder
public static <Key,Bean,Plugin extends IFCPlugin> GuiBeanCache.Builder<Key,Bean,Plugin> builder(Class<? extends Bean> beanClass, IClientScopeProvider clientScopeProvider, IBeanProvidingPluginLocator<Key,Plugin> pluginLocator)
Creates a new builder for a GUI bean cache instance.- Type Parameters:
Key- The type of the key used to identify bean.Bean- The interface type of the beans.Plugin- The type of the plugin that provides the beans.- Parameters:
beanClass- The interface type of the beans.clientScopeProvider- Provider for the currentMandant, if any. Used to find plugins, can return null to search only system scoped plugins.pluginLocator- Locator for the plugin that provides the bean.- Returns:
- A new builder for a GUI bean cache instance.
-
-