/// <summary>
        /// Registers the attribute config processors.
        /// </summary>
        /// <param name="registry">The registry.</param>
        public static void RegisterAttributeConfigProcessors(IObjectDefinitionRegistry registry)
        {
            if (!registry.ContainsObjectDefinition(CONFIGURATION_ATTRIBUTE_PROCESSOR_OBJECT_NAME))
            {
                RootObjectDefinition objectDefinition = new RootObjectDefinition(typeof(ConfigurationClassPostProcessor));
                RegisterPostProcessor(registry, objectDefinition, CONFIGURATION_ATTRIBUTE_PROCESSOR_OBJECT_NAME);
            }

            if (!registry.ContainsObjectDefinition(AUTOWIRED_ATTRIBUTE_PROCESSOR_OBJECT_NAME))
            {
                RootObjectDefinition objectDefinition = new RootObjectDefinition(typeof(AutowiredAttributeObjectPostProcessor));
                RegisterPostProcessor(registry, objectDefinition, AUTOWIRED_ATTRIBUTE_PROCESSOR_OBJECT_NAME);
            }

            if (!registry.ContainsObjectDefinition(REQUIRED_ATTRIBUTE_PROCESSOR_OBJECT_NAME))
            {
                RootObjectDefinition objectDefinition = new RootObjectDefinition(typeof(RequiredAttributeObjectPostProcessor));
                RegisterPostProcessor(registry, objectDefinition, REQUIRED_ATTRIBUTE_PROCESSOR_OBJECT_NAME);
            }

            if (!registry.ContainsObjectDefinition(INITDESTROY_ATTRIBUTE_PROCESSOR_OBJECT_NAME))
            {
                RootObjectDefinition objectDefinition = new RootObjectDefinition(typeof(InitDestroyAttributeObjectPostProcessor));
                RegisterPostProcessor(registry, objectDefinition, INITDESTROY_ATTRIBUTE_PROCESSOR_OBJECT_NAME);
            }
        }
        /// <summary>
        /// Registers the attribute config processors.
        /// </summary>
        /// <param name="registry">The registry.</param>
        public static void RegisterAttributeConfigProcessors(IObjectDefinitionRegistry registry)
        {
            if (!registry.ContainsObjectDefinition(CONFIGURATION_ATTRIBUTE_PROCESSOR_OBJECT_NAME))
            {
                RootObjectDefinition objectDefinition = new RootObjectDefinition(typeof(ConfigurationClassPostProcessor));
                RegisterPostProcessor(registry, objectDefinition, CONFIGURATION_ATTRIBUTE_PROCESSOR_OBJECT_NAME);
            }

            if (!registry.ContainsObjectDefinition(AUTOWIRED_ATTRIBUTE_PROCESSOR_OBJECT_NAME))
            {
                RootObjectDefinition objectDefinition = new RootObjectDefinition(typeof(AutowiredAttributeObjectPostProcessor));
                RegisterPostProcessor(registry, objectDefinition, AUTOWIRED_ATTRIBUTE_PROCESSOR_OBJECT_NAME);
            }

            if (!registry.ContainsObjectDefinition(REQUIRED_ATTRIBUTE_PROCESSOR_OBJECT_NAME))
            {
                RootObjectDefinition objectDefinition = new RootObjectDefinition(typeof(RequiredAttributeObjectPostProcessor));
                RegisterPostProcessor(registry, objectDefinition, REQUIRED_ATTRIBUTE_PROCESSOR_OBJECT_NAME);
            }

            if (!registry.ContainsObjectDefinition(INITDESTROY_ATTRIBUTE_PROCESSOR_OBJECT_NAME))
            {
                RootObjectDefinition objectDefinition = new RootObjectDefinition(typeof(InitDestroyAttributeObjectPostProcessor));
                RegisterPostProcessor(registry, objectDefinition, INITDESTROY_ATTRIBUTE_PROCESSOR_OBJECT_NAME);
            }
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Forces the auto proxy creator to use decorator proxy.
 /// </summary>
 /// <param name="registry">The registry.</param>
 public static void ForceAutoProxyCreatorToUseDecoratorProxy(IObjectDefinitionRegistry registry)
 {
     if (registry.ContainsObjectDefinition(AUTO_PROXY_CREATOR_OBJECT_NAME))
     {
         IObjectDefinition definition = registry.GetObjectDefinition(AUTO_PROXY_CREATOR_OBJECT_NAME);
         definition.PropertyValues.Add("ProxyTargetType", true);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Registers the internal auto proxy creator if necessary.
        /// </summary>
        public static void RegisterAutoProxyCreatorIfNecessary(IObjectDefinitionRegistry registry)
        {
            AssertUtils.ArgumentNotNull(registry, "registry");

            if (!registry.ContainsObjectDefinition(AUTO_PROXY_CREATOR_OBJECT_NAME))
            {
                RootObjectDefinition objectDefinition = new RootObjectDefinition(InfrastructureAutoProxyCreatorType);
                objectDefinition.Role = ObjectRole.ROLE_INFRASTRUCTURE;
                objectDefinition.PropertyValues.Add("order", int.MaxValue);
                registry.RegisterObjectDefinition(AUTO_PROXY_CREATOR_OBJECT_NAME, objectDefinition);
            }
        }
        /// <summary>
        /// Registers the attribute config processors.
        /// </summary>
        /// <param name="registry">The registry.</param>
        public static void RegisterAttributeConfigProcessors(IObjectDefinitionRegistry registry)
        {
            if (!registry.ContainsObjectDefinition(CONFIGURATION_ATTRIBUTE_PROCESSOR_OBJECT_NAME))
            {
                RootObjectDefinition objectDefinition = new RootObjectDefinition(typeof(ConfigurationClassPostProcessor));
                RegisterPostProcessor(registry, objectDefinition, CONFIGURATION_ATTRIBUTE_PROCESSOR_OBJECT_NAME);
            }

            //AUTOWIRED_ATTRIBUTE_PROCESSOR_OBJECT_NAME

            //REQUIRED_ATTRIBUTE_PROCESSOR_OBJECT_NAME
        }
        /// <summary>
        /// Registers the internal auto proxy creator if necessary.
        /// </summary>
        public static void RegisterAutoProxyCreatorIfNecessary(IObjectDefinitionRegistry registry)
        {
            AssertUtils.ArgumentNotNull(registry, "registry");

            if (!registry.ContainsObjectDefinition(AUTO_PROXY_CREATOR_OBJECT_NAME))
            {
                RootObjectDefinition objectDefinition = new RootObjectDefinition(InfrastructureAutoProxyCreatorType);
                objectDefinition.Role = ObjectRole.ROLE_INFRASTRUCTURE;
                objectDefinition.PropertyValues.Add("order", int.MaxValue);
                registry.RegisterObjectDefinition(AUTO_PROXY_CREATOR_OBJECT_NAME, objectDefinition);
            }
        }
        /// <summary>
        /// Generates an object definition name for the supplied
        /// <paramref name="objectDefinition"/> that is guaranteed to be unique
        /// within the scope of the supplied <paramref name="registry"/>.
        /// </summary>
        /// <param name="objectDefinition">The <see cref="Spring.Objects.Factory.Config.IObjectDefinition"/>
        /// that requires a generated name.</param>
        /// <param name="registry">The
        /// <see cref="Spring.Objects.Factory.Support.IObjectDefinitionRegistry"/>
        /// that the supplied <paramref name="objectDefinition"/> is to be
        /// registered with (needed so that the uniqueness of any generated
        /// name can be guaranteed).</param>
        /// <param name="isInnerObject">if set to <c>true</c> if the given object
        /// definition will be registed as an inner object or as a top level objener objects
        /// verses top level objects.</param>
        /// <returns>
        /// An object definition name for the supplied
        /// <paramref name="objectDefinition"/> that is guaranteed to be unique
        /// within the scope of the supplied <paramref name="registry"/> and
        /// never <cref lang="null"/>.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        /// If either of the <paramref name="objectDefinition"/> or
        /// <paramref name="registry"/> arguments is <see langword="null"/>.
        /// </exception>
        /// <exception cref="Spring.Objects.Factory.ObjectDefinitionStoreException">
        /// If a unique name cannot be generated.
        /// </exception>
        public static string GenerateObjectName(
            IConfigurableObjectDefinition objectDefinition, IObjectDefinitionRegistry registry, bool isInnerObject)
        {
            AssertUtils.ArgumentNotNull(objectDefinition, "objectDefinition");
            AssertUtils.ArgumentNotNull(registry, "registry");

            string generatedObjectName = objectDefinition.ObjectTypeName;

            if (StringUtils.IsNullOrEmpty(generatedObjectName))
            {
                if (objectDefinition is ChildObjectDefinition)
                {
                    generatedObjectName = ((ChildObjectDefinition)objectDefinition).ParentName + "$child";
                }
                else if (objectDefinition.FactoryObjectName != null)
                {
                    generatedObjectName = objectDefinition.FactoryObjectName + "$created";
                }
            }
            if (StringUtils.IsNullOrEmpty(generatedObjectName))
            {
                if (!isInnerObject)
                {
                    throw new ObjectDefinitionStoreException(
                              objectDefinition.ResourceDescription, String.Empty,
                              "Unnamed object definition specifies neither 'Type' nor 'Parent' " +
                              "nor 'FactoryObject' property values so a unique name cannot be generated.");
                }
                generatedObjectName = "$nested";
            }

            String id = generatedObjectName;

            if (isInnerObject)
            {
                id = generatedObjectName + GENERATED_OBJECT_NAME_SEPARATOR + ObjectUtils.GetIdentityHexString(objectDefinition);
            }
            else
            {
                int counter = -1;
                while (counter == -1 || registry.ContainsObjectDefinition(id))
                {
                    counter++;
                    id = generatedObjectName + GENERATED_OBJECT_NAME_SEPARATOR + counter;
                }
            }

            return(id);
        }
Ejemplo n.º 9
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);
            }
        }
        /// <summary>
        /// Generates an object definition name for the supplied
        /// <paramref name="objectDefinition"/> that is guaranteed to be unique
        /// within the scope of the supplied <paramref name="registry"/>.
        /// </summary>
        /// <param name="objectDefinition">The <see cref="Spring.Objects.Factory.Config.IObjectDefinition"/>
        /// that requires a generated name.</param>
        /// <param name="registry">The
        /// <see cref="Spring.Objects.Factory.Support.IObjectDefinitionRegistry"/>
        /// that the supplied <paramref name="objectDefinition"/> is to be
        /// registered with (needed so that the uniqueness of any generated
        /// name can be guaranteed).</param>
        /// <param name="isInnerObject">if set to <c>true</c> if the given object
        /// definition will be registed as an inner object or as a top level objener objects
        /// verses top level objects.</param>
        /// <returns>
        /// An object definition name for the supplied
        /// <paramref name="objectDefinition"/> that is guaranteed to be unique
        /// within the scope of the supplied <paramref name="registry"/> and
        /// never <cref lang="null"/>.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        /// If either of the <paramref name="objectDefinition"/> or
        /// <paramref name="registry"/> arguments is <see langword="null"/>.
        /// </exception>
        /// <exception cref="Spring.Objects.Factory.ObjectDefinitionStoreException">
        /// If a unique name cannot be generated.
        /// </exception>
        public static string GenerateObjectName(
            IConfigurableObjectDefinition objectDefinition, IObjectDefinitionRegistry registry, bool isInnerObject)
        {
            AssertUtils.ArgumentNotNull(objectDefinition, "objectDefinition");
            AssertUtils.ArgumentNotNull(registry, "registry");

            string generatedObjectName = objectDefinition.ObjectTypeName;
            if (StringUtils.IsNullOrEmpty(generatedObjectName))
            {
                if (objectDefinition is ChildObjectDefinition)
                {
                    generatedObjectName = ((ChildObjectDefinition)objectDefinition).ParentName + "$child";
                }
                else if (objectDefinition.FactoryObjectName != null)
                {
                    generatedObjectName = objectDefinition.FactoryObjectName + "$created";
                }
            }
            if (StringUtils.IsNullOrEmpty(generatedObjectName))
            {
                if (!isInnerObject)
                {
                    throw new ObjectDefinitionStoreException(
                        objectDefinition.ResourceDescription, String.Empty,
                        "Unnamed object definition specifies neither 'Type' nor 'Parent' " +
                        "nor 'FactoryObject' property values so a unique name cannot be generated.");
                }
                generatedObjectName = "$nested";
            }

            String id = generatedObjectName;
            if (isInnerObject)
            {
                id = generatedObjectName + GENERATED_OBJECT_NAME_SEPARATOR + ObjectUtils.GetIdentityHexString(objectDefinition);
            }
            else
            {
                int counter = -1;
                while (counter == -1 || registry.ContainsObjectDefinition(id))
                {
                    counter++;
                    id = generatedObjectName + GENERATED_OBJECT_NAME_SEPARATOR + counter;
                }
            }

            return id;
        }
 /// <summary>
 /// Forces the auto proxy creator to use decorator proxy.
 /// </summary>
 /// <param name="registry">The registry.</param>
 public static void ForceAutoProxyCreatorToUseDecoratorProxy(IObjectDefinitionRegistry registry)
 {
     if (registry.ContainsObjectDefinition(AUTO_PROXY_CREATOR_OBJECT_NAME))
     {
         IObjectDefinition definition = registry.GetObjectDefinition(AUTO_PROXY_CREATOR_OBJECT_NAME);
         definition.PropertyValues.Add("ProxyTargetType", true);
     }
 }