List of usage examples for org.springframework.beans.factory.support AbstractBeanDefinition setPropertyValues
public void setPropertyValues(MutablePropertyValues propertyValues)
From source file:com.seovic.validation.config.ValidationBeanDefinitionParser.java
private static BeanDefinition parseErrorMessageAction(Element message, ParserContext parserContext) { String messageId = message.getAttribute("id"); String[] providers = message.getAttribute("providers").split(","); String typeName = ErrorMessageAction.class.getName(); ConstructorArgumentValues ctorArgs = new ConstructorArgumentValues(); ctorArgs.addGenericArgumentValue(messageId); ctorArgs.addGenericArgumentValue(providers); String when = message.getAttribute("when"); MutablePropertyValues properties = new MutablePropertyValues(); if (StringUtils.hasText(when)) { properties.addPropertyValue("when", when); }//from w w w . j a v a 2s .com AbstractBeanDefinition action; try { action = BeanDefinitionReaderUtils.createBeanDefinition(null, typeName, parserContext.getReaderContext().getBeanClassLoader()); } catch (ClassNotFoundException e) { throw new BeanCreationException("Error occured during creation of bean definition", e); } action.setConstructorArgumentValues(ctorArgs); action.setPropertyValues(properties); return action; }
From source file:com.zuoxiaolong.niubi.job.spring.config.JobDrivenBeanDefinitionParser.java
@Override public BeanDefinition parse(Element element, ParserContext parserContext) { AbstractBeanDefinition beanDefinition = new GenericBeanDefinition(); MutablePropertyValues propertyValues = new MutablePropertyValues(); beanDefinition.setBeanClass(SpringContextJobDriver.class); propertyValues.addPropertyValue("packagesToScan", element.getAttribute("packagesToScan")); beanDefinition.setPropertyValues(propertyValues); beanDefinition.setInitMethodName("init"); BeanDefinitionReaderUtils.registerWithGeneratedName(beanDefinition, parserContext.getRegistry()); return beanDefinition; }
From source file:org.echocat.jomon.spring.BeanPostConfigurer.java
@Nonnull protected MutablePropertyValues getPropertyValues(@Nonnull AbstractBeanDefinition beanDefinition) { MutablePropertyValues propertyValues = beanDefinition.getPropertyValues(); if (propertyValues == null) { propertyValues = new MutablePropertyValues(); beanDefinition.setPropertyValues(propertyValues); }//ww w . j a va 2 s.c o m return propertyValues; }
From source file:com.googlecode.ehcache.annotations.key.SpELCacheKeyGenerator.java
/** * Create a new key generator with the specified name. *///from w ww .j a v a 2s . c o m @SuppressWarnings("unchecked") protected CacheKeyGenerator<Serializable> createKeyGenerator(String name, Class<CacheKeyGenerator<Serializable>> keyGeneratorClass, MutablePropertyValues properties) { final AbstractBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setBeanClass(keyGeneratorClass); if (this.reflectionHelper != null && ReflectionHelperAware.class.isAssignableFrom(beanDefinition.getBeanClass())) { properties.addPropertyValue("reflectionHelper", this.reflectionHelper); } beanDefinition.setPropertyValues(properties); this.cacheKeyBeanFactory.registerBeanDefinition(name, beanDefinition); return this.cacheKeyBeanFactory.getBean(name, CacheKeyGenerator.class); }
From source file:grails.plugin.cache.CacheBeanPostProcessor.java
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) { log.info("postProcessBeanDefinitionRegistry start"); AbstractBeanDefinition beanDef = findBeanDefinition(registry); if (beanDef == null) { log.error("Unable to find the AnnotationCacheOperationSource bean definition"); return;//from www . ja va 2 s . com } // change the class to the plugin's subclass beanDef.setBeanClass(GrailsAnnotationCacheOperationSource.class); // wire in the dependency for the grailsApplication MutablePropertyValues props = beanDef.getPropertyValues(); if (props == null) { props = new MutablePropertyValues(); beanDef.setPropertyValues(props); } props.addPropertyValue("grailsApplication", new RuntimeBeanReference("grailsApplication", true)); log.debug("updated {}", beanDef); }
From source file:com.bstek.dorado.spring.ClassTypeListShortCutDecorator.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) { AbstractBeanDefinition beanDef = (AbstractBeanDefinition) definition.getBeanDefinition(); MutablePropertyValues propertyValues = (beanDef.getPropertyValues() == null) ? new MutablePropertyValues() : beanDef.getPropertyValues(); ManagedList list = null;/*from w w w . ja v a2s . c om*/ boolean firstPropertyValue = propertyValues.getPropertyValue(IMPL_TYPES) == null; if (!firstPropertyValue) { list = (ManagedList) (propertyValues.getPropertyValue(IMPL_TYPES).getValue()); } else { list = new ManagedList(); list.setSource(node); list.setMergeEnabled(true); propertyValues.addPropertyValue(IMPL_TYPES, list); beanDef.setPropertyValues(propertyValues); } Element el = (Element) node; String className = el.getAttribute("name"); try { list.add(Class.forName(className)); } catch (ClassNotFoundException e) { logger.warn(e, e); } return definition; }
From source file:com.seovic.validation.config.ValidationBeanDefinitionParser.java
@SuppressWarnings("unchecked") private BeanDefinition parseValidator(Element element, ParserContext parserContext) { String parent = element.getAttribute("parent"); if ("".equals(parent)) { parent = null;/*w ww . java 2 s .c o m*/ } String test = element.getAttribute("test"); String when = element.getAttribute("when"); String validateAll = element.getAttribute("validate-all"); String context = element.getAttribute("context"); String includeElementsErrors = element.getAttribute("include-element-errors"); MutablePropertyValues properties = new MutablePropertyValues(); if (StringUtils.hasText(test)) { properties.addPropertyValue("test", test); } if (StringUtils.hasText(when)) { properties.addPropertyValue("when", when); } if (StringUtils.hasText(validateAll)) { properties.addPropertyValue("validateAll", validateAll); } if (StringUtils.hasText(context)) { properties.addPropertyValue("context", context); } if (StringUtils.hasText(includeElementsErrors)) { properties.addPropertyValue("includeElementsErrors", includeElementsErrors); } ManagedList nestedValidators = new ManagedList(); ManagedList actions = new ManagedList(); for (int i = 0; i < element.getChildNodes().getLength(); i++) { Node child = element.getChildNodes().item(i); if (child != null && child instanceof Element) { Element childElement = (Element) child; if ("message".equals(childElement.getLocalName())) { actions.add(parseErrorMessageAction(childElement, parserContext)); } else { nestedValidators.add(parseAndRegisterValidator2(childElement, parserContext)); } } } if (nestedValidators.size() > 0) { properties.addPropertyValue("validators", nestedValidators); } if (actions.size() > 0) { properties.addPropertyValue("actions", actions); } String className; if ("required".equals(element.getLocalName())) { className = RequiredValidator.class.getName(); } else if ("condition".equals(element.getLocalName())) { className = ConditionValidator.class.getName(); } else if ("validator".equals(element.getLocalName())) { className = element.getAttribute("type"); } else { className = ValidatorGroup.class.getName(); } AbstractBeanDefinition validatorDefinition; try { validatorDefinition = BeanDefinitionReaderUtils.createBeanDefinition(parent, className, parserContext.getReaderContext().getBeanClassLoader()); } catch (ClassNotFoundException e) { throw new BeanCreationException("Error occured during creation of bean definition", e); } validatorDefinition.setResource(parserContext.getReaderContext().getResource()); validatorDefinition.setSource(parserContext.extractSource(element)); validatorDefinition.setPropertyValues(properties); validatorDefinition.setLazyInit(true); validatorDefinition.setScope("singleton"); return validatorDefinition; }
From source file:com.bstek.dorado.spring.MapEntryShortCutDecorator.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) { AbstractBeanDefinition beanDef = (AbstractBeanDefinition) definition.getBeanDefinition(); MutablePropertyValues propertyValues = (beanDef.getPropertyValues() == null) ? new MutablePropertyValues() : beanDef.getPropertyValues(); ManagedMap map = null;//from w w w . j a v a 2 s . c om boolean firstPropertyValue = propertyValues.getPropertyValue(property) == null; if (!firstPropertyValue) { map = (ManagedMap) (propertyValues.getPropertyValue(property).getValue()); } else { map = new ManagedMap(); map.setSource(node); map.setMergeEnabled(true); propertyValues.addPropertyValue(property, map); beanDef.setPropertyValues(propertyValues); } Element el = (Element) node; String key = el.getAttribute("key"); String value = el.getAttribute("value"); String valueRef = el.getAttribute("value-ref"); Object entryValue = null; if (StringUtils.isNotEmpty(value)) { entryValue = value; } else if (StringUtils.isNotEmpty(valueRef)) { RuntimeBeanReference ref = new RuntimeBeanReference(valueRef); ref.setSource(parserContext.getReaderContext().extractSource(el)); entryValue = ref; } else { Element beanEl = DomUtils.getChildElementByTagName(el, "bean"); if (beanEl != null) { entryValue = parserContext.getDelegate().parseBeanDefinitionElement(beanEl); } } if (supportsMultiKey && StringUtils.isNotEmpty(key)) { for (String k : StringUtils.split(key, KEY_DELIM)) { map.put(k, entryValue); } } else { map.put(key, entryValue); } return definition; }
From source file:com.googlecode.ehcache.annotations.impl.CacheAttributeSourceImpl.java
protected final <T> T getOrCreateChildBean(Class<T> beanType, String beanClass, Property[] properties) { final StringBuilder beanNameBuilder = new StringBuilder(); beanNameBuilder.append(beanClass);//from ww w .ja v a2 s . c om final MutablePropertyValues mutablePropertyValues = new MutablePropertyValues(); //Sort the properties array first so bean name generation is always consistent Arrays.sort(properties, PropertyComparator.INSTANCE); for (Property property : properties) { final String name = property.name(); final String value = property.value(); final String ref = property.ref(); beanNameBuilder.append("[").append(name).append(",").append(value).append(",").append(ref).append("]"); if (value.length() > 0) { if (ref.length() > 0) { throw new IllegalArgumentException( "Only one of value or ref must be specified no both on Property with name: " + name); } mutablePropertyValues.addPropertyValue(name, value); } else if (ref.length() > 0) { mutablePropertyValues.addPropertyValue(name, new RuntimeBeanReference(ref)); } else { throw new IllegalArgumentException( "Either value or ref must be specified on Property with name: " + name); } } final String beanName = beanNameBuilder.toString(); //See if the bean is already registered using the compiled bean name, if so just use that instance if (this.childBeanFactory.containsBean(beanName)) { return this.childBeanFactory.getBean(beanName, beanType); } //Create and register the bean if it didn't already exist final AbstractBeanDefinition beanDefinition; try { beanDefinition = BeanDefinitionReaderUtils.createBeanDefinition(null, beanClass, ClassUtils.getDefaultClassLoader()); } catch (ClassNotFoundException e) { throw new BeanCreationException( "Could not find class '" + beanClass + "' to create " + beanType + " from", e); } if (ReflectionHelperAware.class.isAssignableFrom(beanDefinition.getBeanClass())) { mutablePropertyValues.addPropertyValue("reflectionHelper", this.reflectionHelper); } beanDefinition.setPropertyValues(mutablePropertyValues); this.childBeanFactory.registerBeanDefinition(beanName, beanDefinition); return this.childBeanFactory.getBean(beanName, beanType); }