Java Code Examples for org.springframework.beans.factory.support.BeanDefinitionBuilder#addPropertyValue()
The following examples show how to use
org.springframework.beans.factory.support.BeanDefinitionBuilder#addPropertyValue() .
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: PropertySourcesPlaceholderConfigurerConfigBean.java From config-toolkit with Apache License 2.0 | 6 votes |
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { builder.addPropertyValue("order", Integer.parseInt(element.getAttribute("order"))); builder.addPropertyValue("ignoreUnresolvablePlaceholders", Boolean.valueOf(element.getAttribute("ignore-unresolvable-placeholders"))); List<Object> list = parserContext.getDelegate().parseListElement(element, builder.getRawBeanDefinition()); // Register property sources BeanDefinitionBuilder configGroupSourceFactoryBuilder = BeanDefinitionBuilder.genericBeanDefinition(ConfigGroupSourceFactory.class); configGroupSourceFactoryBuilder.setFactoryMethod("create"); configGroupSourceFactoryBuilder.addConstructorArgValue(list); String generatedSourceFactoryName = parserContext.getReaderContext().generateBeanName(configGroupSourceFactoryBuilder.getRawBeanDefinition()); parserContext .registerBeanComponent(new BeanComponentDefinition(configGroupSourceFactoryBuilder.getBeanDefinition(), generatedSourceFactoryName)); builder.addPropertyValue("propertySources", new RuntimeBeanReference(generatedSourceFactoryName)); }
Example 2
Source File: CuratorFrameworkBeanDefinitionParser.java From zookeeper-spring with Apache License 2.0 | 6 votes |
@Override protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { final BeanDefinitionBuilder beanDefBuilder = BeanDefinitionBuilder.rootBeanDefinition(CuratorFrameworkFactoryBean.class); beanDefBuilder.setRole(ROLE_APPLICATION); beanDefBuilder.getRawBeanDefinition().setSource(parserContext.extractSource(element)); beanDefBuilder.addPropertyValue("connectString", element.getAttribute("connect-string")); Element retryPolicyElement = DomUtils.getChildElementByTagName(element, "retry-policy"); if (retryPolicyElement != null) { Element retryPolicyBeanElement = DomUtils.getChildElements(retryPolicyElement).get(0); BeanDefinitionHolder retryPolicy = parserContext.getDelegate().parseBeanDefinitionElement(retryPolicyBeanElement, beanDefBuilder.getBeanDefinition()); beanDefBuilder.addPropertyValue("retryPolicy", retryPolicy); } Node namespace = element.getAttributeNode("namespace"); if (namespace != null) { beanDefBuilder.addPropertyValue("namespace", namespace.getNodeValue()); } return beanDefBuilder.getBeanDefinition(); }
Example 3
Source File: TxAdviceBeanDefinitionParser.java From lams with GNU General Public License v2.0 | 6 votes |
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { builder.addPropertyReference("transactionManager", TxNamespaceHandler.getTransactionManagerName(element)); List<Element> txAttributes = DomUtils.getChildElementsByTagName(element, ATTRIBUTES_ELEMENT); if (txAttributes.size() > 1) { parserContext.getReaderContext().error( "Element <attributes> is allowed at most once inside element <advice>", element); } else if (txAttributes.size() == 1) { // Using attributes source. Element attributeSourceElement = txAttributes.get(0); RootBeanDefinition attributeSourceDefinition = parseAttributeSource(attributeSourceElement, parserContext); builder.addPropertyValue("transactionAttributeSource", attributeSourceDefinition); } else { // Assume annotations source. builder.addPropertyValue("transactionAttributeSource", new RootBeanDefinition("org.springframework.transaction.annotation.AnnotationTransactionAttributeSource")); } }
Example 4
Source File: ScheduleModule.java From bulbasaur with Apache License 2.0 | 6 votes |
private void registerJobDetail( String ownSign, String targetObject, String targetMethod, String jobDetailBeanName ) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition( JobDetailFactoryBean.class); builder.addPropertyValue("jobClass", MyDetailQuartzJobBean.class); builder.addPropertyValue("group", ownSign); //durability 表示任务完成之后是否依然保留到数据库,默认false builder.addPropertyValue("durability", "true"); Map<String, String> jobDataAsMap = Maps.newHashMap(); jobDataAsMap.put("targetObject", targetObject); jobDataAsMap.put("targetMethod", targetMethod); builder.addPropertyValue("jobDataAsMap", jobDataAsMap); registry.registerBeanDefinition(jobDetailBeanName, builder.getRawBeanDefinition()); }
Example 5
Source File: JndiLookupBeanDefinitionParser.java From lams with GNU General Public License v2.0 | 6 votes |
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { super.doParse(element, parserContext, builder); String defaultValue = element.getAttribute(DEFAULT_VALUE); String defaultRef = element.getAttribute(DEFAULT_REF); if (StringUtils.hasLength(defaultValue)) { if (StringUtils.hasLength(defaultRef)) { parserContext.getReaderContext().error("<jndi-lookup> element is only allowed to contain either " + "'default-value' attribute OR 'default-ref' attribute, not both", element); } builder.addPropertyValue(DEFAULT_OBJECT, defaultValue); } else if (StringUtils.hasLength(defaultRef)) { builder.addPropertyValue(DEFAULT_OBJECT, new RuntimeBeanReference(defaultRef)); } }
Example 6
Source File: UtilNamespaceHandler.java From lams with GNU General Public License v2.0 | 5 votes |
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { Map<Object, Object> parsedMap = parserContext.getDelegate().parseMapElement(element, builder.getRawBeanDefinition()); builder.addPropertyValue("sourceMap", parsedMap); String mapClass = element.getAttribute("map-class"); if (StringUtils.hasText(mapClass)) { builder.addPropertyValue("targetMapClass", mapClass); } String scope = element.getAttribute(SCOPE_ATTRIBUTE); if (StringUtils.hasLength(scope)) { builder.setScope(scope); } }
Example 7
Source File: EncryptablePropertyOverrideBeanDefinitionParser.java From jasypt with Apache License 2.0 | 5 votes |
@Override protected void doParse(final Element element, final BeanDefinitionBuilder builder) { super.doParse(element, builder); builder.addPropertyValue("ignoreInvalidKeys", Boolean.valueOf(element.getAttribute("ignore-unresolvable"))); final String encryptorBeanName = element.getAttribute(ENCRYPTOR_ATTRIBUTE); if (StringUtils.hasText(encryptorBeanName)) { builder.addConstructorArgReference(encryptorBeanName); } }
Example 8
Source File: EmbeddedDatabaseBeanDefinitionParser.java From java-technology-stack with MIT License | 5 votes |
private void setDatabaseName(Element element, BeanDefinitionBuilder builder) { // 1) Check for an explicit database name String name = element.getAttribute(DB_NAME_ATTRIBUTE); // 2) Fall back to an implicit database name based on the ID if (!StringUtils.hasText(name)) { name = element.getAttribute(ID_ATTRIBUTE); } if (StringUtils.hasText(name)) { builder.addPropertyValue("databaseName", name); } // else, let EmbeddedDatabaseFactory use the default "testdb" name }
Example 9
Source File: AbstractEncryptionBeanDefinitionParser.java From jasypt with Apache License 2.0 | 5 votes |
protected final void processIntegerAttribute(final Element element, final BeanDefinitionBuilder builder, final String attributeName, final String propertyName) { final String attributeValue = element.getAttribute(attributeName); if (StringUtils.hasText(attributeValue)) { try { final Integer attributeIntegerValue = Integer.valueOf(attributeValue); builder.addPropertyValue(propertyName, attributeIntegerValue); } catch (final NumberFormatException e) { throw new NumberFormatException( "Config attribute \"" + attributeName + "\" is not a valid integer"); } } }
Example 10
Source File: ZkClientBeanDefinitionParser.java From cloud-config with MIT License | 5 votes |
@Override protected void doParse(Element element, BeanDefinitionBuilder builder) { String connectionString = element.getAttribute("connection-string"); if(StringUtils.hasLength(connectionString)) { builder.addPropertyValue("connectionString", connectionString); } String credentialString = element.getAttribute("credential-string"); if(StringUtils.hasLength(credentialString)) { builder.addPropertyValue("credentialString", credentialString); } Integer maxRetries = getSafeInteger(element.getAttribute("max-retries")); if(maxRetries!=null) { builder.addPropertyValue("maxRetries", maxRetries); } Integer baseSleepTime = getSafeInteger(element.getAttribute("base-sleep-time")); if(baseSleepTime!=null) { builder.addPropertyValue("baseSleepTime", baseSleepTime); } Boolean readOnly = getSafeBoolean(element.getAttribute("read-only")); if(readOnly!=null) { builder.addPropertyValue("canReadOnly", readOnly); } }
Example 11
Source File: MaintenanceFieldBeanDefinitionParser.java From kfs with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void doParse(Element element, ParserContext context, BeanDefinitionBuilder bean) { // get all attributes String attributeName = element.getAttribute("attributeName"); String required = element.getAttribute("required"); String unconditionallyReadOnly = element.getAttribute("unconditionallyReadOnly"); String defaultValue = element.getAttribute("defaultValue"); String defaultValueFinderClass = element.getAttribute("defaultValueFinderClass"); String javascriptLeaveFieldFunction = element.getAttribute("javascriptLeaveFieldFunction"); String javascriptLeaveFieldCallbackFunction = element.getAttribute("javascriptLeaveFieldCallbackFunction"); // now, set on the bean definition if ( StringUtils.hasText(attributeName) ) { bean.addPropertyValue("name", attributeName); } if ( StringUtils.hasText(required) ) { bean.addPropertyValue("required", Boolean.parseBoolean(required)); } if ( StringUtils.hasText(unconditionallyReadOnly) ) { bean.addPropertyValue("unconditionallyReadOnly", Boolean.parseBoolean(unconditionallyReadOnly)); } if ( StringUtils.hasText(defaultValue) ) { bean.addPropertyValue("defaultValue", defaultValue); } else if ( StringUtils.hasText(defaultValueFinderClass) ) { bean.addPropertyValue("defaultValueFinderClass", defaultValueFinderClass); } if ( StringUtils.hasText(javascriptLeaveFieldFunction) ) { bean.addPropertyValue("webUILeaveFieldFunction", javascriptLeaveFieldFunction); } if ( StringUtils.hasText(javascriptLeaveFieldCallbackFunction) ) { bean.addPropertyValue("webUILeaveFieldCallbackFunction", javascriptLeaveFieldCallbackFunction); } // handle any other simple child properties parseEmbeddedPropertyElements(element, bean); }
Example 12
Source File: GreenMailBeanDefinitionParser.java From greenmail with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override protected void doParse(final Element element, final BeanDefinitionBuilder builder) { builder.addPropertyValue("hostname", extractHostname(element)); builder.addPropertyValue("portOffset", extractPortOffset(element)); builder.addPropertyValue("serverStartupTimeout", extractServerStartupTimeout(element)); }
Example 13
Source File: EndpointDefinitionParser.java From cxf with Apache License 2.0 | 5 votes |
private void loadImplementor(BeanDefinitionBuilder bean, String val) { if (!StringUtils.isEmpty(val)) { bean.addPropertyValue("checkBlockConstruct", Boolean.TRUE); if (val.startsWith("#")) { bean.addConstructorArgReference(val.substring(1)); } else { bean.addConstructorArgValue(BeanDefinitionBuilder .genericBeanDefinition(val).getBeanDefinition()); } } }
Example 14
Source File: UtilNamespaceHandler.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { List<Object> parsedList = parserContext.getDelegate().parseListElement(element, builder.getRawBeanDefinition()); builder.addPropertyValue("sourceList", parsedList); String listClass = element.getAttribute("list-class"); if (StringUtils.hasText(listClass)) { builder.addPropertyValue("targetListClass", listClass); } String scope = element.getAttribute(SCOPE_ATTRIBUTE); if (StringUtils.hasLength(scope)) { builder.setScope(scope); } }
Example 15
Source File: AbstractEncryptablePropertyLoadingBeanDefinitionParser.java From jasypt with Apache License 2.0 | 5 votes |
@Override protected void doParse(final Element element, final BeanDefinitionBuilder builder) { String location = element.getAttribute("location"); if (StringUtils.hasLength(location)) { String[] locations = StringUtils.commaDelimitedListToStringArray(location); builder.addPropertyValue("locations", locations); } String propertiesRef = element.getAttribute("properties-ref"); if (StringUtils.hasLength(propertiesRef)) { builder.addPropertyReference("properties", propertiesRef); } String fileEncoding = element.getAttribute("file-encoding"); if (StringUtils.hasLength(fileEncoding)) { builder.addPropertyReference("fileEncoding", fileEncoding); } String order = element.getAttribute("order"); if (StringUtils.hasLength(order)) { builder.addPropertyValue("order", Integer.valueOf(order)); } builder.addPropertyValue("ignoreResourceNotFound", Boolean.valueOf(element.getAttribute("ignore-resource-not-found"))); builder.addPropertyValue("localOverride", Boolean.valueOf(element.getAttribute("local-override"))); builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); }
Example 16
Source File: EmbeddedDatabaseBeanDefinitionParser.java From spring4-understanding with Apache License 2.0 | 4 votes |
private void setGenerateUniqueDatabaseNameFlag(Element element, BeanDefinitionBuilder builder) { String generateName = element.getAttribute(GENERATE_NAME_ATTRIBUTE); if (StringUtils.hasText(generateName)) { builder.addPropertyValue("generateUniqueDatabaseName", generateName); } }
Example 17
Source File: ShardingJdbcDataSourceBeanDefinitionParser.java From sharding-jdbc-1.5.1 with Apache License 2.0 | 4 votes |
private void parseKeyGenerator(final BeanDefinitionBuilder factory, final Element element) { String keyGeneratorClass = element.getAttribute(ShardingJdbcDataSourceBeanDefinitionParserTag.KEY_GENERATOR_CLASS); if (!Strings.isNullOrEmpty(keyGeneratorClass)) { factory.addPropertyValue("keyGeneratorClass", keyGeneratorClass); } }
Example 18
Source File: AnnotationDrivenJmsBeanDefinitionParser.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override public BeanDefinition parse(Element element, ParserContext parserContext) { Object source = parserContext.extractSource(element); // Register component for the surrounding <jms:annotation-driven> element. CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source); parserContext.pushContainingComponent(compDefinition); // Nest the concrete post-processor bean in the surrounding component. BeanDefinitionRegistry registry = parserContext.getRegistry(); if (registry.containsBeanDefinition(JmsListenerConfigUtils.JMS_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME)) { parserContext.getReaderContext().error( "Only one JmsListenerAnnotationBeanPostProcessor may exist within the context.", source); } else { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition( "org.springframework.jms.annotation.JmsListenerAnnotationBeanPostProcessor"); builder.getRawBeanDefinition().setSource(source); String endpointRegistry = element.getAttribute("registry"); if (StringUtils.hasText(endpointRegistry)) { builder.addPropertyReference("endpointRegistry", endpointRegistry); } else { registerDefaultEndpointRegistry(source, parserContext); } String containerFactory = element.getAttribute("container-factory"); if (StringUtils.hasText(containerFactory)) { builder.addPropertyValue("containerFactoryBeanName", containerFactory); } String handlerMethodFactory = element.getAttribute("handler-method-factory"); if (StringUtils.hasText(handlerMethodFactory)) { builder.addPropertyReference("messageHandlerMethodFactory", handlerMethodFactory); } registerInfrastructureBean(parserContext, builder, JmsListenerConfigUtils.JMS_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME); } // Finally register the composite component. parserContext.popAndRegisterContainingComponent(); return null; }
Example 19
Source File: EmbeddedDatabaseBeanDefinitionParser.java From java-technology-stack with MIT License | 4 votes |
private void setDatabaseType(Element element, BeanDefinitionBuilder builder) { String type = element.getAttribute("type"); if (StringUtils.hasText(type)) { builder.addPropertyValue("databaseType", type); } }
Example 20
Source File: AbstractSimpleBeanDefinitionParser.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Parse the supplied {@link Element} and populate the supplied * {@link BeanDefinitionBuilder} as required. * <p>This implementation maps any attributes present on the * supplied element to {@link org.springframework.beans.PropertyValue} * instances, and * {@link BeanDefinitionBuilder#addPropertyValue(String, Object) adds them} * to the * {@link org.springframework.beans.factory.config.BeanDefinition builder}. * <p>The {@link #extractPropertyName(String)} method is used to * reconcile the name of an attribute with the name of a JavaBean * property. * @param element the XML element being parsed * @param builder used to define the {@code BeanDefinition} * @see #extractPropertyName(String) */ @Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { NamedNodeMap attributes = element.getAttributes(); for (int x = 0; x < attributes.getLength(); x++) { Attr attribute = (Attr) attributes.item(x); if (isEligibleAttribute(attribute, parserContext)) { String propertyName = extractPropertyName(attribute.getLocalName()); Assert.state(StringUtils.hasText(propertyName), "Illegal property name returned from 'extractPropertyName(String)': cannot be null or empty."); builder.addPropertyValue(propertyName, attribute.getValue()); } } postProcess(builder, element); }