List of usage examples for org.springframework.beans MutablePropertyValues addPropertyValue
public void addPropertyValue(String propertyName, Object propertyValue)
From source file:org.impalaframework.web.spring.config.WebMappingBeanDefinitionParser.java
RootBeanDefinition newContributorDefinition(Map<String, ContextAndServletPath> prefixMap) { RootBeanDefinition definition = new RootBeanDefinition(ModuleUrlPrefixContributor.class); MutablePropertyValues propertyValues = definition.getPropertyValues(); propertyValues.addPropertyValue(PREFIX_MAP_PROPERTY, prefixMap); return definition; }
From source file:org.impalaframework.web.spring.config.WebMappingBeanDefinitionParser.java
private void handleSuffixes(Element element, ParserContext parserContext) { List<Element> suffixes = DomUtils.getChildElementsByTagName(element, TO_RESOURCE_ELEMENT); for (Element suffixElement : suffixes) { String extensionAttribute = suffixElement.getAttribute(EXTENSION_ATTRIBUTE); String servletNameAttribute = suffixElement.getAttribute(SERVLET_NAME_ATTTRIBUTE); String filterNamesAttribute = suffixElement.getAttribute(FILTER_NAMES); String[] filterNames = getFilterNames(filterNamesAttribute); String servletName = getServletName(servletNameAttribute); RootBeanDefinition definition = new RootBeanDefinition(ModuleInvokerContributor.class); MutablePropertyValues propertyValues = definition.getPropertyValues(); propertyValues.addPropertyValue("suffix", extensionAttribute); propertyValues.addPropertyValue("servletName", servletName); propertyValues.addPropertyValue("filterNames", filterNames); registerDefinition(parserContext, definition); }/*from w w w . j a v a 2s.c o m*/ }
From source file:org.kuali.rice.krad.datadictionary.DictionaryBeanFactoryPostProcessor.java
/** * Iterates through the properties defined for the bean definition and invokes helper methods to process * the property value// w w w.j a va 2s .c o m * * @param beanDefinition bean definition whose properties will be processed * @param nestedBeanStack stack of beans which contain the given bean */ protected void processBeanProperties(BeanDefinition beanDefinition, Stack<BeanDefinitionHolder> nestedBeanStack) { // iterate through properties and check for any configured message keys within the value MutablePropertyValues pvs = beanDefinition.getPropertyValues(); PropertyValue[] pvArray = pvs.getPropertyValues(); for (PropertyValue pv : pvArray) { Object newPropertyValue = null; if (isStringValue(pv.getValue())) { newPropertyValue = processStringPropertyValue(pv.getName(), getString(pv.getValue()), nestedBeanStack); } else { newPropertyValue = visitPropertyValue(pv.getName(), pv.getValue(), nestedBeanStack); } pvs.removePropertyValue(pv.getName()); pvs.addPropertyValue(pv.getName(), newPropertyValue); } }
From source file:org.kuali.rice.krad.datadictionary.DictionaryBeanProcessorBase.java
/** * Applies the given property name and value to given property values * * @param propertyPath name of the property to add value for * @param propertyValue value for the property * @param pvs property values to add property to *//*w ww .j a va2 s.c o m*/ protected void applyPropertyValueToBean(String propertyPath, String propertyValue, MutablePropertyValues pvs) { pvs.addPropertyValue(propertyPath, propertyValue); }
From source file:org.kuali.rice.krad.datadictionary.uif.UifBeanFactoryPostProcessor.java
/** * Processes a top level (non nested) bean definition for expressions * * <p>//w w w .ja va2s . c o m * 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 * </p> * * @param beanName name of the bean to process * @param beanDefinition bean definition to process * @param beanFactory factory holding all the bean definitions * @param processedBeanNames set of bean names that have already been processed */ protected void processBeanDefinition(String beanName, BeanDefinition beanDefinition, ConfigurableListableBeanFactory beanFactory, Set<String> processedBeanNames) { Class<?> beanClass = getBeanClass(beanDefinition, beanFactory); if ((beanClass == null) || !UifDictionaryBean.class.isAssignableFrom(beanClass) || processedBeanNames.contains(beanName)) { return; } // process bean definition and all nested definitions for expressions ManagedMap<String, String> expressionGraph = new ManagedMap<String, String>(); MutablePropertyValues pvs = beanDefinition.getPropertyValues(); if (pvs.contains(UifPropertyPaths.EXPRESSION_GRAPH)) { expressionGraph = (ManagedMap<String, String>) pvs.getPropertyValue(UifPropertyPaths.EXPRESSION_GRAPH) .getValue(); if (expressionGraph == null) { expressionGraph = new ManagedMap<String, String>(); } } expressionGraph.setMergeEnabled(false); processNestedBeanDefinition(beanName, beanDefinition, "", expressionGraph, beanFactory, processedBeanNames); // add property for expression graph pvs = beanDefinition.getPropertyValues(); pvs.addPropertyValue(UifPropertyPaths.EXPRESSION_GRAPH, expressionGraph); }
From source file:org.kuali.rice.krad.datadictionary.uif.UifBeanFactoryPostProcessor.java
/** * If the bean class is type UifDictionaryBean, iterate through configured property values * and check for expressions.//from w w w. j a v a 2s . c om * * @param beanName name of the bean in the factory (only set for top level beans, not nested) * @param beanDefinition bean definition to process for expressions * @param nestedPropertyName * @param expressionGraph * @param beanFactory bean factory being processed * @param processedBeanNames */ protected void processNestedBeanDefinition(String beanName, BeanDefinition beanDefinition, String nestedPropertyName, Map<String, String> expressionGraph, ConfigurableListableBeanFactory beanFactory, Set<String> processedBeanNames) { Class<?> beanClass = getBeanClass(beanDefinition, beanFactory); if ((beanClass == null) || !UifDictionaryBean.class.isAssignableFrom(beanClass) || processedBeanNames.contains(beanName)) { return; } LOG.debug("Processing bean name '" + beanName + "'"); Map<String, String> parentExpressionGraph = getExpressionGraphFromParent(beanDefinition.getParentName(), beanFactory, processedBeanNames); // process expressions on property values MutablePropertyValues pvs = beanDefinition.getPropertyValues(); PropertyValue[] pvArray = pvs.getPropertyValues(); for (PropertyValue pv : pvArray) { if (pv.getName().equals(UifPropertyPaths.EXPRESSION_GRAPH)) { continue; } String propertyPath = pv.getName(); if (StringUtils.isNotBlank(nestedPropertyName)) { propertyPath = nestedPropertyName + "." + propertyPath; } // for reloading, need to remove the property from the previously loaded bean definition if (expressionGraph.containsKey(propertyPath)) { expressionGraph.remove(propertyPath); } if (hasExpression(pv.getValue())) { // process expression String strValue = getStringValue(pv.getValue()); expressionGraph.put(propertyPath, strValue); // remove property value so expression will not cause binding exception pvs.removePropertyValue(pv.getName()); } else { // process nested objects Object newValue = processPropertyValue(propertyPath, pv.getName(), pv.getValue(), beanDefinition, parentExpressionGraph, expressionGraph, beanFactory, processedBeanNames); pvs.removePropertyValue(pv.getName()); pvs.addPropertyValue(pv.getName(), newValue); } // removed expression (if exists) from parent map since the property was set on child if (parentExpressionGraph.containsKey(pv.getName())) { parentExpressionGraph.remove(pv.getName()); } } // if nested bean set expression graph to null so it is not inherited from parent definition if (StringUtils.isNotBlank(nestedPropertyName)) { pvs.addPropertyValue(UifPropertyPaths.EXPRESSION_GRAPH, null); } // add remaining expressions from parent to expression graph for (Map.Entry<String, String> parentExpression : parentExpressionGraph.entrySet()) { String expressionPath = parentExpression.getKey(); if (StringUtils.isNotBlank(nestedPropertyName)) { expressionPath = nestedPropertyName + "." + expressionPath; } if (!expressionGraph.containsKey(expressionPath)) { expressionGraph.put(expressionPath, parentExpression.getValue()); } } if (StringUtils.isNotBlank(beanName)) { processedBeanNames.add(beanName); } }
From source file:org.kuali.rice.krad.uif.util.UifBeanFactoryPostProcessor.java
/** * If the bean class is type UifDictionaryBean, iterate through configured property values * and check for expressions/*ww w . ja v a 2s .c o m*/ * * @param beanName name of the bean in the factory (only set for top level beans, not nested) * @param beanDefinition bean definition to process for expressions * @param nestedPropertyName * @param expressionGraph * @param beanFactory bean factory being processed * @param processedBeanNames */ protected void processNestedBeanDefinition(String beanName, BeanDefinition beanDefinition, String nestedPropertyName, Map<String, String> expressionGraph, ConfigurableListableBeanFactory beanFactory, Set<String> processedBeanNames) { Class<?> beanClass = getBeanClass(beanDefinition, beanFactory); if ((beanClass == null) || !UifDictionaryBean.class.isAssignableFrom(beanClass) || processedBeanNames.contains(beanName)) { return; } LOG.debug("Processing bean name '" + beanName + "'"); Map<String, String> parentExpressionGraph = getExpressionGraphFromParent(beanDefinition.getParentName(), beanFactory, processedBeanNames); // process expressions on property values MutablePropertyValues pvs = beanDefinition.getPropertyValues(); PropertyValue[] pvArray = pvs.getPropertyValues(); for (PropertyValue pv : pvArray) { if (pv.getName().equals(UifPropertyPaths.EXPRESSION_GRAPH)) { continue; } String propertyPath = pv.getName(); if (StringUtils.isNotBlank(nestedPropertyName)) { propertyPath = nestedPropertyName + "." + propertyPath; } // for reloading, need to remove the property from the previously loaded bean definition if (expressionGraph.containsKey(propertyPath)) { expressionGraph.remove(propertyPath); } if (hasExpression(pv.getValue())) { // process expression String strValue = getStringValue(pv.getValue()); expressionGraph.put(propertyPath, strValue); // remove property value so expression will not cause binding exception pvs.removePropertyValue(pv.getName()); } else { // process nested objects Object newValue = processPropertyValue(propertyPath, pv.getName(), pv.getValue(), beanDefinition, parentExpressionGraph, expressionGraph, beanFactory, processedBeanNames); pvs.removePropertyValue(pv.getName()); pvs.addPropertyValue(pv.getName(), newValue); } // removed expression (if exists) from parent map since the property was set on child if (parentExpressionGraph.containsKey(pv.getName())) { parentExpressionGraph.remove(pv.getName()); } } // if nested bean set expression graph to null so it is not inherited from parent definition if (StringUtils.isNotBlank(nestedPropertyName)) { pvs.addPropertyValue(UifPropertyPaths.EXPRESSION_GRAPH, null); } // add remaining expressions from parent to expression graph for (Map.Entry<String, String> parentExpression : parentExpressionGraph.entrySet()) { String expressionPath = parentExpression.getKey(); if (StringUtils.isNotBlank(nestedPropertyName)) { expressionPath = nestedPropertyName + "." + expressionPath; } if (!expressionGraph.containsKey(expressionPath)) { expressionGraph.put(expressionPath, parentExpression.getValue()); } } // if bean name is given and factory does not have it registered we need to add it (inner beans that // were given an id) if (StringUtils.isNotBlank(beanName) && !StringUtils.contains(beanName, "$") && !StringUtils.contains(beanName, "#") && !beanFactory.containsBean(beanName)) { ((BeanDefinitionRegistry) beanFactory).registerBeanDefinition(beanName, beanDefinition); } if (StringUtils.isNotBlank(beanName)) { processedBeanNames.add(beanName); } }
From source file:org.mule.config.spring.parsers.assembly.DefaultBeanAssembler.java
/** * Insert the bean we have built into the target (typically the parent bean). * * <p>This is the most complex case because the bean can have an aribtrary type. * /*from www .j a v a2 s .co m*/ * @param oldName The identifying the bean (typically element name). */ public void insertBeanInTarget(String oldName) { logger.debug("insert " + bean.getBeanDefinition().getBeanClassName() + " -> " + target.getBeanClassName()); assertTargetPresent(); String beanClass = bean.getBeanDefinition().getBeanClassName(); PropertyValues sourceProperties = bean.getRawBeanDefinition().getPropertyValues(); String newName = bestGuessName(targetConfig, oldName, target.getBeanClassName()); MutablePropertyValues targetProperties = target.getPropertyValues(); PropertyValue pv = targetProperties.getPropertyValue(newName); Object oldValue = null == pv ? null : pv.getValue(); if (!targetConfig.isIgnored(oldName)) { if (targetConfig.isCollection(oldName) || beanClass.equals(ChildListEntryDefinitionParser.ListEntry.class.getName())) { if (null == oldValue) { if (beanClass.equals(ChildMapEntryDefinitionParser.KeyValuePair.class.getName()) || beanClass.equals(MapEntryCombiner.class.getName()) || beanClass.equals(MapFactoryBean.class.getName())) { // a collection of maps requires an extra intermediate object that does the // lazy combination/caching of maps when first used BeanDefinitionBuilder combiner = BeanDefinitionBuilder .rootBeanDefinition(MapCombiner.class); targetProperties.addPropertyValue(newName, combiner.getBeanDefinition()); MutablePropertyValues combinerProperties = combiner.getBeanDefinition().getPropertyValues(); oldValue = new ManagedList(); pv = new PropertyValue(MapCombiner.LIST, oldValue); combinerProperties.addPropertyValue(pv); } else { oldValue = new ManagedList(); pv = new PropertyValue(newName, oldValue); targetProperties.addPropertyValue(pv); } } List list = retrieveList(oldValue); if (ChildMapEntryDefinitionParser.KeyValuePair.class.getName().equals(beanClass)) { list.add(new ManagedMap()); retrieveMap(list.get(list.size() - 1)).put( sourceProperties.getPropertyValue(ChildMapEntryDefinitionParser.KEY).getValue(), sourceProperties.getPropertyValue(ChildMapEntryDefinitionParser.VALUE).getValue()); } else if (beanClass.equals(ChildListEntryDefinitionParser.ListEntry.class.getName())) { list.add(sourceProperties.getPropertyValue(ChildListEntryDefinitionParser.VALUE).getValue()); } else { list.add(bean.getBeanDefinition()); } } else { // not a collection if (ChildMapEntryDefinitionParser.KeyValuePair.class.getName().equals(beanClass)) { if (null == pv || null == oldValue) { pv = new PropertyValue(newName, new ManagedMap()); targetProperties.addPropertyValue(pv); } retrieveMap(pv.getValue()).put( sourceProperties.getPropertyValue(ChildMapEntryDefinitionParser.KEY).getValue(), sourceProperties.getPropertyValue(ChildMapEntryDefinitionParser.VALUE).getValue()); } else { targetProperties.addPropertyValue(newName, bean.getBeanDefinition()); } } } }
From source file:org.mule.config.spring.parsers.assembly.DefaultBeanAssembler.java
/** * Add a key/value pair to existing {@link AnnotatedObject#PROPERTY_NAME} property value. *//* w w w . ja v a 2 s. c o m*/ @SuppressWarnings("unchecked") public final void addAnnotationValue(MutablePropertyValues properties, QName name, Object value) { PropertyValue propertyValue = properties.getPropertyValue(AnnotatedObject.PROPERTY_NAME); Map<QName, Object> oldValue; if (propertyValue != null) { oldValue = (Map<QName, Object>) propertyValue.getValue(); } else { oldValue = new HashMap<QName, Object>(); properties.addPropertyValue(AnnotatedObject.PROPERTY_NAME, oldValue); } oldValue.put(name, value); }
From source file:org.mule.config.spring.parsers.assembly.DefaultBeanAssembler.java
protected void addPropertyWithoutReference(MutablePropertyValues properties, SingleProperty config, String name, Object value) {/* w w w . j ava2 s . c o m*/ if (!config.isIgnored()) { if (logger.isDebugEnabled()) { logger.debug(name + ": " + value); } Object oldValue = null; if (properties.contains(name)) { oldValue = properties.getPropertyValue(name).getValue(); } // merge collections if (config.isCollection() || oldValue instanceof Collection || value instanceof Collection) { Collection values = new ManagedList(); if (null != oldValue) { properties.removePropertyValue(name); if (oldValue instanceof Collection) { values.addAll((Collection) oldValue); } else { values.add(oldValue); } } if (value instanceof Collection) { values.addAll((Collection) value); } else { values.add(value); } properties.addPropertyValue(name, values); } else { properties.addPropertyValue(name, value); } } }