public interface Context
RootContext
at the bottom of the stack. Each context
maintains a reference to its parent context which can be accessed using the Context.getParent()
} method.
Context implementations may provide information about the client, the end-user, auditing information, routing
decisions, etc. While contexts are arranged in a stack, application code will usually access contexts using the
Context.asContext(Class)
method:
Context context = ...; // Opaque reference to the context stack String remoteHost = context.asContext(ClientContext.class).getRemoteHost(); context.asContext(AttributesContext.class).getAttributes().put("key", "value");Alternatively, scripted applications will usually access contexts by name:
var remoteHost = context.client.remoteHost; context.attributes.key = "value";Context implementations should inherit from
AbstractContext
and ensure that they can be serialized to and
from JSON.Modifier and Type | Method and Description |
---|---|
<T extends Context> |
asContext(Class<T> clazz)
Returns the first context in the chain whose type is a sub-type of the
provided
Context class. |
boolean |
containsContext(Class<? extends Context> clazz)
Returns
true if there is a context in the chain whose type is a
sub-type of the provided Context class. |
boolean |
containsContext(String contextName)
Returns
true if there is a context in the chain whose name
matches the provided context name. |
Context |
getContext(String contextName)
Returns the first context in the chain whose context name matches the
provided name.
|
String |
getContextName()
Get this Context's name.
|
String |
getId()
Returns the unique ID identifying this context, usually a UUID.
|
Context |
getParent()
Returns the parent of this context.
|
String |
getRootId()
Returns the unique ID of the root context, usually a UUID.
|
boolean |
isRootContext()
Returns
true if this context is a root context. |
JsonValue |
toJsonValue()
Return this Context as a JsonValue (for persistence).
|
String getContextName()
<T extends Context> T asContext(Class<T> clazz)
Context
class. The method first checks this context to
see if it has the required type, before proceeding to the parent context,
and then continuing up the chain of parents until the root context is
reached.T
- The context type.clazz
- The class of context to be returned.Context
class.IllegalArgumentException
- If no matching context was found in this context's parent
chain.Context getContext(String contextName)
contextName
- The name of the context to be returned.IllegalArgumentException
- If no matching context was found in this context's parent
chain.boolean containsContext(Class<? extends Context> clazz)
true
if there is a context in the chain whose type is a
sub-type of the provided Context
class. The method first checks
this context to see if it has the required type, before proceeding to the
parent context, and then continuing up the chain of parents until the
root context is reached.clazz
- The class of context to be checked.true
if there is a context in the chain whose type is a
sub-type of the provided Context
class.boolean containsContext(String contextName)
true
if there is a context in the chain whose name
matches the provided context name.contextName
- The name of the context to locate.true
if there is a context in the chain whose context name
matches contextName
.String getId()
String getRootId()
Context getParent()
null
if this context is a
root context.boolean isRootContext()
true
if this context is a root context.true
if this context is a root context.JsonValue toJsonValue()
Copyright © 2010-2018, ForgeRock All Rights Reserved.