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 implement IFCPlugin.
PluginBean - The interface type of the plugin bean that all beans from plugins must implement, must implement IPluginGenericCustomGUIBean; and must be a subtype of Bean.
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 corresponding PluginBeanHelper. Creates the bean helper when needed and closes all helpers when destroy() 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 PostConstruct phase of that bean, and call destroy() during the PreDestroy phase.

See Also:
  • Method Details

    • destroy

      public void destroy()
      Destroys all bean entries in the cache. This should be once the beans are not needed anymore. Usually called during the PreDestroy phase 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 of Bean.
      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 of Bean.
      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 current Mandant, 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.