Class ContextConfiguration
- java.lang.Object
-
- org.jboss.logmanager.configuration.ContextConfiguration
-
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
PropertyContextConfiguration
public class ContextConfiguration extends Object implements AutoCloseable
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.If the supplier os not already an instance of a
ConfigurationResource
, then it is wrapped and considered a lazy resource.- Author:
- James R. Perkins
-
-
Field Summary
Fields Modifier and Type Field Description static Logger.AttachmentKey<ContextConfiguration>
CONTEXT_CONFIGURATION_KEY
-
Constructor Summary
Constructors Constructor Description ContextConfiguration(LogContext context)
Creates a new context configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ConfigurationResource<ErrorManager>
addErrorManager(String name, Supplier<ErrorManager> errorManager)
Adds an error manager to the context configuration.ConfigurationResource<Filter>
addFilter(String name, Supplier<Filter> filter)
Adds a filter to the context configuration.ConfigurationResource<Formatter>
addFormatter(String name, Supplier<Formatter> formatter)
Adds a formatter to the context configuration.ConfigurationResource<Handler>
addHandler(String name, Supplier<Handler> handler)
Adds a handler to the context configuration.ConfigurationResource<Object>
addObject(String name, Supplier<Object> object)
Adds an object that can be used as a configuration property for another configuration type.void
close()
LogContext
getContext()
Returns the context for this configuration.ErrorManager
getErrorManager(String name)
Gets the error manager if it exists.Map<String,ConfigurationResource<ErrorManager>>
getErrorManagers()
Returns an unmodifiable map of the error managers and the suppliers used to create them.Filter
getFilter(String name)
Gets the filter if it exists.Map<String,ConfigurationResource<Filter>>
getFilters()
Returns an unmodifiable map of the filters and the suppliers used to create them.Formatter
getFormatter(String name)
Gets the formatter if it exists.Map<String,Supplier<Formatter>>
getFormatters()
Returns an unmodifiable map of the formatters and the suppliers used to create them.Handler
getHandler(String name)
Gets the handler if it exists.Map<String,ConfigurationResource<Handler>>
getHandlers()
Returns an unmodifiable map of the handlers and the suppliers used to create them.Logger
getLogger(String name)
Gets the logger if it exists.Set<String>
getLoggers()
Returns an unmodifiable set of the configured logger namesObject
getObject(String name)
Gets the configuration object if it exists.Map<String,ConfigurationResource<Object>>
getObjects()
Returns an unmodifiable map of the configuration objects and the suppliers used to create them.boolean
hasErrorManager(String name)
Checks if the error manager exists with the name provided.boolean
hasFilter(String name)
Checks if the filter exists with the name provided.boolean
hasFormatter(String name)
Checks if the formatter exists with the name provided.boolean
hasHandler(String name)
Checks if the handler exists with the name provided.boolean
hasLogger(String name)
Checks if the logger exists in this context.boolean
hasObject(String name)
Checks if the configuration object exists with the name provided.ConfigurationResource<ErrorManager>
removeErrorManager(String name)
Removes the error manager from the context configuration.ConfigurationResource<Filter>
removeFilter(String name)
Removes the filter from the context configuration.ConfigurationResource<Formatter>
removeFormatter(String name)
Removes the formatter from the context configuration.ConfigurationResource<Handler>
removeHandler(String name)
Removes the handler from the context configuration.ConfigurationResource<Object>
removeObject(String name)
Removes the configuration object from the context configuration.
-
-
-
Field Detail
-
CONTEXT_CONFIGURATION_KEY
public static final Logger.AttachmentKey<ContextConfiguration> CONTEXT_CONFIGURATION_KEY
-
-
Constructor Detail
-
ContextConfiguration
public ContextConfiguration(LogContext context)
Creates a new context configuration.
-
-
Method Detail
-
getContext
public LogContext getContext()
Returns the context for this configuration.- Returns:
- the context for this configuration
-
hasLogger
public boolean hasLogger(String name)
Checks if the logger exists in this context.- Parameters:
name
- the logger name- Returns:
true
if the logger exists in this context, otherwisefalse
-
getLogger
public Logger getLogger(String name)
Gets the logger if it exists.- Parameters:
name
- the name of the logger- Returns:
- the logger or
null
if the logger does not exist
-
getLoggers
public Set<String> getLoggers()
Returns an unmodifiable set of the configured logger names- Returns:
- an unmodified set of the logger names
-
addErrorManager
public ConfigurationResource<ErrorManager> addErrorManager(String name, Supplier<ErrorManager> errorManager)
Adds an error manager to the context configuration.- Parameters:
name
- the name for the error managererrorManager
- the error manager to add- Returns:
- the previous error manager associated with the name or
null
if one did not exist
-
removeErrorManager
public ConfigurationResource<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, otherwisefalse
-
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,ConfigurationResource<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 ConfigurationResource<Handler> addHandler(String name, Supplier<Handler> handler)
Adds a handler to the context configuration.- Parameters:
name
- the name for the handlerhandler
- the handler to add- Returns:
- the previous handler associated with the name or
null
if one did not exist
-
removeHandler
public ConfigurationResource<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, otherwisefalse
-
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,ConfigurationResource<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 ConfigurationResource<Formatter> addFormatter(String name, Supplier<Formatter> formatter)
Adds a formatter to the context configuration.- Parameters:
name
- the name for the formatterformatter
- the formatter to add- Returns:
- the previous formatter associated with the name or
null
if one did not exist
-
removeFormatter
public ConfigurationResource<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, otherwisefalse
-
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 ConfigurationResource<Filter> addFilter(String name, Supplier<Filter> filter)
Adds a filter to the context configuration.- Parameters:
name
- the name for the filterfilter
- the filter to add- Returns:
- the previous filter associated with the name or
null
if one did not exist
-
removeFilter
public ConfigurationResource<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, otherwisefalse
-
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,ConfigurationResource<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 ConfigurationResource<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 objectobject
- the configuration object to add- Returns:
- the previous configuration object associated with the name or
null
if one did not exist
-
removeObject
public ConfigurationResource<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, otherwisefalse
-
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,ConfigurationResource<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
-
close
public void close() throws Exception
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-
-