コード例 #1
0
        /// <summary>
        /// Method run after all the properties have been set for this object.
        /// Responsible for actual proxy creation.
        /// </summary>
        public void AfterPropertiesSet()
        {
            _transactionInterceptor.AfterPropertiesSet();

            if (_target == null)
            {
                throw new ArgumentException("'target' is required.");
            }
            ProxyFactory proxyFactory = new ProxyFactory();

            if (_preInterceptors != null)
            {
                for (int i = 0; i < _preInterceptors.Length; i++)
                {
                    proxyFactory.AddAdvisor(_advisorAdapterRegistry.Wrap(_preInterceptors[i]));
                }
            }
            if (_pointcut != null)
            {
                IAdvisor advice = new DefaultPointcutAdvisor(_pointcut, _transactionInterceptor);
                proxyFactory.AddAdvisor(advice);
            }
            else
            {
                proxyFactory.AddAdvisor(new TransactionAttributeSourceAdvisor(_transactionInterceptor));
            }
            if (_postInterceptors != null)
            {
                for (int i = 0; i < _postInterceptors.Length; i++)
                {
                    proxyFactory.AddAdvisor(_advisorAdapterRegistry.Wrap(_postInterceptors[i]));
                }
            }
            proxyFactory.CopyFrom(this);
            proxyFactory.TargetSource = createTargetSource(_target);
            if (_proxyInterfaces != null)
            {
                proxyFactory.Interfaces = _proxyInterfaces;
            }
            else if (!ProxyTargetType)
            {
                if (_target is ITargetSource)
                {
                    throw new AopConfigException("Either 'ProxyInterfaces' or 'ProxyTargetType' is required " +
                                                 "when using an ITargetSource as 'target'");
                }
                proxyFactory.Interfaces = AopUtils.GetAllInterfaces(_target);
            }
            _proxy = proxyFactory.GetProxy();
        }
コード例 #2
0
        /// <summary>
        /// Determines the advisors for the given object, including the specific interceptors
        /// as well as the common interceptor, all adapted to the Advisor interface.
        /// </summary>
        /// <param name="targetName">The name of the object.</param>
        /// <param name="specificInterceptors">The set of interceptors that is specific to this
        ///   object (may be empty, but not null)</param>
        /// <returns>The list of Advisors for the given object</returns>
        protected virtual IList <IAdvisor> BuildAdvisors(string targetName, IList <object> specificInterceptors)
        {
            // handle prototypes correctly
            IList <IAdvisor> commonInterceptors = ResolveInterceptorNames();

            List <object> allInterceptors = new List <object>();

            if (specificInterceptors != null)
            {
                allInterceptors.AddRange(specificInterceptors);
                if (commonInterceptors != null)
                {
                    if (applyCommonInterceptorsFirst)
                    {
                        allInterceptors.InsertRange(0, commonInterceptors.Cast <object>());
                    }
                    else
                    {
                        allInterceptors.AddRange(commonInterceptors.Cast <object>());
                    }
                }
            }
            if (logger.IsInfoEnabled)
            {
                int nrOfCommonInterceptors   = commonInterceptors != null ? commonInterceptors.Count : 0;
                int nrOfSpecificInterceptors = specificInterceptors != null ? specificInterceptors.Count : 0;
                logger.Info(string.Format("Creating implicit proxy for object '{0}' with {1} common interceptors and {2} specific interceptors", targetName, nrOfCommonInterceptors, nrOfSpecificInterceptors));
            }


            List <IAdvisor> advisors = new List <IAdvisor>(allInterceptors.Count);

            for (int i = 0; i < allInterceptors.Count; i++)
            {
                advisors.Add(advisorAdapterRegistry.Wrap(allInterceptors[i]));
            }
            return(advisors);
        }
コード例 #3
0
        /// <summary>
        /// Determines the advisors for the given object, including the specific interceptors
        /// as well as the common interceptor, all adapted to the Advisor interface.
        /// </summary>
        /// <param name="targetName">The name of the object.</param>
        /// <param name="specificInterceptors">The set of interceptors that is specific to this
        /// object (may be empty, but not null)</param>
        /// <returns>The list of Advisors for the given object</returns>
        protected virtual IAdvisor[] BuildAdvisors(string targetName, object[] specificInterceptors)
        {
            // handle prototypes correctly
            IAdvisor[] commonInterceptors = ResolveInterceptorNames();

            ArrayList allInterceptors = new ArrayList();

            if (specificInterceptors != null)
            {
                allInterceptors.AddRange(specificInterceptors);
                if (commonInterceptors != null)
                {
                    if (applyCommonInterceptorsFirst)
                    {
                        allInterceptors.InsertRange(0, commonInterceptors);
                    }
                    else
                    {
                        allInterceptors.AddRange(commonInterceptors);
                    }
                }
            }
            if (logger.IsInfoEnabled)
            {
                int nrOfCommonInterceptors   = commonInterceptors != null ? commonInterceptors.Length : 0;
                int nrOfSpecificInterceptors = specificInterceptors != null ? specificInterceptors.Length : 0;
                logger.Info(string.Format("Creating implicit proxy for object '{0}' with {1} common interceptors and {2} specific interceptors", targetName, nrOfCommonInterceptors, nrOfSpecificInterceptors));
            }


            IAdvisor[] advisors = new IAdvisor[allInterceptors.Count];
            for (int i = 0; i < allInterceptors.Count; i++)
            {
                advisors[i] = advisorAdapterRegistry.Wrap(allInterceptors[i]);
            }
            return(advisors);
        }