/// <summary>
        /// Returns the target object that proxy methods will be delegated to.
        /// </summary>
        /// <returns>The target object.</returns>
        public object GetTarget()
        {
            if (this.target == null)
            {
                this.target = targetSource.GetTarget();
            }

            return(this.target);
        }
Beispiel #2
0
        /// <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>
		/// 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 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();
        }
Beispiel #5
0
 /// <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();
 }