org.springframework.beans.factory.xml.AbstractBeanDefinitionParser Java Examples
The following examples show how to use
org.springframework.beans.factory.xml.AbstractBeanDefinitionParser.
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: ZkCacheResourceBeanDefinitionParser.java From cloud-config with MIT License | 6 votes |
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { String path = element.getAttribute("path"); builder.addPropertyValue("path", path); // set bean alias element.setAttribute(AbstractBeanDefinitionParser.NAME_ATTRIBUTE, BeanIdGenerator.getMemcachedBeanId(path)); String cacheName = element.getAttribute("cache-name"); builder.addPropertyValue("cacheName", cacheName); String resolverBeanName = element.getAttribute("resolver-ref"); if(StringUtils.hasLength(resolverBeanName) && parserContext.getRegistry().containsBeanDefinition(resolverBeanName)) { builder.addPropertyReference("resolver", resolverBeanName); } String validatorBeanName = element.getAttribute("validator-ref"); if(StringUtils.hasLength(validatorBeanName) && parserContext.getRegistry().containsBeanDefinition(validatorBeanName)) { builder.addPropertyReference("validator", validatorBeanName); } }
Example #2
Source File: LdapTemplateParser.java From spring-ldap with Apache License 2.0 | 6 votes |
@Override public BeanDefinition parse(Element element, ParserContext parserContext) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(LdapTemplate.class); String contextSourceRef = getString(element, ATT_CONTEXT_SOURCE_REF, ContextSourceParser.DEFAULT_ID); builder.addPropertyReference("contextSource", contextSourceRef); builder.addPropertyValue("defaultCountLimit", getInt(element, ATT_COUNT_LIMIT, DEFAULT_COUNT_LIMIT)); builder.addPropertyValue("defaultTimeLimit", getInt(element, ATT_TIME_LIMIT, DEFAULT_TIME_LIMIT)); String searchScope = getString(element, ATT_SEARCH_SCOPE, SearchScope.SUBTREE.toString()); builder.addPropertyValue("defaultSearchScope", SearchScope.valueOf(searchScope).getId()); builder.addPropertyValue("ignorePartialResultException", getBoolean(element, ATT_IGNORE_PARTIAL_RESULT, false)); builder.addPropertyValue("ignoreNameNotFoundException", getBoolean(element, ATT_IGNORE_NAME_NOT_FOUND, false)); String odmRef = element.getAttribute(ATT_ODM_REF); if(StringUtils.hasText(odmRef)) { builder.addPropertyReference("objectDirectoryMapper", odmRef); } String id = getString(element, AbstractBeanDefinitionParser.ID_ATTRIBUTE, DEFAULT_ID); BeanDefinition beanDefinition = builder.getBeanDefinition(); parserContext.registerBeanComponent(new BeanComponentDefinition(beanDefinition, id)); return beanDefinition; }
Example #3
Source File: ZkJdbcDataSourceBeanDefinitionParser.java From cloud-config with MIT License | 5 votes |
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { String path = element.getAttribute("path"); // add alias for data source bean element.setAttribute(AbstractBeanDefinitionParser.NAME_ATTRIBUTE, BeanIdGenerator.getDataSourceBeanId(path)); String resourceType = element.getAttribute("resource-type"); boolean autoReload = getSafeBoolean(element.getAttribute("auto-reload")); boolean routingSupport = getSafeBoolean(element.getAttribute("routing-support")); String validatorBeanName = element.getAttribute("validator-ref"); if (routingSupport) { String fallbackDsPath = element.getAttribute("fallback"); String resolverBeanName = element.getAttribute("resolver-ref"); if(!parserContext.getRegistry().containsBeanDefinition(resolverBeanName)) { throw new IllegalArgumentException("Undefined routing key resolver"); } if ("BoneCP".equals(resourceType)) { builder.addPropertyValue("resourceFactoryBeanClass", BoneCPDataSourceFactoryBean.class.getName()); } else if ("C3P0".equals(resourceType)) { builder.addPropertyValue("resourceFactoryBeanClass", C3P0DataSourceFactoryBean.class.getName()); } else if ("Druid".equals(resourceType)) { builder.addPropertyValue("resourceFactoryBeanClass", DruidDataSourceFactoryBean.class.getName()); } else { throw new UnsupportedOperationException("Unsupported resource type "+resourceType); } builder.addPropertyReference("resolver", resolverBeanName); builder.addPropertyValue("path", path); builder.addPropertyReference("client", CloudConfigCommon.ZK_CLIENT_BEAN_NAME); if(StringUtils.hasLength(fallbackDsPath)) { builder.addPropertyValue("fallbackDataSourcePath", fallbackDsPath); } } else { builder.addPropertyValue("configPath", path); } if(StringUtils.hasText(validatorBeanName) && parserContext.getRegistry().containsBeanDefinition(validatorBeanName)) { builder.addPropertyReference("validator", validatorBeanName); } builder.addPropertyValue("autoReload", autoReload); }
Example #4
Source File: ZkResourceBeanDefinitionParser.java From cloud-config with MIT License | 5 votes |
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { String path = element.getAttribute("path"); String resourceType = element.getAttribute("resource-type"); element.setAttribute(AbstractBeanDefinitionParser.NAME_ATTRIBUTE, getBeanAliasByType(resourceType, path)); boolean autoReload = getSafeBoolean(element.getAttribute("auto-reload")); boolean routingSupport = getSafeBoolean(element.getAttribute("routing-support")); String validatorBeanName = element.getAttribute("validator-ref"); if(routingSupport) { String fallbackRsPath = element.getAttribute("fallback"); String resolverBeanName = element.getAttribute("resolver-ref"); if(!parserContext.getRegistry().containsBeanDefinition(resolverBeanName)) { throw new IllegalArgumentException("Undefined routing key resolver"); } builder.addPropertyValue("path", path); builder.addPropertyReference("client", CloudConfigCommon.ZK_CLIENT_BEAN_NAME); builder.addPropertyReference("resolver", resolverBeanName); builder.addPropertyValue("resourceFactoryBeanClass", getFactoryBeanClassByType(resourceType, false)); if(StringUtils.hasLength(fallbackRsPath)) { builder.addPropertyValue("fallbackResourcePath", fallbackRsPath); } } else { builder.addPropertyValue("configPath", path); } if(StringUtils.hasLength(validatorBeanName) && parserContext.getRegistry().containsBeanDefinition(validatorBeanName)) { builder.addPropertyReference("validator", validatorBeanName); } builder.addPropertyValue("autoReload", autoReload); }
Example #5
Source File: TransactionManagerParser.java From spring-ldap with Apache License 2.0 | 4 votes |
@Override public BeanDefinition parse(Element element, ParserContext parserContext) { String contextSourceRef = getString(element, ATT_CONTEXT_SOURCE_REF, ContextSourceParser.DEFAULT_ID); String dataSourceRef = element.getAttribute(ATT_DATA_SOURCE_REF); String sessionFactoryRef = element.getAttribute(ATT_SESSION_FACTORY_REF); if(StringUtils.hasText(dataSourceRef) && StringUtils.hasText(sessionFactoryRef)) { throw new IllegalArgumentException( String.format("Only one of %s and %s can be specified", ATT_DATA_SOURCE_REF, ATT_SESSION_FACTORY_REF)); } BeanDefinitionBuilder builder; if(StringUtils.hasText(dataSourceRef)) { builder = BeanDefinitionBuilder.rootBeanDefinition(ContextSourceAndDataSourceTransactionManager.class); builder.addPropertyReference("dataSource", dataSourceRef); } else if(StringUtils.hasText(sessionFactoryRef)) { builder = BeanDefinitionBuilder.rootBeanDefinition(ContextSourceAndHibernateTransactionManager.class); builder.addPropertyReference("sessionFactory", sessionFactoryRef); } else { // Standard transaction manager builder = BeanDefinitionBuilder.rootBeanDefinition(ContextSourceTransactionManager.class); } builder.addPropertyReference("contextSource", contextSourceRef); Element defaultStrategyChild = DomUtils.getChildElementByTagName(element, Elements.DEFAULT_RENAMING_STRATEGY); Element differentSubtreeChild = DomUtils.getChildElementByTagName(element, Elements.DIFFERENT_SUBTREE_RENAMING_STRATEGY); if(defaultStrategyChild != null) { builder.addPropertyValue("renamingStrategy", parseDefaultRenamingStrategy(defaultStrategyChild)); } if(differentSubtreeChild != null) { builder.addPropertyValue("renamingStrategy", parseDifferentSubtreeRenamingStrategy(differentSubtreeChild)); } String id = getString(element, AbstractBeanDefinitionParser.ID_ATTRIBUTE, DEFAULT_ID); BeanDefinition beanDefinition = builder.getBeanDefinition(); parserContext.registerBeanComponent(new BeanComponentDefinition(beanDefinition, id)); return beanDefinition; }
Example #6
Source File: ContextSourceParser.java From spring-ldap with Apache License 2.0 | 4 votes |
@Override public BeanDefinition parse(Element element, ParserContext parserContext) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(LdapContextSource.class); String username = element.getAttribute(ATT_USERNAME); String password = element.getAttribute(ATT_PASSWORD); String url = element.getAttribute(ATT_URL); Assert.hasText(url, "url attribute must be specified"); builder.addPropertyValue("userDn", username); builder.addPropertyValue("password", password); BeanDefinitionBuilder urlsBuilder = BeanDefinitionBuilder .rootBeanDefinition(UrlsFactory.class) .setFactoryMethod("urls") .addConstructorArgValue(url); builder.addPropertyValue("urls", urlsBuilder.getBeanDefinition()); builder.addPropertyValue("base", getString(element, ATT_BASE, "")); builder.addPropertyValue("referral", getString(element, ATT_REFERRAL, null)); boolean anonymousReadOnly = getBoolean(element, ATT_ANONYMOUS_READ_ONLY, false); builder.addPropertyValue("anonymousReadOnly", anonymousReadOnly); boolean nativePooling = getBoolean(element, ATT_NATIVE_POOLING, false); builder.addPropertyValue("pooled", nativePooling); String authStrategyRef = element.getAttribute(ATT_AUTHENTICATION_STRATEGY_REF); if(StringUtils.hasText(authStrategyRef)) { builder.addPropertyReference("authenticationStrategy", authStrategyRef); } String authSourceRef = element.getAttribute(ATT_AUTHENTICATION_SOURCE_REF); if(StringUtils.hasText(authSourceRef)) { builder.addPropertyReference("authenticationSource", authSourceRef); } else { Assert.hasText(username, "username attribute must be specified unless an authentication-source-ref explicitly configured"); Assert.hasText(password, "password attribute must be specified unless an authentication-source-ref explicitly configured"); } String baseEnvPropsRef = element.getAttribute(ATT_BASE_ENV_PROPS_REF); if(StringUtils.hasText(baseEnvPropsRef)) { builder.addPropertyReference("baseEnvironmentProperties", baseEnvPropsRef); } BeanDefinition targetContextSourceDefinition = builder.getBeanDefinition(); targetContextSourceDefinition = applyPoolingIfApplicable(targetContextSourceDefinition, element, nativePooling); BeanDefinition actualContextSourceDefinition = targetContextSourceDefinition; if (!anonymousReadOnly) { BeanDefinitionBuilder proxyBuilder = BeanDefinitionBuilder.rootBeanDefinition(TransactionAwareContextSourceProxy.class); proxyBuilder.addConstructorArgValue(targetContextSourceDefinition); actualContextSourceDefinition = proxyBuilder.getBeanDefinition(); } String id = getString(element, AbstractBeanDefinitionParser.ID_ATTRIBUTE, DEFAULT_ID); parserContext.registerBeanComponent(new BeanComponentDefinition(actualContextSourceDefinition, id)); return actualContextSourceDefinition; }