org.broadleafcommerce.common.extensibility.context.merge
Class AbstractMergeBeanPostProcessor

java.lang.Object
  extended by org.broadleafcommerce.common.extensibility.context.merge.AbstractMergeBeanPostProcessor
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.config.BeanPostProcessor, org.springframework.context.ApplicationContextAware
Direct Known Subclasses:
EarlyStageMergeBeanPostProcessor, LateStageMergeBeanPostProcessor

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>
 
 

Author:
Jeff Fischer
See Also:
LateStageMergeBeanPostProcessor, EarlyStageMergeBeanPostProcessor

Field Summary
protected  org.springframework.context.ApplicationContext applicationContext
           
protected  String collectionRef
           
protected static org.apache.commons.logging.Log LOG
           
protected  Placement placement
           
protected  int position
           
protected  MergeBeanStatusProvider statusProvider
           
protected  String targetRef
           
 
Constructor Summary
AbstractMergeBeanPostProcessor()
           
 
Method Summary
 String getCollectionRef()
          Retrieve the id of the collection to be merged
 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.
 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)
           
 void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
           
 void setCollectionRef(String collectionRef)
          Set the id of the collection to be merged
 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 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

protected static final org.apache.commons.logging.Log LOG

collectionRef

protected String collectionRef

targetRef

protected String targetRef

placement

protected Placement placement

position

protected int position

applicationContext

protected org.springframework.context.ApplicationContext applicationContext

statusProvider

protected MergeBeanStatusProvider statusProvider
Constructor Detail

AbstractMergeBeanPostProcessor

public AbstractMergeBeanPostProcessor()
Method Detail

setApplicationContext

public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
                           throws org.springframework.beans.BeansException
Specified by:
setApplicationContext in interface org.springframework.context.ApplicationContextAware
Throws:
org.springframework.beans.BeansException

postProcessAfterInitialization

public Object postProcessAfterInitialization(Object bean,
                                             String beanName)
                                      throws org.springframework.beans.BeansException
Specified by:
postProcessAfterInitialization in interface org.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:
postProcessBeforeInitialization in interface org.springframework.beans.factory.config.BeanPostProcessor
Throws:
org.springframework.beans.BeansException

getCollectionRef

public String getCollectionRef()
Retrieve the id of the collection to be merged

Returns:
the id of the collection to be merged

setCollectionRef

public void setCollectionRef(String collectionRef)
Set the id of the collection to be merged

Parameters:
collectionRef - the id of the collection to be merged

getTargetRef

public String getTargetRef()
Retrieve the id of the collection to receive the merge

Returns:
the id of the collection receiving the merge

setTargetRef

public void setTargetRef(String targetRef)
Set the id of the collection to receive the merge

Parameters:
targetRef - the id of the collection receiving the merge

getPlacement

public Placement 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

public void setPlacement(Placement placement)
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

public MergeBeanStatusProvider getStatusProvider()
Gets the status provider that is configured for this post processor

Returns:
the MergeStatusBeanProvider

setStatusProvider

public void setStatusProvider(MergeBeanStatusProvider statusProvider)
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 -


Copyright © 2013. All Rights Reserved.