Class AbstractMergeBeanPostProcessor
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.beans.factory.config.BeanPostProcessor,org.springframework.context.ApplicationContextAware
- Direct Known Subclasses:
EarlyStageMergeBeanPostProcessor,LateStageMergeBeanPostProcessor
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>
- Author:
- Jeff Fischer
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.springframework.context.ApplicationContextprotected static final org.apache.commons.logging.Log -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddItemToList(Object bean, Object sourceItem, Placement placement, int position) protected voidaddItemToSet(Object bean, Object sourceItem, Placement placement, int position) protected voidaddListToList(Object bean, Object sourceItem, Placement placement, int position) protected voidaddMapToMap(Object bean, Map sourceItem, Placement placement, int position) protected voidaddSetToSet(Object bean, Object sourceItem, Placement placement, int position) constructBeanPackage(String beanName, Map<String, Object> methodAnnotationAttributes) Deprecated.The position in the target collection to place the merge.intIf 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.Retrieve the id of the collection (or individual bean) to be mergedGets the status provider that is configured for this post processorRetrieve the id of the collection to receive the mergepostProcessAfterInitialization(Object bean, String beanName) postProcessBeforeInitialization(Object bean, String beanName) protected Objectprotected ObjectprocessPackage(AbstractMergeBeanPostProcessor.BeanPackage beanPackage, Object bean, String beanName) voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext) voidsetCollectionRef(String collectionRef) Deprecated.usesetSourceRef(String)insteadvoidsetPlacement(Placement placement) The position in the target collection to place the merge.voidsetPosition(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.voidsetSourceRef(String sourceRef) Set the id of the collection (or individual bean) to be mergedvoidsetStatusProvider(MergeBeanStatusProvider statusProvider) Sets the MergeBeanStatusProvider, which controls whether or not this post processor is activated.voidsetTargetRef(String targetRef) Set the id of the collection to receive the merge
-
Field Details
-
LOG
protected static final org.apache.commons.logging.Log LOG -
applicationContext
protected org.springframework.context.ApplicationContext applicationContext -
defaultBeanPackage
-
-
Constructor Details
-
AbstractMergeBeanPostProcessor
public AbstractMergeBeanPostProcessor()
-
-
Method Details
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException - Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-
postProcessAfterInitialization
public Object postProcessAfterInitialization(Object bean, String beanName) throws org.springframework.beans.BeansException - Specified by:
postProcessAfterInitializationin interfaceorg.springframework.beans.factory.config.BeanPostProcessor- Throws:
org.springframework.beans.BeansException
-
postProcessBeforeInitialization
public Object postProcessBeforeInitialization(Object bean, String beanName) throws org.springframework.beans.BeansException - Specified by:
postProcessBeforeInitializationin interfaceorg.springframework.beans.factory.config.BeanPostProcessor- Throws:
org.springframework.beans.BeansException
-
constructBeanPackage
protected AbstractMergeBeanPostProcessor.BeanPackage constructBeanPackage(String beanName, Map<String, Object> methodAnnotationAttributes) -
processPackage
protected Object processPackage(AbstractMergeBeanPostProcessor.BeanPackage beanPackage, Object bean, String beanName) -
processPackage
-
addMapToMap
protected void addMapToMap(Object bean, Map sourceItem, Placement placement, int position) throws NoSuchFieldException, IllegalAccessException -
addSetToSet
protected void addSetToSet(Object bean, Object sourceItem, Placement placement, int position) throws NoSuchFieldException, IllegalAccessException -
addItemToSet
protected void addItemToSet(Object bean, Object sourceItem, Placement placement, int position) throws NoSuchFieldException, IllegalAccessException -
addListToList
protected void addListToList(Object bean, Object sourceItem, Placement placement, int position) throws NoSuchFieldException, IllegalAccessException -
addItemToList
protected void addItemToList(Object bean, Object sourceItem, Placement placement, int position) throws NoSuchFieldException, IllegalAccessException -
getCollectionRef
Deprecated.usegetSourceRef()insteadRetrieve the id of the collection to be merged- Returns:
- the id of the collection to be merged
-
setCollectionRef
Deprecated.usesetSourceRef(String)insteadSet the id of the collection to be merged- Parameters:
collectionRef- the id of the collection to be merged
-
getSourceRef
Retrieve the id of the collection (or individual bean) to be merged- Returns:
- the id of the item to be merged
-
setSourceRef
Set the id of the collection (or individual bean) to be merged- Parameters:
sourceRef- the id of the item to be merged
-
getTargetRef
Retrieve the id of the collection to receive the merge- Returns:
- the id of the collection receiving the merge
-
setTargetRef
Set the id of the collection to receive the merge- Parameters:
targetRef- the id of the collection receiving the merge
-
getPlacement
The position in the target collection to place the merge. This can be at the beginning, end or at an explicit position.- Returns:
- the position in the target collection to place the merge
-
setPlacement
The position in the target collection to place the merge. This can be at the beginning, end or at an explicit position.- Parameters:
placement- the position in the target collection to place the merge
-
getPosition
public 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.- Returns:
- the specific position in the target collection
-
setPosition
public 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.- Parameters:
position- the specific position in the target collection
-
getStatusProvider
Gets the status provider that is configured for this post processor- Returns:
- the MergeStatusBeanProvider
-
setStatusProvider
Sets the MergeBeanStatusProvider, which controls whether or not this post processor is activated. If no statusProvider is set, then we will always execute.- Parameters:
statusProvider-
-
getSourceRef()instead