AddConstructorArgReference() public method

Adds a reference to the named object as a constructor argument.
public AddConstructorArgReference ( string objectName ) : ObjectDefinitionBuilder
objectName string Name of the object.
return ObjectDefinitionBuilder
Esempio n. 1
0
        /// <summary>The do parse.</summary>
        /// <param name="element">The element.</param>
        /// <param name="parserContext">The parser context.</param>
        /// <param name="builder">The builder.</param>
        protected override void DoParse(XmlElement element, ParserContext parserContext, ObjectDefinitionBuilder builder)
        {
            var connectionFactoryRef = element.GetAttribute(CONNECTION_FACTORY_ATTRIBUTE);

            // At least one of 'templateRef' or 'connectionFactoryRef' attribute must be set.
            if (string.IsNullOrWhiteSpace(connectionFactoryRef))
            {
                parserContext.ReaderContext.ReportFatalException(element, "A '" + CONNECTION_FACTORY_ATTRIBUTE + "' attribute must be set.");
            }

            if (!string.IsNullOrWhiteSpace(connectionFactoryRef))
            {
                // Use constructor with connectionFactory parameter
                builder.AddConstructorArgReference(connectionFactoryRef);
            }

            var attributeValue = element.GetAttribute(AUTO_STARTUP_ATTRIBUTE);
            if (!string.IsNullOrWhiteSpace(attributeValue))
            {
                builder.AddPropertyValue("AutoStartup", attributeValue);
            }
        }
        /// <summary>The do parse.</summary>
        /// <param name="element">The element.</param>
        /// <param name="parserContext">The parser context.</param>
        /// <param name="builder">The builder.</param>
        protected override void DoParse(XmlElement element, ParserContext parserContext, ObjectDefinitionBuilder builder)
        {
            var connectionFactoryRef = element.GetAttribute(CONNECTION_FACTORY_ATTRIBUTE);

            if (string.IsNullOrWhiteSpace(connectionFactoryRef))
            {
                parserContext.ReaderContext.ReportFatalException(element, "A '" + CONNECTION_FACTORY_ATTRIBUTE + "' attribute must be set.");
            }

            if (!string.IsNullOrWhiteSpace(connectionFactoryRef))
            {
                // Use constructor with connectionFactory parameter
                builder.AddConstructorArgReference(connectionFactoryRef);
            }

            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, REPLY_TIMEOUT_ATTRIBUTE);
            NamespaceUtils.SetValueIfAttributeDefined(builder, element, ENCODING_ATTRIBUTE);
            NamespaceUtils.SetReferenceIfAttributeDefined(builder, element, MESSAGE_CONVERTER_ATTRIBUTE);
            NamespaceUtils.SetReferenceIfAttributeDefined(builder, element, REPLY_QUEUE_ATTRIBUTE);
            NamespaceUtils.SetValueIfAttributeDefined(builder, element, MANDATORY_ATTRIBUTE);
            NamespaceUtils.SetValueIfAttributeDefined(builder, element, IMMEDIATE_ATTRIBUTE);
            NamespaceUtils.SetReferenceIfAttributeDefined(builder, element, RETURN_CALLBACK_ATTRIBUTE);
            NamespaceUtils.SetReferenceIfAttributeDefined(builder, element, CONFIRM_CALLBACK_ATTRIBUTE);

            IObjectDefinition replyContainer = null;
            XmlElement childElement = null;
            var childElements = element.SelectChildElementsByTagName(LISTENER_ELEMENT);
            if (childElements.Count > 0)
            {
                childElement = childElements[0] as XmlElement;
            }

            if (childElement != null)
            {
                replyContainer = this.ParseListener(childElement, element, parserContext);
                if (replyContainer != null)
                {
                    replyContainer.PropertyValues.Add("MessageListener", new RuntimeObjectReference(element.GetAttribute(ID_ATTRIBUTE)));
                    var replyContainerName = element.GetAttribute(ID_ATTRIBUTE) + ".ReplyListener";
                    parserContext.Registry.RegisterObjectDefinition(replyContainerName, replyContainer);
                }
            }

            if (replyContainer == null && element.HasAttribute(REPLY_QUEUE_ATTRIBUTE))
            {
                parserContext.ReaderContext.ReportFatalException(element, "For template '" + element.GetAttribute(ID_ATTRIBUTE) + "', when specifying a reply-queue, a <reply-listener/> element is required");
            }
            else if (replyContainer != null && !element.HasAttribute(REPLY_QUEUE_ATTRIBUTE))
            {
                parserContext.ReaderContext.ReportFatalException(element, "For template '" + element.GetAttribute(ID_ATTRIBUTE) + "', a <reply-listener/> element is not allowed if no 'reply-queue' is supplied");
            }
        }
 protected override void DoParse(XmlElement element, ParserContext parserContext, ObjectDefinitionBuilder builder)
 {
     String containerBeanName = ParseMessageListenerContainer(element, parserContext);
     String listenerBeanName = ParseMessageListener(element, parserContext);
     builder.AddConstructorArgReference(containerBeanName);
     builder.AddConstructorArgReference(listenerBeanName);
     IntegrationNamespaceUtils.SetValueIfAttributeDefined(builder, element, "auto-startup");
 }
        /// <summary>Adds the constructor arg ref if attribute defined.</summary>
        /// <param name="builder">The builder.</param>
        /// <param name="element">The element.</param>
        /// <param name="attributeName">Name of the attribute.</param>
        /// <returns><c>true</c> if [is attribute defined] [the specified element]; otherwise, <c>false</c>.</returns>
        public static bool AddConstructorArgRefIfAttributeDefined(ObjectDefinitionBuilder builder, XmlElement element, string attributeName)
        {
            var value = element.GetAttribute(attributeName);
            if (!string.IsNullOrWhiteSpace(value))
            {
                builder.AddConstructorArgReference(value);
                return true;
            }

            return false;
        }
Esempio n. 5
0
        /// <summary>The do parse.</summary>
        /// <param name="element">The element.</param>
        /// <param name="parserContext">The parser context.</param>
        /// <param name="builder">The builder.</param>
        protected override void DoParse(XmlElement element, ParserContext parserContext, ObjectDefinitionBuilder builder)
        {
            if (!NamespaceUtils.IsAttributeDefined(element, "name") && !NamespaceUtils.IsAttributeDefined(element, ID_ATTRIBUTE))
            {
                parserContext.ReaderContext.ReportFatalException(element, "Queue must have either id or name (or both)");
            }

            NamespaceUtils.AddConstructorArgValueIfAttributeDefined(builder, element, "name");

            if (!NamespaceUtils.IsAttributeDefined(element, "name"))
            {
                if (this.AttributeHasIllegalOverride(element, DURABLE_ATTRIBUTE, "false")
                    || this.AttributeHasIllegalOverride(element, EXCLUSIVE_ATTRIBUTE, "true")
                    || this.AttributeHasIllegalOverride(element, AUTO_DELETE_ATTRIBUTE, "true"))
                {
                    parserContext.ReaderContext.ReportFatalException(element, "Anonymous queue cannot specify durable='true', exclusive='false' or auto-delete='false'");
                    return;
                }
            }
            else
            {
                NamespaceUtils.AddConstructorArgBooleanValueIfAttributeDefined(builder, element, DURABLE_ATTRIBUTE, false);
                NamespaceUtils.AddConstructorArgBooleanValueIfAttributeDefined(builder, element, EXCLUSIVE_ATTRIBUTE, false);
                NamespaceUtils.AddConstructorArgBooleanValueIfAttributeDefined(builder, element, AUTO_DELETE_ATTRIBUTE, false);
            }

            var queueArguments = element.GetAttribute(ARGUMENTS);
            var argumentsElement = element.SelectChildElementByTagName(ARGUMENTS);

            if (argumentsElement != null)
            {
                var parser = new ObjectDefinitionParserHelper(parserContext);
                if (!string.IsNullOrWhiteSpace(queueArguments))
                {
                    parserContext.ReaderContext.ReportFatalException(element, "Queue may have either a queue-attributes attribute or element, but not both");
                }

                var map = parser.ParseMapElement(argumentsElement, builder.RawObjectDefinition);
                builder.AddConstructorArg(map);
            }

            if (!string.IsNullOrWhiteSpace(queueArguments))
            {
                builder.AddConstructorArgReference(queueArguments);
            }
        }