/// <summary> Refresh named objects from the interceptor chain.
        /// We need to do this every time a new prototype instance is returned,
        /// to return distinct instances of prototype interfaces and pointcuts.
        /// </summary>
        private IList <IIntroductionAdvisor> FreshIntroductionChain()
        {
            IList <IIntroductionAdvisor> introductions      = Introductions;
            List <IIntroductionAdvisor>  freshIntroductions = new List <IIntroductionAdvisor>();

            foreach (IIntroductionAdvisor introduction in introductions)
            {
                if (introduction is PrototypePlaceholder)
                {
                    PrototypePlaceholder pa = (PrototypePlaceholder)introduction;
                    if (logger.IsDebugEnabled)
                    {
                        logger.Debug(string.Format("Refreshing introduction '{0}'", pa.ObjectName));
                    }

                    AssertUtils.ArgumentNotNull(this.objectFactory, "ObjectFactory");

                    object introductionObject = this.objectFactory.GetObject(pa.ObjectName);
                    IIntroductionAdvisor freshIntroduction = NamedObjectToIntroduction(introductionObject);
                    freshIntroductions.Add(freshIntroduction);
                }
                else
                {
                    freshIntroductions.Add(introduction);
                }
            }
            return(freshIntroductions);
        }
        /// <summary>Add the introduction to the introduction list.</summary>
        /// <remarks>
        /// If specified parameter is IIntroducionAdvisor it is added directly, otherwise it is wrapped
        /// with DefaultIntroductionAdvisor first.
        /// </remarks>
        /// <param name="introduction">introducion to add</param>
        /// <param name="name">object name from which we obtained this object in our owning object factory</param>
        private void AddIntroductionOnChainCreation(object introduction, string name)
        {
            logger.Debug(string.Format("Adding introduction with name '{0}'", name));
            IIntroductionAdvisor advisor = NamedObjectToIntroduction(introduction);

            AddIntroduction(advisor);
        }
Exemple #3
0
        public void CanApplyWithTrueIntroductionAdvisor()
        {
            IIntroductionAdvisor mockIntroAdvisor = A.Fake <IIntroductionAdvisor>();

            A.CallTo(() => mockIntroAdvisor.TypeFilter).Returns(TrueTypeFilter.True);

            Assert.IsTrue(AopUtils.CanApply(mockIntroAdvisor, typeof(TestObject), null));
        }
Exemple #4
0
        public void CanApplyWithTrueIntroductionAdvisor()
        {
            IIntroductionAdvisor mockIntroAdvisor = (IIntroductionAdvisor)mocks.CreateMock(typeof(IIntroductionAdvisor));

            Expect.Call(mockIntroAdvisor.TypeFilter).Return(TrueTypeFilter.True);
            mocks.ReplayAll();

            Assert.IsTrue(AopUtils.CanApply(mockIntroAdvisor, typeof(TestObject), null));
            mocks.VerifyAll();
        }
Exemple #5
0
 void IAdvised.AddIntroduction(IIntroductionAdvisor advisor)
 {
     m_advised.AddIntroduction(advisor);
 }
        /// <summary>
        /// Replaces the <see cref="Spring.Aop.IIntroductionAdvisor"/> that
        /// exists at the supplied <paramref name="index"/> in the list of
        /// <see cref="Spring.Aop.Framework.AdvisedSupport.Introductions"/>
        /// with the supplied <paramref name="introduction"/>.
        /// </summary>
        /// <param name="index">
        /// The index of the <see cref="Spring.Aop.IIntroductionAdvisor"/>
        /// in the list of
        /// <see cref="Spring.Aop.Framework.AdvisedSupport.Introductions"/>
        /// that is to be replaced.
        /// </param>
        /// <param name="introduction">
        /// The new (replacement) <see cref="Spring.Aop.IIntroductionAdvisor"/>.
        /// </param>
        /// <exception cref="AopConfigException">
        /// If the supplied <paramref name="index"/> is out of range.
        /// </exception>
        public virtual void ReplaceIntroduction(int index, IIntroductionAdvisor introduction)
        {
            lock (this.SyncRoot)
            {
                if (index < 0 || index >= _introductions.Count)
                {
                    throw new AopConfigException(
                        "Introduction index " + index + " is out of bounds:" +
                        " there are currently " + _introductions.Count +
                        " introductions.");
                }

                _introductions[index] = introduction;
            }
        }
 /// <summary>
 /// Adds the supplied <paramref name="introductionAdvisor"/> to the list
 /// of <see cref="Spring.Aop.Framework.AdvisedSupport.Introductions"/>.
 /// </summary>
 /// <param name="introductionAdvisor">
 /// The <see cref="Spring.Aop.IIntroductionAdvisor"/> to add.
 /// </param>
 /// <exception cref="AopConfigException">
 /// If this proxy configuration is frozen and the
 /// <paramref name="introductionAdvisor"/> cannot be added.
 /// </exception>
 public virtual void AddIntroduction(IIntroductionAdvisor introductionAdvisor)
 {
     Type introductionType = introductionAdvisor.Advice.GetType();
     lock (this.SyncRoot)
     {
         int pos = this._introductions.Count;
         for (int i = 0; i < pos; i++)
         {
             IIntroductionAdvisor introduction
                 = (IIntroductionAdvisor)this._introductions[i];
             if (introduction.Advice.GetType() == introductionType)
             {
                 pos = i;
             }
         }
         AddIntroduction(pos, introductionAdvisor);
     }
 }
 void IAdvised.AddIntroduction(IIntroductionAdvisor advisor)
 {
     m_advised.AddIntroduction(advisor);
 }
Exemple #9
0
 bool IAdvised.RemoveIntroduction(IIntroductionAdvisor advisor)
 {
     return(m_advised.RemoveIntroduction(advisor));
 }
 /// <summary> 
 /// Return the index (0 based) of the supplied
 /// <see cref="Spring.Aop.IIntroductionAdvisor"/> in the introductions
 /// for this proxy.
 /// </summary>
 /// <param name="advisor">
 /// The <see cref="Spring.Aop.IIntroductionAdvisor"/> to search for.
 /// </param>
 /// <returns>
 /// The zero (0) based index of this advisor, or -1 if the
 /// supplied <paramref name="advisor"/> is not an introduction advisor
 /// for this proxy.
 /// </returns>
 public virtual int IndexOf(IIntroductionAdvisor advisor)
 {
     lock (this.SyncRoot)
     {
         return IndexOfInternal(advisor);
     }
 }
 /// <summary> 
 /// Return the index (0 based) of the supplied
 /// <see cref="Spring.Aop.IIntroductionAdvisor"/> in the introductions
 /// for this proxy.
 /// </summary>
 /// <param name="advisor">
 /// The <see cref="Spring.Aop.IIntroductionAdvisor"/> to search for.
 /// </param>
 /// <returns>
 /// The zero (0) based index of this advisor, or -1 if the
 /// supplied <paramref name="advisor"/> is not an introduction advisor
 /// for this proxy.
 /// </returns>
 /// <remarks>
 /// Access is not synchronized
 /// </remarks>
 private int IndexOfInternal(IIntroductionAdvisor advisor)
 {
     return this._introductions.IndexOf(advisor);
 }
 void IAdvised.ReplaceIntroduction(int index, IIntroductionAdvisor advisor)
 {
     m_advised.ReplaceIntroduction(index, advisor);
 }
 bool IAdvised.RemoveIntroduction(IIntroductionAdvisor advisor)
 {
     return m_advised.RemoveIntroduction(advisor);
 }
 int IAdvised.IndexOf(IIntroductionAdvisor advisor)
 {
     return m_advised.IndexOf(advisor);
 }
 void IAdvised.AddIntroduction(int pos, IIntroductionAdvisor advisor)
 {
     m_advised.AddIntroduction(pos, advisor);
 }
Exemple #16
0
 void IAdvised.AddIntroduction(int pos, IIntroductionAdvisor advisor)
 {
     m_advised.AddIntroduction(pos, advisor);
 }
Exemple #17
0
 int IAdvised.IndexOf(IIntroductionAdvisor advisor)
 {
     return(m_advised.IndexOf(advisor));
 }
 /// <summary>
 /// Removes the supplied <paramref name="introduction"/> from the list
 /// of <see cref="Spring.Aop.Framework.AdvisedSupport.Introductions"/>.
 /// </summary>
 /// <param name="introduction">
 /// The <see cref="Spring.Aop.IIntroductionAdvisor"/> to remove.
 /// </param>
 /// <returns>
 /// <see langword="true"/> if the supplied <paramref name="introduction"/> was
 /// found in the list of <see cref="Spring.Aop.Framework.AdvisedSupport.Introductions"/>
 /// and successfully removed.
 /// </returns>
 /// <exception cref="AopConfigException">
 /// If this proxy configuration is frozen and the
 /// <see cref="Spring.Aop.IIntroductionAdvisor"/> cannot be removed.
 /// </exception>
 public bool RemoveIntroduction(IIntroductionAdvisor introduction)
 {
     DieIfFrozen("Cannot remove introduction: config is frozen");
     bool wasRemoved = false;
     if (introduction != null)
     {
         lock (this.SyncRoot)
         {
             int index = IndexOf(introduction);
             if (index == -1)
             {
                 wasRemoved = false;
             }
             else
             {
                 RemoveIntroduction(index);
                 wasRemoved = true;
             }
         }
     }
     return wasRemoved;
 }
Exemple #19
0
 void IAdvised.ReplaceIntroduction(int index, IIntroductionAdvisor advisor)
 {
     m_advised.ReplaceIntroduction(index, advisor);
 }
        /// <summary>
        /// Adds the supplied <paramref name="introductionAdvisor"/> to the list
        /// of <see cref="Spring.Aop.Framework.AdvisedSupport.Introductions"/>.
        /// </summary>
        /// <param name="index">
        /// The index in the <see cref="Spring.Aop.Framework.AdvisedSupport.Introductions"/>
        /// list at which the supplied <paramref name="introductionAdvisor"/>
        /// is to be inserted.
        /// </param>
        /// <param name="introductionAdvisor">
        /// The <see cref="Spring.Aop.IIntroductionAdvisor"/> to add.
        /// </param>
        /// <exception cref="AopConfigException">
        /// If this proxy configuration is frozen and the
        /// <paramref name="introductionAdvisor"/> cannot be added.
        /// </exception>
        public virtual void AddIntroduction(int index, IIntroductionAdvisor introductionAdvisor)
        {
            DieIfFrozen("Cannot add introduction: config is frozen");
            introductionAdvisor.ValidateInterfaces();

            lock (this.SyncRoot)
            {
                if (index < this._introductions.Count)
                {
                    this._introductions.RemoveAt(index);
                }
                this._introductions.Insert(index, introductionAdvisor);

                int intfCount = this.interfaceMap.Count;
                // If the advisor passed validation we can make the change
                foreach (Type intf in introductionAdvisor.Interfaces)
                {
                    this.interfaceMap[intf] = introductionAdvisor;
                }
                if (this.interfaceMap.Count != intfCount)
                {
                    InterfacesChanged();
                }
            }
        }