private String createJobConfiguration(final Element element, final ParserContext parserContext) { BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(getJobConfigurationDTO()); factory.addConstructorArgValue(element.getAttribute(ID_ATTRIBUTE)); if (!getJobConfigurationDTO().isAssignableFrom(ScriptJobConfigurationDto.class)) { factory.addConstructorArgValue(element.getAttribute(CLASS_ATTRIBUTE)); } factory.addConstructorArgValue(element.getAttribute(SHARDING_TOTAL_COUNT_ATTRIBUTE)); factory.addConstructorArgValue(element.getAttribute(CRON_ATTRIBUTE)); if (getJobConfigurationDTO().isAssignableFrom(ScriptJobConfigurationDto.class)) { factory.addConstructorArgValue(element.getAttribute(SCRIPT_COMMAND_LINE_ATTRIBUTE)); } addPropertyValueIfNotEmpty( SHARDING_ITEM_PARAMETERS_ATTRIBUTE, "shardingItemParameters", element, factory); addPropertyValueIfNotEmpty(JOB_PARAMETER_ATTRIBUTE, "jobParameter", element, factory); addPropertyValueIfNotEmpty(MONITOR_EXECUTION_ATTRIBUTE, "monitorExecution", element, factory); addPropertyValueIfNotEmpty(MONITOR_PORT_ATTRIBUTE, "monitorPort", element, factory); addPropertyValueIfNotEmpty( MAX_TIME_DIFF_SECONDS_ATTRIBUTE, "maxTimeDiffSeconds", element, factory); addPropertyValueIfNotEmpty(FAILOVER_ATTRIBUTE, "failover", element, factory); addPropertyValueIfNotEmpty(MISFIRE_ATTRIBUTE, "misfire", element, factory); addPropertyValueIfNotEmpty( JOB_SHARDING_STRATEGY_CLASS_ATTRIBUTE, "jobShardingStrategyClass", element, factory); addPropertyValueIfNotEmpty(DESCRIPTION_ATTRIBUTE, "description", element, factory); addPropertyValueIfNotEmpty(DISABLED_ATTRIBUTE, "disabled", element, factory); addPropertyValueIfNotEmpty(OVERWRITE_ATTRIBUTE, "overwrite", element, factory); setPropertiesValue(element, factory); String result = element.getAttribute(ID_ATTRIBUTE) + "Conf"; parserContext.getRegistry().registerBeanDefinition(result, factory.getBeanDefinition()); return result; }
@Override protected void doParse( Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { super.doParse(element, parserContext, builder); BeanDefinitionBuilder redisConfigBeanBuilder = BeanDefinitionBuilder.genericBeanDefinition(RedisConnectionFactoryConfig.class.getName()); BeanDefinition cloudPoolConfiguration = null; Element poolElement = DomUtils.getChildElementByTagName(element, ELEMENT_POOL); if (poolElement != null) { cloudPoolConfiguration = parsePoolElement(poolElement, parserContext); } redisConfigBeanBuilder.addConstructorArgValue(cloudPoolConfiguration); Element propertiesElement = DomUtils.getChildElementByTagName(element, CONNECTION_PROPERTIES); if (propertiesElement != null) { Map<?, ?> properties = parserContext .getDelegate() .parseMapElement(propertiesElement, builder.getRawBeanDefinition()); redisConfigBeanBuilder.addConstructorArgValue(properties); } builder.addConstructorArgValue(redisConfigBeanBuilder.getBeanDefinition()); }
@Override protected void doParse( Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { String exchangeName = element.getAttribute(NAME_ATTRIBUTE); builder.addConstructorArgValue(new TypedStringValue(exchangeName)); parseBindings(element, parserContext, builder, exchangeName); NamespaceUtils.addConstructorArgBooleanValueIfAttributeDefined( builder, element, DURABLE_ATTRIBUTE, true); NamespaceUtils.addConstructorArgBooleanValueIfAttributeDefined( builder, element, AUTO_DELETE_ATTRIBUTE, false); Element argumentsElement = DomUtils.getChildElementByTagName(element, ARGUMENTS_ELEMENT); if (argumentsElement != null) { String ref = argumentsElement.getAttribute(REF_ATTRIBUTE); Map<?, ?> map = parserContext .getDelegate() .parseMapElement(argumentsElement, builder.getRawBeanDefinition()); if (StringUtils.hasText(ref)) { if (map != null && map.size() > 0) { parserContext .getReaderContext() .error("You cannot have both a 'ref' and a nested map", element); } builder.addConstructorArgReference(ref); } else { builder.addConstructorArgValue(map); } } NamespaceUtils.parseDeclarationControls(element, builder); }
@Override protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) { final BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ContentEnricher.class); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "request-channel"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "reply-channel"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "request-timeout"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "reply-timeout"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "requires-reply"); List<Element> subElements = DomUtils.getChildElementsByTagName(element, "property"); if (!CollectionUtils.isEmpty(subElements)) { ManagedMap<String, Object> expressions = new ManagedMap<String, Object>(); for (Element subElement : subElements) { String name = subElement.getAttribute("name"); BeanDefinition beanDefinition = IntegrationNamespaceUtils.createExpressionDefinitionFromValueOrExpression( "value", "expression", parserContext, subElement, true); expressions.put(name, beanDefinition); } builder.addPropertyValue("propertyExpressions", expressions); } subElements = DomUtils.getChildElementsByTagName(element, "header"); if (!CollectionUtils.isEmpty(subElements)) { ManagedMap<String, Object> expressions = new ManagedMap<String, Object>(); for (Element subElement : subElements) { String name = subElement.getAttribute("name"); BeanDefinition expressionDefinition = IntegrationNamespaceUtils.createExpressionDefinitionFromValueOrExpression( "value", "expression", parserContext, subElement, true); BeanDefinitionBuilder valueProcessorBuilder = BeanDefinitionBuilder.genericBeanDefinition( IntegrationNamespaceUtils.BASE_PACKAGE + ".transformer.support.ExpressionEvaluatingHeaderValueMessageProcessor"); valueProcessorBuilder .addConstructorArgValue(expressionDefinition) .addConstructorArgValue(subElement.getAttribute("type")); IntegrationNamespaceUtils.setValueIfAttributeDefined( valueProcessorBuilder, subElement, "overwrite"); expressions.put(name, valueProcessorBuilder.getBeanDefinition()); } builder.addPropertyValue("headerExpressions", expressions); } IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "should-clone-payload"); String requestPayloadExpression = element.getAttribute("request-payload-expression"); if (StringUtils.hasText(requestPayloadExpression)) { BeanDefinitionBuilder expressionBuilder = BeanDefinitionBuilder.genericBeanDefinition(ExpressionFactoryBean.class); expressionBuilder.addConstructorArgValue(requestPayloadExpression); builder.addPropertyValue("requestPayloadExpression", expressionBuilder.getBeanDefinition()); } return builder; }
@Override protected void doParse( Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { String scriptLocation = element.getAttribute(LOCATION_ATTRIBUTE); String scriptText = DomUtils.getTextValue(element); if (!(StringUtils.hasText(scriptLocation) ^ StringUtils.hasText(scriptText))) { parserContext .getReaderContext() .error( "Either the 'location' attribute or inline script text must be provided, but not both.", element); return; } List<Element> variableElements = DomUtils.getChildElementsByTagName(element, "variable"); String scriptVariableGeneratorName = element.getAttribute("script-variable-generator"); if (StringUtils.hasText(scriptVariableGeneratorName) && variableElements.size() > 0) { parserContext .getReaderContext() .error( "'script-variable-generator' and 'variable' sub-elements are mutually exclusive.", element); return; } if (StringUtils.hasText(scriptLocation)) { builder.addConstructorArgValue( this.resolveScriptLocation(element, parserContext.getReaderContext(), scriptLocation)); } else { if (getScriptSourceClassName() != null) { builder.addConstructorArgValue( new StaticScriptSource(scriptText, getScriptSourceClassName())); } else { builder.addConstructorArgValue(new StaticScriptSource(scriptText)); } } BeanMetadataElement scriptVariableGeneratorDef = null; if (!StringUtils.hasText(scriptVariableGeneratorName)) { BeanDefinitionBuilder scriptVariableGeneratorBuilder = BeanDefinitionBuilder.genericBeanDefinition(DefaultScriptVariableGenerator.class); ManagedMap<String, Object> variableMap = buildVariablesMap(element, parserContext, variableElements); if (!CollectionUtils.isEmpty(variableMap)) { scriptVariableGeneratorBuilder.addConstructorArgValue(variableMap); } scriptVariableGeneratorDef = scriptVariableGeneratorBuilder.getBeanDefinition(); } else { scriptVariableGeneratorDef = new RuntimeBeanReference(scriptVariableGeneratorName); } builder.addConstructorArgValue(scriptVariableGeneratorDef); postProcess(builder, element, parserContext); }
/** * Create a new {@link BeanDefinitionBuilder} for the class {@link StoredProcExecutor}. Initialize * the wrapped {@link StoredProcExecutor} with common properties. * * @param element Must not be Null * @param parserContext Must not be Null * @return The {@link BeanDefinitionBuilder} for the {@link StoredProcExecutor} */ public static BeanDefinitionBuilder getStoredProcExecutorBuilder( final Element element, final ParserContext parserContext) { Assert.notNull(element, "The provided element must not be Null."); Assert.notNull(parserContext, "The provided parserContext must not be Null."); final String dataSourceRef = element.getAttribute("data-source"); final BeanDefinitionBuilder storedProcExecutorBuilder = BeanDefinitionBuilder.genericBeanDefinition(StoredProcExecutor.class); storedProcExecutorBuilder.addConstructorArgReference(dataSourceRef); final String storedProcedureName = element.getAttribute("stored-procedure-name"); final String storedProcedureNameExpression = element.getAttribute("stored-procedure-name-expression"); boolean hasStoredProcedureName = StringUtils.hasText(storedProcedureName); boolean hasStoredProcedureNameExpression = StringUtils.hasText(storedProcedureNameExpression); if (!(hasStoredProcedureName ^ hasStoredProcedureNameExpression)) { parserContext .getReaderContext() .error( "Exactly one of 'stored-procedure-name' or 'stored-procedure-name-expression' is required", element); } BeanDefinitionBuilder expressionBuilder; if (hasStoredProcedureNameExpression) { expressionBuilder = BeanDefinitionBuilder.genericBeanDefinition(ExpressionFactoryBean.class); expressionBuilder.addConstructorArgValue(storedProcedureNameExpression); } else { expressionBuilder = BeanDefinitionBuilder.genericBeanDefinition(LiteralExpression.class); expressionBuilder.addConstructorArgValue(storedProcedureName); } storedProcExecutorBuilder.addPropertyValue( "storedProcedureNameExpression", expressionBuilder.getBeanDefinition()); IntegrationNamespaceUtils.setValueIfAttributeDefined( storedProcExecutorBuilder, element, "ignore-column-meta-data"); IntegrationNamespaceUtils.setValueIfAttributeDefined( storedProcExecutorBuilder, element, "jdbc-call-operations-cache-size"); final ManagedList<BeanDefinition> procedureParameterList = StoredProcParserUtils.getProcedureParameterBeanDefinitions(element, parserContext); final ManagedList<BeanDefinition> sqlParameterDefinitionList = StoredProcParserUtils.getSqlParameterDefinitionBeanDefinitions(element, parserContext); if (!procedureParameterList.isEmpty()) { storedProcExecutorBuilder.addPropertyValue("procedureParameters", procedureParameterList); } if (!sqlParameterDefinitionList.isEmpty()) { storedProcExecutorBuilder.addPropertyValue("sqlParameters", sqlParameterDefinitionList); } return storedProcExecutorBuilder; }
private BeanDefinition parsePath(Element element, ParserContext parserContext) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(SearchPath.class); String type = defaultIfNull(trimToNull(element.getAttribute("type")), "relative"); String path = trimToEmpty(element.getTextContent()); builder.addConstructorArgValue(path); builder.addConstructorArgValue("relative".equals(type)); return builder.getBeanDefinition(); }
/** {@inheritDoc} */ protected void doParse(Element config, BeanDefinitionBuilder builder) { log.info("Parsing configuration for JSP error handler."); super.doParse(config, builder); if (config.hasAttributeNS(null, "jspPagePath")) { builder.addConstructorArgValue(config.getAttributeNS(null, "jspPagePath")); } else { builder.addConstructorArgValue(config.getAttributeNS(null, "/error.jsp")); } }
/** * @param storedProcComponent * @param parserContext */ public static ManagedList<BeanDefinition> getSqlParameterDefinitionBeanDefinitions( Element storedProcComponent, ParserContext parserContext) { List<Element> sqlParameterDefinitionChildElements = DomUtils.getChildElementsByTagName(storedProcComponent, "sql-parameter-definition"); ManagedList<BeanDefinition> sqlParameterList = new ManagedList<BeanDefinition>(); for (Element childElement : sqlParameterDefinitionChildElements) { String name = childElement.getAttribute("name"); String sqlType = childElement.getAttribute("type"); String direction = childElement.getAttribute("direction"); String scale = childElement.getAttribute("scale"); final BeanDefinitionBuilder parameterBuilder; if ("OUT".equalsIgnoreCase(direction)) { parameterBuilder = BeanDefinitionBuilder.genericBeanDefinition(SqlOutParameter.class); } else if ("INOUT".equalsIgnoreCase(direction)) { parameterBuilder = BeanDefinitionBuilder.genericBeanDefinition(SqlInOutParameter.class); } else { parameterBuilder = BeanDefinitionBuilder.genericBeanDefinition(SqlParameter.class); } if (StringUtils.hasText(name)) { parameterBuilder.addConstructorArgValue(name); } else { parserContext .getReaderContext() .error( "The 'name' attribute must be set for the Sql parameter element.", storedProcComponent); } if (StringUtils.hasText(sqlType)) { JdbcTypesEnum jdbcTypeEnum = JdbcTypesEnum.convertToJdbcTypesEnum(sqlType); if (jdbcTypeEnum != null) { parameterBuilder.addConstructorArgValue(jdbcTypeEnum.getCode()); } else { parameterBuilder.addConstructorArgValue(sqlType); } } else { parameterBuilder.addConstructorArgValue(Types.VARCHAR); } if (StringUtils.hasText(scale)) { parameterBuilder.addConstructorArgValue(new TypedStringValue(scale, Integer.class)); } sqlParameterList.add(parameterBuilder.getBeanDefinition()); } return sqlParameterList; }
private void parseEntries( Element element, String name, EntryType type, List<BeanDefinition> entries) { List<Element> cp = DomUtils.getChildElementsByTagName(element, name); for (Element entry : cp) { BeanDefinitionBuilder bd = BeanDefinitionBuilder.genericBeanDefinition(CacheEntry.class); bd.addConstructorArgValue(type); bd.addConstructorArgValue(entry.getAttribute("value")); entries.add(bd.getBeanDefinition()); } }
@Override protected void configureAppender(Element element, BeanDefinitionBuilder appender) { String host = element.getAttribute("host"); String port = element.getAttribute("port"); String db = element.getAttribute("db"); String collection = element.getAttribute("collection"); appender.addConstructorArgValue(host); appender.addConstructorArgValue(port); appender.addConstructorArgValue(db); appender.addConstructorArgValue(collection); }
/* (non-Javadoc) * @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser#doParse(org.w3c.dom.Element, org.springframework.beans.factory.support.BeanDefinitionBuilder) */ @Override protected void doParse(Element element, BeanDefinitionBuilder builder) { builder.setScope("prototype"); String path = element.getAttribute("path"); builder.addConstructorArgValue(path); String encoding = element.getAttribute("encoding"); if (StringUtils.hasText(encoding)) { builder.addConstructorArgValue(encoding); } }
/** * Parse the split and turn it into a list of transitions. * * @param element the <split/gt; element to parse * @param parserContext the parser context for the bean factory * @return a collection of bean definitions for {@link * org.springframework.batch.core.job.flow.support.StateTransition} instances objects */ public Collection<BeanDefinition> parse(Element element, ParserContext parserContext) { String idAttribute = element.getAttribute("id"); BeanDefinitionBuilder stateBuilder = BeanDefinitionBuilder.genericBeanDefinition( "org.springframework.batch.core.job.flow.support.state.SplitState"); String taskExecutorBeanId = element.getAttribute("task-executor"); if (StringUtils.hasText(taskExecutorBeanId)) { RuntimeBeanReference taskExecutorRef = new RuntimeBeanReference(taskExecutorBeanId); stateBuilder.addPropertyValue("taskExecutor", taskExecutorRef); } List<Element> flowElements = DomUtils.getChildElementsByTagName(element, "flow"); if (flowElements.size() < 2) { parserContext .getReaderContext() .error("A <split/> must contain at least two 'flow' elements.", element); } Collection<BeanDefinition> flows = new ManagedList<BeanDefinition>(); int i = 0; String prefix = idAttribute; for (Element nextElement : flowElements) { String ref = nextElement.getAttribute(PARENT_ATTR); if (StringUtils.hasText(ref)) { if (nextElement.getElementsByTagName("*").getLength() > 0) { parserContext .getReaderContext() .error( "A <flow/> in a <split/> must have ref= or nested <flow/>, but not both.", nextElement); } AbstractBeanDefinition flowDefinition = new GenericBeanDefinition(); flowDefinition.setParentName(ref); MutablePropertyValues propertyValues = flowDefinition.getPropertyValues(); propertyValues.addPropertyValue("name", prefix + "." + i); flows.add(flowDefinition); } else { InlineFlowParser flowParser = new InlineFlowParser(prefix + "." + i, jobFactoryRef); flows.add(flowParser.parse(nextElement, parserContext)); } i++; } stateBuilder.addConstructorArgValue(flows); stateBuilder.addConstructorArgValue(prefix); return InlineFlowParser.getNextElements( parserContext, stateBuilder.getBeanDefinition(), element); }
/** * Build the POJO with the username and password. * * @param element the HTTPMetadataProvider parser. * @return the bean definition with the username and password. */ private BeanDefinition buildBasicCredentials(Element element) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(UsernamePasswordCredentials.class); builder.setLazyInit(true); builder.addConstructorArgValue( StringSupport.trimOrNull(element.getAttributeNS(null, BASIC_AUTH_USER))); builder.addConstructorArgValue( StringSupport.trimOrNull(element.getAttributeNS(null, BASIC_AUTH_PASSWORD))); return builder.getBeanDefinition(); }
private Object resolveScriptLocation( Element element, XmlReaderContext readerContext, String scriptLocation) { String refreshDelayText = element.getAttribute(REFRESH_CHECK_DELAY_ATTRIBUTE); String beanClassName = RefreshableResourceScriptSource.class.getName(); BeanDefinitionBuilder resourceScriptSourceBuilder = BeanDefinitionBuilder.genericBeanDefinition(beanClassName); resourceScriptSourceBuilder.addConstructorArgValue(scriptLocation); if (StringUtils.hasText(refreshDelayText)) { resourceScriptSourceBuilder.addConstructorArgValue(refreshDelayText); } else { resourceScriptSourceBuilder.addConstructorArgValue(-1L); } return resourceScriptSourceBuilder.getBeanDefinition(); }
/** * Registers bean definitions for a {@link PluginRegistry} to capture {@link RelProvider} * instances. Wraps the registry into a {@link DelegatingRelProvider} bean definition backed by * the registry. * * @param registry */ private static void registerRelProviderPluginRegistryAndDelegate( BeanDefinitionRegistry registry) { Class<?> defaultRelProviderType = EVO_PRESENT ? EvoInflectorRelProvider.class : DefaultRelProvider.class; RootBeanDefinition defaultRelProviderBeanDefinition = new RootBeanDefinition(defaultRelProviderType); registry.registerBeanDefinition("defaultRelProvider", defaultRelProviderBeanDefinition); RootBeanDefinition annotationRelProviderBeanDefinition = new RootBeanDefinition(AnnotationRelProvider.class); registry.registerBeanDefinition("annotationRelProvider", annotationRelProviderBeanDefinition); BeanDefinitionBuilder registryFactoryBeanBuilder = BeanDefinitionBuilder.rootBeanDefinition(PluginRegistryFactoryBean.class); registryFactoryBeanBuilder.addPropertyValue("type", RelProvider.class); registryFactoryBeanBuilder.addPropertyValue("exclusions", DelegatingRelProvider.class); AbstractBeanDefinition registryBeanDefinition = registryFactoryBeanBuilder.getBeanDefinition(); registry.registerBeanDefinition("relProviderPluginRegistry", registryBeanDefinition); BeanDefinitionBuilder delegateBuilder = BeanDefinitionBuilder.rootBeanDefinition(DelegatingRelProvider.class); delegateBuilder.addConstructorArgValue(registryBeanDefinition); AbstractBeanDefinition beanDefinition = delegateBuilder.getBeanDefinition(); beanDefinition.setPrimary(true); registry.registerBeanDefinition(DELEGATING_REL_PROVIDER_BEAN_NAME, beanDefinition); }
@Override protected final void doParse( final Element e, final ParserContext parserContext, final BeanDefinitionBuilder builder) { builder.addConstructorArgValue( parserContext.getDelegate().parseListElement(e, builder.getBeanDefinition())); }
@Override protected void doParse( final Element element, final ParserContext parserContext, final BeanDefinitionBuilder builder) { String serviceRef = element.getAttribute("service-ref"); builder.addConstructorArgValue(":" + serviceRef); builder.addConstructorArgReference(serviceRef); String marker = element.getAttribute("marker"); if (StringUtils.hasLength(marker)) { Class<?> theClass = ClassUtils.resolveClassName(marker, Thread.currentThread().getContextClassLoader()); if (!theClass.isAnnotation()) { throw new ConfigurationException( String.format("The class '%s' is not an annotation", marker)); } builder.addPropertyValue("markerAnnotation", theClass); } // Register the post processor if there is not already one in this context String beanName = NamespaceBeanFactoryPostProcessor.class.getName(); if (!parserContext.getRegistry().containsBeanDefinition(beanName)) { BeanDefinitionBuilder namespacePostProcessor = BeanDefinitionBuilder.genericBeanDefinition(NamespaceBeanFactoryPostProcessor.class); parserContext.registerBeanComponent( new BeanComponentDefinition(namespacePostProcessor.getBeanDefinition(), beanName)); } }
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( "session-timeout-milliseconds", "sessionTimeoutMilliseconds", element, configuration); addPropertyValueIfNotEmpty( "connection-timeout-milliseconds", "connectionTimeoutMilliseconds", element, configuration); addPropertyValueIfNotEmpty("digest", "digest", element, configuration); return configuration.getBeanDefinition(); }
@Override protected void doParse( Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { builder.addConstructorArgValue(this.expectReply); String inputChannelAttributeName = this.getInputChannelAttributeName(); String inputChannelRef = element.getAttribute(inputChannelAttributeName); if (!StringUtils.hasText(inputChannelRef)) { parserContext .getReaderContext() .error("a '" + inputChannelAttributeName + "' reference is required", element); } builder.addPropertyReference("requestChannel", inputChannelRef); if (this.expectReply) { IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "reply-channel"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "request-timeout"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "reply-timeout"); IntegrationNamespaceUtils.setValueIfAttributeDefined( builder, element, "extract-reply-payload"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "reply-key"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "convert-exceptions"); } else { IntegrationNamespaceUtils.setValueIfAttributeDefined( builder, element, "send-timeout", "requestTimeout"); } IntegrationNamespaceUtils.setValueIfAttributeDefined( builder, element, "supported-methods", "supportedMethodNames"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "request-payload-type"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "view-name"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "errors-key"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "error-code"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined( builder, element, "message-converters"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "header-mapper"); }
/** {@inheritDoc} */ @Override protected void doParse( @Nonnull final Element config, @Nonnull final ParserContext parserContext, @Nonnull final BeanDefinitionBuilder builder) { log.warn("PrincipalConnector feature is DEPRECATED in favor of subject c14n flows"); builder.setInitMethodName("initialize"); builder.setDestroyMethodName("destroy"); super.doParse(config, parserContext, builder); // First up, add the per type decoders addSAMLDecoders(config, parserContext, builder); final String format = StringSupport.trimOrNull(config.getAttributeNS(null, "nameIDFormat")); builder.addConstructorArgValue(format); final String id = StringSupport.trimOrNull(config.getAttributeNS(null, "id")); builder.addPropertyValue("id", id); final List<Element> children = ElementSupport.getChildElements(config, RELYING_PARTY); final List<String> relyingParties = new ManagedList<>(children.size()); for (Element child : children) { relyingParties.add(child.getTextContent()); } builder.addPropertyValue("relyingParties", relyingParties); }
@Override public void registerBeanDefinitions(AnnotationMetadata meta, BeanDefinitionRegistry registry) { Map<String, Object> attrs = meta.getAnnotationAttributes(EnableReactor.class.getName()); // Create a root Enivronment if (!registry.containsBeanDefinition(Environment.class.getName())) { BeanDefinitionBuilder envBeanDef = BeanDefinitionBuilder.rootBeanDefinition(Environment.class); String configReaderBean = (String) attrs.get("configurationReader"); if (StringUtils.hasText(configReaderBean)) { envBeanDef.addConstructorArgReference(configReaderBean); } else { String profileName = (String) attrs.get("value"); if (StringUtils.hasText(profileName)) { envBeanDef.addConstructorArgValue(new PropertiesConfigurationReader(profileName)); } } registry.registerBeanDefinition(Environment.class.getName(), envBeanDef.getBeanDefinition()); } // Create a ConsumerBeanPostProcessor if (!registry.containsBeanDefinition(ConsumerBeanPostProcessor.class.getName())) { BeanDefinitionBuilder envBeanDef = BeanDefinitionBuilder.rootBeanDefinition(ConsumerBeanPostProcessor.class); registry.registerBeanDefinition( ConsumerBeanPostProcessor.class.getName(), envBeanDef.getBeanDefinition()); } }
private BeanDefinition createSecurityFilterChain(BeanDefinition matcher, ManagedList<?> filters) { BeanDefinitionBuilder sfc = BeanDefinitionBuilder.rootBeanDefinition(DefaultSecurityFilterChain.class); sfc.addConstructorArgValue(matcher); sfc.addConstructorArgValue(filters); return sfc.getBeanDefinition(); }
@Override protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition( "org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler"); builder.addConstructorArgValue(element.getAttribute("url")); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "http-method"); String restTemplate = element.getAttribute("rest-template"); if (StringUtils.hasText(restTemplate)) { HttpAdapterParsingUtils.verifyNoRestTemplateAttributes(element, parserContext); builder.addConstructorArgReference(restTemplate); } else { for (String referenceAttributeName : HttpAdapterParsingUtils.REST_TEMPLATE_REFERENCE_ATTRIBUTES) { IntegrationNamespaceUtils.setReferenceIfAttributeDefined( builder, element, referenceAttributeName); } } String headerMapper = element.getAttribute("header-mapper"); String mappedRequestHeaders = element.getAttribute("mapped-request-headers"); String mappedResponseHeaders = element.getAttribute("mapped-response-headers"); if (StringUtils.hasText(headerMapper)) { if (StringUtils.hasText(mappedRequestHeaders) || StringUtils.hasText(mappedResponseHeaders)) { parserContext .getReaderContext() .error( "Neither 'mappped-request-headers' or 'mapped-response-headers' " + "attributes are allowed when a 'header-mapper' has been specified.", parserContext.extractSource(element)); return null; } builder.addPropertyReference("headerMapper", headerMapper); } else { BeanDefinitionBuilder headerMapperBuilder = BeanDefinitionBuilder.genericBeanDefinition( "org.springframework.integration.http.support.DefaultHttpHeaderMapper"); headerMapperBuilder.setFactoryMethod("outboundMapper"); IntegrationNamespaceUtils.setValueIfAttributeDefined( headerMapperBuilder, element, "mapped-request-headers", "outboundHeaderNames"); IntegrationNamespaceUtils.setValueIfAttributeDefined( headerMapperBuilder, element, "mapped-response-headers", "inboundHeaderNames"); builder.addPropertyValue("headerMapper", headerMapperBuilder.getBeanDefinition()); } IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "charset"); IntegrationNamespaceUtils.setValueIfAttributeDefined( builder, element, "extract-request-payload", "extractPayload"); IntegrationNamespaceUtils.setValueIfAttributeDefined( builder, element, "expected-response-type"); IntegrationNamespaceUtils.setValueIfAttributeDefined( builder, element, "reply-timeout", "sendTimeout"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined( builder, element, "reply-channel", "outputChannel"); HttpAdapterParsingUtils.configureUriVariableExpressions(builder, element); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "transfer-cookies"); return builder; }
@Override protected AbstractBeanDefinition parseInternal( final Element element, final ParserContext parserContext) { BeanDefinitionBuilder result = BeanDefinitionBuilder.rootBeanDefinition(ZookeeperRegistryCenter.class); result.addConstructorArgValue(buildZookeeperConfigurationBeanDefinition(element)); result.setInitMethodName("init"); return result.getBeanDefinition(); }
@Override protected BeanDefinition buildBeanDefinition( AnnotationMetadata importingClassMetadata, Class<? extends Annotation> namedAnnotation) throws Exception { String enableStateMachineEnclosingClassName = importingClassMetadata.getClassName(); // for below classloader, see gh122 Class<?> enableStateMachineEnclosingClass = ClassUtils.forName( enableStateMachineEnclosingClassName, ClassUtils.getDefaultClassLoader()); // return null if it looks like @EnableStateMachine was annotated with class // not extending StateMachineConfigurer. if (!ClassUtils.isAssignable(StateMachineConfigurer.class, enableStateMachineEnclosingClass)) { return null; } BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.rootBeanDefinition(StateMachineDelegatingFactoryBean.class); AnnotationAttributes esmAttributes = AnnotationAttributes.fromMap( importingClassMetadata.getAnnotationAttributes( EnableStateMachine.class.getName(), false)); Boolean contextEvents = esmAttributes.getBoolean("contextEvents"); // check if Scope annotation is defined and set scope from it AnnotationAttributes scopeAttributes = AnnotationAttributes.fromMap( importingClassMetadata.getAnnotationAttributes(Scope.class.getName(), false)); if (scopeAttributes != null) { String scope = scopeAttributes.getAliasedString("value", Scope.class, enableStateMachineEnclosingClass); if (StringUtils.hasText(scope)) { beanDefinitionBuilder.setScope(scope); } } beanDefinitionBuilder.addConstructorArgValue(builder); beanDefinitionBuilder.addConstructorArgValue(StateMachine.class); beanDefinitionBuilder.addConstructorArgValue(importingClassMetadata.getClassName()); beanDefinitionBuilder.addConstructorArgValue(contextEvents); return beanDefinitionBuilder.getBeanDefinition(); }
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()); } } }
@Override protected AbstractBeanDefinition parseInternal( final Element element, final ParserContext parserContext) { BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(SpringJobScheduler.class); factory.setInitMethodName("init"); factory.addConstructorArgReference(element.getAttribute(REGISTRY_CENTER_REF_ATTRIBUTE)); factory.addConstructorArgReference(createJobConfiguration(element, parserContext)); factory.addConstructorArgValue(createJobListeners(element)); return factory.getBeanDefinition(); }
@Override protected void doParse( Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { super.doParse(element, parserContext, builder); Map<String, String> attributeMap = new HashMap<String, String>(); parseWriteConcern(element, attributeMap); parseMongoOptionsElement(element, parserContext, attributeMap); BeanDefinitionBuilder cloudMongoConfigurationBeanBuilder = BeanDefinitionBuilder.genericBeanDefinition( "org.springframework.cloud.service.document.MongoDbFactoryConfig"); for (String key : new String[] {WRITE_CONCERN, CONNECTIONS_PER_HOST, MAX_WAIT_TIME}) { String value = attributeMap.get(key); // if (value != null) { cloudMongoConfigurationBeanBuilder.addConstructorArgValue(value); // } } builder.addConstructorArgValue(cloudMongoConfigurationBeanBuilder.getBeanDefinition()); }
private List<BeanDefinition> createJobListeners(final Element element) { List<Element> listenerElements = DomUtils.getChildElementsByTagName(element, LISTENER_TAG); List<BeanDefinition> result = new ManagedList<>(listenerElements.size()); for (Element each : listenerElements) { String className = each.getAttribute(CLASS_ATTRIBUTE); BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(className); factory.setScope(BeanDefinition.SCOPE_PROTOTYPE); try { Class listenerClass = Class.forName(className); if (AbstractDistributeOnceElasticJobListener.class.isAssignableFrom(listenerClass)) { factory.addConstructorArgValue(each.getAttribute(STARTED_TIMEOUT_MILLISECONDS_ATTRIBUTE)); factory.addConstructorArgValue( each.getAttribute(COMPLETED_TIMEOUT_MILLISECONDS_ATTRIBUTE)); } } catch (final ClassNotFoundException ex) { throw new RuntimeException(ex); } result.add(factory.getBeanDefinition()); } return result; }