Class UifBeanFactoryPostProcessor
- All Implemented Interfaces:
org.springframework.beans.factory.config.BeanFactoryPostProcessor
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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected 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.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 StringgetStringValue(Object value) Determines whether the given value is of String type and if so returns the string valueprotected booleanhasExpression(Object propertyValue) Checks whether the given property value is of String type, and if so whether it contains the expression placholder(s)voidpostProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory) Iterates through all beans in the factory and invokes processingprotected voidprocessBeanDefinition(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 expressionsprotected voidprocessNestedBeanDefinition(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 ObjectprocessPropertyValue(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 valuesprotected voidremoveExpressionsByPrefix(String propertyNamePrefix, Map<String, String> expressionGraph) Removes entries from the given expressions map whose key starts with the given prefixprotected voidvisitArray(String propertyName, Map<String, String> parentExpressionGraph, Map<String, String> expressionGraph, Object array, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Set<String> processedBeanNames) protected voidvisitList(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 voidvisitMap(String propertyName, Map<String, String> parentExpressionGraph, Map<String, String> expressionGraph, Map<?, ?> mapVal, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Set<String> processedBeanNames) protected voidvisitSet(String propertyName, Map<String, String> parentPropertyExpressions, Map<String, String> propertyExpressions, Set setVal, org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Set<String> processedBeanNames)
-
Constructor Details
-
UifBeanFactoryPostProcessor
public UifBeanFactoryPostProcessor()
-
-
Method Details
-
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:
postProcessBeanFactoryin interfaceorg.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 expressionsA 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 processbeanDefinition- bean definition to processbeanFactory- factory holding all the bean definitionsprocessedBeanNames- 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 expressionsnestedPropertyName-expressionGraph-beanFactory- bean factory being processedprocessedBeanNames-
-
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 forbeanFactory- bean factory that contains the bean definition- Returns:
- 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 fromprocessedBeanNames- set of bean names that have been processed so far- Returns:
- expression graph map from parent or new instance
-
hasExpression
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:
- 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 processedpropertyName- name of the property in the bean definition being processedpropertyValue- value to checkbeanDefinition- bean definition the property belongs toparentExpressionGraph- map that holds property expressions for the parent bean definition, used for mergingexpressionGraph- map that holds property expressions for the bean definition being processedbeanFactory- bean factory that contains the bean definition being processedprocessedBeanNames- set of bean names that have been processed so far- Returns:
- 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 removeexpressionGraph- map of property expressions to filter
-
getStringValue
Determines whether the given value is of String type and if so returns the string value- Parameters:
value- object value to check- Returns:
- string value for object or null if object is not a string type
-
visitArray
-
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
-
visitMap
-