public class Johnson extends Object
Because Johnson is intended to be a maintenance and application consistency layer around an application, its functionality is exposed statically. This class provides both the mechanisms for initialising and terminating Johnson, as well as for retrieving its configuration and the container of events.
Where possible to avoid synchronisation issues, it is preferable to bind Johnson to the lifecycle for the servlet
container, using JohnsonContextListener to initialise
and terminate Johnson.
| Modifier and Type | Field and Description |
|---|---|
static String |
ATTR_CONFIG
When used in a web environment, the
JohnsonConfig will be exposed in the ServletContext under
an attribute with this key. |
static String |
ATTR_EVENT_CONTAINER
When used in a web environment, the
JohnsonEventContainer will be exposed in the ServletContext
under an attribute with this key. |
static String |
PARAM_CONFIG_LOCATION
|
| Modifier and Type | Method and Description |
|---|---|
static JohnsonConfig |
getConfig()
Retrieves the statically-bound
JohnsonConfig. |
static JohnsonConfig |
getConfig(javax.servlet.ServletContext context)
Attempts to retrieve the
JohnsonConfig from the provided ServletContext under the key
ATTR_CONFIG before falling back on getConfig(). |
static JohnsonEventContainer |
getEventContainer()
Retrieves the statically-bound
JohnsonEventContainer. |
static JohnsonEventContainer |
getEventContainer(javax.servlet.ServletContext context)
Attempts to retrieve the
JohnsonEventContainer from the provided ServletContext under the key
ATTR_EVENT_CONTAINER before falling back on the statically-bound instance. |
static void |
initialize(javax.servlet.ServletContext context)
Initialises Johnson, additionally binding the
JohnsonConfig and JohnsonEventContainer to the
provided ServletContext and performing any ApplicationEventChecks which have been configured. |
static void |
initialize(String location)
Initialises Johnson, loading its configuration from the provided location, and sets the statically-bound
instances of
JohnsonConfig and JohnsonEventContainer. |
static void |
terminate()
Terminates Johnson, clearing the statically-bound
JohnsonConfig and JohnsonEventContainer. |
static void |
terminate(javax.servlet.ServletContext context)
Terminates Johnson, removing Johnson-related attributes from the provided
ServletContext and clearing
the statically-bound JohnsonConfig and JohnsonEventContainer. |
public static final String ATTR_CONFIG
JohnsonConfig will be exposed in the ServletContext under
an attribute with this key.public static final String ATTR_EVENT_CONTAINER
JohnsonEventContainer will be exposed in the ServletContext
under an attribute with this key.public static final String PARAM_CONFIG_LOCATION
initialisation, the ServletContext is examined
for an init-param with this name. If one is found, it controls the location from which the configuration
is loaded. Otherwise, XmlJohnsonConfig.DEFAULT_CONFIGURATION_FILE is used as the default.@Nonnull public static JohnsonConfig getConfig()
JohnsonConfig.
Note: If Johnson has not been initialised, this method will not initialise
it. Before attempting to use Johnson, it is left to the application developer to ensure it has been correctly
initialised.
IllegalStateException - if initialize(javax.servlet.ServletContext) has not been called@Nonnull public static JohnsonConfig getConfig(@Nonnull javax.servlet.ServletContext context)
JohnsonConfig from the provided ServletContext under the key
ATTR_CONFIG before falling back on getConfig().
Note: If Johnson has not been initialised, this method will not
initialise it. Before attempting to use Johnson, it is left to the application developer to ensure it has
been correctly initialised.
context - the servlet contextIllegalStateException - if initialize(javax.servlet.ServletContext) has not been called@Nonnull public static JohnsonEventContainer getEventContainer()
JohnsonEventContainer.
Note: If Johnson has not been initialised, this method will not initialise
it. Before attempting to use Johnson, it is left to the application developer to ensure it has been correctly
initialised.
IllegalStateException - if initialize(javax.servlet.ServletContext) has not been called@Nonnull public static JohnsonEventContainer getEventContainer(@Nonnull javax.servlet.ServletContext context)
JohnsonEventContainer from the provided ServletContext under the key
ATTR_EVENT_CONTAINER before falling back on the statically-bound instance.
Note: If Johnson has not been initialised, this method will not
initialise it. Before attempting to use Johnson, it is left to the application developer to ensure it has
been correctly initialised.
context - the servlet contextIllegalStateException - if initialize(javax.servlet.ServletContext) has not been calledpublic static void initialize(@Nonnull javax.servlet.ServletContext context)
JohnsonConfig and JohnsonEventContainer to the
provided ServletContext and performing any ApplicationEventChecks which have been configured.
If the PARAM_CONFIG_LOCATION init-param is set, it is used to determine the location of the
Johnson configuration file. Otherwise, XmlJohnsonConfig.DEFAULT_CONFIGURATION_FILE is assumed.
Note: This method is not synchronised and not thread-safe. It is left to the calling code
to ensure proper synchronisation. The easiest way to do this is to initialise Johnson by adding the
JohnsonContextListener to web.xml.
context - the servlet contextpublic static void initialize(@Nullable String location)
JohnsonConfig and JohnsonEventContainer.
If the location provided is null or empty, XmlJohnsonConfig.DEFAULT_CONFIGURATION_FILE is
assumed.
Note: If the configuration fails to load, DefaultJohnsonConfig is used to provide defaults. For more
information about what those defaults are, see the documentation for that class.
location - the location of the Johnson configuration filepublic static void terminate()
JohnsonConfig and JohnsonEventContainer.public static void terminate(@Nonnull javax.servlet.ServletContext context)
ServletContext and clearing
the statically-bound JohnsonConfig and JohnsonEventContainer.context - the servlet contextCopyright © 2017 Atlassian. All rights reserved.