public abstract class AbstractContext extends Object implements Context
Context interface. Derived Contexts MUST support persistence by providing
AbstractContext(JsonValue, ClassLoader)Context.toJsonValue()Here is an example of the JSON representation of the core attributes of all contexts:
{
"id" : "56f0fb7e-3837-464d-b9ec-9d3b6af665c3",
"class" : ...Java class name..,
"parent" : {
...
}
}
| Modifier and Type | Field and Description |
|---|---|
protected JsonValue |
data
The Context data.
|
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractContext(Context parent,
String name)
Constructs a new
AbstractContext with a null id. |
|
AbstractContext(JsonValue savedContext,
ClassLoader classLoader)
Creates a new context from the JSON representation of a previously
persisted context.
|
protected |
AbstractContext(String id,
String name,
Context parent)
Constructs a new
AbstractContext. |
| 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.
|
boolean |
isRootContext()
Returns
true if this context is a root context. |
JsonValue |
toJsonValue()
Return this Context as a JsonValue (for persistence).
|
String |
toString() |
protected final JsonValue data
protected AbstractContext(Context parent, String name)
AbstractContext with a null id.parent - The parent context.name - The name of the context.protected AbstractContext(String id, String name, Context parent)
AbstractContext.id - The id of the context.parent - The parent context.name - The name of the context.public AbstractContext(JsonValue savedContext, ClassLoader classLoader)
Sub-classes MUST provide a constructor having the same declaration as this constructor in order to support persistence. Implementations MUST take care to invoke the super class implementation before parsing their own context attributes. Below is an example implementation for a security context which stores the user name and password of the authenticated user:
protected SecurityContext(JsonValue savedContext, ClassLoader classLoader) {
// Invoke the super-class implementation first.
super(savedContext, classLoader);
// Now parse the attributes for this context.
this.username = savedContext.get("username").required().asString();
this.password = savedContext.get("password").required().asString();
}
In order to create a context's persisted JSON representation,
implementations must override.savedContext - The JSON representation from which this context's attributes
should be parsed.classLoader - The ClassLoader which can properly resolve the persisted class-name.public final String getContextName()
ContextgetContextName in interface Contextpublic final <T extends Context> T asContext(Class<T> clazz)
ContextContext 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.public final Context getContext(String contextName)
ContextgetContext in interface ContextcontextName - The name of the context to be returned.public final boolean containsContext(Class<? extends Context> clazz)
Contexttrue 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.containsContext in interface Contextclazz - 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.public final boolean containsContext(String contextName)
Contexttrue if there is a context in the chain whose name
matches the provided context name.containsContext in interface ContextcontextName - The name of the context to locate.true if there is a context in the chain whose context name
matches contextName.public final String getId()
Contextpublic final Context getParent()
Contextpublic final boolean isRootContext()
Contexttrue if this context is a root context.isRootContext in interface Contexttrue if this context is a root context.public JsonValue toJsonValue()
ContexttoJsonValue in interface ContextCopyright © 2025 Open Identity Platform Community. All rights reserved.