public class Context extends Object
ContextManager| Modifier | Constructor and Description |
|---|---|
protected |
Context() |
|
Context(ContextManager contextManager,
Context parentCtx,
String contextId)
Create a context using the specified manager and context id
Should not be used directly
|
| Modifier and Type | Method and Description |
|---|---|
Map<String,Object> |
allByAnnotatedWith(Class<? extends Annotation> annotationClass)
Return a map of all component instances annotated with the specified annotation
|
<T> T[] |
allByType(Class<T> type)
Return an array of all component instances implementing the expected type
|
<T> T[] |
allByType(Class<T> type,
boolean create)
Return an array of all component instances implementing the expected type
|
List<String> |
allNames()
Return a list of all component names in this context
|
<T> T |
byName(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(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(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(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
|
String |
getContextId()
Context id
|
ContextManager |
getContextManager()
Managed for this context
|
DataManager |
getDataManager()
Data manager for this context
|
EntityManager |
getEntityManager()
Entity manager for this context
|
EventBus |
getEventBus()
Event bus for this context
|
Map<String,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
|
void |
initContext(Application application,
EventBus eventBus,
InstanceStore instanceStore)
Initialize the context
|
void |
initInstance(Object instance,
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
|
void |
markAsFinished()
Mark this context as eligible for destruction
|
void |
postInit() |
void |
remove(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(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(String contextId,
boolean fromServer)
Update the context id
|
void |
setDataManager(DataManager dataManager)
Set the data manager for this context
|
protected Context()
public Context(ContextManager contextManager, Context parentCtx, String contextId)
contextManager - context managerparentCtx - parent context for conversation contexts (not supported yet)contextId - context idpublic ContextManager getContextManager()
public EntityManager getEntityManager()
public void setDataManager(DataManager dataManager)
dataManager - data managerDataManagerpublic DataManager getDataManager()
public Map<String,Object> getInitialBeans()
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 String getContextId()
public boolean isContextIdFromServer()
public boolean isFinished()
public void setContextId(String contextId, boolean fromServer)
contextId - context idfromServer - is this id received from the server ?public <T> T byName(String name)
T - component typename - component namepublic <T> T byNameNoProxy(String name)
ComponentImpl) if no instance existsT - component typename - component namepublic <T> T byType(Class<T> type)
T - expected component typetype - expected component typepublic <T> T[] allByType(Class<T> type)
T - expected component typetype - expected component typepublic <T> T[] allByType(Class<T> type, boolean create)
T - expected component typetype - expected component typecreate - if true, should create an instance if none is existingpublic Map<String,Object> allByAnnotatedWith(Class<? extends Annotation> annotationClass)
annotationClass - annotationpublic List<String> allNames()
public <T> T set(String name, T instance)
T - component typename - component nameinstance - component instancepublic <T> T set(T instance)
T - component typeinstance - component instancepublic void remove(String name)
name - component namepublic void clear()
public void initInstance(Object instance, String name)
instance - component instancename - component namepublic void checkValid()
InvalidContextException - when context finishedpublic void callLater(Runnable runnable)
runnable - runnable methodpublic void markAsFinished()