Java Code Examples for org.springframework.beans.factory.support.GenericBeanDefinition#setBeanClassName()

The following examples show how to use org.springframework.beans.factory.support.GenericBeanDefinition#setBeanClassName() . 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: BeanDefinitionDtoConverterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Convert from a DTO to an internal Spring bean definition.
 * 
 * @param beanDefinitionDto The DTO object.
 * @return Returns a Spring bean definition.
 */
public BeanDefinition toInternal(BeanDefinitionInfo beanDefinitionInfo) {
	if (beanDefinitionInfo instanceof GenericBeanDefinitionInfo) {
		GenericBeanDefinitionInfo genericInfo = (GenericBeanDefinitionInfo) beanDefinitionInfo;
		GenericBeanDefinition def = new GenericBeanDefinition();
		def.setBeanClassName(genericInfo.getClassName());
		if (genericInfo.getPropertyValues() != null) {
			MutablePropertyValues propertyValues = new MutablePropertyValues();
			for (Entry<String, BeanMetadataElementInfo> entry : genericInfo.getPropertyValues().entrySet()) {
				BeanMetadataElementInfo info = entry.getValue();
				propertyValues.add(entry.getKey(), toInternal(info));
			}
			def.setPropertyValues(propertyValues);
		}
		return def;
	} else if (beanDefinitionInfo instanceof ObjectBeanDefinitionInfo) {
		ObjectBeanDefinitionInfo objectInfo = (ObjectBeanDefinitionInfo) beanDefinitionInfo;
		return createBeanDefinitionByIntrospection(objectInfo.getObject());
	} else {
		throw new IllegalArgumentException("Conversion to internal of " + beanDefinitionInfo.getClass().getName()
				+ " not implemented");
	}
}
 
Example 2
Source File: BaseBeanFactory.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
public List<BeanDefinitionHolder> createBeans(Map<String, Object> parameters) throws RuntimeConfigException {
	GenericBeanDefinition def = new GenericBeanDefinition();
	def.setBeanClassName(className);
	MutablePropertyValues propertyValues = new MutablePropertyValues();
	List<NamedObject> namedObjects = new ArrayList<NamedObject>();
	if (checkCollection(BEAN_REFS, NamedObject.class, parameters) != Priority.NONE) {
		namedObjects.addAll((Collection) parameters.get(BEAN_REFS));
	}
	for (String name : parameters.keySet()) {
		if (!ignoredParams.contains(name)) {
			propertyValues.addPropertyValue(name, beanDefinitionDtoConverterService
					.createBeanMetadataElementByIntrospection(parameters.get(name), namedObjects));
		}
	}
	def.setPropertyValues(propertyValues);
	BeanDefinitionHolder holder = new BeanDefinitionHolder(def, (String) parameters.get(BEAN_NAME));
	List<BeanDefinitionHolder> holders = new ArrayList<BeanDefinitionHolder>();
	holders.add(holder);
	return holders;
}
 
Example 3
Source File: ImportAwareTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
	GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
	beanDefinition.setBeanClassName(String.class.getName());
	registry.registerBeanDefinition("registrarImportedBean", beanDefinition);
	GenericBeanDefinition beanDefinition2 = new GenericBeanDefinition();
	beanDefinition2.setBeanClass(OtherImportedConfig.class);
	registry.registerBeanDefinition("registrarImportedConfig", beanDefinition2);
	Assert.state(!called, "ImportedRegistrar called twice");
	called = true;
}
 
Example 4
Source File: ImportAwareTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
	GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
	beanDefinition.setBeanClassName(String.class.getName());
	registry.registerBeanDefinition("registrarImportedBean", beanDefinition);
	GenericBeanDefinition beanDefinition2 = new GenericBeanDefinition();
	beanDefinition2.setBeanClass(OtherImportedConfig.class);
	registry.registerBeanDefinition("registrarImportedConfig", beanDefinition2);
	Assert.state(!called, "ImportedRegistrar called twice");
	called = true;
}
 
Example 5
Source File: MangoDaoAutoCreator.java    From mango-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/**
 * 向spring中注入dao代理
 * @param beanFactory
 */
private void registryMangoDao(DefaultListableBeanFactory beanFactory){
    for (Class<?> daoClass : findMangoDaoClasses(config.getScanPackage())) {
        GenericBeanDefinition bf = new GenericBeanDefinition();
        bf.setBeanClassName(daoClass.getName());
        MutablePropertyValues pvs = bf.getPropertyValues();
        pvs.addPropertyValue("daoClass", daoClass);
        bf.setBeanClass(factoryBeanClass);
        bf.setPropertyValues(pvs);
        bf.setLazyInit(false);
        beanFactory.registerBeanDefinition(daoClass.getName(), bf);
    }
}
 
Example 6
Source File: ImportAwareTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
	GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
	beanDefinition.setBeanClassName(String.class.getName());
	registry.registerBeanDefinition("registrarImportedBean", beanDefinition);
	GenericBeanDefinition beanDefinition2 = new GenericBeanDefinition();
	beanDefinition2.setBeanClass(OtherImportedConfig.class);
	registry.registerBeanDefinition("registrarImportedConfig", beanDefinition2);
	Assert.state(!called, "ImportedRegistrar called twice");
	called = true;
}
 
Example 7
Source File: SimpleTaskAutoConfigurationTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Bean
public BeanDefinitionHolder proxyDataSource() {
	GenericBeanDefinition proxyBeanDefinition = new GenericBeanDefinition();
	proxyBeanDefinition.setBeanClassName("javax.sql.DataSource");
	BeanDefinitionHolder myDataSource = new BeanDefinitionHolder(
			proxyBeanDefinition, "dataSource2");
	ScopedProxyUtils.createScopedProxy(myDataSource,
			(BeanDefinitionRegistry) this.context.getBeanFactory(), true);
	return myDataSource;
}
 
Example 8
Source File: MangoDaoScanner.java    From mango with Apache License 2.0 5 votes vote down vote up
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
  DefaultListableBeanFactory dlbf = (DefaultListableBeanFactory) beanFactory;
  for (Class<?> daoClass : findMangoDaoClasses()) {
    GenericBeanDefinition bf = new GenericBeanDefinition();
    bf.setBeanClassName(daoClass.getName());
    MutablePropertyValues pvs = bf.getPropertyValues();
    pvs.addPropertyValue("daoClass", daoClass);
    bf.setBeanClass(factoryBeanClass);
    bf.setPropertyValues(pvs);
    bf.setLazyInit(false);
    dlbf.registerBeanDefinition(daoClass.getName(), bf);
  }
}
 
Example 9
Source File: ScriptFactoryPostProcessor.java    From spring-analysis-note with MIT License 3 votes vote down vote up
/**
 * Create a ScriptFactory bean definition based on the given script definition,
 * extracting only the definition data that is relevant for the ScriptFactory
 * (that is, only bean class and constructor arguments).
 * @param bd the full script bean definition
 * @return the extracted ScriptFactory bean definition
 * @see org.springframework.scripting.ScriptFactory
 */
protected BeanDefinition createScriptFactoryBeanDefinition(BeanDefinition bd) {
	GenericBeanDefinition scriptBd = new GenericBeanDefinition();
	scriptBd.setBeanClassName(bd.getBeanClassName());
	scriptBd.getConstructorArgumentValues().addArgumentValues(bd.getConstructorArgumentValues());
	return scriptBd;
}
 
Example 10
Source File: ScriptFactoryPostProcessor.java    From java-technology-stack with MIT License 3 votes vote down vote up
/**
 * Create a ScriptFactory bean definition based on the given script definition,
 * extracting only the definition data that is relevant for the ScriptFactory
 * (that is, only bean class and constructor arguments).
 * @param bd the full script bean definition
 * @return the extracted ScriptFactory bean definition
 * @see org.springframework.scripting.ScriptFactory
 */
protected BeanDefinition createScriptFactoryBeanDefinition(BeanDefinition bd) {
	GenericBeanDefinition scriptBd = new GenericBeanDefinition();
	scriptBd.setBeanClassName(bd.getBeanClassName());
	scriptBd.getConstructorArgumentValues().addArgumentValues(bd.getConstructorArgumentValues());
	return scriptBd;
}
 
Example 11
Source File: ScriptFactoryPostProcessor.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create a ScriptFactory bean definition based on the given script definition,
 * extracting only the definition data that is relevant for the ScriptFactory
 * (that is, only bean class and constructor arguments).
 * @param bd the full script bean definition
 * @return the extracted ScriptFactory bean definition
 * @see org.springframework.scripting.ScriptFactory
 */
protected BeanDefinition createScriptFactoryBeanDefinition(BeanDefinition bd) {
	GenericBeanDefinition scriptBd = new GenericBeanDefinition();
	scriptBd.setBeanClassName(bd.getBeanClassName());
	scriptBd.getConstructorArgumentValues().addArgumentValues(bd.getConstructorArgumentValues());
	return scriptBd;
}
 
Example 12
Source File: ScriptFactoryPostProcessor.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
/**
 * Create a ScriptFactory bean definition based on the given script definition,
 * extracting only the definition data that is relevant for the ScriptFactory
 * (that is, only bean class and constructor arguments).
 * @param bd the full script bean definition
 * @return the extracted ScriptFactory bean definition
 * @see org.springframework.scripting.ScriptFactory
 */
protected BeanDefinition createScriptFactoryBeanDefinition(BeanDefinition bd) {
	GenericBeanDefinition scriptBd = new GenericBeanDefinition();
	scriptBd.setBeanClassName(bd.getBeanClassName());
	scriptBd.getConstructorArgumentValues().addArgumentValues(bd.getConstructorArgumentValues());
	return scriptBd;
}