/// <summary>Sets the reference if attribute defined.</summary>
        /// <param name="builder">The builder.</param>
        /// <param name="element">The element.</param>
        /// <param name="attributeName">Name of the attribute.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <returns><c>true</c> if [is attribute defined] [the specified element]; otherwise, <c>false</c>.</returns>
        public static bool SetReferenceIfAttributeDefined(ObjectDefinitionBuilder builder, XmlElement element, string attributeName, string propertyName)
        {
            var attributeValue = element.GetAttribute(attributeName);

            if (!string.IsNullOrWhiteSpace(attributeValue))
            {
                builder.AddPropertyReference(propertyName, attributeValue);
                return(true);
            }

            return(false);
        }
        protected override AbstractObjectDefinition DoParse(XmlElement element, ParserContext parserContext, string channelName)
        {
            string source = ParseSource(element, parserContext);

            if (!StringUtils.HasText(source))
            {
                parserContext.ReaderContext.ReportException(element, element.Name, "failed to parse source");
            }
            ObjectDefinitionBuilder adapterBuilder = ObjectDefinitionBuilder.GenericObjectDefinition(IntegrationNamespaceUtils.CONFIG_PACKAGE + ".SourcePollingChannelAdapterFactoryObject");

            adapterBuilder.AddPropertyReference("source", source);
            adapterBuilder.AddPropertyReference("outputChannel", channelName);
            XmlElement pollerElement = DomUtils.GetChildElementByTagName(element, "poller");

            if (pollerElement != null)
            {
                IntegrationNamespaceUtils.ConfigurePollerMetadata(pollerElement, adapterBuilder, parserContext);
            }
            IntegrationNamespaceUtils.SetValueIfAttributeDefined(adapterBuilder, element, "auto-startup");
            return(adapterBuilder.ObjectDefinition);
        }
        protected override ObjectDefinitionBuilder ParseHandler(XmlElement element, ParserContext parserContext)
        {
            ObjectDefinitionBuilder builder = ObjectDefinitionBuilder.GenericObjectDefinition(IntegrationNamespaceUtils.AGGREGATOR_PACKAGE + ".MethodInvokingAggregator");
            string refatr = element.GetAttribute(RefAttribute);

            if (!StringUtils.HasText(refatr))
            {
                parserContext.ReaderContext.ReportException(element, element.Name, "The '" + RefAttribute + "' attribute is required.");
            }
            builder.AddConstructorArgReference(refatr);
            if (StringUtils.HasText(element.GetAttribute(MethodAttribute)))
            {
                string method = element.GetAttribute(MethodAttribute);
                builder.AddConstructorArg(method);
            }
            IntegrationNamespaceUtils.SetReferenceIfAttributeDefined(builder, element, DiscardChannelAttribute);
            IntegrationNamespaceUtils.SetValueIfAttributeDefined(builder, element, SendTimeoutAttribute);
            IntegrationNamespaceUtils.SetValueIfAttributeDefined(builder, element, SendPartialResultOnTimeoutAttribute);
            IntegrationNamespaceUtils.SetValueIfAttributeDefined(builder, element, ReaperIntervalAttribute);
            IntegrationNamespaceUtils.SetValueIfAttributeDefined(builder, element, TrackedCorrelationIdCapacityAttribute);
            IntegrationNamespaceUtils.SetValueIfAttributeDefined(builder, element, "auto-startup");
            IntegrationNamespaceUtils.SetValueIfAttributeDefined(builder, element, TimeoutAttribute);
            string completionStrategyRef    = element.GetAttribute(CompletionStrategyRefAttribute);
            string completionStrategyMethod = element.GetAttribute(CompletionStrategyMethodAttribute);

            if (StringUtils.HasText(completionStrategyRef))
            {
                if (StringUtils.HasText(completionStrategyMethod))
                {
                    string adapterBeanName = CreateCompletionStrategyAdapter(
                        completionStrategyRef, completionStrategyMethod, parserContext);
                    builder.AddPropertyReference(CompletionStrategyProperty, adapterBeanName);
                }
                else
                {
                    builder.AddPropertyReference(CompletionStrategyProperty, completionStrategyRef);
                }
            }
            return(builder);
        }
Example #4
0
        /// <summary>The parse destination.</summary>
        /// <param name="binding">The binding.</param>
        /// <param name="parserContext">The parser context.</param>
        /// <param name="builder">The builder.</param>
        protected void ParseDestination(XmlElement binding, ParserContext parserContext, ObjectDefinitionBuilder builder)
        {
            var queueAttribute       = binding.GetAttribute(BINDING_QUEUE_ATTR);
            var exchangeAttribute    = binding.GetAttribute(BINDING_EXCHANGE_ATTR);
            var hasQueueAttribute    = !string.IsNullOrWhiteSpace(queueAttribute);
            var hasExchangeAttribute = !string.IsNullOrWhiteSpace(exchangeAttribute);

            if (!(hasQueueAttribute ^ hasExchangeAttribute))
            {
                parserContext.ReaderContext.ReportFatalException(binding, "Binding must have exactly one of 'queue' or 'exchange'");
            }

            if (hasQueueAttribute)
            {
                builder.AddPropertyReference("DestinationQueue", queueAttribute);
            }

            if (hasExchangeAttribute)
            {
                builder.AddPropertyReference("DestinationExchange", exchangeAttribute);
            }
        }
        protected override ObjectDefinitionBuilder ParseHandler(XmlElement element, ParserContext parserContext)
        {
            ObjectDefinitionBuilder builder = ObjectDefinitionBuilder.GenericObjectDefinition(typeof(NmsOutboundGateway));

            builder.AddPropertyReference("connectionFactory", element.GetAttribute("connection-factory"));
            String requestDestination     = element.GetAttribute("request-destination");
            String requestDestinationName = element.GetAttribute("request-destination-name");

            if (!(StringUtils.HasText(requestDestination) ^ StringUtils.HasText(requestDestinationName)))
            {
                parserContext.ReaderContext.ReportException(element, "request-destination or request-destination-name",
                                                            "Exactly one of the 'request-destination' or 'request-destination-name' attributes is required.");
            }
            if (StringUtils.HasText(requestDestination))
            {
                builder.AddPropertyReference("requestDestination", requestDestination);
            }
            else if (StringUtils.HasText(requestDestinationName))
            {
                builder.AddPropertyValue("requestDestinationName", requestDestinationName);
            }
            IntegrationNamespaceUtils.SetReferenceIfAttributeDefined(builder, element, "reply-destination");
            IntegrationNamespaceUtils.SetValueIfAttributeDefined(builder, element, "reply-destination-name");
            IntegrationNamespaceUtils.SetReferenceIfAttributeDefined(builder, element, "reply-channel");
            IntegrationNamespaceUtils.SetReferenceIfAttributeDefined(builder, element, "message-converter");
            IntegrationNamespaceUtils.SetReferenceIfAttributeDefined(builder, element, "header-mapper");
            IntegrationNamespaceUtils.SetValueIfAttributeDefined(builder, element, "extract-request-payload");
            IntegrationNamespaceUtils.SetValueIfAttributeDefined(builder, element, "extract-reply-payload");
            IntegrationNamespaceUtils.SetValueIfAttributeDefined(builder, element, "receive-timeout");
            IntegrationNamespaceUtils.SetValueIfAttributeDefined(builder, element, "pub-sub-domain");
            IntegrationNamespaceUtils.SetValueIfAttributeDefined(builder, element, "delivery-mode");
            IntegrationNamespaceUtils.SetValueIfAttributeDefined(builder, element, "time-to-live");
            IntegrationNamespaceUtils.SetValueIfAttributeDefined(builder, element, "priority");



            return(builder);
        }
        protected override string ParseSource(XmlElement element, ParserContext parserContext)
        {
            ObjectDefinitionBuilder builder = ObjectDefinitionBuilder.GenericObjectDefinition(typeof(NmsDestinationPollingSource));
            string nmsTemplate     = element.GetAttribute(NmsAdapterParserUtils.NMS_TEMPLATE_ATTRIBUTE);
            string destination     = element.GetAttribute(NmsAdapterParserUtils.DESTINATION_ATTRIBUTE);
            string destinationName = element.GetAttribute(NmsAdapterParserUtils.DESTINATION_NAME_ATTRIBUTE);
            string headerMapper    = element.GetAttribute(NmsAdapterParserUtils.HEADER_MAPPER_ATTRIBUTE);

            if (StringUtils.HasText(nmsTemplate))
            {
                if (element.HasAttribute(NmsAdapterParserUtils.CONNECTION_FACTORY_ATTRIBUTE) ||
                    element.HasAttribute(NmsAdapterParserUtils.DESTINATION_NAME_ATTRIBUTE) ||
                    element.HasAttribute(NmsAdapterParserUtils.DESTINATION_ATTRIBUTE))
                {
                    throw new ObjectCreationException(
                              "When providing '" + NmsAdapterParserUtils.NMS_TEMPLATE_ATTRIBUTE +
                              "', none of '" + NmsAdapterParserUtils.CONNECTION_FACTORY_ATTRIBUTE +
                              "', '" + NmsAdapterParserUtils.DESTINATION_ATTRIBUTE + "', or '" +
                              NmsAdapterParserUtils.DESTINATION_NAME_ATTRIBUTE + "' should be provided.");
                }
                builder.AddConstructorArgReference(nmsTemplate);
            }

            else if (StringUtils.HasText(destination) || StringUtils.HasText(destinationName))
            {
                builder.AddConstructorArgReference(NmsAdapterParserUtils.DetermineConnectionFactoryBeanName(element,
                                                                                                            parserContext));
                if (StringUtils.HasText(destination))
                {
                    builder.AddConstructorArgReference(destination);
                }
                else if (StringUtils.HasText(destinationName))
                {
                    builder.AddConstructorArg(destinationName);
                }
            }
            else
            {
                throw new ObjectCreationException("either a '" + NmsAdapterParserUtils.NMS_TEMPLATE_ATTRIBUTE + "' or one of '" +
                                                  NmsAdapterParserUtils.DESTINATION_ATTRIBUTE + "' or '" + NmsAdapterParserUtils.DESTINATION_NAME_ATTRIBUTE +
                                                  "' attributes must be provided for a polling NMS adapter");
            }
            if (StringUtils.HasText(headerMapper))
            {
                builder.AddPropertyReference(NmsAdapterParserUtils.HEADER_MAPPER_PROPERTY, headerMapper);
            }
            IntegrationNamespaceUtils.SetValueIfAttributeDefined(builder, element, "extract-payload");
            IntegrationNamespaceUtils.SetReferenceIfAttributeDefined(builder, element, "destination-resolver");
            return(parserContext.ReaderContext.RegisterWithGeneratedName(builder.ObjectDefinition));
        }
Example #7
0
        protected override ObjectDefinitionBuilder ParseHandler(XmlElement element, ParserContext parserContext)
        {
            string refAttribute = element.GetAttribute(RefAttribute);

            if (!StringUtils.HasText(refAttribute))
            {
                parserContext.ReaderContext.ReportException(element, "router", "The '" + RefAttribute + "' attribute is required.");
            }
            ObjectDefinitionBuilder builder = ObjectDefinitionBuilder.GenericObjectDefinition(IntegrationNamespaceUtils.CONFIG_PACKAGE + ".RouterFactoryObject");

            builder.AddPropertyReference("targetObject", refAttribute);
            if (StringUtils.HasText(element.GetAttribute(MethodAttribute)))
            {
                string method = element.GetAttribute(MethodAttribute);
                builder.AddPropertyValue("targetMethodName", method);
            }
            ObjectDefinitionBuilder resolverBuilder = ObjectDefinitionBuilder.GenericObjectDefinition(IntegrationNamespaceUtils.CHANNEL_PACKAGE + ".ObjectFactoryChannelResolver");
            string resolverObjectName = parserContext.ReaderContext.RegisterWithGeneratedName(resolverBuilder.ObjectDefinition);

            builder.AddPropertyReference("channelResolver", resolverObjectName);
            IntegrationNamespaceUtils.SetReferenceIfAttributeDefined(builder, element, "default-output-channel");
            return(builder);
        }
Example #8
0
        protected override ObjectDefinitionBuilder ParseHandler(XmlElement element, ParserContext parserContext)
        {
            ObjectDefinitionBuilder builder = ObjectDefinitionBuilder.GenericObjectDefinition(GetGatewayClassName(element));
            string url = ParseUrl(element, parserContext);

            builder.AddConstructorArg(url);
            string replyChannel = element.GetAttribute("reply-channel");

            if (StringUtils.HasText(replyChannel))
            {
                builder.AddPropertyReference("replyChannel", replyChannel);
            }
            PostProcessGateway(builder, element, parserContext);
            return(builder);
        }
        protected override ObjectDefinitionBuilder ParseHandler(XmlElement element, ParserContext parserContext)
        {
            ObjectDefinitionBuilder builder = ObjectDefinitionBuilder.GenericObjectDefinition(IntegrationNamespaceUtils.CONFIG_PACKAGE + ".SplitterFactoryBean");

            if (element.HasAttribute(RefAttribute))
            {
                string refatr = element.GetAttribute(RefAttribute);
                builder.AddPropertyReference("targetObject", refatr);
                if (StringUtils.HasText(element.GetAttribute(MethodAttribute)))
                {
                    string method = element.GetAttribute(MethodAttribute);
                    builder.AddPropertyValue("targetMethodName", method);
                }
            }
            return(builder);
        }
        protected override void DoParse(XmlElement element, ParserContext parserContext, ObjectDefinitionBuilder builder)
        {
            String taskExecutorRef = element.GetAttribute("task-executor");

            if (StringUtils.HasText(taskExecutorRef))
            {
                builder.AddPropertyReference("taskExecutor", taskExecutorRef);
            }
            else
            {
                IExecutor taskExecutor = IntegrationContextUtils.CreateThreadPoolTaskExecutor(1, 10, 0, "event-multicaster-");
                builder.AddPropertyValue("taskExecutor", taskExecutor);
            }
            // TODO CopyOnWriteArraySet
            builder.AddPropertyValue("collectionClass", typeof(Set));  //CopyOnWriteArraySet));
        }
        protected override ObjectDefinitionBuilder ParseHandler(XmlElement element, ParserContext parserContext)
        {
            ObjectDefinitionBuilder builder = ObjectDefinitionBuilder.GenericObjectDefinition(IntegrationNamespaceUtils.CONFIG_PACKAGE + ".TransformerFactoryObject");
            string refAttribute             = element.GetAttribute(RefAttribute);

            if (!StringUtils.HasText(refAttribute))
            {
                parserContext.ReaderContext.ReportException(element, "transformer", "The 'ref' attribute is required.");
                return(null);
            }
            builder.AddPropertyReference("targetObject", refAttribute);
            string method = element.GetAttribute(MethodAttribute);

            if (StringUtils.HasText(method))
            {
                builder.AddPropertyValue("targetMethodName", method);
            }
            return(builder);
        }
Example #12
0
        protected override string ParseSource(XmlElement element, ParserContext parserContext)
        {
            string sourceRef = element.GetAttribute("ref");

            if (!StringUtils.HasText(sourceRef))
            {
                parserContext.ReaderContext.ReportException(element, element.Name, "The 'ref' attribute is required.");
            }
            string methodName = element.GetAttribute("method");

            if (StringUtils.HasText(methodName))
            {
                ObjectDefinitionBuilder builder = ObjectDefinitionBuilder.GenericObjectDefinition(IntegrationNamespaceUtils.MESSAGE_PACKAGE + ".MethodInvokingMessageSource");
                builder.AddPropertyReference("object", sourceRef);
                builder.AddPropertyValue("methodName", methodName);
                sourceRef = parserContext.ReaderContext.RegisterWithGeneratedName(builder.ObjectDefinition);
            }
            return(sourceRef);
        }
        private static void ConfigureTrigger(XmlElement pollerElement, ObjectDefinitionBuilder targetBuilder, ParserContext parserContext)
        {
            string     triggerBeanName;
            XmlElement intervalElement = DomUtils.GetChildElementByTagName(pollerElement, "interval-trigger");

            if (intervalElement != null)
            {
                triggerBeanName = ParseIntervalTrigger(intervalElement, parserContext);
            }
            else
            {
                XmlElement cronElement = DomUtils.GetChildElementByTagName(pollerElement, "cron-trigger");
                if (cronElement == null)
                {
                    parserContext.ReaderContext.ReportException(pollerElement, pollerElement.Name, "A <poller> element must include either an <interval-trigger/> or <cron-trigger/> child element.");
                }
                triggerBeanName = ParseCronTrigger(cronElement, parserContext);
            }
            targetBuilder.AddPropertyReference("trigger", triggerBeanName);
        }
        /// <summary>
        /// Parse a "poller" element to provide a reference for the target
        /// ObjectDefinitionBuilder. If the poller element does not contain a "ref"
        /// attribute, this will create and register a PollerMetadata instance and
        /// then add it as a property reference of the target builder.
        /// </summary>
        /// <param name="pollerElement">the "poller" element to parse</param>
        /// <param name="targetBuilder">the builder that expects the "trigger" property</param>
        /// <param name="parserContext">the parserContext for the target builder</param>
        public static void ConfigurePollerMetadata(XmlElement pollerElement, ObjectDefinitionBuilder targetBuilder, ParserContext parserContext)
        {
            string pollerMetadataRef;

            if (pollerElement.HasAttribute("ref"))
            {
                if (pollerElement.Attributes.Count != 1)
                {
                    parserContext.ReaderContext.ReportException(pollerElement, "poller", "A 'poller' element that provides a 'ref' must have no other attributes.");
                }
                if (pollerElement.ChildNodes.Count != 0)
                {
                    parserContext.ReaderContext.ReportException(pollerElement, "poller", "A 'poller' element that provides a 'ref' must have no child elements.");
                }
                pollerMetadataRef = pollerElement.GetAttribute("ref");
            }
            else
            {
                IObjectDefinition pollerDef = parserContext.ParserHelper.ParseCustomElement(pollerElement, targetBuilder.ObjectDefinition);
                pollerMetadataRef = parserContext.ReaderContext.RegisterWithGeneratedName(pollerDef);
            }
            targetBuilder.AddPropertyReference("pollerMetadata", pollerMetadataRef);
        }
Example #15
0
        private static IApplicationContext CreateContextProgrammatically()
        {
            InitializeCommonLogging();
            GenericApplicationContext ctx = new GenericApplicationContext();

            IObjectDefinitionFactory objectDefinitionFactory = new DefaultObjectDefinitionFactory();


            //Create MovieLister and dependency on
            ObjectDefinitionBuilder builder =
                ObjectDefinitionBuilder.RootObjectDefinition(objectDefinitionFactory, typeof(MovieLister));

            builder.AddPropertyReference("MovieFinder", "AnotherMovieFinder");

            ctx.RegisterObjectDefinition("MyMovieLister", builder.ObjectDefinition);

            builder = ObjectDefinitionBuilder.RootObjectDefinition(objectDefinitionFactory, typeof(ColonDelimitedMovieFinder));
            builder.AddConstructorArg("movies.txt");
            ctx.RegisterObjectDefinition("AnotherMovieFinder", builder.ObjectDefinition);

            ctx.Refresh();

            return(ctx);
        }
Example #16
0
        /// <summary>
        /// Register a TaskScheduler in the given <see cref="IObjectDefinitionFactory"/> if not yet present.
        /// The object name for which this is checking is defined by the constant <see cref="IntegrationContextUtils.TaskSchedulerObjectName"/>
        /// </summary>
        /// <param name="registry">the <see cref="IObjectDefinitionFactory"/></param>
        private void RegisterTaskSchedulerIfNecessary(IObjectDefinitionRegistry registry)
        {
            if (!registry.ContainsObjectDefinition(IntegrationContextUtils.TaskSchedulerObjectName))
            {
                if (logger.IsInfoEnabled)
                {
                    logger.Info("No object named '" + IntegrationContextUtils.TaskSchedulerObjectName +
                                "' has been explicitly defined. Therefore, a default SimpleTaskScheduler will be created.");
                }
                IExecutor taskExecutor = IntegrationContextUtils.CreateThreadPoolTaskExecutor(2, 100, 0, "task-scheduler-");
                ObjectDefinitionBuilder schedulerBuilder = ObjectDefinitionBuilder.GenericObjectDefinition(IntegrationNamespaceUtils.SCHEDULING_PACKAGE + ".SimpleTaskScheduler");
                schedulerBuilder.AddConstructorArg(taskExecutor);

                ObjectDefinitionBuilder errorHandlerBuilder = ObjectDefinitionBuilder.GenericObjectDefinition(IntegrationNamespaceUtils.CHANNEL_PACKAGE + ".MessagePublishingErrorHandler");
                errorHandlerBuilder.AddPropertyReference("defaultErrorChannel", IntegrationContextUtils.ErrorChannelObjectName);
                string errorHandlerBeanName = ObjectDefinitionReaderUtils.GenerateObjectName(errorHandlerBuilder.ObjectDefinition, registry);
                ObjectDefinitionHolder errorHandlerHolder = new ObjectDefinitionHolder(errorHandlerBuilder.ObjectDefinition, errorHandlerBeanName);
                ObjectDefinitionReaderUtils.RegisterObjectDefinition(errorHandlerHolder, registry);

                schedulerBuilder.AddPropertyReference("errorHandler", errorHandlerBeanName);
                ObjectDefinitionHolder schedulerHolder = new ObjectDefinitionHolder(schedulerBuilder.ObjectDefinition, IntegrationContextUtils.TaskSchedulerObjectName);
                ObjectDefinitionReaderUtils.RegisterObjectDefinition(schedulerHolder, registry);
            }
        }
Example #17
0
 public void Inject(ReferenceInjection injection)
 {
     builder.AddPropertyReference(property, injection.ReferencedLemming);
 }