コード例 #1
0
 /// <summary>
 /// Returns an <see cref="AopAlliance.Intercept.IInterceptor"/> to
 /// allow the use of the supplied <paramref name="advisor"/> in an
 /// interception-based framework.
 /// </summary>
 /// <param name="advisor">The advisor to find an interceptor for.</param>
 /// <returns>
 /// An interceptor to expose this advisor's behaviour.
 /// </returns>
 /// <exception cref="UnknownAdviceTypeException">
 /// If the advisor type is not understood by any registered
 /// <see cref="Spring.Aop.Framework.Adapter.IAdvisorAdapter"/>.
 /// </exception>
 public virtual IInterceptor GetInterceptor(IAdvisor advisor)
 {
     IAdvice advice = advisor.Advice;
     if (advice is IInterceptor)
     {
         return (IInterceptor) advice;
     }
     foreach (IAdvisorAdapter adapter in this.adapters)
     {
         if (adapter.SupportsAdvice(advice))
         {
             return adapter.GetInterceptor(advisor);
         }
     }
     throw new UnknownAdviceTypeException(advice);
 }
コード例 #2
0
 /// <summary>
 /// Wraps the supplied <paramref name="advisor"/>'s
 /// <see cref="Spring.Aop.IAdvisor.Advice"/> within a
 /// <see cref="Spring.Aop.Framework.Adapter.ThrowsAdviceInterceptor"/>
 /// instance.
 /// </summary>
 /// <param name="advisor">
 /// The advisor exposing the <see cref="AopAlliance.Aop.IAdvice"/> that
 /// is to be wrapped.
 /// </param>
 /// <returns>
 /// The supplied <paramref name="advisor"/>'s
 /// <see cref="Spring.Aop.IAdvisor.Advice"/> wrapped within a
 /// <see cref="Spring.Aop.Framework.Adapter.ThrowsAdviceInterceptor"/>
 /// instance.
 /// </returns>
 public virtual IInterceptor GetInterceptor(IAdvisor advisor)
 {
     return new ThrowsAdviceInterceptor(advisor.Advice);
 }
コード例 #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;
        }
コード例 #4
0
 public void AddAdvisor(IAdvisor <Person> advisor)
 {
     Advisors.Add(advisor);
 }
コード例 #5
0
		public IInterceptor GetInterceptor(IAdvisor advisor)
		{
			ISimpleBeforeAdvice advice = (ISimpleBeforeAdvice) advisor.Advice;
			return new SimpleBeforeAdviceInterceptor(advice) ;
		}
コード例 #6
0
 /// <summary>
 /// Adds the supplied <paramref name="advisor"/> to the list
 /// of <see cref="Spring.Aop.Framework.AdvisedSupport.Advisors"/>.
 /// </summary>
 /// <param name="advisor">
 /// The <see cref="Spring.Aop.IAdvisor"/> to add.
 /// </param>
 /// <exception cref="AopConfigException">
 /// If this proxy configuration is frozen and the
 /// <paramref name="advisor"/> cannot be added.
 /// </exception>
 public virtual void AddAdvisor(IAdvisor advisor)
 {
     AddAdvisor(this._advisors.Count, advisor);
 }
コード例 #7
0
 /// <summary>
 /// Removes the supplied <paramref name="advisor"/> the list of advisors
 /// for this proxy.
 /// </summary>
 /// <param name="advisor">The advisor to remove.</param>
 /// <returns>
 /// <see langword="true"/> if advisor was found in the list of
 /// <see cref="Spring.Aop.Framework.AdvisedSupport.Advisors"/> for this
 /// proxy and was successfully removed; <see langword="false"/> if not
 /// or if the supplied <paramref name="advisor"/> is <cref lang="null"/>.
 /// </returns>
 /// <exception cref="AopConfigException">
 /// If this proxy configuration is frozen and the
 /// <paramref name="advisor"/> cannot be removed.
 /// </exception>
 public bool RemoveAdvisor(IAdvisor advisor)
 {
     DieIfFrozen("Cannot remove advisor: config is frozen");
     bool wasRemoved = false;
     if (advisor != null)
     {
         lock (this.SyncRoot)
         {
             int index = IndexOf(advisor);
             if (index == -1)
             {
                 wasRemoved = false;
             }
             else
             {
                 RemoveAdvisorInternal(index);
                 wasRemoved = true;
             }
         }
     }
     return wasRemoved;
 }
コード例 #8
0
 /// <summary>
 /// Bring the advisors array up to date with the list.
 /// </summary>
 private void UpdateAdvisorsArray()
 {
     IAdvisor[] advisorsArray = new IAdvisor[this._advisors.Count];
     this._advisors.CopyTo(advisorsArray, 0);
     this._advisorsArray = advisorsArray;
 }
 void IAdvised.AddAdvisor(IAdvisor advisor)
 {
     m_advised.AddAdvisor(advisor);
 }
コード例 #10
0
 public void AddAdvisor(IAdvisor advise, string key)
 {
     advisorsPool.Add(key, advise);
 }
コード例 #11
0
ファイル: AopUtils.cs プロジェクト: tomcarter/spring-net
 /// <summary> 
 /// Can the supplied <paramref name="advisor"/> apply at all on the
 /// supplied <paramref name="targetType"/>?
 /// </summary>
 /// <remarks>
 /// <p>
 /// This is an important test as it can be used to optimize out an
 /// advisor for a class.
 /// </p>
 /// </remarks>
 /// <param name="advisor">The advisor to check.</param>
 /// <param name="targetType">The class being tested.</param>
 /// <param name="proxyInterfaces">
 /// The interfaces being proxied. If <see langword="null"/>, all
 /// methods on a class may be proxied.
 /// </param>
 /// <param name="hasIntroductions">whether or not the advisor chain for the target object includes any introductions.</param>
 /// <returns>
 /// <see langword="true"/> if the advisor can apply on any method.
 /// </returns>
 public static bool CanApply(IAdvisor advisor, Type targetType, Type[] proxyInterfaces, bool hasIntroductions)
 {
     if (advisor is IIntroductionAdvisor)
     {
         return ((IIntroductionAdvisor)advisor).TypeFilter.Matches(targetType);
     }
     else if (advisor is IPointcutAdvisor)
     {
         IPointcutAdvisor pca = (IPointcutAdvisor)advisor;
         return CanApply(pca.Pointcut, targetType, proxyInterfaces, hasIntroductions);
     }
     // no pointcut specified so assume it applies...
     return true;
 }
コード例 #12
0
ファイル: AopUtils.cs プロジェクト: tomcarter/spring-net
 /// <summary> 
 /// Can the supplied <paramref name="advisor"/> apply at all on the
 /// supplied <paramref name="targetType"/>?
 /// </summary>
 /// <remarks>
 /// <p>
 /// This is an important test as it can be used to optimize out an
 /// advisor for a class.
 /// </p>
 /// </remarks>
 /// <param name="advisor">The advisor to check.</param>
 /// <param name="targetType">The class being tested.</param>
 /// <param name="proxyInterfaces">
 /// The interfaces being proxied. If <see langword="null"/>, all
 /// methods on a class may be proxied.
 /// </param>
 /// <returns>
 /// <see langword="true"/> if the advisor can apply on any method.
 /// </returns>
 public static bool CanApply(IAdvisor advisor, Type targetType, Type[] proxyInterfaces)
 {
     return CanApply(advisor, targetType, proxyInterfaces, false);
 }
コード例 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DynamicProxyInterceptor"/> class.
 /// </summary>
 /// <param name="advisors"></param>
 public DynamicProxyInterceptor(IAdvisor[] advisors)
 {
     this.advisors = advisors;
 }
コード例 #14
0
 /// <summary>
 /// Wraps the supplied <paramref name="advisor"/>'s
 /// <see cref="Spring.Aop.IAdvisor.Advice"/> within a
 /// <see cref="Spring.Aop.Framework.Adapter.MethodBeforeAdviceInterceptor"/>
 /// instance.
 /// </summary>
 /// <param name="advisor">
 /// The advisor exposing the <see cref="AopAlliance.Aop.IAdvice"/> that
 /// is to be wrapped.
 /// </param>
 /// <returns>
 /// The supplied <paramref name="advisor"/>'s
 /// <see cref="Spring.Aop.IAdvisor.Advice"/> wrapped within a
 /// <see cref="Spring.Aop.Framework.Adapter.MethodBeforeAdviceInterceptor"/>
 /// instance.
 /// </returns>
 public virtual IInterceptor GetInterceptor(IAdvisor advisor)
 {
     IMethodBeforeAdvice advice = (IMethodBeforeAdvice) advisor.Advice;
     return new MethodBeforeAdviceInterceptor(advice);
 }
コード例 #15
0
 /// <summary>
 /// Wraps the supplied <paramref name="advisor"/>'s
 /// <see cref="Spring.Aop.IAdvisor.Advice"/> within a
 /// <see cref="Spring.Aop.Framework.Adapter.AfterReturningAdviceInterceptor"/>
 /// instance.
 /// </summary>
 /// <param name="advisor">
 /// The advisor exposing the <see cref="AopAlliance.Aop.IAdvice"/> that
 /// is to be wrapped.
 /// </param>
 /// <returns>
 /// The supplied <paramref name="advisor"/>'s
 /// <see cref="Spring.Aop.IAdvisor.Advice"/> wrapped within a
 /// <see cref="Spring.Aop.Framework.Adapter.AfterReturningAdviceInterceptor"/>
 /// instance.
 /// </returns>
 public virtual IInterceptor GetInterceptor(IAdvisor advisor)
 {
     IAfterReturningAdvice advice = (IAfterReturningAdvice) advisor.Advice;
     return new AfterReturningAdviceInterceptor(advice);
 }
コード例 #16
0
 /// <summary> 
 /// Return the index (0 based) of the supplied
 /// <see cref="Spring.Aop.IAdvisor"/> in the interceptor
 /// (advice) chain for this proxy.
 /// </summary>
 /// <param name="advisor">
 /// The <see cref="Spring.Aop.IAdvisor"/> to search for.
 /// </param>
 /// <returns>
 /// The zero (0) based index of this advisor, or -1 if the
 /// supplied <paramref name="advisor"/> is not an advisor for this
 /// proxy.
 /// </returns>
 /// <remarks>
 /// Access is not synchronized.
 /// </remarks>
 private int IndexOfInternal(IAdvisor advisor)
 {
     return this._advisors != null ? this._advisors.IndexOf(advisor) : -1;
 }
 void IAdvised.AddAdvisor(int pos, IAdvisor advisor)
 {
     m_advised.AddAdvisor(pos, advisor);
 }
コード例 #18
0
 /// <summary> 
 /// Return the index (0 based) of the supplied
 /// <see cref="Spring.Aop.IAdvisor"/> in the interceptor
 /// (advice) chain for this proxy.
 /// </summary>
 /// <param name="advisor">
 /// The <see cref="Spring.Aop.IAdvisor"/> to search for.
 /// </param>
 /// <returns>
 /// The zero (0) based index of this advisor, or -1 if the
 /// supplied <paramref name="advisor"/> is not an advisor for this
 /// proxy.
 /// </returns>
 public virtual int IndexOf(IAdvisor advisor)
 {
     lock (this.SyncRoot)
     {
         return IndexOfInternal(advisor);
     }
 }
 int IAdvised.IndexOf(IAdvisor advisor)
 {
     return m_advised.IndexOf(advisor);
 }
コード例 #20
0
        /// <summary>
        /// Adds the supplied <paramref name="advisor"/> to the list
        /// of <see cref="Spring.Aop.Framework.AdvisedSupport.Advisors"/>.
        /// </summary>
        /// <param name="index">
        /// The index in the <see cref="Spring.Aop.Framework.AdvisedSupport.Advisors"/>
        /// list at which the supplied <paramref name="advisor"/>
        /// is to be inserted. If -1, appends to the end of the list.
        /// </param>
        /// <param name="advisor">
        /// The <see cref="Spring.Aop.IIntroductionAdvisor"/> to add.
        /// </param>
        /// <exception cref="AopConfigException">
        /// If this proxy configuration is frozen and the
        /// <paramref name="advisor"/> cannot be added.
        /// </exception>
        public virtual void AddAdvisor(int index, IAdvisor advisor)
        {
            DieIfFrozen("Cannot add advisor: config is frozen");
            lock (this.SyncRoot)
            {
                // advisor already in list (SPRNET-846)
                if (_advisors.Contains(advisor)) return;

                if (index == -1)
                {
                    this._advisors.Add(advisor);
                }
                else
                {
                    this._advisors.Insert(index, advisor);
                }
                UpdateAdvisorsArray();
                AdviceChanged();
            }
        }
 bool IAdvised.RemoveAdvisor(IAdvisor advisor)
 {
     return m_advised.RemoveAdvisor(advisor);
 }
コード例 #22
0
 /// <summary> 
 /// Replaces the <paramref name="oldAdvisor"/> with the
 /// <paramref name="newAdvisor"/>.
 /// </summary>
 /// <param name="oldAdvisor">
 /// The original (old) advisor to be replaced.
 /// </param>
 /// <param name="newAdvisor">
 /// The new advisor to replace the <paramref name="oldAdvisor"/> with.
 /// </param>
 /// <returns>
 /// <see langword="true"/> if the <paramref name="oldAdvisor"/> was
 /// replaced; if the <paramref name="oldAdvisor"/> was not found in the
 /// advisors collection (or the <paramref name="newAdvisor"/> is
 /// <see lang="null"/>, this method returns <see langword="false"/>
 /// and (effectively) does nothing.
 /// </returns>
 /// <exception cref="AopConfigException">
 /// If this proxy configuration is frozen and the
 /// <paramref name="oldAdvisor"/> cannot be replaced.
 /// </exception>
 /// <seealso cref="Spring.Aop.Framework.ProxyConfig.IsFrozen"/>
 public bool ReplaceAdvisor(IAdvisor oldAdvisor, IAdvisor newAdvisor)
 {
     DieIfFrozen("Cannot replace advisor: config is frozen.");
     lock (this.SyncRoot)
     {
         int index = IndexOf(oldAdvisor);
         if (index == -1 || newAdvisor == null)
         {
             return false;
         }
         RemoveAdvisor(index);
         AddAdvisor(index, newAdvisor);
     }
     return true;
 }
 bool IAdvised.ReplaceAdvisor(IAdvisor a, IAdvisor b)
 {
     return m_advised.ReplaceAdvisor(a, b);
 }
コード例 #24
0
        /// <summary>
        /// Wraps the supplied <paramref name="advisor"/>'s
        /// <see cref="Spring.Aop.IAdvisor.Advice"/> within a
        /// <see cref="Spring.Aop.Framework.Adapter.AfterReturningAdviceInterceptor"/>
        /// instance.
        /// </summary>
        /// <param name="advisor">
        /// The advisor exposing the <see cref="AopAlliance.Aop.IAdvice"/> that
        /// is to be wrapped.
        /// </param>
        /// <returns>
        /// The supplied <paramref name="advisor"/>'s
        /// <see cref="Spring.Aop.IAdvisor.Advice"/> wrapped within a
        /// <see cref="Spring.Aop.Framework.Adapter.AfterReturningAdviceInterceptor"/>
        /// instance.
        /// </returns>
        public virtual IInterceptor GetInterceptor(IAdvisor advisor)
        {
            IAfterReturningAdvice advice = (IAfterReturningAdvice)advisor.Advice;

            return(new AfterReturningAdviceInterceptor(advice));
        }
コード例 #25
0
ファイル: AopUtilsTests.cs プロジェクト: swalters/spring-net
        public void CanApplyWithAdvisorYieldsTrueIfAdvisorIsNotKnownAdvisorType()
        {
            IAdvisor advisor = A.Fake <IAdvisor>();

            Assert.IsTrue(AopUtils.CanApply(advisor, typeof(TestObject), null));
        }