public class StandaloneBeanContext extends Object implements BeanContext
Constructor and Description |
---|
StandaloneBeanContext(ExecutionContext executionContext,
BeanIdStore beanIdStore,
Map<String,Object> beanMap)
Create the StandAloneBeanContext
|
Modifier and Type | Method and Description |
---|---|
void |
addBean(BeanId beanId,
Object bean)
Add a bean instance under the specified
BeanId . |
void |
addBean(BeanId beanId,
Object bean,
Fragment source)
Add a bean instance under the specified beanId string.
|
void |
addBean(String beanId,
Object bean)
Add a bean instance under the specified beanId.
|
void |
addBean(String beanId,
Object bean,
Fragment source)
Add a bean instance under the specified beanId.
|
void |
addObserver(BeanContextLifecycleObserver observer)
Registers a bean context observer.
|
void |
changeBean(BeanId beanId,
Object bean,
Fragment source)
Changes a bean instance of the given
BeanId . |
void |
clear()
Removes all the beans from the bean map
|
boolean |
containsBean(BeanId beanId)
Looks if a bean instance is set under the
BeanId |
Object |
getBean(BeanId beanId)
Get the current bean, specified by the supplied
BeanId . |
<T> T |
getBean(Class<T> beanType)
Returns the bean by it's beanId name.
|
static <T> T |
getBean(Class<T> beanType,
Map<String,Object> beanMap) |
Object |
getBean(String beanId)
Returns the bean by it's beanId name.
|
BeanId |
getBeanId(String beanId)
Get the
BeanId instance for the specified beanId String. |
Map<String,Object> |
getBeanMap()
This returns a map which is backed by this repository.
|
BeanContext |
newSubContext(ExecutionContext executionContext)
|
void |
notifyObservers(BeanContextLifecycleEvent event)
Notify all observers of a specific bean lifecycle event.
|
Object |
removeBean(BeanId beanId,
Fragment source)
Removes a bean and all its associated lifecycle beans from the bean map
|
Object |
removeBean(String beanId,
Fragment source)
Removes a bean and all its associated lifecycle beans from the bean map
|
void |
removeObserver(BeanContextLifecycleObserver observer)
Unregisters a bean observer.
|
void |
setBeanInContext(BeanId beanId,
boolean inContext)
Mark the bean as being in context.
|
String |
toString() |
public StandaloneBeanContext(ExecutionContext executionContext, BeanIdStore beanIdStore, Map<String,Object> beanMap)
executionContext
- The ExecutionContext
to which this object is bound to.beanIdStore
- The BeanIdStore
to which this object is bound to.beanMap
- The Map
in which the bean's will be set. It is
important not to modify this map outside of the
BeanRepository! It is only provided as constructor parameter
because in some situations we need to control which
Map
is used.public void addBean(BeanId beanId, Object bean)
BeanContext
BeanId
.addBean
in interface BeanContext
beanId
- The BeanId
under which the bean is to be stored.bean
- The bean instance to be stored.public void addBean(BeanId beanId, Object bean, Fragment source)
BeanContext
BeanId
in the background.addBean
in interface BeanContext
beanId
- The BeanId
under which the bean is to be stored.bean
- The bean instance to be stored.source
- Source fragment.public void addBean(String beanId, Object bean)
BeanContext
BeanId
instance
for the beanId String and then use the BeanContext.addBean(BeanId, Object, Fragment)
method.addBean
in interface BeanContext
beanId
- The beanId under which the bean is to be stored.bean
- The bean instance to be stored.public void addBean(String beanId, Object bean, Fragment source)
BeanContext
BeanId
instance
for the beanId String and then use the BeanContext.addBean(BeanId, Object, Fragment)
method.addBean
in interface BeanContext
beanId
- The beanId under which the bean is to be stored.bean
- The bean instance to be stored.source
- Source fragment.public boolean containsBean(BeanId beanId)
BeanContext
BeanId
containsBean
in interface BeanContext
beanId
- The BeanId
under which is looked.public BeanId getBeanId(String beanId)
BeanContext
BeanId
instance for the specified beanId String.
Regsiters the beanId if it's not already registered.getBeanId
in interface BeanContext
beanId
- The beanId String.BeanId
instance.public Object getBean(BeanId beanId)
BeanContext
BeanId
.
getBean
in interface BeanContext
beanId
- The BeanId
of the bean to be returned.null
.public Object getBean(String beanId)
BeanContext
getBean
in interface BeanContext
beanId
- The type of the bean to be returned.null
.public <T> T getBean(Class<T> beanType)
BeanContext
getBean
in interface BeanContext
beanType
- The type of the bean to be returned.null
.public void changeBean(BeanId beanId, Object bean, Fragment source)
BeanContext
BeanId
. The difference to BeanContext.addBean(BeanId, Object)
is that the bean must exist, the associated beans aren't removed and the observers of the
BeanLifecycle.CHANGE
event are notified.changeBean
in interface BeanContext
beanId
- The BeanId
under which the bean instance is to be stored.bean
- The bean instance to be stored.source
- Source fragment.public Object removeBean(BeanId beanId, Fragment source)
BeanContext
removeBean
in interface BeanContext
beanId
- The beanId to remove the beans from.source
- Source fragment.public Object removeBean(String beanId, Fragment source)
BeanContext
removeBean
in interface BeanContext
beanId
- The beanId to remove the beans from.source
- Source fragment.public void clear()
BeanContext
clear
in interface BeanContext
public Map<String,Object> getBeanMap()
BeanContext
getBeanMap
in interface BeanContext
public void setBeanInContext(BeanId beanId, boolean inContext)
BeanContext
setBeanInContext
in interface BeanContext
beanId
- The bean ID.inContext
- True if the bean is in context, otherwise false.public String toString()
toString
in interface BeanContext
toString
in class Object
public BeanContext newSubContext(ExecutionContext executionContext)
BeanContext
newSubContext
in interface BeanContext
executionContext
- The Associated ExecutionContext
.BeanContext
.public void addObserver(BeanContextLifecycleObserver observer)
BeanContext
addObserver
in interface BeanContext
observer
- The actual BeanObserver instance.public void notifyObservers(BeanContextLifecycleEvent event)
BeanContext
notifyObservers
in interface BeanContext
event
- The event.public void removeObserver(BeanContextLifecycleObserver observer)
BeanContext
removeObserver
in interface BeanContext
observer
- The actual BeanObserver instance.Copyright © 2020. All rights reserved.