/// <summary> /// Refreshes target object for prototype instances. /// </summary> private ITargetSource FreshTargetSource() { if (StringUtils.IsNullOrEmpty(this.targetName)) { if (logger.IsDebugEnabled) { logger.Debug("Not Refreshing TargetSource: No target name specified"); } return(this.TargetSource); } AssertUtils.ArgumentNotNull(this.objectFactory, "ObjectFactory"); if (logger.IsDebugEnabled) { logger.Debug("Refreshing TargetSource with name '" + this.targetName + "'"); } object target = this.objectFactory.GetObject(this.targetName); ITargetSource targetSource = NamedObjectToTargetSource(target); return(targetSource); }
/// <summary> /// Creates a new instance of the /// <see cref="Spring.Aop.Framework.StaticTargetSourceWrapper"/> /// class. /// </summary> /// <param name="targetSource"> /// The target object that proxy methods will be delegated to. /// </param> /// <exception cref="System.ArgumentNullException"> /// If the supplied <paramref name="targetSource"/> is /// <see langword="null"/>. /// </exception> internal StaticTargetSourceWrapper(ITargetSource targetSource) { AssertUtils.ArgumentNotNull(targetSource, "targetSource"); this.target = targetSource.GetTarget(); }
/// <summary> /// Create a new instance of the <see cref="ProxyFactory"/> class for the specified /// <see cref="ITargetSource"/> making the proxy implement the specified interface. /// </summary> /// <remarks></remarks> /// <param name="proxyInterface">The interface that the proxy should implement.</param> /// <param name="targetSource">The target source that the proxy should invoek.</param> public ProxyFactory(Type proxyInterface, ITargetSource targetSource) { AddInterface(proxyInterface); TargetSource = targetSource; }
protected override object[] GetAdvicesAndAdvisorsForObject(Type targetType, string targetName, ITargetSource customTargetSource) { if (typeof(IFactoryObject).IsAssignableFrom(targetType)) { return(DO_NOT_PROXY); } return(new object[] { NopInterceptor }); }
protected override IList <object> GetAdvicesAndAdvisorsForObject(Type targetType, string targetName, ITargetSource customTargetSource) { _logger.Trace("GetAdvicesAndAdvisorsForObject begin"); IList <object> advices = base.GetAdvicesAndAdvisorsForObject(targetType, targetName, customTargetSource); _logger.Trace("GetAdvicesAndAdvisorsForObject end"); return(advices); }
protected override object[] GetAdvicesAndAdvisorsForObject(Type targetType, string targetName, ITargetSource customTargetSource) { if (typeof(IFactoryObject).IsAssignableFrom(targetType)) { return DO_NOT_PROXY; } return new object[] { NopInterceptor }; }
/// <summary> /// Copies the configuration from the supplied other /// <see cref="Spring.Aop.Framework.AdvisedSupport"/> into this instance. /// </summary> /// <remarks> /// <p> /// Useful when this instance has been created using the no-argument /// constructor, and needs to get all of its confiuration data from /// another <see cref="Spring.Aop.Framework.AdvisedSupport"/> (most /// usually to have an independant copy of said configuration data). /// </p> /// </remarks> /// <param name="other"> /// The <see cref="Spring.Aop.Framework.AdvisedSupport"/> instance /// containing the configiration data that is to be copied into this /// instance. /// </param> /// <param name="targetSource">the new target source</param> /// <param name="advisors">the advisors for the chain</param> /// <param name="introductions">the introductions for the chain</param> protected internal virtual void CopyConfigurationFrom(AdvisedSupport other, ITargetSource targetSource, IList advisors, IList introductions) { CopyFrom(other); this.AdvisorChainFactory = other.advisorChainFactory; this.m_targetSource = targetSource; // this.cachedProxyType = other.cachedProxyType; // this.cachedProxyConstructor = other.cachedProxyConstructor; this.Interfaces = (Type[]) CollectionUtils.ToArray(other.Interfaces, typeof(Type)); foreach (Type intf in other.interfaceMap.Keys) { this.interfaceMap[intf] = other.interfaceMap[intf]; } this._advisors = new ArrayList(); foreach (IAdvisor advisor in advisors) { AssertUtils.ArgumentNotNull(advisor, "Advisor must not be null"); AddAdvisor(advisor); } this._introductions = new ArrayList(); foreach (IIntroductionAdvisor advisor in introductions) { // TODO (EE): implement // ValidateIntroductionAdvisor((IIntroductionAdvisor) advisor); AssertUtils.ArgumentNotNull(advisor, "IntroductionAdvisor must not be null"); AddIntroduction(advisor); } UpdateAdvisorsArray(); AdviceChanged(); }
/// <summary> /// Return whether the given object is to be proxied, what additional /// advices (e.g. AOP Alliance interceptors) and advisors to apply. /// </summary> /// <remarks> /// <p>The previous targetName of this method was "GetInterceptorAndAdvisorForObject". /// It has been renamed in the course of general terminology clarification /// in Spring 1.1. An AOP Alliance Interceptor is just a special form of /// Advice, so the generic Advice term is preferred now.</p> /// <p>The third parameter, customTargetSource, is new in Spring 1.1; /// add it to existing implementations of this method.</p> /// </remarks> /// <param name="targetType">the new object instance</param> /// <param name="targetName">the name of the object</param> /// <param name="customTargetSource">targetSource returned by TargetSource property: /// may be ignored. Will be null unless a custom target source is in use.</param> /// <returns>an array of additional interceptors for the particular object; /// or an empty array if no additional interceptors but just the common ones; /// or null if no proxy at all, not even with the common interceptors.</returns> protected abstract object[] GetAdvicesAndAdvisorsForObject(Type targetType, string targetName, ITargetSource customTargetSource);
/// <summary> /// Return whether the given object is to be proxied, what additional /// advices (e.g. AOP Alliance interceptors) and advisors to apply. /// </summary> /// <remarks> /// <p>The previous targetName of this method was "GetInterceptorAndAdvisorForObject". /// It has been renamed in the course of general terminology clarification /// in Spring 1.1. An AOP Alliance Interceptor is just a special form of /// Advice, so the generic Advice term is preferred now.</p> /// <p>The third parameter, customTargetSource, is new in Spring 1.1; /// add it to existing implementations of this method.</p> /// </remarks> /// <param name="targetType">the type of the target object</param> /// <param name="targetName">the name of the target object</param> /// <param name="customTargetSource">targetSource returned by TargetSource property: /// may be ignored. Will be null unless a custom target source is in use.</param> /// <returns> /// an array of additional interceptors for the particular object; /// or an empty array if no additional interceptors but just the common ones; /// or null if no proxy at all, not even with the common interceptors. /// </returns> protected override object[] GetAdvicesAndAdvisorsForObject(Type targetType, string targetName, ITargetSource customTargetSource) { IList advisors = FindEligibleAdvisors(targetType, targetName); if (advisors.Count == 0) { return DO_NOT_PROXY; } return (object[]) CollectionUtils.ToArray(advisors, typeof (object)); }
/// <summary> /// Checks, if the given <paramref name="targetSource"/> holds a proxy generated by this factory. /// </summary> /// <returns></returns> protected virtual bool IsAopProxyType(ITargetSource targetSource) { return(AopUtils.IsAopProxyType(targetSource.TargetType)); }
public void ActiveTarget(TargetAction action, ITargetSource source = null) { _source = source; _action = action; OnActiveTarget?.Invoke(_action, _source); }
/// <summary> /// Creates a new instance of the /// <see cref="Spring.Aop.Framework.DynamicTargetSourceWrapper"/> /// class. /// </summary> /// <param name="targetSource"> /// The target object that proxy methods will be delegated to. /// </param> /// <exception cref="System.ArgumentNullException"> /// If the supplied <paramref name="targetSource"/> is /// <see langword="null"/>. /// </exception> internal DynamicTargetSourceWrapper(ITargetSource targetSource) { AssertUtils.ArgumentNotNull(targetSource, "targetSource"); this.targetSource = targetSource; }
/// <summary> /// Return whether the given object is to be proxied, what additional /// advices (e.g. AOP Alliance interceptors) and advisors to apply. /// </summary> /// <remarks> /// <p>The previous targetName of this method was "GetInterceptorAndAdvisorForObject". /// It has been renamed in the course of general terminology clarification /// in Spring 1.1. An AOP Alliance Interceptor is just a special form of /// Advice, so the generic Advice term is preferred now.</p> /// <p>The third parameter, customTargetSource, is new in Spring 1.1; /// add it to existing implementations of this method.</p> /// </remarks> /// <param name="targetType">the type of the target object</param> /// <param name="targetName">the name of the target object</param> /// <param name="customTargetSource">targetSource returned by TargetSource property: /// may be ignored. Will be null unless a custom target source is in use.</param> /// <returns> /// an array of additional interceptors for the particular object; /// or an empty array if no additional interceptors but just the common ones; /// or null if no proxy at all, not even with the common interceptors. /// </returns> protected override object[] GetAdvicesAndAdvisorsForObject(Type targetType, string targetName, ITargetSource customTargetSource) { IList advisors = FindEligibleAdvisors(targetType, targetName); if (advisors.Count == 0) { return(DO_NOT_PROXY); } return((object[])CollectionUtils.ToArray(advisors, typeof(object))); }
protected override IList<object> GetAdvicesAndAdvisorsForObject(Type targetType, string targetName, ITargetSource customTargetSource) { _logger.Trace("GetAdvicesAndAdvisorsForObject begin"); IList<object> advices = base.GetAdvicesAndAdvisorsForObject(targetType, targetName, customTargetSource); _logger.Trace("GetAdvicesAndAdvisorsForObject end"); return advices; }
/// <summary> /// Return whether the given object is to be proxied, what additional /// advices (e.g. AOP Alliance interceptors) and advisors to apply. /// </summary> /// <remarks> /// <p>The previous targetName of this method was "GetInterceptorAndAdvisorForObject". /// It has been renamed in the course of general terminology clarification /// in Spring 1.1. An AOP Alliance Interceptor is just a special form of /// Advice, so the generic Advice term is preferred now.</p> /// <p>The third parameter, customTargetSource, is new in Spring 1.1; /// add it to existing implementations of this method.</p> /// </remarks> /// <param name="targetType">the type of the target object</param> /// <param name="targetName">the name of the target object</param> /// <param name="customTargetSource">targetSource returned by TargetSource property: /// may be ignored. Will be null unless a custom target source is in use.</param> /// <returns> /// an array of additional interceptors for the particular object; /// or an empty array if no additional interceptors but just the common ones; /// or null if no proxy at all, not even with the common interceptors. /// </returns> protected override IList <object> GetAdvicesAndAdvisorsForObject(Type targetType, string targetName, ITargetSource customTargetSource) { IList <IAdvisor> advisors = FindEligibleAdvisors(targetType, targetName); if (advisors.Count == 0) { return(DO_NOT_PROXY); } return(advisors.Cast <object>().ToArray()); }
/// <summary> /// Override to always return <see cref="AbstractAutoProxyCreator.PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS"/>. /// </summary> /// <remarks> /// Whether an object shall be proxied or not is determined by the result of <see cref="IsEligibleForProxying"/>. /// </remarks> /// <param name="targetType">ingored</param> /// <param name="targetName">ignored</param> /// <param name="customTargetSource">ignored</param> /// <returns> /// Always <see cref="AbstractAutoProxyCreator.PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS"/> to indicate, that the object shall be proxied. /// </returns> /// <seealso cref="AbstractAutoProxyCreator.PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS"/> protected override object[] GetAdvicesAndAdvisorsForObject( Type targetType, string targetName, ITargetSource customTargetSource ) { return PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS; }
/// <summary> /// Deserialization constructor. /// </summary> /// <param name="info">Serialization data.</param> /// <param name="context">Serialization context.</param> protected AdvisedProxy(SerializationInfo info, StreamingContext context) { m_advised = (IAdvised)info.GetValue("advised", typeof(IAdvised)); m_introductions = (IAdvice[])info.GetValue("introductions", typeof(IAdvice[])); m_targetSource = (ITargetSource)info.GetValue("targetSource", typeof(ITargetSource)); m_targetType = (Type)info.GetValue("targetType", typeof(Type)); }
/// <summary> /// Create an AOP proxy for the given object. /// </summary> /// <param name="targetType">Type of the object.</param> /// <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> /// <param name="targetSource">The target source for the proxy, already pre-configured to access the object.</param> /// <returns>The AOP Proxy for the object.</returns> protected virtual object CreateProxy(Type targetType, string targetName, object[] specificInterceptors, ITargetSource targetSource) { ProxyFactory proxyFactory = CreateProxyFactory(); // copy our properties (proxyTargetClass) inherited from ProxyConfig proxyFactory.CopyFrom(this); object target = targetSource.GetTarget(); if (!ProxyTargetType) { // Must allow for introductions; can't just set interfaces to // the target's interfaces only. Type[] targetInterfaceTypes = AopUtils.GetAllInterfacesFromType(targetType); foreach (Type interfaceType in targetInterfaceTypes) { proxyFactory.AddInterface(interfaceType); } } IAdvisor[] advisors = BuildAdvisors(targetName, specificInterceptors); foreach (IAdvisor advisor in advisors) { if (advisor is IIntroductionAdvisor) { proxyFactory.AddIntroduction((IIntroductionAdvisor)advisor); } else { proxyFactory.AddAdvisor(advisor); } } proxyFactory.TargetSource = targetSource; CustomizeProxyFactory(proxyFactory); proxyFactory.IsFrozen = freezeProxy; return(proxyFactory.GetProxy()); }
/// <summary> /// Initialization method. /// </summary> /// <param name="advised">The proxy configuration.</param> /// <param name="proxy"> /// The current <see cref="Spring.Aop.Framework.IAopProxy"/> implementation. /// </param> protected void Initialize(IAdvised advised, IAopProxy proxy) { this.m_advised = advised; this.m_targetSource = advised.TargetSource; this.m_targetType = advised.TargetSource.TargetType; // initialize introduction advice this.m_introductions = new IAdvice[advised.Introductions.Count]; for (int i = 0; i < advised.Introductions.Count; i++) { this.m_introductions[i] = advised.Introductions[i].Advice; // set target proxy on introduction instance if it implements ITargetAware if (this.m_introductions[i] is ITargetAware) { ((ITargetAware)this.m_introductions[i]).TargetProxy = proxy; } } }
/// <summary> /// Creates a new instance of the <see cref="Spring.Aop.Framework.ProxyFactory"/> /// class that proxys all of the interfaces exposed by the supplied /// <paramref name="targetSource"/>'s target. /// </summary> /// <param name="targetSource">The <see cref="ITargetSource"/> providing access to the object to proxy.</param> /// <exception cref="AopConfigException"> /// If the <paramref name="targetSource"/> is <cref lang="null"/>. /// </exception> public AdvisedSupport(ITargetSource targetSource) : this(GetInterfaces(targetSource != null ? targetSource.TargetType : null)) { TargetSource = targetSource; }
/// <summary> /// Create an AOP proxy for the given object. /// </summary> /// <param name="targetType">Type of the object.</param> /// <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> /// <param name="targetSource">The target source for the proxy, already pre-configured to access the object.</param> /// <returns>The AOP Proxy for the object.</returns> protected virtual object CreateProxy(Type targetType, string targetName, object[] specificInterceptors, ITargetSource targetSource) { ProxyFactory proxyFactory = CreateProxyFactory(); // copy our properties (proxyTargetClass) inherited from ProxyConfig proxyFactory.CopyFrom(this); object target = targetSource.GetTarget(); if (!ProxyTargetType) { // Must allow for introductions; can't just set interfaces to // the target's interfaces only. Type[] targetInterfaceTypes = AopUtils.GetAllInterfacesFromType(targetType); foreach (Type interfaceType in targetInterfaceTypes) { proxyFactory.AddInterface(interfaceType); } } IAdvisor[] advisors = BuildAdvisors(targetName, specificInterceptors); foreach (IAdvisor advisor in advisors) { if (advisor is IIntroductionAdvisor) { proxyFactory.AddIntroduction((IIntroductionAdvisor)advisor); } else { proxyFactory.AddAdvisor(advisor); } } proxyFactory.TargetSource = targetSource; CustomizeProxyFactory(proxyFactory); proxyFactory.IsFrozen = freezeProxy; return proxyFactory.GetProxy(); }
/// <summary> /// Override to always return <see cref="AbstractAutoProxyCreator.PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS"/>. /// </summary> /// <remarks> /// Whether an object shall be proxied or not is determined by the result of <see cref="IsEligibleForProxying"/>. /// </remarks> /// <param name="targetType">ingored</param> /// <param name="targetName">ignored</param> /// <param name="customTargetSource">ignored</param> /// <returns> /// Always <see cref="AbstractAutoProxyCreator.PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS"/> to indicate, that the object shall be proxied. /// </returns> /// <seealso cref="AbstractAutoProxyCreator.PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS"/> protected override object[] GetAdvicesAndAdvisorsForObject(Type targetType, string targetName, ITargetSource customTargetSource) { return(PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS); }
/// <summary> /// Return whether the given object is to be proxied, what additional /// advices (e.g. AOP Alliance interceptors) and advisors to apply. /// </summary> /// <remarks> /// <p>The previous targetName of this method was "GetInterceptorAndAdvisorForObject". /// It has been renamed in the course of general terminology clarification /// in Spring 1.1. An AOP Alliance Interceptor is just a special form of /// Advice, so the generic Advice term is preferred now.</p> /// <p>The third parameter, customTargetSource, is new in Spring 1.1; /// add it to existing implementations of this method.</p> /// </remarks> /// <param name="targetType">the type of the target object</param> /// <param name="targetName">the name of the target object</param> /// <param name="customTargetSource">targetSource returned by TargetSource property: /// may be ignored. Will be null unless a custom target source is in use.</param> /// <returns> /// an array of additional interceptors for the particular object; /// or an empty array if no additional interceptors but just the common ones; /// or null if no proxy at all, not even with the common interceptors. /// </returns> protected override IList<object> GetAdvicesAndAdvisorsForObject(Type targetType, string targetName, ITargetSource customTargetSource) { IList<IAdvisor> advisors = FindEligibleAdvisors(targetType, targetName); if (advisors.Count == 0) { return DO_NOT_PROXY; } return advisors.Cast<object>().ToArray(); }
/// <summary> /// Checks, if the given <paramref name="targetSource"/> holds a proxy generated by this factory. /// </summary> /// <returns></returns> protected virtual bool IsAopProxyType(ITargetSource targetSource) { return AopUtils.IsAopProxyType(targetSource.TargetType); }