Class PackageManager


  • public final class PackageManager
    extends java.lang.Object
    The PackageManager is used to load and configure the modules of JFreeReport. Modules are used to extend the basic capabilities of JFreeReport by providing a simple plugin-interface.

    Modules provide a simple capability to remove unneeded functionality from the JFreeReport system and to reduce the overall code size. The modularisation provides a very strict way of removing unnecessary dependencies between the various packages.

    The package manager can be used to add new modules to the system or to check the existence and state of installed modules.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  PackageManager.PackageConfiguration
      The PackageConfiguration handles the module level configuration.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private AbstractBoot booter
      The boot implementation for which the modules are managed.
      private java.util.ArrayList initSections
      A list of module name definitions.
      private static java.util.HashMap instances
      The instances of all modules for all booters.
      private java.util.ArrayList modules
      A list of all defined modules.
      private PackageManager.PackageConfiguration packageConfiguration
      The module configuration instance that should be used to store module properties.
      private static int RETURN_MODULE_ERROR
      An internal constant declaring that the specified module produced an error while loading.
      private static int RETURN_MODULE_LOADED
      An internal constant declaring that the specified module was already loaded.
      private static int RETURN_MODULE_UNKNOWN
      An internal constant declaring that the specified module is not known.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private PackageManager​(AbstractBoot booter)
      Creates a new package manager.
    • Field Detail

      • RETURN_MODULE_LOADED

        private static final int RETURN_MODULE_LOADED
        An internal constant declaring that the specified module was already loaded.
        See Also:
        Constant Field Values
      • RETURN_MODULE_UNKNOWN

        private static final int RETURN_MODULE_UNKNOWN
        An internal constant declaring that the specified module is not known.
        See Also:
        Constant Field Values
      • RETURN_MODULE_ERROR

        private static final int RETURN_MODULE_ERROR
        An internal constant declaring that the specified module produced an error while loading.
        See Also:
        Constant Field Values
      • packageConfiguration

        private final PackageManager.PackageConfiguration packageConfiguration
        The module configuration instance that should be used to store module properties. This separates the user defined properties from the implementation defined properties.
      • modules

        private final java.util.ArrayList modules
        A list of all defined modules.
      • initSections

        private final java.util.ArrayList initSections
        A list of module name definitions.
      • booter

        private AbstractBoot booter
        The boot implementation for which the modules are managed.
      • instances

        private static java.util.HashMap instances
        The instances of all modules for all booters.
    • Constructor Detail

      • PackageManager

        private PackageManager​(AbstractBoot booter)
        Creates a new package manager.
        Parameters:
        booter - the booter (null not permitted).
    • Method Detail

      • createInstance

        public static PackageManager createInstance​(AbstractBoot booter)
        Creates a package manager instance.
        Parameters:
        booter - the booter.
        Returns:
        A package manager.
      • isModuleAvailable

        public boolean isModuleAvailable​(ModuleInfo moduleDescription)
        Checks, whether a certain module is available.
        Parameters:
        moduleDescription - the module description of the desired module.
        Returns:
        true, if the module is available and the version of the module is compatible, false otherwise.
      • load

        public void load​(java.lang.String modulePrefix)
        Loads all modules mentioned in the report configuration starting with the given prefix. This method is used during the boot process of JFreeReport. You should never need to call this method directly.
        Parameters:
        modulePrefix - the module prefix.
      • initializeModules

        public void initializeModules()
        Initializes all previously uninitialized modules. Once a module is initialized, it is not re-initialized a second time.
      • addModule

        public void addModule​(java.lang.String modClass)
        Adds a module to the package manager. Once all modules are added, you have to call initializeModules() to configure and initialize the new modules.
        Parameters:
        modClass - the module class
      • containsModule

        private int containsModule​(java.util.ArrayList tempModules,
                                   ModuleInfo module)
        Checks, whether the given module is already loaded in either the given tempModules list or the global package registry. If tmpModules is null, only the previously installed modules are checked.
        Parameters:
        tempModules - a list of previously loaded modules.
        module - the module specification that is checked.
        Returns:
        true, if the module is already loaded, false otherwise.
      • dropFailedModule

        private void dropFailedModule​(PackageState state)
        A utility method that collects all failed modules. Such an module caused an error while being loaded, and is now cached in case it is referenced elsewhere.
        Parameters:
        state - the failed module.
      • loadModule

        private boolean loadModule​(ModuleInfo moduleInfo,
                                   java.util.ArrayList incompleteModules,
                                   java.util.ArrayList modules,
                                   boolean fatal)
        Tries to load a given module and all dependent modules. If the dependency check fails for that module (or for one of the dependent modules), the loaded modules are discarded and no action is taken.
        Parameters:
        moduleInfo - the module info of the module that should be loaded.
        incompleteModules - a list of incompletly loaded modules. This are module specifications which depend on the current module and wait for the module to be completly loaded.
        modules - the list of previously loaded modules for this module.
        fatal - a flag that states, whether the failure of loading a module should be considered an error. Root-modules load errors are never fatal, as we try to load all known modules, regardless whether they are active or not.
        Returns:
        true, if the module was loaded successfully, false otherwise.
      • acceptVersion

        private boolean acceptVersion​(ModuleInfo moduleRequirement,
                                      Module module)
        Checks, whether the given module meets the requirements defined in the module information.
        Parameters:
        moduleRequirement - the required module specification.
        module - the module that should be checked against the specification.
        Returns:
        true, if the module meets the given specifications, false otherwise.
      • acceptVersion

        private int acceptVersion​(java.lang.String modVer,
                                  java.lang.String depModVer)
        Compare the version strings. If the strings have a different length, the shorter string is padded with spaces to make them compareable.
        Parameters:
        modVer - the version string of the module
        depModVer - the version string of the dependent or optional module
        Returns:
        0, if the dependent module version is equal tothe module's required version, a negative number if the dependent module is newer or a positive number if the dependent module is older and does not fit.
      • getPackageConfiguration

        public PackageManager.PackageConfiguration getPackageConfiguration()
        Returns the default package configuration. Private report configuration instances may be inserted here. These inserted configuration can never override the settings from this package configuration.
        Returns:
        the package configuration.
      • getAllModules

        public Module[] getAllModules()
        Returns an array of the currently active modules. The module definition returned contain all known modules, including buggy and unconfigured instances.
        Returns:
        the modules.
      • getActiveModules

        public Module[] getActiveModules()
        Returns all active modules. This array does only contain modules which were successfully configured and initialized.
        Returns:
        the list of all active modules.
      • printUsedModules

        public void printUsedModules​(java.io.PrintStream p)
        Prints the modules that are used.
        Parameters:
        p - the print stream.