Class ContextReplacementUtility
- java.lang.Object
-
- ch.sahits.game.openpatrician.utilities.spring.ContextReplacementUtility
-
public class ContextReplacementUtility extends java.lang.Object
Utility class to replace existing beans in the context and update their references.
-
-
Field Summary
Fields Modifier and Type Field Description private DependentAnnotationConfigApplicationContext
context
private PrototypeBeanRegistry
instantiatedPrototypes
-
Constructor Summary
Constructors Constructor Description ContextReplacementUtility(DependentAnnotationConfigApplicationContext context, PrototypeBeanRegistry instantiatedPrototypes)
Constuctor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) java.util.List<java.lang.Object>
getAllInstantiatedBeans()
private java.lang.Class
getFieldType(java.lang.reflect.Field field)
private boolean
isSerializableBean(java.lang.Class clazz)
<T> boolean
replace(T bean, T instantiatedBean, java.util.Set<IRebinabable> rebindalbeObjects)
Replace all references to the bean in other registered beans and replace it in the context.(package private) <T> void
replaceInContext(T replacement, T instantiatedBean)
(package private) <T> void
replaceWiredBean(java.lang.Object b, T bean, T instanciatedBean, java.util.Set<IRebinabable> rebindalbeObjects)
Replace the instanceinstanciatedBean
of type T inb
that is wired withbean
.
-
-
-
Field Detail
-
context
private DependentAnnotationConfigApplicationContext context
-
instantiatedPrototypes
private PrototypeBeanRegistry instantiatedPrototypes
-
-
Constructor Detail
-
ContextReplacementUtility
public ContextReplacementUtility(DependentAnnotationConfigApplicationContext context, PrototypeBeanRegistry instantiatedPrototypes)
Constuctor.- Parameters:
context
- reference to the application contextinstantiatedPrototypes
- reference to the property bean registry
-
-
Method Detail
-
replace
public <T> boolean replace(T bean, T instantiatedBean, java.util.Set<IRebinabable> rebindalbeObjects)
Replace all references to the bean in other registered beans and replace it in the context. If the bean is not instanciated and stored in the context false will be returned. This may happen for lazy beans that are not yet instantiated or beans of Scope prototype which are not stored in the context.- Type Parameters:
T
- type of the bean- Parameters:
bean
- that will replace the existing beaninstantiatedBean
- bean currently in the contextrebindalbeObjects
- set of beans that are rebindable- Returns:
- true if all references and the instance in the context were replaced.
-
replaceInContext
<T> void replaceInContext(T replacement, T instantiatedBean)
-
replaceWiredBean
<T> void replaceWiredBean(java.lang.Object b, T bean, T instanciatedBean, java.util.Set<IRebinabable> rebindalbeObjects)
Replace the instanceinstanciatedBean
of type T inb
that is wired withbean
. T is a singleton bean.- Type Parameters:
T
- type of the bean- Parameters:
b
- Bean in which the new bean should be replacedbean
- that there reference should be replaced with.instanciatedBean
- bean currently in the contextrebindalbeObjects
- set of beans that are rebindable
-
getFieldType
private java.lang.Class getFieldType(java.lang.reflect.Field field)
-
isSerializableBean
private boolean isSerializableBean(java.lang.Class clazz)
-
getAllInstantiatedBeans
java.util.List<java.lang.Object> getAllInstantiatedBeans()
-
-