Java Code Examples for org.springframework.beans.factory.support.BeanDefinitionBuilder#getBeanDefinition()
The following examples show how to use
org.springframework.beans.factory.support.BeanDefinitionBuilder#getBeanDefinition() .
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: CratePersistentEntitySchemaManagerBeanDefinitionParser.java From spring-data-crate with Apache License 2.0 | 6 votes |
@Override protected AbstractBeanDefinition parseInternal(Element element, ParserContext context) { BeanComponentDefinitionBuilder helper = new BeanComponentDefinitionBuilder(element, context); String crateTemplateRef = element.getAttribute("crate-template-ref"); String exportOptionString = element.getAttribute("export-option"); BeanDefinitionBuilder schemaManagerBuilder = BeanDefinitionBuilder.genericBeanDefinition(CratePersistentEntitySchemaManager.class); schemaManagerBuilder.addConstructorArgReference(crateTemplateRef); schemaManagerBuilder.addConstructorArgValue(valueOf(exportOptionString)); setPropertyValue(schemaManagerBuilder, element, "ignoreFailures", "ignoreFailures"); schemaManagerBuilder.getBeanDefinition(); return (AbstractBeanDefinition)helper.getComponentIdButFallback(schemaManagerBuilder, SCHEMA_EXPORT_MANAGER) .getBeanDefinition(); }
Example 2
Source File: ConfigBeanDefinitionParser.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Parse a '{@code declare-parents}' element and register the appropriate * DeclareParentsAdvisor with the BeanDefinitionRegistry encapsulated in the * supplied ParserContext. */ private AbstractBeanDefinition parseDeclareParents(Element declareParentsElement, ParserContext parserContext) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(DeclareParentsAdvisor.class); builder.addConstructorArgValue(declareParentsElement.getAttribute(IMPLEMENT_INTERFACE)); builder.addConstructorArgValue(declareParentsElement.getAttribute(TYPE_PATTERN)); String defaultImpl = declareParentsElement.getAttribute(DEFAULT_IMPL); String delegateRef = declareParentsElement.getAttribute(DELEGATE_REF); if (StringUtils.hasText(defaultImpl) && !StringUtils.hasText(delegateRef)) { builder.addConstructorArgValue(defaultImpl); } else if (StringUtils.hasText(delegateRef) && !StringUtils.hasText(defaultImpl)) { builder.addConstructorArgReference(delegateRef); } else { parserContext.getReaderContext().error( "Exactly one of the " + DEFAULT_IMPL + " or " + DELEGATE_REF + " attributes must be specified", declareParentsElement, this.parseState.snapshot()); } AbstractBeanDefinition definition = builder.getBeanDefinition(); definition.setSource(parserContext.extractSource(declareParentsElement)); parserContext.getReaderContext().registerWithGeneratedName(definition); return definition; }
Example 3
Source File: ActivitiAnnotationDrivenBeanDefinitionParser.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
private void registerProcessScope(Element element, ParserContext parserContext) { Class clz = ProcessScope.class; BeanDefinitionBuilder processScopeBDBuilder = BeanDefinitionBuilder.genericBeanDefinition(clz); AbstractBeanDefinition scopeBeanDefinition = processScopeBDBuilder.getBeanDefinition(); scopeBeanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); configureProcessEngine(scopeBeanDefinition, element); String beanName = baseBeanName(clz); parserContext.getRegistry().registerBeanDefinition(beanName, scopeBeanDefinition); }
Example 4
Source File: AbstractSingleBeanDefinitionParser.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Creates a {@link BeanDefinitionBuilder} instance for the * {@link #getBeanClass bean Class} and passes it to the * {@link #doParse} strategy method. * @param element the element that is to be parsed into a single BeanDefinition * @param parserContext the object encapsulating the current state of the parsing process * @return the BeanDefinition resulting from the parsing of the supplied {@link Element} * @throws IllegalStateException if the bean {@link Class} returned from * {@link #getBeanClass(org.w3c.dom.Element)} is {@code null} * @see #doParse */ @Override protected final AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(); String parentName = getParentName(element); if (parentName != null) { builder.getRawBeanDefinition().setParentName(parentName); } Class<?> beanClass = getBeanClass(element); if (beanClass != null) { builder.getRawBeanDefinition().setBeanClass(beanClass); } else { String beanClassName = getBeanClassName(element); if (beanClassName != null) { builder.getRawBeanDefinition().setBeanClassName(beanClassName); } } builder.getRawBeanDefinition().setSource(parserContext.extractSource(element)); if (parserContext.isNested()) { // Inner bean definition must receive same scope as containing bean. builder.setScope(parserContext.getContainingBeanDefinition().getScope()); } if (parserContext.isDefaultLazyInit()) { // Default-lazy-init applies to custom bean definitions as well. builder.setLazyInit(true); } doParse(element, parserContext, builder); return builder.getBeanDefinition(); }
Example 5
Source File: RedissonDefinitionParser.java From redisson with Apache License 2.0 | 5 votes |
@Override public BeanDefinition parse(Element element, ParserContext parserContext) { //Sort out the Config Class BeanDefinitionBuilder configBuilder = helper.createBeanDefinitionBuilder(element, parserContext, Config.class); String configId = helper.getId(null, configBuilder, parserContext); helper.parseAttributes(element, parserContext, configBuilder); helper.registerBeanDefinition(configBuilder, configId, null, parserContext); //Do the main Redisson bean BeanDefinitionBuilder builder = helper.createBeanDefinitionBuilder(element, parserContext, Redisson.class); builder.setFactoryMethod("create"); builder.setDestroyMethodName("shutdown"); builder.addConstructorArgReference(configId); parserContext.getDelegate().parseQualifierElements(element, builder.getRawBeanDefinition()); String id = helper.getId(element, builder, parserContext); helper.parseAttributes(element, parserContext, configBuilder); //Sort out all the nested elements parseChildElements(element, configId, id, builder, parserContext); helper.registerBeanDefinition(builder, id, helper.parseAliase(element), parserContext); return builder.getBeanDefinition(); }
Example 6
Source File: RedissonNamespaceParserSupport.java From redisson with Apache License 2.0 | 5 votes |
public BeanComponentDefinition registerBeanDefinition(BeanDefinitionBuilder builder, Element element, ParserContext parserContext) { BeanDefinitionHolder holder = new BeanDefinitionHolder(builder.getBeanDefinition(), getId(element, builder, parserContext), parseAliase(element)); BeanDefinitionReaderUtils .registerBeanDefinition(holder, parserContext.getRegistry()); BeanComponentDefinition componentDefinition = new BeanComponentDefinition(holder); parserContext.registerComponent(componentDefinition); return componentDefinition; }
Example 7
Source File: ZookeeperBeanDefinitionParser.java From shardingsphere-elasticjob-lite with Apache License 2.0 | 5 votes |
private AbstractBeanDefinition buildZookeeperConfigurationBeanDefinition(final Element element) { BeanDefinitionBuilder configuration = BeanDefinitionBuilder.rootBeanDefinition(ZookeeperConfiguration.class); configuration.addConstructorArgValue(element.getAttribute("server-lists")); configuration.addConstructorArgValue(element.getAttribute("namespace")); addPropertyValueIfNotEmpty("base-sleep-time-milliseconds", "baseSleepTimeMilliseconds", element, configuration); addPropertyValueIfNotEmpty("max-sleep-time-milliseconds", "maxSleepTimeMilliseconds", element, configuration); addPropertyValueIfNotEmpty("max-retries", "maxRetries", element, configuration); addPropertyValueIfNotEmpty("session-timeout-milliseconds", "sessionTimeoutMilliseconds", element, configuration); addPropertyValueIfNotEmpty("connection-timeout-milliseconds", "connectionTimeoutMilliseconds", element, configuration); addPropertyValueIfNotEmpty("digest", "digest", element, configuration); return configuration.getBeanDefinition(); }
Example 8
Source File: MasterSlaveRuleBeanDefinitionParser.java From shardingsphere with Apache License 2.0 | 5 votes |
private BeanDefinition parseMasterSlaveDataSourceRuleConfiguration(final Element element) { BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(MasterSlaveDataSourceRuleConfiguration.class); factory.addConstructorArgValue(element.getAttribute(MasterSlaveRuleBeanDefinitionTag.MASTER_SLAVE_DATA_SOURCE_ID_ATTRIBUTE)); factory.addConstructorArgValue(element.getAttribute(MasterSlaveRuleBeanDefinitionTag.MASTER_DATA_SOURCE_NAME_ATTRIBUTE)); factory.addConstructorArgValue(parseSlaveDataSourcesRef(element)); factory.addConstructorArgValue(element.getAttribute(MasterSlaveRuleBeanDefinitionTag.LOAD_BALANCE_ALGORITHM_REF_ATTRIBUTE)); return factory.getBeanDefinition(); }
Example 9
Source File: TransactionManagerParser.java From spring-ldap with Apache License 2.0 | 5 votes |
public BeanDefinition parseDefaultRenamingStrategy(Element element) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(DefaultTempEntryRenamingStrategy.class); builder.addPropertyValue("tempSuffix", getString(element, ATT_TEMP_SUFFIX, DefaultTempEntryRenamingStrategy.DEFAULT_TEMP_SUFFIX)); return builder.getBeanDefinition(); }
Example 10
Source File: KeyGenerateAlgorithmTest.java From shardingsphere with Apache License 2.0 | 5 votes |
@Test(expected = BeanCreationException.class) public void assertTypelessKeyGenerateAlgorithm() { GenericApplicationContext context = (GenericApplicationContext) applicationContext; BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(KeyGenerateAlgorithmFactoryBean.class); BeanDefinition beanDefinition = builder.getBeanDefinition(); context.registerBeanDefinition("typelessAlgorithm", beanDefinition); context.getBean("typelessAlgorithm"); }
Example 11
Source File: DubboComponentScanRegistrar.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
/** * Registers {@link ServiceAnnotationBeanPostProcessor} * * @param packagesToScan packages to scan without resolving placeholders * @param registry {@link BeanDefinitionRegistry} * @since 2.5.8 */ private void registerServiceAnnotationBeanPostProcessor(Set<String> packagesToScan, BeanDefinitionRegistry registry) { BeanDefinitionBuilder builder = rootBeanDefinition(ServiceAnnotationBeanPostProcessor.class); builder.addConstructorArgValue(packagesToScan); builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); AbstractBeanDefinition beanDefinition = builder.getBeanDefinition(); BeanDefinitionReaderUtils.registerWithGeneratedName(beanDefinition, registry); }
Example 12
Source File: EncryptRuleBeanDefinitionParser.java From shardingsphere with Apache License 2.0 | 5 votes |
@Override protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) { BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(AlgorithmProvidedEncryptRuleConfiguration.class); factory.addConstructorArgValue(parseEncryptTableRuleConfigurations(element)); factory.addConstructorArgValue(ShardingSphereAlgorithmBeanRegistry.getAlgorithmBeanReferences(parserContext, EncryptAlgorithmFactoryBean.class)); return factory.getBeanDefinition(); }
Example 13
Source File: AbstractImportRegistrar.java From onetwo with Apache License 2.0 | 5 votes |
protected void registerComponent(BeanDefinitionRegistry registry, AnnotationMetadata annotationMetadata, AnnotationAttributes tagAttributes) { String className = annotationMetadata.getClassName(); String beanName = resolveName(tagAttributes, className); if(logger.isInfoEnabled()){ logger.info("register api client beanName: {}, class: {}", beanName, className); } BeanDefinitionBuilder definition = createComponentFactoryBeanBuilder(annotationMetadata, tagAttributes); String alias = beanName + "-" + getComponentAnnotationClass().getSimpleName(); AbstractBeanDefinition beanDefinition = definition.getBeanDefinition(); beanDefinition.setPrimary(true); BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDefinition, beanName, new String[] { alias }); BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry); }
Example 14
Source File: AbstractSingleBeanDefinitionParser.java From java-technology-stack with MIT License | 5 votes |
/** * Creates a {@link BeanDefinitionBuilder} instance for the * {@link #getBeanClass bean Class} and passes it to the * {@link #doParse} strategy method. * @param element the element that is to be parsed into a single BeanDefinition * @param parserContext the object encapsulating the current state of the parsing process * @return the BeanDefinition resulting from the parsing of the supplied {@link Element} * @throws IllegalStateException if the bean {@link Class} returned from * {@link #getBeanClass(org.w3c.dom.Element)} is {@code null} * @see #doParse */ @Override protected final AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(); String parentName = getParentName(element); if (parentName != null) { builder.getRawBeanDefinition().setParentName(parentName); } Class<?> beanClass = getBeanClass(element); if (beanClass != null) { builder.getRawBeanDefinition().setBeanClass(beanClass); } else { String beanClassName = getBeanClassName(element); if (beanClassName != null) { builder.getRawBeanDefinition().setBeanClassName(beanClassName); } } builder.getRawBeanDefinition().setSource(parserContext.extractSource(element)); BeanDefinition containingBd = parserContext.getContainingBeanDefinition(); if (containingBd != null) { // Inner bean definition must receive same scope as containing bean. builder.setScope(containingBd.getScope()); } if (parserContext.isDefaultLazyInit()) { // Default-lazy-init applies to custom bean definitions as well. builder.setLazyInit(true); } doParse(element, parserContext, builder); return builder.getBeanDefinition(); }
Example 15
Source File: ScaleInfoToBeanDefinitionConverter.java From geomajas-project-server with GNU Affero General Public License v3.0 | 4 votes |
public BeanDefinition convert(ScaleInfo source) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ScaleInfo.class); builder.addPropertyValue("pixelPerUnit", source.getPixelPerUnit()); return builder.getBeanDefinition(); }
Example 16
Source File: SnsOutboundGatewayParser.java From spring-integration-aws with MIT License | 4 votes |
@Override protected BeanDefinitionBuilder parseHandler(Element gatewayElement, ParserContext parserContext) { final BeanDefinitionBuilder snsOutboundGatewayBuilder = BeanDefinitionBuilder .genericBeanDefinition(SnsOutboundGateway.class); IntegrationNamespaceUtils.setValueIfAttributeDefined( snsOutboundGatewayBuilder, gatewayElement, "reply-timeout", "sendTimeout"); final String replyChannel = gatewayElement .getAttribute("reply-channel"); if (StringUtils.hasText(replyChannel)) { snsOutboundGatewayBuilder.addPropertyReference("outputChannel", replyChannel); } final BeanDefinitionBuilder snsExecutorBuilder = SnsParserUtils .getSnsExecutorBuilder(gatewayElement, parserContext); final BeanDefinition snsExecutorBuilderBeanDefinition = snsExecutorBuilder .getBeanDefinition(); final String gatewayId = this .resolveId(gatewayElement, snsOutboundGatewayBuilder.getRawBeanDefinition(), parserContext); final String snsExecutorBeanName = gatewayId + ".snsExecutor"; SnsParserUtils.registerSubscriptions(gatewayElement, parserContext, snsExecutorBuilder, gatewayId); parserContext.registerBeanComponent(new BeanComponentDefinition( snsExecutorBuilderBeanDefinition, snsExecutorBeanName)); snsOutboundGatewayBuilder.addPropertyReference("snsExecutor", snsExecutorBeanName); SnsParserUtils.registerExecutorProxy(gatewayElement, snsExecutorBeanName, parserContext); AwsParserUtils.registerPermissions(gatewayElement, snsExecutorBuilder, parserContext); return snsOutboundGatewayBuilder; }
Example 17
Source File: DataSourceBeanDefinitionParser.java From shardingsphere with Apache License 2.0 | 4 votes |
@Override protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) { BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(OrchestrationSpringShardingSphereDataSource.class); configureFactory(element, factory); return factory.getBeanDefinition(); }
Example 18
Source File: SoaServiceBeanDefinitionParser.java From dapeng-soa with Apache License 2.0 | 4 votes |
@Override public BeanDefinition parse(Element element, ParserContext parserContext) { String id = element.getAttribute("id"); String ref = element.getAttribute("ref"); if (StringUtils.isBlank(id)) { id = ref + "_SoaProcessor"; } BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(SoaProcessorFactory.class); builder.addConstructorArgReference(ref); builder.addConstructorArgValue(ref); AbstractBeanDefinition beanDefinition = builder.getBeanDefinition(); parserContext.getRegistry().registerBeanDefinition(id, beanDefinition); return beanDefinition; }
Example 19
Source File: DubboConfigBindingRegistrar.java From dubbo-2.6.5 with Apache License 2.0 | 3 votes |
private void registerDubboConfigBean(String beanName, Class<? extends AbstractConfig> configClass, BeanDefinitionRegistry registry) { BeanDefinitionBuilder builder = rootBeanDefinition(configClass); AbstractBeanDefinition beanDefinition = builder.getBeanDefinition(); registry.registerBeanDefinition(beanName, beanDefinition); if (log.isInfoEnabled()) { log.info("The dubbo config bean definition [name : " + beanName + ", class : " + configClass.getName() + "] has been registered."); } }
Example 20
Source File: SpringContextUtil.java From nimrod with MIT License | 3 votes |
public static void registerBean(String beanId, String className) { ConfigurableApplicationContext configurableContext = (ConfigurableApplicationContext) getApplicationContext(); BeanDefinitionRegistry beanDefinitionRegistry = (DefaultListableBeanFactory) configurableContext.getBeanFactory(); BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(className); // get the BeanDefinition BeanDefinition beanDefinition = beanDefinitionBuilder.getBeanDefinition(); // register the bean beanDefinitionRegistry.registerBeanDefinition(beanId, beanDefinition); }