Example #1
0
        /**
         * Register an error channel in the given ObjectDefinitionRegistry if not yet present.
         * The bean name for which this is checking is defined by the constant
         * {@link IntegrationContextUtils#ERROR_CHANNEL_BEAN_NAME}.
         */
        private void RegisterErrorChannelIfNecessary(IObjectDefinitionRegistry registry)
        {
            if (!registry.ContainsObjectDefinition(IntegrationContextUtils.ErrorChannelObjectName))
            {
                if (logger.IsInfoEnabled)
                {
                    logger.Info("No bean named '" + IntegrationContextUtils.ErrorChannelObjectName +
                                "' has been explicitly defined. Therefore, a default PublishSubscribeChannel will be created.");
                }

                RootObjectDefinition errorChannelDef = new RootObjectDefinition();
                errorChannelDef.ObjectTypeName = IntegrationNamespaceUtils.BASE_PACKAGE + ".Channel.PublishSubscribeChannel";
                ObjectDefinitionHolder errorChannelHolder = new ObjectDefinitionHolder(errorChannelDef, IntegrationContextUtils.ErrorChannelObjectName);
                ObjectDefinitionReaderUtils.RegisterObjectDefinition(errorChannelHolder, registry);

                ObjectDefinitionBuilder loggingHandlerBuilder = ObjectDefinitionBuilder.GenericObjectDefinition(IntegrationNamespaceUtils.HANDLER_PACKAGE + ".LoggingHandler");

                string loggingHandlerObjectName = ObjectDefinitionReaderUtils.GenerateObjectName(loggingHandlerBuilder.ObjectDefinition, registry);

                loggingHandlerBuilder.AddConstructorArg("ERROR");
                ObjectDefinitionHolder loggingHandlerHolder = new ObjectDefinitionHolder(loggingHandlerBuilder.ObjectDefinition, loggingHandlerObjectName);
                ObjectDefinitionReaderUtils.RegisterObjectDefinition(loggingHandlerHolder, registry);

                ObjectDefinitionBuilder loggingEndpointBuilder = ObjectDefinitionBuilder.GenericObjectDefinition(IntegrationNamespaceUtils.ENDPOINT_PACKAGE + ".EventDrivenConsumer");
                loggingEndpointBuilder.AddConstructorArgReference(IntegrationContextUtils.ErrorChannelObjectName);
                loggingEndpointBuilder.AddConstructorArgReference(loggingHandlerObjectName);
                string loggingEndpointObjectName             = ObjectDefinitionReaderUtils.GenerateObjectName(loggingEndpointBuilder.ObjectDefinition, registry);
                ObjectDefinitionHolder loggingEndpointHolder = new ObjectDefinitionHolder(loggingEndpointBuilder.ObjectDefinition, loggingEndpointObjectName);
                ObjectDefinitionReaderUtils.RegisterObjectDefinition(loggingEndpointHolder, registry);
            }
        }
Example #2
0
        /// <summary>
        /// Process the object element
        /// </summary>
        protected virtual void ProcessObjectDefinition(XmlElement element, ObjectDefinitionParserHelper helper)
        {
            // TODO: add event handling
            try
            {
                ObjectDefinitionHolder bdHolder = helper.ParseObjectDefinitionElement(element);
                if (bdHolder == null)
                {
                    return;
                }
                bdHolder = helper.DecorateObjectDefinitionIfRequired(element, bdHolder);

                if (log.IsEnabled(LogLevel.Debug))
                {
                    log.LogDebug(string.Format(CultureInfo.InvariantCulture, "Registering object definition with id '{0}'.", bdHolder.ObjectName));
                }

                ObjectDefinitionReaderUtils.RegisterObjectDefinition(bdHolder, ReaderContext.Registry);
                // TODO: Send registration event.
                // ReaderContext.FireComponentRegistered(new BeanComponentDefinition(bdHolder));
            }
            catch (ObjectDefinitionStoreException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new ObjectDefinitionStoreException(
                          $"Failed parsing object definition '{element.OuterXml}'", ex);
            }
        }
Example #3
0
        /// <summary>
        /// Parse the specified element and register any resulting
        /// IObjectDefinitions with the IObjectDefinitionRegistry that is
        /// embedded in the supplied ParserContext.
        /// </summary>
        /// <param name="element">The element to be parsed into one or more IObjectDefinitions</param>
        /// <param name="parserContext">The object encapsulating the current state of the parsing
        /// process.</param>
        /// <returns>
        /// The primary IObjectDefinition (can be null as explained above)
        /// </returns>
        /// <remarks>
        /// Implementations should return the primary IObjectDefinition
        /// that results from the parse phase if they wish to used nested
        /// inside (for example) a <code>&lt;property&gt;</code> tag.
        /// <para>Implementations may return null if they will not
        /// be used in a nested scenario.
        /// </para>
        /// </remarks>
        public override IObjectDefinition ParseElement(XmlElement element, ParserContext parserContext)
        {
            ParseElementCalled = true;
            ObjectDefinitionHolder holder = ParseTestObjectDefinition(element, parserContext);

            ObjectDefinitionReaderUtils.RegisterObjectDefinition(holder, parserContext.Registry);
            return(null);
        }
Example #4
0
 private void RegisterDefaultConfiguringObjectFactoryPostProcessorIfNecessary(ParserContext parserContext)
 {
     if (!parserContext.Registry.IsObjectNameInUse(DEFAULT_CONFIGURING_POSTPROCESSOR_OBJECT_NAME))
     {
         ObjectDefinitionBuilder builder =
             ObjectDefinitionBuilder.GenericObjectDefinition(IntegrationNamespaceUtils.CONFIG_XML_PACKAGE + "." +
                                                             DEFAULT_CONFIGURING_POSTPROCESSOR_SIMPLE_CLASS_NAME);
         ObjectDefinitionHolder holder = new ObjectDefinitionHolder(builder.ObjectDefinition,
                                                                    DEFAULT_CONFIGURING_POSTPROCESSOR_OBJECT_NAME);
         ObjectDefinitionReaderUtils.RegisterObjectDefinition(holder, parserContext.Registry);
     }
 }
Example #5
0
        private void RegisterNullChannel(IObjectDefinitionRegistry registry)
        {
            if (registry.IsObjectNameInUse(IntegrationContextUtils.NullChannelObjectName))
            {
                throw new IllegalStateException("The object name '" + IntegrationContextUtils.NullChannelObjectName
                                                + "' is reserved.");
            }
            RootObjectDefinition nullChannelDef = new RootObjectDefinition();

            nullChannelDef.ObjectTypeName = IntegrationNamespaceUtils.BASE_PACKAGE + ".Channel.NullChannel";
            ObjectDefinitionHolder nullChannelHolder = new ObjectDefinitionHolder(nullChannelDef, IntegrationContextUtils.NullChannelObjectName);

            ObjectDefinitionReaderUtils.RegisterObjectDefinition(nullChannelHolder, registry);
        }
Example #6
0
        private static string CreateDirectChannel(XmlElement element, ParserContext parserContext)
        {
            string channelId = element.GetAttribute("id");

            if (!StringUtils.HasText(channelId))
            {
                parserContext.ReaderContext.ReportException(element, "channel", "The channel-adapter's 'id' attribute is required when no 'channel' "
                                                            + "reference has been provided, because that 'id' would be used for the created channel.");
            }
            ObjectDefinitionBuilder channelBuilder = ObjectDefinitionBuilder.GenericObjectDefinition(IntegrationNamespaceUtils.CHANNEL_PACKAGE + ".DirectChannel");
            ObjectDefinitionHolder  holder         = new ObjectDefinitionHolder(channelBuilder.ObjectDefinition, channelId);

            ObjectDefinitionReaderUtils.RegisterObjectDefinition(holder, parserContext.Registry);
            return(channelId);
        }
Example #7
0
        protected override AbstractObjectDefinition ParseInternal(XmlElement element, ParserContext parserContext)
        {
            ObjectDefinitionBuilder handlerBuilder = ParseHandler(element, parserContext);

            IntegrationNamespaceUtils.SetReferenceIfAttributeDefined(handlerBuilder, element, "output-channel");
            IntegrationNamespaceUtils.SetValueIfAttributeDefined(handlerBuilder, element, "order");
            AbstractObjectDefinition handlerBeanDefinition = handlerBuilder.ObjectDefinition;
            string inputChannelAttributeName = InputChannelAttributeName;

            if (!element.HasAttribute(inputChannelAttributeName))
            {
                if (!parserContext.IsNested)
                {
                    parserContext.ReaderContext.ReportException(element, element.Name, "The '" + inputChannelAttributeName
                                                                + "' attribute is required for top-level endpoint elements.");
                }
                return(handlerBeanDefinition);
            }
            ObjectDefinitionBuilder builder = ObjectDefinitionBuilder.GenericObjectDefinition(IntegrationNamespaceUtils.CONFIG_PACKAGE + ".ConsumerEndpointFactoryObject");
            string handlerBeanName          = parserContext.ReaderContext.RegisterWithGeneratedName(handlerBeanDefinition);

            builder.AddConstructorArgReference(handlerBeanName);
            string inputChannelName = element.GetAttribute(inputChannelAttributeName);

            if (!parserContext.Registry.ContainsObjectDefinition(inputChannelName))
            {
                ObjectDefinitionBuilder channelDef = ObjectDefinitionBuilder.GenericObjectDefinition(IntegrationNamespaceUtils.CHANNEL_PACKAGE + ".DirectChannel");
                ObjectDefinitionHolder  holder     = new ObjectDefinitionHolder(channelDef.ObjectDefinition, inputChannelName);
                ObjectDefinitionReaderUtils.RegisterObjectDefinition(holder, parserContext.Registry);
            }
            builder.AddPropertyValue("inputChannelName", inputChannelName);
            XmlElement pollerElement = DomUtils.GetChildElementByTagName(element, "poller");

            if (pollerElement != null)
            {
                IntegrationNamespaceUtils.ConfigurePollerMetadata(pollerElement, builder, parserContext);
            }
            IntegrationNamespaceUtils.SetValueIfAttributeDefined(builder, element, "auto-startup");
            return(builder.ObjectDefinition);
        }
Example #8
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 #9
0
 /// <summary>
 /// Registers the supplied <see cref="ObjectDefinitionHolder"/> with the supplied
 /// <see cref="IObjectDefinitionRegistry"/>.
 /// </summary>
 /// <remarks>Subclasses can override this method to control whether or not the supplied
 /// <see cref="ObjectDefinitionHolder"/> is actually even registered, or to
 /// register even more objects.
 /// <para>
 /// The default implementation registers the supplied <see cref="ObjectDefinitionHolder"/>
 /// with the supplied <see cref="ObjectDefinitionHolder"/> only if the <code>IsNested</code>
 /// parameter is <code>false</code>, because one typically does not want inner objects
 /// to be registered as top level objects.
 /// </para>
 /// </remarks>
 ///
 /// <param name="definition">The object definition to be registered.</param>
 /// <param name="registry">The registry that the bean is to be registered with.</param>
 protected virtual void RegisterObjectDefinition(ObjectDefinitionHolder definition, IObjectDefinitionRegistry registry)
 {
     ObjectDefinitionReaderUtils.RegisterObjectDefinition(definition, registry);
 }