Java Code Examples for org.springframework.beans.factory.support.AbstractBeanDefinition#setConstructorArgumentValues()

The following examples show how to use org.springframework.beans.factory.support.AbstractBeanDefinition#setConstructorArgumentValues() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GroovyBeanDefinitionWrapper.java    From spring-analysis-note with MIT License 6 votes vote down vote up
protected AbstractBeanDefinition createBeanDefinition() {
	AbstractBeanDefinition bd = new GenericBeanDefinition();
	bd.setBeanClass(this.clazz);
	if (!CollectionUtils.isEmpty(this.constructorArgs)) {
		ConstructorArgumentValues cav = new ConstructorArgumentValues();
		for (Object constructorArg : this.constructorArgs) {
			cav.addGenericArgumentValue(constructorArg);
		}
		bd.setConstructorArgumentValues(cav);
	}
	if (this.parentName != null) {
		bd.setParentName(this.parentName);
	}
	this.definitionWrapper = new BeanWrapperImpl(bd);
	return bd;
}
 
Example 2
Source File: GroovyBeanDefinitionWrapper.java    From java-technology-stack with MIT License 6 votes vote down vote up
protected AbstractBeanDefinition createBeanDefinition() {
	AbstractBeanDefinition bd = new GenericBeanDefinition();
	bd.setBeanClass(this.clazz);
	if (!CollectionUtils.isEmpty(this.constructorArgs)) {
		ConstructorArgumentValues cav = new ConstructorArgumentValues();
		for (Object constructorArg : this.constructorArgs) {
			cav.addGenericArgumentValue(constructorArg);
		}
		bd.setConstructorArgumentValues(cav);
	}
	if (this.parentName != null) {
		bd.setParentName(this.parentName);
	}
	this.definitionWrapper = new BeanWrapperImpl(bd);
	return bd;
}
 
Example 3
Source File: GroovyBeanDefinitionWrapper.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
protected AbstractBeanDefinition createBeanDefinition() {
	AbstractBeanDefinition bd = new GenericBeanDefinition();
	bd.setBeanClass(this.clazz);
	if (!CollectionUtils.isEmpty(this.constructorArgs)) {
		ConstructorArgumentValues cav = new ConstructorArgumentValues();
		for (Object constructorArg : this.constructorArgs) {
			cav.addGenericArgumentValue(constructorArg);
		}
		bd.setConstructorArgumentValues(cav);
	}
	if (this.parentName != null) {
		bd.setParentName(this.parentName);
	}
	this.definitionWrapper = new BeanWrapperImpl(bd);
	return bd;
}
 
Example 4
Source File: GroovyBeanDefinitionWrapper.java    From blog_demos with Apache License 2.0 6 votes vote down vote up
protected AbstractBeanDefinition createBeanDefinition() {
	AbstractBeanDefinition bd = new GenericBeanDefinition();
	bd.setBeanClass(this.clazz);
	if (!CollectionUtils.isEmpty(this.constructorArgs)) {
		ConstructorArgumentValues cav = new ConstructorArgumentValues();
		for (Object constructorArg : this.constructorArgs) {
			cav.addGenericArgumentValue(constructorArg);
		}
		bd.setConstructorArgumentValues(cav);
	}
	if (this.parentName != null) {
		bd.setParentName(this.parentName);
	}
	this.definitionWrapper = new BeanWrapperImpl(bd);
	return bd;
}
 
Example 5
Source File: GroovyBeanDefinitionWrapper.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
protected AbstractBeanDefinition createBeanDefinition() {
	AbstractBeanDefinition bd = new GenericBeanDefinition();
	bd.setBeanClass(this.clazz);
	if (!CollectionUtils.isEmpty(this.constructorArgs)) {
		ConstructorArgumentValues cav = new ConstructorArgumentValues();
		for (Object constructorArg : this.constructorArgs) {
			cav.addGenericArgumentValue(constructorArg);
		}
		bd.setConstructorArgumentValues(cav);
	}
	if (this.parentName != null) {
		bd.setParentName(this.parentName);
	}
	this.definitionWrapper = new BeanWrapperImpl(bd);
	return bd;
}
 
Example 6
Source File: MulCommonBaseServiceParser.java    From zxl with Apache License 2.0 5 votes vote down vote up
private BeanDefinition buildSqlSessionTemplateBeanDefinition(Element element, String name) {
	AbstractBeanDefinition beanDefinition = new GenericBeanDefinition();
	beanDefinition.setAttribute(ID_ATTRIBUTE, name + SQL_SESSION_TEMPLATE_SUFFIX);
	beanDefinition.setBeanClass(SqlSessionTemplate.class);
	ConstructorArgumentValues constructorArgumentValues = new ConstructorArgumentValues();
	constructorArgumentValues.addIndexedArgumentValue(0, new RuntimeBeanReference(name + SQL_SESSION_FACTORY_SUFFIX));
	beanDefinition.setConstructorArgumentValues(constructorArgumentValues);
	return beanDefinition;
}
 
Example 7
Source File: MqBeanParser.java    From zxl with Apache License 2.0 5 votes vote down vote up
protected void buildRabbitTemplateBeanDefinition(String beanName, String connectionFactoryBeanName, BeanDefinitionRegistry beanDefinitionRegistry) {
	AbstractBeanDefinition rabbitTemplateBeanDefinition = new GenericBeanDefinition();
	rabbitTemplateBeanDefinition.setBeanClass(RabbitTemplate.class);
	ConstructorArgumentValues rabbitTemplateConstructorArgumentValues = new ConstructorArgumentValues();
	rabbitTemplateConstructorArgumentValues.addIndexedArgumentValue(0, new RuntimeBeanReference(connectionFactoryBeanName));
	rabbitTemplateBeanDefinition.setConstructorArgumentValues(rabbitTemplateConstructorArgumentValues);
	beanDefinitionRegistry.registerBeanDefinition(beanName, rabbitTemplateBeanDefinition);
}
 
Example 8
Source File: MqBeanParser.java    From zxl with Apache License 2.0 5 votes vote down vote up
protected void buildRabbitAdminBeanDefinition(String beanName, String connectionFactoryBeanName, BeanDefinitionRegistry beanDefinitionRegistry) {
	AbstractBeanDefinition rabbitAdminBeanDefinition = new GenericBeanDefinition();
	rabbitAdminBeanDefinition.setBeanClass(RabbitAdmin.class);
	ConstructorArgumentValues rabbitAdminConstructorArgumentValues = new ConstructorArgumentValues();
	rabbitAdminConstructorArgumentValues.addIndexedArgumentValue(0, new RuntimeBeanReference(connectionFactoryBeanName));
	rabbitAdminBeanDefinition.setConstructorArgumentValues(rabbitAdminConstructorArgumentValues);
	beanDefinitionRegistry.registerBeanDefinition(beanName, rabbitAdminBeanDefinition);
}
 
Example 9
Source File: GroovyBeanDefinitionWrapper.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public void setProperty(String property, Object newValue) {
	if (PARENT.equals(property)) {
		setParent(newValue);
	}
	else {
		AbstractBeanDefinition bd = getBeanDefinition();
		if (AUTOWIRE.equals(property)) {
			if ("byName".equals(newValue)) {
				bd.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_NAME);
			}
			else if ("byType".equals(newValue)) {
				bd.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);
			}
			else if ("constructor".equals(newValue)) {
				bd.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR);
			}
			else if (Boolean.TRUE.equals(newValue)) {
				bd.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_NAME);
			}
		}
		// constructorArgs
		else if (CONSTRUCTOR_ARGS.equals(property) && newValue instanceof List) {
			ConstructorArgumentValues cav = new ConstructorArgumentValues();
			List args = (List) newValue;
			for (Object arg : args) {
				cav.addGenericArgumentValue(arg);
			}
			bd.setConstructorArgumentValues(cav);
		}
		// factoryBean
		else if (FACTORY_BEAN.equals(property)) {
			if (newValue != null) {
				bd.setFactoryBeanName(newValue.toString());
			}
		}
		// factoryMethod
		else if (FACTORY_METHOD.equals(property)) {
			if (newValue != null) {
				bd.setFactoryMethodName(newValue.toString());
			}
		}
		// initMethod
		else if (INIT_METHOD.equals(property)) {
			if (newValue != null) {
				bd.setInitMethodName(newValue.toString());
			}
		}
		// destroyMethod
		else if (DESTROY_METHOD.equals(property)) {
			if (newValue != null) {
				bd.setDestroyMethodName(newValue.toString());
			}
		}
		// singleton property
		else if (SINGLETON.equals(property)) {
			bd.setScope(Boolean.TRUE.equals(newValue) ?
					BeanDefinition.SCOPE_SINGLETON : BeanDefinition.SCOPE_PROTOTYPE);
		}
		else if (this.definitionWrapper.isWritableProperty(property)) {
			this.definitionWrapper.setPropertyValue(property, newValue);
		}
		else {
			super.setProperty(property, newValue);
		}
	}
}
 
Example 10
Source File: GroovyBeanDefinitionWrapper.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public void setProperty(String property, Object newValue) {
	if (PARENT.equals(property)) {
		setParent(newValue);
	}
	else {
		AbstractBeanDefinition bd = getBeanDefinition();
		if (AUTOWIRE.equals(property)) {
			if ("byName".equals(newValue)) {
				bd.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_NAME);
			}
			else if ("byType".equals(newValue)) {
				bd.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);
			}
			else if ("constructor".equals(newValue)) {
				bd.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR);
			}
			else if (Boolean.TRUE.equals(newValue)) {
				bd.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_NAME);
			}
		}
		// constructorArgs
		else if (CONSTRUCTOR_ARGS.equals(property) && newValue instanceof List) {
			ConstructorArgumentValues cav = new ConstructorArgumentValues();
			List args = (List) newValue;
			for (Object arg : args) {
				cav.addGenericArgumentValue(arg);
			}
			bd.setConstructorArgumentValues(cav);
		}
		// factoryBean
		else if (FACTORY_BEAN.equals(property)) {
			if (newValue != null) {
				bd.setFactoryBeanName(newValue.toString());
			}
		}
		// factoryMethod
		else if (FACTORY_METHOD.equals(property)) {
			if (newValue != null) {
				bd.setFactoryMethodName(newValue.toString());
			}
		}
		// initMethod
		else if (INIT_METHOD.equals(property)) {
			if (newValue != null) {
				bd.setInitMethodName(newValue.toString());
			}
		}
		// destroyMethod
		else if (DESTROY_METHOD.equals(property)) {
			if (newValue != null) {
				bd.setDestroyMethodName(newValue.toString());
			}
		}
		// singleton property
		else if (SINGLETON.equals(property)) {
			bd.setScope(Boolean.TRUE.equals(newValue) ?
					BeanDefinition.SCOPE_SINGLETON : BeanDefinition.SCOPE_PROTOTYPE);
		}
		else if (this.definitionWrapper.isWritableProperty(property)) {
			this.definitionWrapper.setPropertyValue(property, newValue);
		}
		else {
			super.setProperty(property, newValue);
		}
	}
}
 
Example 11
Source File: GroovyBeanDefinitionWrapper.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public void setProperty(String property, Object newValue) {
	if (PARENT.equals(property)) {
		setParent(newValue);
	}
	else {
		AbstractBeanDefinition bd = getBeanDefinition();
		if (AUTOWIRE.equals(property)) {
			if ("byName".equals(newValue)) {
				bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_BY_NAME);
			}
			else if ("byType".equals(newValue)) {
				bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE);
			}
			else if ("constructor".equals(newValue)) {
				bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR);
			}
			else if (Boolean.TRUE.equals(newValue)) {
				bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_BY_NAME);
			}
		}
		// constructorArgs
		else if (CONSTRUCTOR_ARGS.equals(property) && newValue instanceof List) {
			ConstructorArgumentValues cav = new ConstructorArgumentValues();
			List args = (List) newValue;
			for (Object arg : args) {
				cav.addGenericArgumentValue(arg);
			}
			bd.setConstructorArgumentValues(cav);
		}
		// factoryBean
		else if (FACTORY_BEAN.equals(property)) {
			if (newValue != null) {
				bd.setFactoryBeanName(newValue.toString());
			}
		}
		// factoryMethod
		else if (FACTORY_METHOD.equals(property)) {
			if (newValue != null)
				bd.setFactoryMethodName(newValue.toString());
		}
		// initMethod
		else if (INIT_METHOD.equals(property)) {
			if (newValue != null) {
				bd.setInitMethodName(newValue.toString());
			}
		}
		// destroyMethod
		else if (DESTROY_METHOD.equals(property)) {
			if (newValue != null) {
				bd.setDestroyMethodName(newValue.toString());
			}
		}
		// singleton property
		else if (SINGLETON.equals(property)) {
			bd.setScope(Boolean.TRUE.equals(newValue) ?
					BeanDefinition.SCOPE_SINGLETON : BeanDefinition.SCOPE_PROTOTYPE);
		}
		else if (this.definitionWrapper.isWritableProperty(property)) {
			this.definitionWrapper.setPropertyValue(property, newValue);
		}
		else {
			super.setProperty(property, newValue);
		}
	}
}
 
Example 12
Source File: GroovyBeanDefinitionWrapper.java    From blog_demos with Apache License 2.0 4 votes vote down vote up
public void setProperty(String property, Object newValue) {
	if (PARENT.equals(property)) {
		setParent(newValue);
	}
	else {
		AbstractBeanDefinition bd = getBeanDefinition();
		if (AUTOWIRE.equals(property)) {
			if ("byName".equals(newValue)) {
				bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_BY_NAME);
			}
			else if ("byType".equals(newValue)) {
				bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE);
			}
			else if ("constructor".equals(newValue)) {
				bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR);
			}
			else if (Boolean.TRUE.equals(newValue)) {
				bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_BY_NAME);
			}
		}
		// constructorArgs
		else if (CONSTRUCTOR_ARGS.equals(property) && newValue instanceof List) {
			ConstructorArgumentValues cav = new ConstructorArgumentValues();
			List args = (List) newValue;
			for (Object arg : args) {
				cav.addGenericArgumentValue(arg);
			}
			bd.setConstructorArgumentValues(cav);
		}
		// factoryBean
		else if (FACTORY_BEAN.equals(property)) {
			if (newValue != null) {
				bd.setFactoryBeanName(newValue.toString());
			}
		}
		// factoryMethod
		else if (FACTORY_METHOD.equals(property)) {
			if (newValue != null)
				bd.setFactoryMethodName(newValue.toString());
		}
		// initMethod
		else if (INIT_METHOD.equals(property)) {
			if (newValue != null) {
				bd.setInitMethodName(newValue.toString());
			}
		}
		// destroyMethod
		else if (DESTROY_METHOD.equals(property)) {
			if (newValue != null) {
				bd.setDestroyMethodName(newValue.toString());
			}
		}
		// singleton property
		else if (SINGLETON.equals(property)) {
			bd.setScope(Boolean.TRUE.equals(newValue) ?
					BeanDefinition.SCOPE_SINGLETON : BeanDefinition.SCOPE_PROTOTYPE);
		}
		else if (this.definitionWrapper.isWritableProperty(property)) {
			this.definitionWrapper.setPropertyValue(property, newValue);
		}
		else {
			super.setProperty(property, newValue);
		}
	}
}
 
Example 13
Source File: GroovyBeanDefinitionWrapper.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
public void setProperty(String property, Object newValue) {
	if (PARENT.equals(property)) {
		setParent(newValue);
	}
	else {
		AbstractBeanDefinition bd = getBeanDefinition();
		if (AUTOWIRE.equals(property)) {
			if ("byName".equals(newValue)) {
				bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_BY_NAME);
			}
			else if ("byType".equals(newValue)) {
				bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE);
			}
			else if ("constructor".equals(newValue)) {
				bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR);
			}
			else if (Boolean.TRUE.equals(newValue)) {
				bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_BY_NAME);
			}
		}
		// constructorArgs
		else if (CONSTRUCTOR_ARGS.equals(property) && newValue instanceof List) {
			ConstructorArgumentValues cav = new ConstructorArgumentValues();
			List args = (List) newValue;
			for (Object arg : args) {
				cav.addGenericArgumentValue(arg);
			}
			bd.setConstructorArgumentValues(cav);
		}
		// factoryBean
		else if (FACTORY_BEAN.equals(property)) {
			if (newValue != null) {
				bd.setFactoryBeanName(newValue.toString());
			}
		}
		// factoryMethod
		else if (FACTORY_METHOD.equals(property)) {
			if (newValue != null)
				bd.setFactoryMethodName(newValue.toString());
		}
		// initMethod
		else if (INIT_METHOD.equals(property)) {
			if (newValue != null) {
				bd.setInitMethodName(newValue.toString());
			}
		}
		// destroyMethod
		else if (DESTROY_METHOD.equals(property)) {
			if (newValue != null) {
				bd.setDestroyMethodName(newValue.toString());
			}
		}
		// singleton property
		else if (SINGLETON.equals(property)) {
			bd.setScope(Boolean.TRUE.equals(newValue) ?
					BeanDefinition.SCOPE_SINGLETON : BeanDefinition.SCOPE_PROTOTYPE);
		}
		else if (this.definitionWrapper.isWritableProperty(property)) {
			this.definitionWrapper.setPropertyValue(property, newValue);
		}
		else {
			super.setProperty(property, newValue);
		}
	}
}
 
Example 14
Source File: GridFactorySelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Gets test Spring application context with single {@link StringBuilder} bean
 * with name "myBean" and value "Test string".
 *
 * @return Spring application context.
 */
private ApplicationContext getTestApplicationContext() {
    AbstractBeanDefinition def = new GenericBeanDefinition();

    def.setBeanClass(StringBuilder.class);

    ConstructorArgumentValues args = new ConstructorArgumentValues();
    args.addGenericArgumentValue("Test string");

    def.setConstructorArgumentValues(args);

    GenericApplicationContext ctx = new GenericApplicationContext();

    ctx.registerBeanDefinition("myBean", def);

    return ctx;
}