@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); NamespaceUtils.setValueIfAttributeDefined(builder, element, DELAYED_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, "internal"); this.parseArguments(element, ARGUMENTS_ELEMENT, parserContext, builder, null); NamespaceUtils.parseDeclarationControls(element, builder); CURRENT_ELEMENT.set(element); }
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { if (element.hasAttribute(ADDRESSES) && (element.hasAttribute(HOST_ATTRIBUTE) || element.hasAttribute(PORT_ATTRIBUTE))) { parserContext.getReaderContext().error("If the 'addresses' attribute is provided, a connection " + "factory can not have 'host' or 'port' attributes.", element); } NamespaceUtils.addConstructorArgParentRefIfAttributeDefined(builder, element, CONNECTION_FACTORY_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, CHANNEL_CACHE_SIZE_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, HOST_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, PORT_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, USER_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, PASSWORD_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, VIRTUAL_HOST_ATTRIBUTE); NamespaceUtils.setReferenceIfAttributeDefined(builder, element, EXECUTOR_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, ADDRESSES); NamespaceUtils.setValueIfAttributeDefined(builder, element, PUBLISHER_CONFIRMS); NamespaceUtils.setValueIfAttributeDefined(builder, element, PUBLISHER_RETURNS); NamespaceUtils.setValueIfAttributeDefined(builder, element, REQUESTED_HEARTBEAT, "requestedHeartBeat"); NamespaceUtils.setValueIfAttributeDefined(builder, element, CONNECTION_TIMEOUT); NamespaceUtils.setValueIfAttributeDefined(builder, element, CACHE_MODE); NamespaceUtils.setValueIfAttributeDefined(builder, element, CONNECTION_CACHE_SIZE_ATTRIBUTE); NamespaceUtils.setReferenceIfAttributeDefined(builder, element, THREAD_FACTORY, "connectionThreadFactory"); NamespaceUtils.setValueIfAttributeDefined(builder, element, FACTORY_TIMEOUT, "channelCheckoutTimeout"); NamespaceUtils.setValueIfAttributeDefined(builder, element, CONNECTION_LIMIT); NamespaceUtils.setReferenceIfAttributeDefined(builder, element, "connection-name-strategy"); }
@Override protected Class<?> getBeanClass(Element element) { if (NamespaceUtils.isAttributeDefined(element, NAME_ATTRIBUTE)) { return Queue.class; } else { return AnonymousQueue.class; } }
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { // NOSONAR complexity if (!NamespaceUtils.isAttributeDefined(element, NAME_ATTRIBUTE) && !NamespaceUtils.isAttributeDefined(element, ID_ATTRIBUTE)) { parserContext.getReaderContext().error("Queue must have either id or name (or both)", element); NamespaceUtils.addConstructorArgValueIfAttributeDefined(builder, element, NAME_ATTRIBUTE); if (!NamespaceUtils.isAttributeDefined(element, NAME_ATTRIBUTE)) { element); NamespaceUtils.addConstructorArgRefIfAttributeDefined(builder, element, NAMING_STRATEGY); parserContext.getReaderContext().error("Only one of 'name' or 'naming-strategy' is allowed", element); NamespaceUtils.addConstructorArgBooleanValueIfAttributeDefined(builder, element, DURABLE_ATTRIBUTE, false); NamespaceUtils .addConstructorArgBooleanValueIfAttributeDefined(builder, element, EXCLUSIVE_ATTRIBUTE, false); NamespaceUtils.addConstructorArgBooleanValueIfAttributeDefined(builder, element, AUTO_DELETE_ATTRIBUTE, false); NamespaceUtils.parseDeclarationControls(element, builder); CURRENT_ELEMENT.set(element);
NamespaceUtils.setValueIfAttributeDefined(builder, element, CHANNEL_TRANSACTED_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, QUEUE_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, EXCHANGE_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, ROUTING_KEY_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, RECEIVE_TIMEOUT_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, REPLY_TIMEOUT_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, ENCODING_ATTRIBUTE); NamespaceUtils.setReferenceIfAttributeDefined(builder, element, MESSAGE_CONVERTER_ATTRIBUTE); String replyAddress = element.getAttribute(REPLY_ADDRESS_ATTRIBUTE); if (!StringUtils.hasText(replyAddress)) { NamespaceUtils.setReferenceIfAttributeDefined(builder, element, REPLY_QUEUE_ATTRIBUTE, Conventions.attributeNameToPropertyName(REPLY_ADDRESS_ATTRIBUTE)); NamespaceUtils.setValueIfAttributeDefined(builder, element, USE_TEMPORARY_REPLY_QUEUES_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, REPLY_ADDRESS_ATTRIBUTE); NamespaceUtils.setReferenceIfAttributeDefined(builder, element, RETURN_CALLBACK_ATTRIBUTE); NamespaceUtils.setReferenceIfAttributeDefined(builder, element, CONFIRM_CALLBACK_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, CORRELATION_KEY); NamespaceUtils.setReferenceIfAttributeDefined(builder, element, RETRY_TEMPLATE); NamespaceUtils.setReferenceIfAttributeDefined(builder, element, RECOVERY_CALLBACK); NamespaceUtils.setValueIfAttributeDefined(builder, element, DIRECT_REPLY_TO_CONTAINER, "useDirectReplyToContainer"); NamespaceUtils.createExpressionDefinitionFromValueOrExpression(MANDATORY_ATTRIBUTE, "mandatory-expression", parserContext, element, false); if (expressionDef != null) { NamespaceUtils.createExpressionDefIfAttributeDefined("send-connection-factory-selector-expression", element);
/** * Parses 'auto-declare' and 'declared-by' attributes. * * @param element The element. * @param builder The builder. */ public static void parseDeclarationControls(Element element, BeanDefinitionBuilder builder) { NamespaceUtils.setValueIfAttributeDefined(builder, element, "auto-declare", "shouldDeclare"); String admins = element.getAttribute("declared-by"); if (StringUtils.hasText(admins)) { String[] adminBeanNames = admins.split(","); ManagedList<BeanReference> adminBeanRefs = new ManagedList<BeanReference>(); for (String adminBeanName : adminBeanNames) { adminBeanRefs.add(new RuntimeBeanReference(adminBeanName.trim())); } builder.addPropertyValue("adminsThatShouldDeclare", adminBeanRefs); } NamespaceUtils.setValueIfAttributeDefined(builder, element, "ignore-declaration-exceptions"); }
protected void doParseBindings(Element element, ParserContext parserContext, String exchangeName, Element bindings, AbstractExchangeParser parser) { if (bindings != null) { for (Element binding : DomUtils.getChildElementsByTagName(bindings, BINDING_ELE)) { BeanDefinitionBuilder bindingBuilder = parser.parseBinding(exchangeName, binding, parserContext); NamespaceUtils.parseDeclarationControls(element, bindingBuilder); BeanDefinition beanDefinition = bindingBuilder.getBeanDefinition(); registerBeanDefinition(new BeanDefinitionHolder(beanDefinition, parserContext.getReaderContext() .generateBeanName(beanDefinition)), parserContext.getRegistry()); } } }
/** * Populates the bean definition property corresponding to the specified attributeName with the reference to a bean * identified by the value of that attribute if the attribute is defined in the given element. * * <p> * The property name will be the camel-case equivalent of the lower case hyphen separated attribute (e.g. the * "foo-bar" attribute would match the "fooBar" property). * * @param builder the bean definition builder to be configured * @param element the XML element where the attribute should be defined * @param attributeName the name of the attribute whose value will be used as a bean reference to populate the * property * @return true if defined. * @see Conventions#attributeNameToPropertyName(String) */ public static boolean setReferenceIfAttributeDefined(BeanDefinitionBuilder builder, Element element, String attributeName) { return setReferenceIfAttributeDefined(builder, element, attributeName, Conventions.attributeNameToPropertyName(attributeName)); }
public static BeanDefinition createExpressionDefinitionFromValueOrExpression(String valueElementName, String expressionElementName, ParserContext parserContext, Element element, boolean oneRequired) { Assert.hasText(valueElementName, "'valueElementName' must not be empty"); Assert.hasText(expressionElementName, "'expressionElementName' must not be empty"); String valueElementValue = element.getAttribute(valueElementName); String expressionElementValue = element.getAttribute(expressionElementName); boolean hasAttributeValue = StringUtils.hasText(valueElementValue); boolean hasAttributeExpression = StringUtils.hasText(expressionElementValue); if (hasAttributeValue && hasAttributeExpression) { parserContext.getReaderContext().error("Only one of '" + valueElementName + "' or '" + expressionElementName + "' is allowed", element); } if (oneRequired && (!hasAttributeValue && !hasAttributeExpression)) { parserContext.getReaderContext().error("One of '" + valueElementName + "' or '" + expressionElementName + "' is required", element); } BeanDefinition expressionDef; if (hasAttributeValue) { expressionDef = new RootBeanDefinition(LiteralExpression.class); expressionDef.getConstructorArgumentValues().addGenericArgumentValue(valueElementValue); } else { expressionDef = createExpressionDefIfAttributeDefined(expressionElementName, element); } return expressionDef; }
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { // NOSONAR complexity if (!NamespaceUtils.isAttributeDefined(element, NAME_ATTRIBUTE) && !NamespaceUtils.isAttributeDefined(element, ID_ATTRIBUTE)) { parserContext.getReaderContext().error("Queue must have either id or name (or both)", element); NamespaceUtils.addConstructorArgValueIfAttributeDefined(builder, element, NAME_ATTRIBUTE); if (!NamespaceUtils.isAttributeDefined(element, NAME_ATTRIBUTE)) { element); NamespaceUtils.addConstructorArgRefIfAttributeDefined(builder, element, NAMING_STRATEGY); parserContext.getReaderContext().error("Only one of 'name' or 'naming-strategy' is allowed", element); NamespaceUtils.addConstructorArgBooleanValueIfAttributeDefined(builder, element, DURABLE_ATTRIBUTE, false); NamespaceUtils .addConstructorArgBooleanValueIfAttributeDefined(builder, element, EXCLUSIVE_ATTRIBUTE, false); NamespaceUtils.addConstructorArgBooleanValueIfAttributeDefined(builder, element, AUTO_DELETE_ATTRIBUTE, false); NamespaceUtils.parseDeclarationControls(element, builder); CURRENT_ELEMENT.set(element);
NamespaceUtils.setValueIfAttributeDefined(builder, element, CHANNEL_TRANSACTED_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, QUEUE_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, EXCHANGE_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, ROUTING_KEY_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, RECEIVE_TIMEOUT_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, REPLY_TIMEOUT_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, ENCODING_ATTRIBUTE); NamespaceUtils.setReferenceIfAttributeDefined(builder, element, MESSAGE_CONVERTER_ATTRIBUTE); String replyAddress = element.getAttribute(REPLY_ADDRESS_ATTRIBUTE); if (!StringUtils.hasText(replyAddress)) { NamespaceUtils.setReferenceIfAttributeDefined(builder, element, REPLY_QUEUE_ATTRIBUTE, Conventions.attributeNameToPropertyName(REPLY_ADDRESS_ATTRIBUTE)); NamespaceUtils.setValueIfAttributeDefined(builder, element, USE_TEMPORARY_REPLY_QUEUES_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, REPLY_ADDRESS_ATTRIBUTE); NamespaceUtils.setReferenceIfAttributeDefined(builder, element, RETURN_CALLBACK_ATTRIBUTE); NamespaceUtils.setReferenceIfAttributeDefined(builder, element, CONFIRM_CALLBACK_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, CORRELATION_KEY); NamespaceUtils.setReferenceIfAttributeDefined(builder, element, RETRY_TEMPLATE); NamespaceUtils.setReferenceIfAttributeDefined(builder, element, RECOVERY_CALLBACK); NamespaceUtils.setValueIfAttributeDefined(builder, element, DIRECT_REPLY_TO_CONTAINER, "useDirectReplyToContainer"); NamespaceUtils.createExpressionDefinitionFromValueOrExpression(MANDATORY_ATTRIBUTE, "mandatory-expression", parserContext, element, false); if (expressionDef != null) { NamespaceUtils.createExpressionDefIfAttributeDefined("send-connection-factory-selector-expression", element);
/** * Parses 'auto-declare' and 'declared-by' attributes. * * @param element The element. * @param builder The builder. */ public static void parseDeclarationControls(Element element, BeanDefinitionBuilder builder) { NamespaceUtils.setValueIfAttributeDefined(builder, element, "auto-declare", "shouldDeclare"); String admins = element.getAttribute("declared-by"); if (StringUtils.hasText(admins)) { String[] adminBeanNames = admins.split(","); ManagedList<BeanReference> adminBeanRefs = new ManagedList<BeanReference>(); for (String adminBeanName : adminBeanNames) { adminBeanRefs.add(new RuntimeBeanReference(adminBeanName.trim())); } builder.addPropertyValue("adminsThatShouldDeclare", adminBeanRefs); } NamespaceUtils.setValueIfAttributeDefined(builder, element, "ignore-declaration-exceptions"); }
protected void doParseBindings(Element element, ParserContext parserContext, String exchangeName, Element bindings, AbstractExchangeParser parser) { if (bindings != null) { for (Element binding : DomUtils.getChildElementsByTagName(bindings, BINDING_ELE)) { BeanDefinitionBuilder bindingBuilder = parser.parseBinding(exchangeName, binding, parserContext); NamespaceUtils.parseDeclarationControls(element, bindingBuilder); BeanDefinition beanDefinition = bindingBuilder.getBeanDefinition(); registerBeanDefinition(new BeanDefinitionHolder(beanDefinition, parserContext.getReaderContext() .generateBeanName(beanDefinition)), parserContext.getRegistry()); } } }
/** * Populates the bean definition property corresponding to the specified attributeName with the reference to a bean * identified by the value of that attribute if the attribute is defined in the given element. * * <p> * The property name will be the camel-case equivalent of the lower case hyphen separated attribute (e.g. the * "foo-bar" attribute would match the "fooBar" property). * * @param builder the bean definition builder to be configured * @param element the XML element where the attribute should be defined * @param attributeName the name of the attribute whose value will be used as a bean reference to populate the * property * @return true if defined. * @see Conventions#attributeNameToPropertyName(String) */ public static boolean setReferenceIfAttributeDefined(BeanDefinitionBuilder builder, Element element, String attributeName) { return setReferenceIfAttributeDefined(builder, element, attributeName, Conventions.attributeNameToPropertyName(attributeName)); }
public static BeanDefinition createExpressionDefinitionFromValueOrExpression(String valueElementName, String expressionElementName, ParserContext parserContext, Element element, boolean oneRequired) { Assert.hasText(valueElementName, "'valueElementName' must not be empty"); Assert.hasText(expressionElementName, "'expressionElementName' must not be empty"); String valueElementValue = element.getAttribute(valueElementName); String expressionElementValue = element.getAttribute(expressionElementName); boolean hasAttributeValue = StringUtils.hasText(valueElementValue); boolean hasAttributeExpression = StringUtils.hasText(expressionElementValue); if (hasAttributeValue && hasAttributeExpression) { parserContext.getReaderContext().error("Only one of '" + valueElementName + "' or '" + expressionElementName + "' is allowed", element); } if (oneRequired && (!hasAttributeValue && !hasAttributeExpression)) { parserContext.getReaderContext().error("One of '" + valueElementName + "' or '" + expressionElementName + "' is required", element); } BeanDefinition expressionDef; if (hasAttributeValue) { expressionDef = new RootBeanDefinition(LiteralExpression.class); expressionDef.getConstructorArgumentValues().addGenericArgumentValue(valueElementValue); } else { expressionDef = createExpressionDefIfAttributeDefined(expressionElementName, element); } return expressionDef; }
@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); NamespaceUtils.setValueIfAttributeDefined(builder, element, DELAYED_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, "internal"); this.parseArguments(element, ARGUMENTS_ELEMENT, parserContext, builder, null); NamespaceUtils.parseDeclarationControls(element, builder); CURRENT_ELEMENT.set(element); }
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { if (element.hasAttribute(ADDRESSES) && (element.hasAttribute(HOST_ATTRIBUTE) || element.hasAttribute(PORT_ATTRIBUTE))) { parserContext.getReaderContext().error("If the 'addresses' attribute is provided, a connection " + "factory can not have 'host' or 'port' attributes.", element); } NamespaceUtils.addConstructorArgParentRefIfAttributeDefined(builder, element, CONNECTION_FACTORY_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, CHANNEL_CACHE_SIZE_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, HOST_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, PORT_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, USER_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, PASSWORD_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, VIRTUAL_HOST_ATTRIBUTE); NamespaceUtils.setReferenceIfAttributeDefined(builder, element, EXECUTOR_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, ADDRESSES); NamespaceUtils.setValueIfAttributeDefined(builder, element, PUBLISHER_CONFIRMS); NamespaceUtils.setValueIfAttributeDefined(builder, element, PUBLISHER_RETURNS); NamespaceUtils.setValueIfAttributeDefined(builder, element, REQUESTED_HEARTBEAT, "requestedHeartBeat"); NamespaceUtils.setValueIfAttributeDefined(builder, element, CONNECTION_TIMEOUT); NamespaceUtils.setValueIfAttributeDefined(builder, element, CACHE_MODE); NamespaceUtils.setValueIfAttributeDefined(builder, element, CONNECTION_CACHE_SIZE_ATTRIBUTE); NamespaceUtils.setReferenceIfAttributeDefined(builder, element, THREAD_FACTORY, "connectionThreadFactory"); NamespaceUtils.setValueIfAttributeDefined(builder, element, FACTORY_TIMEOUT, "channelCheckoutTimeout"); NamespaceUtils.setValueIfAttributeDefined(builder, element, CONNECTION_LIMIT); NamespaceUtils.setReferenceIfAttributeDefined(builder, element, "connection-name-strategy"); }
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { String connectionFactoryRef = element.getAttribute(CONNECTION_FACTORY_ATTRIBUTE); // At least one of 'templateRef' or 'connectionFactoryRef' attribute must be set. if (!StringUtils.hasText(connectionFactoryRef)) { parserContext.getReaderContext().error("A '" + CONNECTION_FACTORY_ATTRIBUTE + "' attribute must be set.", element); } if (StringUtils.hasText(connectionFactoryRef)) { // Use constructor with connectionFactory parameter builder.addConstructorArgReference(connectionFactoryRef); } String attributeValue; attributeValue = element.getAttribute(AUTO_STARTUP_ATTRIBUTE); if (StringUtils.hasText(attributeValue)) { builder.addPropertyValue("autoStartup", attributeValue); } NamespaceUtils.setValueIfAttributeDefined(builder, element, IGNORE_DECLARATION_EXCEPTIONS); } }
@Override protected Class<?> getBeanClass(Element element) { if (NamespaceUtils.isAttributeDefined(element, NAME_ATTRIBUTE)) { return Queue.class; } else { return AnonymousQueue.class; } }
/** * Populates the bean definition property corresponding to the specified attributeName with the value of that * attribute if it is defined in the given element. * * <p> * The property name will be the camel-case equivalent of the lower case hyphen separated attribute (e.g. the * "foo-bar" attribute would match the "fooBar" property). * * @param builder the bean definition builder to be configured * @param element the XML element where the attribute should be defined * @param attributeName the name of the attribute whose value will be set on the property * @return true if defined. * @see Conventions#attributeNameToPropertyName(String) */ public static boolean setValueIfAttributeDefined(BeanDefinitionBuilder builder, Element element, String attributeName) { return setValueIfAttributeDefined(builder, element, attributeName, Conventions.attributeNameToPropertyName(attributeName)); }