de.vc.jfo.renderer

## Class RendererFactory

- java.lang.Object
- - de.vc.jfo.renderer.RendererFactory

-     public class RendererFactory
      extends java.lang.Object

  A renderer factory can be used for creating a renderer for a certain output format instead of constructing it directly. Using the factory pattern has the advantage that you may switch the concrete renderer very easily at runtime or by modifying the configuration of JFO. Thus we recommend using this factory and to avoid constructing a certain renderer with the `new` keyword.

  In general this factory is initalized by the jfo-config.xml. That file contains a list of renderers this factory tries to find and to initialize. If a configured renderer is not found or can't be created (e.g. a class of a used third party library is not available), a warning message is logged at startup. Nevertheless, configurations of unavailable renderers are hold but renderers (and prototypes) are not available.

  Renderers are managed as follows: The factory holds a map of configurations to renderer-prototypes (or null of the prototype couldn't be created). If a renderer is requested by `getRenderer()`, `getRenderers()` or `newCompositeRenderer()` the factory searches a matching renderer prototype with the hightest priority and copy of the prototype is returned. This means, that changing a configuration (at runtime) and not the prototype has no effect. If you change a configuration at runtime and you need to apply these changes to the corresponding prototype (or requested renderer), you have to reconfigure (Renderer.reconfigure()) the prototype (or renderer). However, the need of changing the configuration at runtime is really rare.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `RendererFactory()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `configure(de.vc.config.Configuration config)` Configures this renderer factory with a <renderer> XML tree from JFO configuration.
    `java.util.List` | `getAvailableRenderers()` Returns a list of all available renderers.
    `de.vc.config.Configuration[]` | `getConfigurations()` Gets all configurations.
    `de.vc.config.Configuration` | `getFactoryConfiguration()` Gets the configuration of this factory that includes all configuration of renderers.
    `Renderer` | `getPrototype(de.vc.config.Configuration c)` Gets the prototype of a given configuration from the configuration to prototype map.
    `Renderer[]` | `getPrototypes()` Gets all available prototypes.
    `Renderer[]` | `getPrototypes(OutputFormat format)` Gets all prototypes that can render into the given ouput format.
    `Renderer` | `getRenderer(OutputFormat format)` Finds the best renderer (clone of the prototype) with the highest priority that can render a document into output format `format`.
    `Renderer[]` | `getRenderers(OutputFormat format)` Gets all renderers (clone of the prototypes) that can render into the given ouput format.
    `OutputFormat[]` | `getSupportedOutputFormats()` Gets all output formats which are supported by any registered renderer.
    `static RendererFactory` | `instance()` Gets the default renderer factory that is equipped through JFOs configuration.
    `CompositeRenderer` | `newCompositeRenderer()` Creates a composite renderer that contains all available renderes.
    `Renderer` | `newRenderer(de.vc.config.Configuration c)` Creates a new renderer specified by a configuration object.
    `void` | `register(java.lang.Class rendererClass, de.vc.config.Configuration config)` Registers a renderer class with its configuration.
    `void` | `register(java.lang.String rendererClass, de.vc.config.Configuration config)` Registers a renderer class with a specific configuration.
    `void` | `registerDefaultRenderers()` Registers following renderers at this factory: de.vc.jfo.renderer.PlainRenderer de.vc.jfo.renderer.XMLTreeViewer de.vc.jfo.renderer.SimpleHTMLRenderer
    `void` | `unregisterAll()` Unregisters all renderers (Prototypes).

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### RendererFactory

          public RendererFactory()

  - ### Method Detail

    - #### instance

          public static RendererFactory instance()

      Gets the default renderer factory that is equipped through JFOs configuration.
      Returns:
        RendererFactory
      See Also:
        `JFOConfig.getDefaultRendererFactory()`

    - #### registerDefaultRenderers

          public void registerDefaultRenderers()

      Registers following renderers at this factory:
      - de.vc.jfo.renderer.PlainRenderer
      - de.vc.jfo.renderer.XMLTreeViewer
      - de.vc.jfo.renderer.SimpleHTMLRenderer
      See Also:
        `PlainRenderer`, `SimpleHTMLRenderer`, `XMLTreeViewer`

    - #### getAvailableRenderers

          public java.util.List getAvailableRenderers()

      Returns a list of all available renderers. All elements are have type `de.vc.jfo.renderer.Renderer`
      Returns:
        List of all available renderers.

    - #### newCompositeRenderer

          public CompositeRenderer newCompositeRenderer()

      Creates a composite renderer that contains all available renderes. The concret renderer is choosen by output format and priority.
      Returns:
        Composite renderer.

    - #### getRenderer

          public Renderer getRenderer(OutputFormat format)

      Finds the best renderer (clone of the prototype) with the highest priority that can render a document into output format `format`.
      Parameters:
        `format` - Desired output format.
      Returns:
        Renderer or `null` if no renderer supporting `format` is available.

    - #### register

          public void register(java.lang.Class rendererClass,
                      de.vc.config.Configuration config)

      Registers a renderer class with its configuration. The `rendererClass` must be a subclass of `de.vc.jfo.renderer.Renderer and must have a parameterless constructor.`
      Parameters:
        `rendererClass` - Renderer class.
        `config` - Configuration.

    - #### register

          public void register(java.lang.String rendererClass,
                      de.vc.config.Configuration config)

      Registers a renderer class with a specific configuration. The `rendererClass` must be a subclass of `de.vc.jfo.renderer.Renderer and must have a parameterless constructor.`
      Parameters:
        `rendererClass` - Renderer class.
        `config` - Configuration.

    - #### unregisterAll

          public void unregisterAll()

      Unregisters all renderers (Prototypes).

    - #### configure

          public void configure(de.vc.config.Configuration config)
                         throws de.vc.config.ConfigurationException

      Configures this renderer factory with a <renderer> XML tree from JFO configuration. Is method is for internal purpose and you shouldn't have the need to use it.
      Parameters:
        `config` - Configuration
      Throws:
        `de.vc.config.ConfigurationException`

    - #### getFactoryConfiguration

          public de.vc.config.Configuration getFactoryConfiguration()

      Gets the configuration of this factory that includes all configuration of renderers.
      Returns:
        Configuration.

    - #### getConfigurations

          public de.vc.config.Configuration[] getConfigurations()

      Gets all configurations. This method is for internal purpose and in most cases there is no need to use it.
      Returns:
        Configuration[]

    - #### getRenderers

          public Renderer[] getRenderers(OutputFormat format)

      Gets all renderers (clone of the prototypes) that can render into the given ouput format.
      Parameters:
        `format` - OutputFormat
      Returns:
        Renderers that support `format`.

    - #### getSupportedOutputFormats

          public OutputFormat[] getSupportedOutputFormats()

      Gets all output formats which are supported by any registered renderer.
      Returns:
        Output formats.

    - #### getPrototype

          public Renderer getPrototype(de.vc.config.Configuration c)

      Gets the prototype of a given configuration from the configuration to prototype map.
      Parameters:
        `c` - Configuration
      Returns:
        Prototype

    - #### getPrototypes

          public Renderer[] getPrototypes(OutputFormat format)

      Gets all prototypes that can render into the given ouput format.
      Parameters:
        `format` - OutputFormat
      Returns:
        Renderers that support `format`.

    - #### getPrototypes

          public Renderer[] getPrototypes()

      Gets all available prototypes.
      Returns:
        Prototypes.

    - #### newRenderer

          public Renderer newRenderer(de.vc.config.Configuration c)

      Creates a new renderer specified by a configuration object.
      Parameters:
        `c` - Configuration
      Returns:
        Renderer or null.

© 2003-2011 by Sascha Schmidt (vision-cloud.de). All Rights Reserved.