public class Context
extends java.lang.Object
ContextManager| Modifier and Type | Class and Description |
|---|---|
static interface |
Context.Properties |
| Modifier | Constructor and Description |
|---|---|
protected |
Context() |
|
Context(ContextManager contextManager,
Context parentCtx,
java.lang.String contextId)
Create a context using the specified manager and context id
Should not be used directly
|
| Modifier and Type | Method and Description |
|---|---|
java.util.Map<java.lang.String,java.lang.Object> |
allByAnnotatedWith(java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Return a map of all component instances annotated with the specified annotation
|
<T> T[] |
allByType(java.lang.Class<T> type)
Return an array of all component instances implementing the expected type
|
<T> T[] |
allByType(java.lang.Class<T> type,
boolean create)
Return an array of all component instances implementing the expected type
|
java.util.List<java.lang.String> |
allNames()
Return a list of all component names in this context
|
<T> T |
byName(java.lang.String name)
Return a component instance by its name in the container
InstanceStore implementations are free to (but don't have to) automatically create a suitable component instance
with the expected name when no instance exists
|
<T> T |
byNameNoProxy(java.lang.String name)
Return a component instance by its name in the container
Does not create a default proxy (
ComponentImpl) if no instance exists |
<T> T |
byType(java.lang.Class<T> type)
Return a component instance looked up by its type
If more than one instance is found, throws a runtime exception
|
void |
callLater(java.lang.Runnable runnable)
Convenience method to defer execution of a method in the main UI thread
|
void |
checkValid()
Check that this context is not finished
|
void |
clear()
Clear all data and instances in the context
|
void |
defineProperties(Context.Properties properties) |
void |
destroyInstance(java.lang.Object instance)
Destroy an instance when it is removed from the context
|
java.lang.String |
getContextId()
Context id
|
ContextManager |
getContextManager()
Manager for this context
|
DataManager |
getDataManager()
Data manager for this context
|
EntityManager |
getEntityManager()
Entity manager for this context
|
EventBus |
getEventBus()
Event bus for this context
|
java.util.Map<java.lang.String,java.lang.Object> |
getInitialBeans()
Map of beans defined before the initialization of the context so they can be registered in the DI container
|
Context |
getParentContext()
Parent context for conversation contexts
|
java.lang.Object |
getPlatformContext()
Get platform context
|
void |
initContext(Application application,
EventBus eventBus,
InstanceStore instanceStore)
Initialize the context
|
void |
initInstance(java.lang.Object instance,
java.lang.String name)
Initialize an instance when it is added to the context
|
boolean |
isContextIdFromServer()
Indicate that the context id has been defined by the server
Unused for now
|
boolean |
isFinished()
Indicate that the context is eligible for destruction
|
boolean |
isGlobal()
Is this context the global context ?
|
void |
markAsFinished()
Mark this context as eligible for destruction
|
void |
postInit() |
void |
remove(java.lang.Object instance)
Remove the component instance from the context
May not work with all containers (Spring and CDI are static and cannot be modified after initialization)
|
void |
remove(java.lang.String name)
Remove the component instance having the specified name from the context
May not work with all containers (Spring and CDI are static and cannot be modified after initialization)
|
<T> T |
set(java.lang.String name,
T instance)
Set a component instance as a managed instance with the specified name in the context
May not work with all containers (Spring and CDI are static and cannot be modified after initialization)
|
<T> T |
set(T instance)
Set a component instance as a managed instance in the context
May not work with all containers (Spring and CDI are static and cannot be modified after initialization)
|
void |
setContextId(java.lang.String contextId,
boolean fromServer)
Update the context id
|
void |
setDataManager(DataManager dataManager)
Set the data manager for this context
|
void |
setPlatformContext(java.lang.Object context)
Set the internal platform context
|
protected Context()
public Context(ContextManager contextManager, Context parentCtx, java.lang.String contextId)
contextManager - context managerparentCtx - parent context for conversation contexts (not supported yet)contextId - context idpublic ContextManager getContextManager()
public void setPlatformContext(java.lang.Object context)
context - internal contextpublic java.lang.Object getPlatformContext()
public EntityManager getEntityManager()
public void setDataManager(DataManager dataManager)
dataManager - data managerDataManagerpublic DataManager getDataManager()
public java.util.Map<java.lang.String,java.lang.Object> getInitialBeans()
public boolean isGlobal()
public void initContext(Application application, EventBus eventBus, InstanceStore instanceStore)
application - application for this context (depends on the target platform/framework)eventBus - event bus for this context (depends on the framework and/or the DI container)instanceStore - instance store (depends on the DI container)public EventBus getEventBus()
public void postInit()
public Context getParentContext()
public java.lang.String getContextId()
public boolean isContextIdFromServer()
public boolean isFinished()
public void setContextId(java.lang.String contextId,
boolean fromServer)
contextId - context idfromServer - is this id received from the server ?public <T> T byName(java.lang.String name)
T - component typename - component namepublic <T> T byNameNoProxy(java.lang.String name)
ComponentImpl) if no instance existsT - component typename - component namepublic <T> T byType(java.lang.Class<T> type)
T - expected component typetype - expected component typepublic <T> T[] allByType(java.lang.Class<T> type)
T - expected component typetype - expected component typepublic <T> T[] allByType(java.lang.Class<T> type,
boolean create)
T - expected component typetype - expected component typecreate - if true, should create an instance if none is existingpublic java.util.Map<java.lang.String,java.lang.Object> allByAnnotatedWith(java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
annotationClass - annotationpublic java.util.List<java.lang.String> allNames()
public <T> T set(java.lang.String name,
T instance)
T - component typename - component nameinstance - component instancepublic <T> T set(T instance)
T - component typeinstance - component instancepublic void remove(java.lang.String name)
name - component namepublic void remove(java.lang.Object instance)
instance - component instancepublic void clear()
public void initInstance(java.lang.Object instance,
java.lang.String name)
instance - component instancename - component namepublic void destroyInstance(java.lang.Object instance)
instance - component instancepublic void defineProperties(Context.Properties properties)
public void checkValid()
InvalidContextException - when context finishedpublic void callLater(java.lang.Runnable runnable)
runnable - runnable methodpublic void markAsFinished()