Class ContextConfiguration


  • public class ContextConfiguration
    extends Object
    A configuration which can be stored on a log context to store information about the configured error managers, handlers, filters, formatters and objects that might be associated with a configured object.

    The addObject(String, Supplier) can be used to allow objects to be set when configuring error managers, handlers, filters and formatters.

    Suppliers are used to lazily create objects. Note the passed in supplier is wrapped and invoked at most once.

    Author:
    James R. Perkins
    • Constructor Detail

      • ContextConfiguration

        public ContextConfiguration()
        Creates a new context configuration.
    • Method Detail

      • addErrorManager

        public Supplier<ErrorManager> addErrorManager​(String name,
                                                      Supplier<ErrorManager> errorManager)
        Adds an error manager to the context configuration.
        Parameters:
        name - the name for the error manager
        errorManager - the error manager to add
        Returns:
        the previous error manager associated with the name or null if one did not exist
      • removeErrorManager

        public Supplier<ErrorManager> removeErrorManager​(String name)
        Removes the error manager from the context configuration.
        Parameters:
        name - the name of the error manager
        Returns:
        the error manager removed or null if the error manager did not exist
      • hasErrorManager

        public boolean hasErrorManager​(String name)
        Checks if the error manager exists with the name provided.
        Parameters:
        name - the name for the error manager
        Returns:
        true if the error manager exists in this context, otherwise false
      • getErrorManager

        public ErrorManager getErrorManager​(String name)
        Gets the error manager if it exists.
        Parameters:
        name - the name of the error manager
        Returns:
        the error manager or null if the error manager does not exist
      • getErrorManagers

        public Map<String,​Supplier<ErrorManager>> getErrorManagers()
        Returns an unmodifiable map of the error managers and the suppliers used to create them.
        Returns:
        an unmodified map of the error managers
      • addHandler

        public Supplier<Handler> addHandler​(String name,
                                            Supplier<Handler> handler)
        Adds a handler to the context configuration.
        Parameters:
        name - the name for the handler
        handler - the handler to add
        Returns:
        the previous handler associated with the name or null if one did not exist
      • removeHandler

        public Supplier<Handler> removeHandler​(String name)
        Removes the handler from the context configuration.
        Parameters:
        name - the name of the handler
        Returns:
        the handler removed or null if the handler did not exist
      • hasHandler

        public boolean hasHandler​(String name)
        Checks if the handler exists with the name provided.
        Parameters:
        name - the name for the handler
        Returns:
        true if the handler exists in this context, otherwise false
      • getHandler

        public Handler getHandler​(String name)
        Gets the handler if it exists.
        Parameters:
        name - the name of the handler
        Returns:
        the handler or null if the handler does not exist
      • getHandlers

        public Map<String,​Supplier<Handler>> getHandlers()
        Returns an unmodifiable map of the handlers and the suppliers used to create them.
        Returns:
        an unmodified map of the handlers
      • addFormatter

        public Supplier<Formatter> addFormatter​(String name,
                                                Supplier<Formatter> formatter)
        Adds a formatter to the context configuration.
        Parameters:
        name - the name for the formatter
        formatter - the formatter to add
        Returns:
        the previous formatter associated with the name or null if one did not exist
      • removeFormatter

        public Supplier<Formatter> removeFormatter​(String name)
        Removes the formatter from the context configuration.
        Parameters:
        name - the name of the formatter
        Returns:
        the formatter removed or null if the formatter did not exist
      • hasFormatter

        public boolean hasFormatter​(String name)
        Checks if the formatter exists with the name provided.
        Parameters:
        name - the name for the formatter
        Returns:
        true if the formatter exists in this context, otherwise false
      • getFormatter

        public Formatter getFormatter​(String name)
        Gets the formatter if it exists.
        Parameters:
        name - the name of the formatter
        Returns:
        the formatter or null if the formatter does not exist
      • getFormatters

        public Map<String,​Supplier<Formatter>> getFormatters()
        Returns an unmodifiable map of the formatters and the suppliers used to create them.
        Returns:
        an unmodified map of the formatters
      • addFilter

        public Supplier<Filter> addFilter​(String name,
                                          Supplier<Filter> filter)
        Adds a filter to the context configuration.
        Parameters:
        name - the name for the filter
        filter - the filter to add
        Returns:
        the previous filter associated with the name or null if one did not exist
      • removeFilter

        public Supplier<Filter> removeFilter​(String name)
        Removes the filter from the context configuration.
        Parameters:
        name - the name of the filter
        Returns:
        the filter removed or null if the filter did not exist
      • hasFilter

        public boolean hasFilter​(String name)
        Checks if the filter exists with the name provided.
        Parameters:
        name - the name for the filter
        Returns:
        true if the filter exists in this context, otherwise false
      • getFilter

        public Filter getFilter​(String name)
        Gets the filter if it exists.
        Parameters:
        name - the name of the filter
        Returns:
        the filer or null if the filter does not exist
      • getFilters

        public Map<String,​Supplier<Filter>> getFilters()
        Returns an unmodifiable map of the filters and the suppliers used to create them.
        Returns:
        an unmodified map of the filters
      • addObject

        public Supplier<Object> addObject​(String name,
                                          Supplier<Object> object)
        Adds an object that can be used as a configuration property for another configuration type. This is used for cases when an object cannot simply be converted from a string.
        Parameters:
        name - the name for the configuration object
        object - the configuration object to add
        Returns:
        the previous configuration object associated with the name or null if one did not exist
      • removeObject

        public Supplier<Object> removeObject​(String name)
        Removes the configuration object from the context configuration.
        Parameters:
        name - the name of the configuration object
        Returns:
        the configuration object removed or null if the configuration object did not exist
      • hasObject

        public boolean hasObject​(String name)
        Checks if the configuration object exists with the name provided.
        Parameters:
        name - the name for the configuration object
        Returns:
        true if the configuration object exists in this context, otherwise false
      • getObject

        public Object getObject​(String name)
        Gets the configuration object if it exists.
        Parameters:
        name - the name of the configuration object
        Returns:
        the configuration object or null if the configuration object does not exist
      • getObjects

        public Map<String,​Supplier<Object>> getObjects()
        Returns an unmodifiable map of the configuration objects and the suppliers used to create them.
        Returns:
        an unmodified map of the configuration objects