List of usage examples for org.springframework.beans.factory.config ConstructorArgumentValues addGenericArgumentValue
public void addGenericArgumentValue(ValueHolder newValue)
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 ww . j a va2 s. co m*/ 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.griddynamics.banshun.xml.ImportBeanDefinitionParser.java
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { String exportInterface = element.getAttribute(INTERFACE_ATTR); if (isBlank(exportInterface)) { return;/* w w w.j a v a 2s. com*/ } String externalName = element.getAttribute(ID_ATTR); if (isBlank(externalName)) { return; } String rootName = element.getAttribute(ROOT_ATTR); if (isBlank(rootName)) { rootName = DEFAULT_ROOT_FACTORY_NAME; } ConstructorArgumentValues constructorArgValues = new ConstructorArgumentValues(); constructorArgValues.addGenericArgumentValue(externalName); constructorArgValues.addGenericArgumentValue(findClass(exportInterface, element.getAttribute(ID_ATTR), parserContext.getReaderContext().getResource().getDescription())); AbstractBeanDefinition beanDef = builder.getRawBeanDefinition(); beanDef.setFactoryBeanName(rootName); beanDef.setFactoryMethodName("lookup"); beanDef.setConstructorArgumentValues(constructorArgValues); beanDef.setLazyInit(true); beanDef.setScope(SCOPE_SINGLETON); }
From source file:org.bigtester.ate.xmlschema.PagePropertyCorrectBeanDefinitionParser.java
/** * {@inheritDoc}//w w w. j a v a2s. com */ @Override protected AbstractBeanDefinition parseInternal(@Nullable Element element, @Nullable ParserContext parserContext) { // Here we parse the Spring elements such as < property> if (parserContext == null || element == null) throw GlobalUtils.createNotInitializedException("element and parserContext"); // Here we parse the Spring elements such as < property> BeanDefinitionHolder holder = parserContext.getDelegate().parseBeanDefinitionElement(element); BeanDefinition bDef = holder.getBeanDefinition(); bDef.setBeanClassName(PagePropertyCorrectnessAsserter.class.getName()); String resultPage = element .getAttribute(XsdElementConstants.ATTR_ABSTRACTEXPECTEDRESULTASSERTER_RESULTPAGE); if (StringUtils.hasText(resultPage)) { bDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(resultPage)); } String stepERValue = element .getAttribute(XsdElementConstants.ATTR_ABSTRACTEXPECTEDRESULTASSERTER_STEPERVALUE); if (StringUtils.hasText(stepERValue)) { ConstructorArgumentValues erValueDefConstrs = new ConstructorArgumentValues(); erValueDefConstrs.addGenericArgumentValue(stepERValue); BeanDefinition erValueDef = new ChildBeanDefinition(XsdElementConstants.ELEMENT_ID_BASEERVALUE, StepErPagePropertyValue.class, erValueDefConstrs, null); parserContext.getRegistry() .registerBeanDefinition(element.getAttribute("id") + "_ASSERTER_STEPERVALUE_ID", erValueDef); bDef.getConstructorArgumentValues().addGenericArgumentValue( new RuntimeBeanReference(element.getAttribute("id") + "_ASSERTER_STEPERVALUE_ID")); } parserContext.getRegistry().registerBeanDefinition(element.getAttribute("id"), bDef); return (AbstractBeanDefinition) bDef; }
From source file:org.bigtester.ate.xmlschema.PageElementExistBeanDefinitionParser.java
/** * {@inheritDoc}/*from www . j ava 2s. c o m*/ */ @Override protected AbstractBeanDefinition parseInternal(@Nullable Element element, @Nullable ParserContext parserContext) { // Here we parse the Spring elements such as < property> if (parserContext == null || element == null) throw GlobalUtils.createNotInitializedException("element and parserContext"); // Here we parse the Spring elements such as < property> BeanDefinitionHolder holder = parserContext.getDelegate().parseBeanDefinitionElement(element); BeanDefinition bDef = holder.getBeanDefinition(); bDef.setBeanClassName(PageElementExistenceAsserter.class.getName()); String resultPage = element .getAttribute(XsdElementConstants.ATTR_ABSTRACTEXPECTEDRESULTASSERTER_RESULTPAGE); if (StringUtils.hasText(resultPage)) { bDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference(resultPage)); } String stepERValue = element .getAttribute(XsdElementConstants.ATTR_ABSTRACTEXPECTEDRESULTASSERTER_STEPERVALUE); if (StringUtils.hasText(stepERValue)) { ConstructorArgumentValues erValueDefConstrs = new ConstructorArgumentValues(); erValueDefConstrs.addGenericArgumentValue(stepERValue); BeanDefinition erValueDef = new ChildBeanDefinition(XsdElementConstants.ELEMENT_ID_BASEERVALUE, StepErElementExistenceValue.class, erValueDefConstrs, null); parserContext.getRegistry() .registerBeanDefinition(element.getAttribute("id") + "_ASSERTER_STEPERVALUE_ID", erValueDef); bDef.getConstructorArgumentValues().addGenericArgumentValue( new RuntimeBeanReference(element.getAttribute("id") + "_ASSERTER_STEPERVALUE_ID")); } parserContext.getRegistry().registerBeanDefinition(element.getAttribute("id"), bDef); return (AbstractBeanDefinition) bDef; }
From source file:pl.chilldev.web.spring.config.HandlePageModelBeanDefinitionParser.java
/** * {@inheritDoc}/* ww w . ja va 2s . c om*/ * @since 0.0.1 */ @Override public BeanDefinition parse(Element element, ParserContext parserContext) { // page model bean prototype GenericBeanDefinition pageMetaModelBean = new GenericBeanDefinition(); pageMetaModelBean.setBeanClass(PageMetaModel.class); pageMetaModelBean.setScope(WebApplicationContext.SCOPE_REQUEST); pageMetaModelBean.setFactoryBeanName(PageMetaModelFactoryBean.class.getName()); pageMetaModelBean.setFactoryMethodName(HandlePageModelBeanDefinitionParser.METHOD_CREATEPAGEMETAMODEL); parserContext.getRegistry().registerBeanDefinition(PageMetaModel.class.getName(), pageMetaModelBean); parserContext.getRegistry().registerBeanDefinition(PageMetaModelFactoryBean.class.getName(), this.pageMetaModelFactoryBean); // XHTML switch needs to be handled with generator bean if (element.hasAttribute(HandlePageModelBeanDefinitionParser.ATTRIBUTE_XHTML)) { boolean xhtml = element.getAttribute(HandlePageModelBeanDefinitionParser.ATTRIBUTE_XHTML) .equals("true"); GenericBeanDefinition generatorBean = new GenericBeanDefinition(); generatorBean.setBeanClass(Generator.class); this.logger.info("Setting markup generator XHTML mode to {}.", xhtml); ConstructorArgumentValues arguments = generatorBean.getConstructorArgumentValues(); arguments.addGenericArgumentValue(xhtml); parserContext.getRegistry().registerBeanDefinition(Generator.class.getName(), generatorBean); arguments = pageMetaModelBean.getConstructorArgumentValues(); arguments.addGenericArgumentValue(new RuntimeBeanReference(Generator.class.getName())); } // register new resolving strategy PageMetaModelContextUtils.setPageMetaModelResolver(new SpringBeansJspPageMetaModelResolver()); pl.chilldev.web.faces.context.PageMetaModelContextUtils .setPageMetaModelResolver(new SpringBeansFacesPageMetaModelResolver()); return null; }
From source file:com.griddynamics.banshun.xml.ExportBeanDefinitionParser.java
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { BeanDefinitionRegistry registry = parserContext.getRegistry(); String exportInterface = element.getAttribute(INTERFACE_ATTR); if (isBlank(exportInterface)) { return;//from www.jav a2 s .c o m } String exportBeanRef = element.getAttribute(REF_ATTR); if (isBlank(exportBeanRef)) { return; } String rootName = element.getAttribute(ROOT_ATTR); if (isBlank(rootName)) { rootName = DEFAULT_ROOT_FACTORY_NAME; } String exportName = element.getAttribute(NAME_ATTR); if (isBlank(exportName)) { exportName = exportBeanRef; } String exportRefName = exportName + BEAN_NAME_SUFFIX; if (registry.containsBeanDefinition(exportRefName)) { throw new BeanCreationException("Registry already contains bean with name: " + exportRefName); } ConstructorArgumentValues exportBeanConstructorArgValues = new ConstructorArgumentValues(); exportBeanConstructorArgValues.addGenericArgumentValue(exportName); exportBeanConstructorArgValues.addGenericArgumentValue(findClass(exportInterface, exportBeanRef, parserContext.getReaderContext().getResource().getDescription())); AbstractBeanDefinition exportBeanDef = rootBeanDefinition(ExportRef.class).getRawBeanDefinition(); exportBeanDef.setConstructorArgumentValues(exportBeanConstructorArgValues); ConstructorArgumentValues voidBeanConstructorArgValues = new ConstructorArgumentValues(); voidBeanConstructorArgValues.addGenericArgumentValue(exportBeanDef, ExportRef.class.getName()); AbstractBeanDefinition voidBeanDef = rootBeanDefinition(Void.class).getRawBeanDefinition(); voidBeanDef.setFactoryBeanName(rootName); voidBeanDef.setFactoryMethodName("export"); voidBeanDef.setLazyInit(false); voidBeanDef.setScope(SCOPE_SINGLETON); voidBeanDef.setConstructorArgumentValues(voidBeanConstructorArgValues); // voidBeanDefinition.setDependsOn(new String[] { exportBeanRef }); TODO ? registry.registerBeanDefinition(exportRefName, voidBeanDef); }
From source file:org.mybatis.spring.annotation.EnableMapperScanningTest.java
@Test public void testScanWithExplicitSqlSessionTemplate() throws Exception { GenericBeanDefinition definition = new GenericBeanDefinition(); definition.setBeanClass(SqlSessionTemplate.class); ConstructorArgumentValues constructorArgs = new ConstructorArgumentValues(); constructorArgs.addGenericArgumentValue(new RuntimeBeanReference("sqlSessionFactory")); definition.setConstructorArgumentValues(constructorArgs); applicationContext.registerBeanDefinition("sqlSessionTemplate", definition); applicationContext.register(AppConfigWithSqlSessionTemplate.class); startContext();/*from w w w . ja v a 2s. c om*/ // all interfaces with methods should be loaded applicationContext.getBean("mapperInterface"); applicationContext.getBean("mapperSubinterface"); applicationContext.getBean("mapperChildInterface"); applicationContext.getBean("annotatedMapper"); }
From source file:org.mybatis.spring.config.NamespaceTest.java
private GenericApplicationContext setupSqlSessionTemplate() { GenericApplicationContext genericApplicationContext = setupSqlSessionFactory(); GenericBeanDefinition definition = new GenericBeanDefinition(); definition.setBeanClass(SqlSessionTemplate.class); ConstructorArgumentValues constructorArgs = new ConstructorArgumentValues(); constructorArgs.addGenericArgumentValue(new RuntimeBeanReference("sqlSessionFactory")); definition.setConstructorArgumentValues(constructorArgs); genericApplicationContext.registerBeanDefinition("sqlSessionTemplate", definition); return genericApplicationContext; }
From source file:org.mybatis.spring.mapper.MapperScannerConfigurerTest.java
@Test public void testScanWithExplicitSqlSessionTemplate() throws Exception { GenericBeanDefinition definition = new GenericBeanDefinition(); definition.setBeanClass(SqlSessionTemplate.class); ConstructorArgumentValues constructorArgs = new ConstructorArgumentValues(); constructorArgs.addGenericArgumentValue(new RuntimeBeanReference("sqlSessionFactory")); definition.setConstructorArgumentValues(constructorArgs); applicationContext.registerBeanDefinition("sqlSessionTemplate", definition); applicationContext.getBeanDefinition("mapperScanner").getPropertyValues().add("sqlSessionTemplateBeanName", "sqlSessionTemplate"); testInterfaceScan();/*from w ww. j av a 2 s .co m*/ }
From source file:com.inspiresoftware.lib.dto.geda.config.AnnotationDrivenGeDABeanDefinitionParser.java
protected RuntimeBeanReference setupPointcut(final ParserContext parserContext, final Object elementSource, final RuntimeBeanReference resolver, final String[] pointcutMatchRegex, final String[] pointcutNoMatchRegex) { final RootBeanDefinition pointcut; if (pointcutMatchRegex.length == 0 && pointcutNoMatchRegex.length == 0) { pointcut = new RootBeanDefinition(GeDAMethodMatcherPointcut.class); final ConstructorArgumentValues constructorArgs = pointcut.getConstructorArgumentValues(); constructorArgs.addGenericArgumentValue(resolver); } else {//from ww w . ja v a 2s .c om pointcut = new RootBeanDefinition(GeDAMethodRegExMatcherPointcut.class); final ConstructorArgumentValues constructorArgs = pointcut.getConstructorArgumentValues(); constructorArgs.addGenericArgumentValue(resolver); final MutablePropertyValues propertyValues = pointcut.getPropertyValues(); if (pointcutMatchRegex.length > 0) { propertyValues.addPropertyValue("patterns", pointcutMatchRegex); } if (pointcutNoMatchRegex.length > 0) { propertyValues.addPropertyValue("excludedPatterns", pointcutNoMatchRegex); } } pointcut.setSource(elementSource); pointcut.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); final XmlReaderContext readerContext = parserContext.getReaderContext(); final String pointcutBeanName = readerContext.registerWithGeneratedName(pointcut); return new RuntimeBeanReference(pointcutBeanName); }