org.kuali.rice.krad.uif.util
Class UifBeanFactoryPostProcessor

java.lang.Object
  extended by org.kuali.rice.krad.uif.util.UifBeanFactoryPostProcessor
All Implemented Interfaces:
org.springframework.beans.factory.config.BeanFactoryPostProcessor

public class UifBeanFactoryPostProcessor
extends Object
implements org.springframework.beans.factory.config.BeanFactoryPostProcessor

Post processes the bean factory to handle UIF property expressions and IDs on inner beans

Conditional logic can be implemented with the UIF dictionary by means of property expressions. These are expressions that follow SPEL and can be given as the value for a property using the @{} placeholder. Since such a value would cause an exception when creating the object if the property is a non-string type (value cannot be converted), we need to move those expressions to a Map for processing, and then remove the original property configuration containing the expression. The expressions are then evaluated during the view apply model phase and the result is set as the value for the corresponding property.

Spring will not register inner beans with IDs so that the bean definition can be retrieved through the factory, therefore this post processor adds them as top level registered beans

Author:
Kuali Rice Team (rice.collab@kuali.org)

Constructor Summary
UifBeanFactoryPostProcessor()
           
 
Method Summary
protected  Class<?> getBeanClass(org.springframework.beans.factory.config.BeanDefinition beanDefinition, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)
          Retrieves the class for the object that will be created from the bean definition.
protected  Map<String,String> getPropertyExpressionsFromParent(String parentBeanName, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Set<String> processedBeanNames)
          Retrieves the property expressions map set on the bean with given name.
protected  String getStringValue(Object value)
          Determines whether the given value is of String type and if so returns the string value
protected  boolean hasExpression(Object propertyValue)
          Checks whether the given property value is of String type, and if so whether it contains the expression placholder(s)
 void postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)
          Iterates through all beans in the factory and invokes processing
protected  void processBeanDefinition(String beanName, org.springframework.beans.factory.config.BeanDefinition beanDefinition, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Set<String> processedBeanNames)
          If the bean class is type Component, LayoutManager, or BindingInfo, iterate through configured property values and check for expressions
protected  Object processPropertyValue(String propertyName, Object propertyValue, Map<String,String> parentPropertyExpressions, Map<String,String> propertyExpressions, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Set<String> processedBeanNames)
          Processes the given property name/value pair for complex objects, such as bean definitions or collections, which if found will be processed for contained property expression values
protected  void removeExpressionsByPrefix(String propertyNamePrefix, Map<String,String> propertyExpressions)
          Removes entries from the given expressions map whose key starts with the given prefix
protected  void removeParentExpressionsOnNested(String propertyName, org.springframework.beans.MutablePropertyValues pvs, String parentBeanName, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)
           
protected  void visitArray(String propertyName, Map<String,String> parentPropertyExpressions, Map<String,String> propertyExpressions, Object[] arrayVal, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Set<String> processedBeanNames)
           
protected  void visitList(String propertyName, Map<String,String> parentPropertyExpressions, Map<String,String> propertyExpressions, List listVal, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Set<String> processedBeanNames)
           
protected  void visitMap(String propertyName, Map<String,String> parentPropertyExpressions, Map<String,String> propertyExpressions, Map<?,?> mapVal, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Set<String> processedBeanNames)
           
protected  void visitSet(String propertyName, Map<String,String> parentPropertyExpressions, Map<String,String> propertyExpressions, Set setVal, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Set<String> processedBeanNames)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UifBeanFactoryPostProcessor

public UifBeanFactoryPostProcessor()
Method Detail

postProcessBeanFactory

public void postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)
                            throws org.springframework.beans.BeansException
Iterates through all beans in the factory and invokes processing

Specified by:
postProcessBeanFactory in interface org.springframework.beans.factory.config.BeanFactoryPostProcessor
Parameters:
beanFactory - - bean factory instance to process
Throws:
org.springframework.beans.BeansException

processBeanDefinition

protected void processBeanDefinition(String beanName,
                                     org.springframework.beans.factory.config.BeanDefinition beanDefinition,
                                     org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory,
                                     Set<String> processedBeanNames)
If the bean class is type Component, LayoutManager, or BindingInfo, iterate through configured property values and check for expressions

If a expression is found for a property, it is added to the 'propertyExpressions' map and then the original property value is removed to prevent binding errors (when converting to a non string type)

Parameters:
beanName - - name of the bean in the factory (only set for top level beans, not nested)
beanDefinition - - bean definition to process for expressions
beanFactory - - bean factory being processed

removeParentExpressionsOnNested

protected void removeParentExpressionsOnNested(String propertyName,
                                               org.springframework.beans.MutablePropertyValues pvs,
                                               String parentBeanName,
                                               org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)

getBeanClass

protected Class<?> getBeanClass(org.springframework.beans.factory.config.BeanDefinition beanDefinition,
                                org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)
Retrieves the class for the object that will be created from the bean definition. Since the class might not be configured on the bean definition, but by a parent, each parent bean definition is recursively checked for a class until one is found

Parameters:
beanDefinition - - bean definition to get class for
beanFactory - - bean factory that contains the bean definition
Returns:
Class class configured for the bean definition, or null

getPropertyExpressionsFromParent

protected Map<String,String> getPropertyExpressionsFromParent(String parentBeanName,
                                                              org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory,
                                                              Set<String> processedBeanNames)
Retrieves the property expressions map set on the bean with given name. If the bean has not been processed by the bean factory post processor, that is done before retrieving the map

Parameters:
parentBeanName - - name of the parent bean to retrieve map for (if empty a new map will be returned)
beanFactory - - bean factory to retrieve bean definition from
processedBeanNames - - set of bean names that have been processed so far
Returns:
Map property expressions map from parent or new instance

hasExpression

protected boolean hasExpression(Object propertyValue)
Checks whether the given property value is of String type, and if so whether it contains the expression placholder(s)

Parameters:
propertyValue - - value to check for expressions
Returns:
boolean true if the property value contains expression(s), false if it does not

processPropertyValue

protected Object processPropertyValue(String propertyName,
                                      Object propertyValue,
                                      Map<String,String> parentPropertyExpressions,
                                      Map<String,String> propertyExpressions,
                                      org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory,
                                      Set<String> processedBeanNames)
Processes the given property name/value pair for complex objects, such as bean definitions or collections, which if found will be processed for contained property expression values

Parameters:
propertyName - - name of the property whose value is being processed
propertyValue - - value to check
parentPropertyExpressions - - map that holds property expressions for the parent bean definition, used for merging
propertyExpressions - - map that holds property expressions for the bean definition being processed
beanFactory - - bean factory that contains the bean definition being processed
processedBeanNames - - set of bean names that have been processed so far
Returns:
Object new value to set for property

removeExpressionsByPrefix

protected void removeExpressionsByPrefix(String propertyNamePrefix,
                                         Map<String,String> propertyExpressions)
Removes entries from the given expressions map whose key starts with the given prefix

Parameters:
propertyNamePrefix - - prefix to search for and remove
propertyExpressions - - map of property expressions to filter

getStringValue

protected String getStringValue(Object value)
Determines whether the given value is of String type and if so returns the string value

Parameters:
value - - object value to check
Returns:
String string value for object or null if object is not a string type

visitArray

protected void visitArray(String propertyName,
                          Map<String,String> parentPropertyExpressions,
                          Map<String,String> propertyExpressions,
                          Object[] arrayVal,
                          org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory,
                          Set<String> processedBeanNames)

visitList

protected void visitList(String propertyName,
                         Map<String,String> parentPropertyExpressions,
                         Map<String,String> propertyExpressions,
                         List listVal,
                         org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory,
                         Set<String> processedBeanNames)

visitSet

protected void visitSet(String propertyName,
                        Map<String,String> parentPropertyExpressions,
                        Map<String,String> propertyExpressions,
                        Set setVal,
                        org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory,
                        Set<String> processedBeanNames)

visitMap

protected void visitMap(String propertyName,
                        Map<String,String> parentPropertyExpressions,
                        Map<String,String> propertyExpressions,
                        Map<?,?> mapVal,
                        org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory,
                        Set<String> processedBeanNames)


Copyright © 2005-2012 The Kuali Foundation. All Rights Reserved.