Ejemplo n.º 1
0
        public override IObjectDefinition ParseElement(XmlElement element, ParserContext parserContext)
        {
            AbstractObjectDefinition definition = this.ParseInternal(element, parserContext);

            if (!parserContext.IsNested)
            {
                string id = null;
                try
                {
                    id = this.ResolveId(element, definition, parserContext);
                    if (!StringUtils.HasText(id))
                    {
                        parserContext.ReaderContext.ReportException(element, "null",
                                                                    "Id is required for element '" + element.LocalName + "' when used as a top-level tag", null);
                    }

                    string[] name = new string[0];

                    if (NamespaceUtils.IsAttributeDefined(element, "name"))
                    {
                        name = new[] { GetAttributeValue(element, "name") };
                    }

                    ObjectDefinitionHolder holder;

                    if (name.Length == 0)
                    {
                        holder = new ObjectDefinitionHolder(definition, id);
                    }
                    else
                    {
                        holder = new ObjectDefinitionHolder(definition, id, name);
                    }


                    this.RegisterObjectDefinition(holder, parserContext.Registry);
                }
                catch (ObjectDefinitionStoreException ex)
                {
                    parserContext.ReaderContext.ReportException(element, id, ex.Message);
                    return(null);
                }
            }
            return(definition);
        }
Ejemplo n.º 2
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 exchangeName = element.GetAttribute("name");

            builder.AddConstructorArg(new TypedStringValue(exchangeName));
            this.ParseBindings(element, parserContext, builder, exchangeName);

            NamespaceUtils.AddConstructorArgBooleanValueIfAttributeDefined(builder, element, DURABLE_ATTRIBUTE, true);
            NamespaceUtils.AddConstructorArgBooleanValueIfAttributeDefined(builder, element, AUTO_DELETE_ATTRIBUTE, false);

            var argumentsElement = element.SelectChildElementByTagName(ARGUMENTS_ELEMENT);

            if (argumentsElement != null)
            {
                var parser = new ObjectDefinitionParserHelper(parserContext);
                var map    = parser.ParseMapElementToTypedDictionary(argumentsElement, builder.RawObjectDefinition);

                builder.AddConstructorArg(map);
            }
        }
Ejemplo n.º 3
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 (element.HasAttribute(ADDRESSES) && (element.HasAttribute(HOST_ATTRIBUTE) || element.HasAttribute(PORT_ATTRIBUTE)))
            {
                parserContext.ReaderContext.ReportFatalException(element, "If the 'addresses' attribute is provided, a connection factory can not have 'host' or 'port' attributes.");
            }

            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);

            // TODO: Currently no .NET equivalent to the Java Task Executor that can be used by RabbitMQ.Client
            // NamespaceUtils.SetReferenceIfAttributeDefined(builder, element, EXECUTOR_ATTRIBUTE);
            NamespaceUtils.SetValueIfAttributeDefined(builder, element, ADDRESSES);
            NamespaceUtils.SetValueIfAttributeDefined(builder, element, PUBLISHER_CONFIRMS);
            NamespaceUtils.SetValueIfAttributeDefined(builder, element, PUBLISHER_RETURNS);
        }
        private void ParseListener(XmlElement listenerEle, XmlElement containerEle, ParserContext parserContext)
        {
            var listenerDef = new RootObjectDefinition();

            // listenerDef.setSource(parserContext.extractSource(listenerEle));
            var aRef = listenerEle.GetAttribute(REF_ATTRIBUTE);

            if (string.IsNullOrWhiteSpace(aRef))
            {
                parserContext.ReaderContext.ReportFatalException(listenerEle, "Listener 'ref' attribute contains empty value.");
            }
            else
            {
                listenerDef.PropertyValues.Add("HandlerObject", new RuntimeObjectReference(aRef));
            }

            string method = null;

            if (listenerEle.HasAttribute(METHOD_ATTRIBUTE))
            {
                method = listenerEle.GetAttribute(METHOD_ATTRIBUTE);
                if (string.IsNullOrWhiteSpace(method))
                {
                    parserContext.ReaderContext.ReportFatalException(listenerEle, "Listener 'method' attribute contains empty value.");
                }
            }

            listenerDef.PropertyValues.Add("DefaultListenerMethod", method);

            if (containerEle.HasAttribute(MESSAGE_CONVERTER_ATTRIBUTE))
            {
                var messageConverter = containerEle.GetAttribute(MESSAGE_CONVERTER_ATTRIBUTE);
                if (string.IsNullOrWhiteSpace(messageConverter))
                {
                    parserContext.ReaderContext.ReportFatalException(containerEle, "Listener container 'message-converter' attribute contains empty value.");
                }
                else
                {
                    listenerDef.PropertyValues.Add("MessageConverter", new RuntimeObjectReference(messageConverter));
                }
            }

            var containerDef = RabbitNamespaceUtils.ParseContainer(containerEle, parserContext);

            if (listenerEle.HasAttribute(RESPONSE_EXCHANGE_ATTRIBUTE))
            {
                var responseExchange = listenerEle.GetAttribute(RESPONSE_EXCHANGE_ATTRIBUTE);
                listenerDef.PropertyValues.Add("ResponseExchange", responseExchange);
            }

            if (listenerEle.HasAttribute(RESPONSE_ROUTING_KEY_ATTRIBUTE))
            {
                var responseRoutingKey = listenerEle.GetAttribute(RESPONSE_ROUTING_KEY_ATTRIBUTE);
                listenerDef.PropertyValues.Add("ResponseRoutingKey", responseRoutingKey);
            }

            listenerDef.ObjectTypeName = "Spring.Messaging.Amqp.Rabbit.Listener.Adapter.MessageListenerAdapter";
            containerDef.PropertyValues.Add("MessageListener", listenerDef);

            var containerObjectName = containerEle.GetAttribute(ID_ATTRIBUTE);

            // If no object id is given auto generate one using the ReaderContext's ObjectNameGenerator
            if (string.IsNullOrWhiteSpace(containerObjectName))
            {
                containerObjectName = parserContext.ReaderContext.GenerateObjectName(containerDef);
            }

            if (!NamespaceUtils.IsAttributeDefined(listenerEle, QUEUE_NAMES_ATTRIBUTE) && !NamespaceUtils.IsAttributeDefined(listenerEle, QUEUES_ATTRIBUTE))
            {
                parserContext.ReaderContext.ReportFatalException(listenerEle, "Listener 'queue-names' or 'queues' attribute must be provided.");
            }

            if (NamespaceUtils.IsAttributeDefined(listenerEle, QUEUE_NAMES_ATTRIBUTE) && NamespaceUtils.IsAttributeDefined(listenerEle, QUEUES_ATTRIBUTE))
            {
                parserContext.ReaderContext.ReportFatalException(listenerEle, "Listener 'queue-names' or 'queues' attribute must be provided but not both.");
            }

            var queueNames = listenerEle.GetAttribute(QUEUE_NAMES_ATTRIBUTE);

            if (!string.IsNullOrWhiteSpace(queueNames))
            {
                var names  = StringUtils.CommaDelimitedListToStringArray(queueNames);
                var values = new ManagedList();
                foreach (var name in names)
                {
                    values.Add(new TypedStringValue(name.Trim()));
                }

                containerDef.PropertyValues.Add("QueueNames", values);
            }

            var queues = listenerEle.GetAttribute(QUEUES_ATTRIBUTE);

            if (!string.IsNullOrWhiteSpace(queues))
            {
                var names  = StringUtils.CommaDelimitedListToStringArray(queues);
                var values = new ManagedList();
                foreach (var name in names)
                {
                    values.Add(new RuntimeObjectReference(name.Trim()));
                }

                containerDef.PropertyValues.Add("Queues", values);
            }

            // Register the listener and fire event
            parserContext.Registry.RegisterObjectDefinition(containerObjectName, containerDef);
        }
 /// <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)
 {
     base.DoParse(element, parserContext, builder);
     NamespaceUtils.SetValueIfAttributeDefined(builder, element, BACKING_TYPE_ATTRIBUTE);
     NamespaceUtils.SetValueIfAttributeDefined(builder, element, UPSTREAM_SET_ATTRIBUTE);
 }