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

TODO: convert to dictionary bean processor

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> getExpressionGraphFromParent(String parentBeanName, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Set<String> processedBeanNames)
          Retrieves the expression graph 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)
          Processes a top level (non nested) bean definition for expressions
protected  void processNestedBeanDefinition(String beanName, org.springframework.beans.factory.config.BeanDefinition beanDefinition, String nestedPropertyName, Map<String,String> expressionGraph, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Set<String> processedBeanNames)
          If the bean class is type UifDictionaryBean, iterate through configured property values and check for expressions
protected  Object processPropertyValue(String nestedPropertyName, String propertyName, Object propertyValue, org.springframework.beans.factory.config.BeanDefinition beanDefinition, Map<String,String> parentExpressionGraph, Map<String,String> expressionGraph, 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> expressionGraph)
          Removes entries from the given expressions map whose key starts with the given prefix
protected  void visitArray(String propertyName, Map<String,String> parentExpressionGraph, Map<String,String> expressionGraph, Object array, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Set<String> processedBeanNames)
           
protected  void visitList(String nestedPropertyName, String propertyName, org.springframework.beans.factory.config.BeanDefinition beanDefinition, Map<String,String> parentExpressionGraph, Map<String,String> expressionGraph, List listVal, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Set<String> processedBeanNames)
           
protected  void visitMap(String propertyName, Map<String,String> parentExpressionGraph, Map<String,String> expressionGraph, 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)
Processes a top level (non nested) bean definition for expressions

A bean that is non nested (or top of a collection) will hold all the expressions for the graph. A new expression graph is initialized and expressions are collected as the bean and all its children are processed. The expression graph is then set as a property on the top bean definition

Parameters:
beanName - - name of the bean to process
beanDefinition - - bean definition to process
beanFactory - - factory holding all the bean definitions
processedBeanNames - - set of bean names that have already been processed

processNestedBeanDefinition

protected void processNestedBeanDefinition(String beanName,
                                           org.springframework.beans.factory.config.BeanDefinition beanDefinition,
                                           String nestedPropertyName,
                                           Map<String,String> expressionGraph,
                                           org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory,
                                           Set<String> processedBeanNames)
If the bean class is type UifDictionaryBean, iterate through configured property values and check for expressions

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

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

getExpressionGraphFromParent

protected Map<String,String> getExpressionGraphFromParent(String parentBeanName,
                                                          org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory,
                                                          Set<String> processedBeanNames)
Retrieves the expression graph 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 expression graph 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 nestedPropertyName,
                                      String propertyName,
                                      Object propertyValue,
                                      org.springframework.beans.factory.config.BeanDefinition beanDefinition,
                                      Map<String,String> parentExpressionGraph,
                                      Map<String,String> expressionGraph,
                                      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:
nestedPropertyName - - nested path of the property whose value is being processed
propertyName - - name of the property in the bean definition being processed
propertyValue - - value to check
beanDefinition - - bean definition the property belongs to
parentExpressionGraph - - map that holds property expressions for the parent bean definition, used for merging
expressionGraph - - 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> expressionGraph)
Removes entries from the given expressions map whose key starts with the given prefix

Parameters:
propertyNamePrefix - - prefix to search for and remove
expressionGraph - - 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> parentExpressionGraph,
                          Map<String,String> expressionGraph,
                          Object array,
                          org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory,
                          Set<String> processedBeanNames)

visitList

protected void visitList(String nestedPropertyName,
                         String propertyName,
                         org.springframework.beans.factory.config.BeanDefinition beanDefinition,
                         Map<String,String> parentExpressionGraph,
                         Map<String,String> expressionGraph,
                         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> parentExpressionGraph,
                        Map<String,String> expressionGraph,
                        Map<?,?> mapVal,
                        org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory,
                        Set<String> processedBeanNames)


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