Class PluginManager


  • public class PluginManager
    extends Object
    Class for managing plugins
    Author:
    XIMA MEDIA GmbH
    • Constructor Detail

      • PluginManager

        public PluginManager()
    • Method Detail

      • initPlugins

        public static void initPlugins()
        Initialize all plugins stored in the database
      • registerSystemPlugin

        public static PluginRuntime registerSystemPlugin​(Class<? extends IFCPlugin> clazz,
                                                         String runtimeKey)
                                                  throws FCPluginException
        Method to register a plugin-class in system-scope
        Parameters:
        clazz - IFCPlugin-class to register
        runtimeKey - Runtime key (UUID) of the plugin to register.
        Returns:
        The newly created plugin runtime for the registered plugin.
        Throws:
        FCPluginException - When the plugin could not be registered.
      • registerClientPlugin

        public static <T extends IFCPluginPluginRuntime registerClientPlugin​(Mandant man,
                                                                               Class<T> clazz,
                                                                               String runtimeKey)
                                                                        throws FCPluginException
        Method to register a plugin-class in scope of the given client
        Type Parameters:
        T - Type of the plugin to register.
        Parameters:
        man - The client for which to register the plugin.
        clazz - The class of the plugin to register.
        runtimeKey - Runtime key (UUID) of the plugin to register.
        Returns:
        The newly created plugin runtime for the registered plugin.
        Throws:
        FCPluginException - When the plugin could not be registered.
      • registerPlugin

        public static <T extends IFCPlugin> void registerPlugin​(boolean isInstall,
                                                                PluginRuntime prtm,
                                                                Class<T> clazz)
                                                         throws FCPluginException
        Register a plugin to the given key and PluginRuntime
        Type Parameters:
        T - Type of the plugin to register.
        Parameters:
        isInstall - true if the plugin is installed for the first time, false if the plugin configuration is only updated.
        prtm - The runtime of the plugin to register.
        clazz - Class of the plugin to register.
        Throws:
        FCPluginException - When the plugin could not be registered.
      • releasePlugins

        public static void releasePlugins()
        Releases all registered plugins
      • uninstallPlugin

        public static void uninstallPlugin​(String scopeKey,
                                           String runtimeKey)
                                    throws IOException
        Parameters:
        scopeKey - the plugin scope key
        runtimeKey - the plugin runtime key
        Throws:
        IOException - on errors while uninstall
      • getClientPlugins

        public static <T extends IFCPluginSet<T> getClientPlugins​(Mandant client,
                                                                    Class<T> pluginType)
        Get a set of plugins with the given interfaces registered to the given client
        Parameters:
        client - The client-scope to use for retrieving client plugins, if any.
        pluginType - Type of the plugins to retrieve.
        Returns:
        All active plugins for the given client, if any (does not include systm plugins!)
      • getClientPlugins

        public static <T extends IFCPluginSet<T> getClientPlugins​(UUID clientUuid,
                                                                    Class<T> pluginType)
        Get a set of plugins with the given interfaces registered to the given client
        Parameters:
        clientUuid - The client-scope to use for retrieving client plugins, if any.
        pluginType - Type of the plugins to retrieve.
        Returns:
        All active plugins for the given client, if any (does not include systm plugins!)
      • getClientPluginsWithRuntime

        public static <T extends IFCPluginSet<org.apache.commons.lang3.tuple.Pair<PluginRuntime,​T>> getClientPluginsWithRuntime​(Mandant client,
                                                                                                                                        Class<T> clazz)
      • getClientPluginsWithRuntime

        public static <T extends IFCPluginSet<org.apache.commons.lang3.tuple.Pair<PluginRuntime,​T>> getClientPluginsWithRuntime​(UUID clientUuid,
                                                                                                                                        Class<T> clazz)
      • getClientPlugins

        public static Set<PluginRuntime> getClientPlugins​(Mandant client)
        Gets a list of all plugin runtimes registered to the given client (not including system plugins!)
        Parameters:
        client - A client for which to retrieve the plugins.
        Returns:
        A list of all plugin runtimes corresponding to the plugin installed for the given client
      • getClientPlugins

        public static Set<PluginRuntime> getClientPlugins​(UUID clientUuid)
        Gets a list of all plugin runtimes registered to the given client (not including system plugins!)
        Parameters:
        clientUuid - UUID of a client.
        Returns:
        A list of all plugin runtimes corresponding to the plugin installed for the given client
      • getSystemPlugins

        public static <T extends IFCPluginSet<T> getSystemPlugins​(Class<T> clazz)
        Get a set of plugins with the given interfaces registered in system-scope
        Type Parameters:
        T - Type of the plugins to retrieve.
        Parameters:
        clazz - IFCPlugin-interface
        Returns:
        Set of IFCPlugin-instances
      • getSystemPluginsWithRuntime

        public static <T extends IFCPluginSet<org.apache.commons.lang3.tuple.Pair<PluginRuntime,​T>> getSystemPluginsWithRuntime​(Class<T> clazz)
      • isHasAnyPluginsOfType

        public static boolean isHasAnyPluginsOfType​(Mandant client,
                                                    Class<? extends IFCPlugin> pluginType)
        Checks if any plugins of the given type exist.
        Parameters:
        client - Optional client scope. When given, the client and system scope is searched. Otherwise, only the system scope is searched.
        pluginType - Type of plugin to search for.
        Returns:
        Whether any plugins of the given type exist.
      • getAllPlugins

        public static <T extends IFCPluginSet<T> getAllPlugins​(Mandant client,
                                                                 Class<T> pluginType)
        Get a set of plugins with the given interface registered in system-scope OR to the given client. (client-scope wins over system-scope)
        Parameters:
        client - Client scope for which to retrieve all plugins.
        pluginType - Type of the plugins to retrieve.
        Returns:
        All plugins from the given client (if any) and from the system scope. A client-scoped plugin overwrites a system-scoped plugin.
      • getAllPlugins

        public static <T extends IFCPluginSet<T> getAllPlugins​(UUID clientUuid,
                                                                 Class<T> pluginType)
        Get a set of plugins with the given interface registered in system-scope OR to the given client. (client-scope wins over system-scope)
        Parameters:
        clientUuid - UUID of a client.
        pluginType - Type of the plugins to retrieve.
        Returns:
        All plugins from the given client (if any) and from the system scope. A client-scoped plugin overwrites a system-scoped plugin.
      • getAllPluginsWithRuntime

        public static <T extends IFCPluginSet<org.apache.commons.lang3.tuple.Pair<PluginRuntime,​T>> getAllPluginsWithRuntime​(Mandant man,
                                                                                                                                     Class<T> clazz)
      • getAllPluginsWithRuntime

        public static <T extends IFCPluginSet<org.apache.commons.lang3.tuple.Pair<PluginRuntime,​T>> getAllPluginsWithRuntime​(UUID clientUuid,
                                                                                                                                     Class<T> clazz)
      • getRegisteredPlugins

        public static <T extends IFCPluginSet<T> getRegisteredPlugins​(Class<T> clazz)
        Get a set with all registered plugins of the given IFCPlugin-interface
        Type Parameters:
        T - Type of the plugins to retrieve.
        Parameters:
        clazz - IFCPlugin-interfaces
        Returns:
        Set of IFCPlugin-instances
      • getPluginByName

        public static <T extends IFCPlugin> T getPluginByName​(Mandant man,
                                                              Class<T> clazz,
                                                              String pluginName)
        Get a plugin by name and IFCPlugin-interface from client- and system-scope
        Type Parameters:
        T - Type of the plugins to retrieve.
        Parameters:
        man - The client from which to retrieve the plugins.
        clazz - IFCPlugin-interface to search for
        pluginName - String name of the searched plugin
        Returns:
        IFCPlugin-instance or null if no plugin could be found
      • getPluginRuntimeByPluginKey

        public static PluginRuntime getPluginRuntimeByPluginKey​(Mandant client,
                                                                String pluginKey)
        Gets the plugin runtime for the plugin bundle with the given plugin key.

        A plugin bundle is a JAR file that contains one or more implementations of the IFCPlugin interface. Each bundle must specify a Plugin-Key in its manifest file, which uniquely identifies the plugin bundle amongst all available formcycle plugins. Each implementation of IFCPlugin has a name, which uniquely identifies that plugin within the bundle. In principle, different plugin bundles could contain plugins with the same name. The combination of the plugin key and the plugin name uniquely identifies a plugin.

        When a client is given, looks for plugins installed either in that client scope, or within the system scope. In case a plugin is found in both scopes, the client-scoped plugin is returned. When no client is given, only system-scoped plugins are searched.

        You may also specify the expected subtype of IFCPlugin. If you do, the plugin instance gets returned only if matches the given type. Use IFCPlugin.class to apply no restriction.

        Parameters:
        client - The client for which to retrieve the plugin.
        pluginKey - The plugin key to search for.
        Returns:
        The plugin runtime, or null if no matching plugin could be found.
      • getPluginRuntimeByPluginKey

        public static PluginRuntime getPluginRuntimeByPluginKey​(UUID clientUuid,
                                                                String pluginKey)
        Gets the plugin runtime for the plugin bundle with the given plugin key.

        A plugin bundle is a JAR file that contains one or more implementations of the IFCPlugin interface. Each bundle must specify a Plugin-Key in its manifest file, which uniquely identifies the plugin bundle amongst all available formcycle plugins. Each implementation of IFCPlugin has a name, which uniquely identifies that plugin within the bundle. In principle, different plugin bundles could contain plugins with the same name. The combination of the plugin key and the plugin name uniquely identifies a plugin.

        When a client is given, looks for plugins installed either in that client scope, or within the system scope. In case a plugin is found in both scopes, the client-scoped plugin is returned. When no client is given, only system-scoped plugins are searched.

        You may also specify the expected subtype of IFCPlugin. If you do, the plugin instance gets returned only if matches the given type. Use IFCPlugin.class to apply no restriction.

        Parameters:
        clientUuid - The UUID of the client for which to retrieve the plugin.
        pluginKey - The plugin key to search for.
        Returns:
        The plugin runtime, or null if no matching plugin could be found.
      • getPluginByPluginKeyAndName

        public static <Plugin extends IFCPlugin> Plugin getPluginByPluginKeyAndName​(Mandant client,
                                                                                    String pluginKey,
                                                                                    String pluginName,
                                                                                    Class<Plugin> pluginClass)
        Gets a plugin with a certain name from the plugin bundle with the given plugin key.

        A plugin bundle is a JAR file that contains one or more implementations of the IFCPlugin interface. Each bundle must specify a Plugin-Key in its manifest file, which uniquely identifies the plugin bundle amongst all available formcycle plugins. Each implementation of IFCPlugin has a name, which uniquely identifies that plugin within the bundle. In principle, different plugin bundles could contain plugins with the same name. The combination of the plugin key and the plugin name uniquely identifies a plugin.

        When a client is given, looks for plugins installed either in that client scope, or within the system scope. In case a plugin is found in both scopes, the client-scoped plugin is returned. When no client is given, only system-scoped plugins are searched.

        You may also specify the expected subtype of IFCPlugin. If you do, the plugin instance gets returned only if matches the given type. Use IFCPlugin.class to apply no restriction.

        Type Parameters:
        Plugin - Type of the plugin to retrieve.
        Parameters:
        client - The client for which to retrieve the plugin.
        pluginKey - The plugin key to search for.
        pluginName - The name of the plugin to search for.
        pluginClass - The expected subtype of IFCPlugin to return.
        Returns:
        The plugin instance, or null if no matching plugin could be found.
      • getPluginsByPluginKey

        public static <Plugin extends IFCPluginSet<Plugin> getPluginsByPluginKey​(Mandant client,
                                                                                   String pluginKey,
                                                                                   Class<Plugin> pluginClass)
        Gets all plugins from the plugin bundle with the given plugin key, limited to plugins of the given type.

        A plugin bundle is a JAR file that contains one or more implementations of the IFCPlugin interface. Each bundle must specify a Plugin-Key in its manifest file, which uniquely identifies the plugin bundle amongst all available formcycle plugins. Each implementation of IFCPlugin has a name, which uniquely identifies that plugin within the bundle. In principle, different plugin bundles could contain plugins with the same name. The combination of the plugin key and the plugin name uniquely identifies a plugin.

        When a client is given, looks for plugins installed either in that client scope, or within the system scope. In case a plugin is found in both scopes, the client-scoped plugin is returned. When no client is given, only system-scoped plugins are searched.

        You may also specify the expected subtype of IFCPlugin. If you do, the plugin instance gets returned only if matches the given type. Use IFCPlugin.class to apply no restriction.

        Type Parameters:
        Plugin - Type of the plugin to retrieve.
        Parameters:
        client - The client for which to retrieve the plugin.
        pluginKey - The plugin key to search for.
        pluginClass - The expected subtype of IFCPlugin to return.
        Returns:
        All plugin instances, or an empty set if no matching plugins could be found.
      • getPluginByNameWithRuntime

        public static <T extends IFCPlugin> org.apache.commons.lang3.tuple.Pair<PluginRuntime,​T> getPluginByNameWithRuntime​(Mandant man,
                                                                                                                                  Class<T> clazz,
                                                                                                                                  String pluginName)
      • getSystemPluginByName

        public static <T extends IFCPlugin> T getSystemPluginByName​(Class<T> clazz,
                                                                    String pluginName)
        Get a system-plugin by name, IFCPlugin-interface
        Type Parameters:
        T - Type of the plugins to retrieve.
        Parameters:
        clazz - IFCPlugin-interface to search for
        pluginName - String name of the searched plugin
        Returns:
        IFCPlugin-instance or null if no plugin could be found
      • createSystemProtocolEntry

        public static void createSystemProtocolEntry​(UserContext uc,
                                                     String protocolEntry,
                                                     Object... params)
        Creates a system protocol entry
        Parameters:
        uc - UserContext
        protocolEntry - String protocol-text
        params - Objects parameters
      • createClientProtocolEntry

        public static void createClientProtocolEntry​(UserContext uc,
                                                     Mandant man,
                                                     String protocolEntry,
                                                     Object... params)
        Creates a client protocol entry
        Parameters:
        uc - UserContext with the user who uploaded the plugin.
        man - The client for which to create the protocol entry.
        protocolEntry - String protocol-text
        params - Objects parameters
      • isPluginJar

        @Deprecated
        public static boolean isPluginJar​(File file)
        Deprecated.
      • getMandantPlugins

        @Deprecated
        public static SortedSet<IFCPlugin> getMandantPlugins​(Mandant man,
                                                             EPluginTypes type)
        Deprecated.
        will be removed!
        Parameters:
        man - The client scope from which to retrieve plugins.
        type - The type of the plugins to retrieve.
        Returns:
        A set of all matching plugins.
      • getMandantPluginByName

        @Deprecated
        public static IFCPlugin getMandantPluginByName​(Mandant man,
                                                       EPluginTypes type,
                                                       String pluginName)
        Deprecated.
        will be removed!
        Parameters:
        man - The client scope from which to retrieve plugins.
        type - The type of the plugins to retrieve.
        pluginName - The name of the plugin to retrieve.
        Returns:
        The plugin or null when no plugin matches.
      • scanAndRegisterSystemPlugin

        @Deprecated
        public static boolean scanAndRegisterSystemPlugin​(PluginRuntime pluginMeta,
                                                          byte[] jarData)
        Deprecated.
        Parameters:
        pluginMeta - Runtime of the plugin to register.
        jarData - Binary content of the JAR file to register.
        Returns:
        Always false - this method is deprecated!
      • scanAndRegisterMandantPlugin

        @Deprecated
        public static boolean scanAndRegisterMandantPlugin​(Mandant man,
                                                           PluginRuntime pluginMeta,
                                                           byte[] jarData)
        Parameters:
        man - The client for which to register a plugin.
        pluginMeta - Runtime of the plugin to register.
        jarData - Binary content of the JAR file to register.
        Returns:
        Always false - this method is deprecated!