public abstract class AbstractMergeBeanPostProcessor extends Object implements org.springframework.beans.factory.config.BeanPostProcessor, org.springframework.context.ApplicationContextAware
Contains useful processing code for merge bean post processors. The BeanPostProcessor instances can be used to merge additional collection members into collections declared elsewhere. In effect, this allows an implementer to only declare the collection members they're currently interested in cause those members to be merged into a larger, pre-existing list. This is more desirable than a traditional, comprehensive override that would require re-declaring the original bean and all of its members in addition to the current members being considered.
This code demonstrates using one of the concrete implementations, LateStageMergeBeanPostProcessor. The
basic usage pattern is to specify the id of the collection you want to merge (collectionRef) and the id
of the pre-existing, target collection (targetRef) that should receive the merge collection. The collection
can be represented using ListFactoryBean, SetFactoryBean or MapFactoryBean.
<bean class="org.broadleafcommerce.common.extensibility.context.merge.LateStageMergeBeanPostProcessor">
<property name="collectionRef" value="blPriceListRuleBuilderFieldServices"/>
<property name="targetRef" value="blRuleBuilderFieldServices"/>
</bean>
<bean id="blPriceListRuleBuilderFieldServices" class="org.springframework.beans.factory.config.ListFactoryBean">
<property name="sourceList">
<list>
<ref bean="blPricingContextFieldService"/>
</list>
</property>
</bean>
LateStageMergeBeanPostProcessor,
EarlyStageMergeBeanPostProcessor| Modifier and Type | Class and Description |
|---|---|
static class |
AbstractMergeBeanPostProcessor.BeanPackage |
| Modifier and Type | Field and Description |
|---|---|
protected org.springframework.context.ApplicationContext |
applicationContext |
protected AbstractMergeBeanPostProcessor.BeanPackage |
defaultBeanPackage |
protected static org.apache.commons.logging.Log |
LOG |
| Constructor and Description |
|---|
AbstractMergeBeanPostProcessor() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addItemToList(Object bean,
Object sourceItem,
Placement placement,
int position) |
protected void |
addItemToSet(Object bean,
Object sourceItem,
Placement placement,
int position) |
protected void |
addListToList(Object bean,
Object sourceItem,
Placement placement,
int position) |
protected void |
addMapToMap(Object bean,
Map sourceItem,
Placement placement,
int position) |
protected void |
addSetToSet(Object bean,
Object sourceItem,
Placement placement,
int position) |
protected AbstractMergeBeanPostProcessor.BeanPackage |
constructBeanPackage(String beanName,
Map<String,Object> methodAnnotationAttributes) |
String |
getCollectionRef()
Deprecated.
use
getSourceRef() instead |
Placement |
getPlacement()
The position in the target collection to place the merge.
|
int |
getPosition()
If a placement of type Placement.SPECIFIC is used, then this is the integer position in the target
target collection at which the merge will be performed.
|
String |
getSourceRef()
Retrieve the id of the collection (or individual bean) to be merged
|
MergeBeanStatusProvider |
getStatusProvider()
Gets the status provider that is configured for this post processor
|
String |
getTargetRef()
Retrieve the id of the collection to receive the merge
|
Object |
postProcessAfterInitialization(Object bean,
String beanName) |
Object |
postProcessBeforeInitialization(Object bean,
String beanName) |
protected Object |
processPackage(AbstractMergeBeanPostProcessor.BeanPackage beanPackage,
Object bean,
String beanName) |
protected Object |
processPackage(Map<String,Object> methodAnnotationAttributes,
Object bean,
String beanName) |
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext) |
void |
setCollectionRef(String collectionRef)
Deprecated.
use
setSourceRef(String) instead |
void |
setPlacement(Placement placement)
The position in the target collection to place the merge.
|
void |
setPosition(int position)
If a placement of type Placement.SPECIFIC is used, then this is the integer position in the target
target collection at which the merge will be performed.
|
void |
setSourceRef(String sourceRef)
Set the id of the collection (or individual bean) to be merged
|
void |
setStatusProvider(MergeBeanStatusProvider statusProvider)
Sets the MergeBeanStatusProvider, which controls whether or not this post processor is activated.
|
void |
setTargetRef(String targetRef)
Set the id of the collection to receive the merge
|
protected static final org.apache.commons.logging.Log LOG
protected org.springframework.context.ApplicationContext applicationContext
protected AbstractMergeBeanPostProcessor.BeanPackage defaultBeanPackage
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
throws org.springframework.beans.BeansException
setApplicationContext in interface org.springframework.context.ApplicationContextAwareorg.springframework.beans.BeansExceptionpublic Object postProcessAfterInitialization(Object bean, String beanName) throws org.springframework.beans.BeansException
postProcessAfterInitialization in interface org.springframework.beans.factory.config.BeanPostProcessororg.springframework.beans.BeansExceptionpublic Object postProcessBeforeInitialization(Object bean, String beanName) throws org.springframework.beans.BeansException
postProcessBeforeInitialization in interface org.springframework.beans.factory.config.BeanPostProcessororg.springframework.beans.BeansExceptionprotected AbstractMergeBeanPostProcessor.BeanPackage constructBeanPackage(String beanName, Map<String,Object> methodAnnotationAttributes)
protected Object processPackage(AbstractMergeBeanPostProcessor.BeanPackage beanPackage, Object bean, String beanName)
protected Object processPackage(Map<String,Object> methodAnnotationAttributes, Object bean, String beanName)
protected void addMapToMap(Object bean, Map sourceItem, Placement placement, int position) throws NoSuchFieldException, IllegalAccessException
protected void addSetToSet(Object bean, Object sourceItem, Placement placement, int position) throws NoSuchFieldException, IllegalAccessException
protected void addItemToSet(Object bean, Object sourceItem, Placement placement, int position) throws NoSuchFieldException, IllegalAccessException
protected void addListToList(Object bean, Object sourceItem, Placement placement, int position) throws NoSuchFieldException, IllegalAccessException
protected void addItemToList(Object bean, Object sourceItem, Placement placement, int position) throws NoSuchFieldException, IllegalAccessException
@Deprecated public String getCollectionRef()
getSourceRef() instead@Deprecated public void setCollectionRef(String collectionRef)
setSourceRef(String) insteadcollectionRef - the id of the collection to be mergedpublic String getSourceRef()
public void setSourceRef(String sourceRef)
sourceRef - the id of the item to be mergedpublic String getTargetRef()
public void setTargetRef(String targetRef)
targetRef - the id of the collection receiving the mergepublic Placement getPlacement()
public void setPlacement(Placement placement)
placement - the position in the target collection to place the mergepublic int getPosition()
public void setPosition(int position)
position - the specific position in the target collectionpublic MergeBeanStatusProvider getStatusProvider()
public void setStatusProvider(MergeBeanStatusProvider statusProvider)
statusProvider - Copyright © 2023. All rights reserved.